Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Loading...
Searching...
No Matches
Energy.hpp
Go to the documentation of this file.
1// Copyright © 2020-2024 Alexandre Coderre-Chabot
2//
3// This file is part of Physical Quantities (PhQ), a C++ library of physical quantities, physical
4// models, and units of measure for scientific computing.
5//
6// Physical Quantities is hosted at:
7// https://github.com/acodcha/phq
8//
9// Physical Quantities is licensed under the MIT License:
10// https://mit-license.org
11//
12// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
13// associated documentation files (the "Software"), to deal in the Software without restriction,
14// including without limitation the rights to use, copy, modify, merge, publish, distribute,
15// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
16// furnished to do so, subject to the following conditions:
17// - The above copyright notice and this permission notice shall be included in all copies or
18// substantial portions of the Software.
19// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
20// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
23// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25#ifndef PHQ_UNIT_ENERGY_HPP
26#define PHQ_UNIT_ENERGY_HPP
27
28#include <cstddef>
29#include <cstdint>
30#include <functional>
31#include <map>
32#include <ostream>
33#include <string_view>
34#include <unordered_map>
35
36#include "../Base.hpp"
37#include "../Dimension/ElectricCurrent.hpp"
38#include "../Dimension/Length.hpp"
39#include "../Dimension/LuminousIntensity.hpp"
40#include "../Dimension/Mass.hpp"
41#include "../Dimension/SubstanceAmount.hpp"
42#include "../Dimension/Temperature.hpp"
43#include "../Dimension/Time.hpp"
44#include "../Dimensions.hpp"
45#include "../Unit.hpp"
46#include "../UnitSystem.hpp"
47
48namespace PhQ {
49
50namespace Unit {
51
52/// \brief Energy units.
53enum class Energy : int8_t {
54 /// \brief Joule (J) energy unit.
55 Joule,
56
57 /// \brief Millijoule (mJ) energy unit.
59
60 /// \brief Microjoule (μJ) energy unit.
62
63 /// \brief Nanojoule (nJ) energy unit.
65
66 /// \brief Kilojoule (kJ) energy unit.
68
69 /// \brief Megajoule (MJ) energy unit.
71
72 /// \brief Gigajoule (GJ) energy unit.
74
75 /// \brief Watt-minute (W·min) energy unit.
77
78 /// \brief Watt-hour (W·hr) energy unit.
80
81 /// \brief Kilowatt-minute (kW·min) energy unit.
83
84 /// \brief Kilowatt-hour (kW·hr) energy unit.
86
87 /// \brief Megawatt-minute (MW·min) energy unit.
89
90 /// \brief Megawatt-hour (MW·hr) energy unit.
92
93 /// \brief Gigawatt-minute (GW·min) energy unit.
95
96 /// \brief Gigawatt-hour (GW·hr) energy unit.
98
99 /// \brief Foot-pound (ft·lbf) energy unit.
100 FootPound,
101
102 /// \brief Inch-pound (in·lbf) energy unit.
103 InchPound,
104
105 /// \brief Calorie (cal) energy unit.
106 Calorie,
107
108 /// \brief Millicalorie (mcal) energy unit.
110
111 /// \brief Microcalorie (μcal) energy unit.
113
114 /// \brief Nanocalorie (ncal) energy unit.
116
117 /// \brief Kilocalorie (kcal) energy unit.
119
120 /// \brief Megacalorie (Mcal) energy unit.
122
123 /// \brief Gigacalorie (Gcal) energy unit.
125
126 /// \brief Electronvolt (eV) energy unit.
128
129 /// \brief Millielectronvolt (meV) energy unit.
131
132 /// \brief Microelectronvolt (μeV) energy unit.
134
135 /// \brief Nanoelectronvolt (neV) energy unit.
137
138 /// \brief Kiloelectronvolt (keV) energy unit.
140
141 /// \brief Megaelectronvolt (MeV) energy unit.
143
144 /// \brief Gigaelectronvolt (GeV) energy unit.
146
147 /// \brief British thermal unit (BTU) energy unit.
149};
150
151} // namespace Unit
152
153/// \brief Standard energy unit: joule (J).
154template <>
155inline constexpr const Unit::Energy Standard<Unit::Energy>{Unit::Energy::Joule};
156
157/// \brief Physical dimension set of energy units.
158template <>
159inline constexpr const Dimensions RelatedDimensions<Unit::Energy>{
160 Dimensions{Dimension::Time{-2}, Dimension::Length{2}, Dimension::Mass{1},
161 Dimension::ElectricCurrent{0}, Dimension::Temperature{0},
162 Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
163};
164
165inline std::ostream& operator<<(std::ostream& stream, const Unit::Energy unit) {
166 stream << Abbreviation(unit);
167 return stream;
168}
169
170namespace Internal {
171
172template <>
173inline const std::map<UnitSystem, Unit::Energy> ConsistentUnits<Unit::Energy>{
178};
179
180template <>
181inline const std::map<Unit::Energy, UnitSystem> RelatedUnitSystems<Unit::Energy>{
186};
187
188// clang-format off
189
190template <>
191inline const std::map<Unit::Energy, std::string_view> Abbreviations<Unit::Energy>{
192 {Unit::Energy::Joule, "J" },
194 {Unit::Energy::Microjoule, "μJ" },
199 {Unit::Energy::WattMinute, "W·min" },
200 {Unit::Energy::WattHour, "W·hr" },
201 {Unit::Energy::KilowattMinute, "kW·min"},
202 {Unit::Energy::KilowattHour, "kW·hr" },
203 {Unit::Energy::MegawattMinute, "MW·min"},
204 {Unit::Energy::MegawattHour, "MW·hr" },
205 {Unit::Energy::GigawattMinute, "GW·min"},
206 {Unit::Energy::GigawattHour, "GW·hr" },
207 {Unit::Energy::FootPound, "ft·lbf"},
208 {Unit::Energy::InchPound, "in·lbf"},
209 {Unit::Energy::Calorie, "cal" },
211 {Unit::Energy::Microcalorie, "μcal" },
212 {Unit::Energy::Nanocalorie, "ncal" },
213 {Unit::Energy::Kilocalorie, "kcal" },
214 {Unit::Energy::Megacalorie, "Mcal" },
215 {Unit::Energy::Gigacalorie, "Gcal" },
224};
225
226template <>
227inline const std::unordered_map<std::string_view, Unit::Energy> Spellings<Unit::Energy>{
228 {"J", Unit::Energy::Joule },
229 {"N·m", Unit::Energy::Joule },
230 {"N*m", Unit::Energy::Joule },
231 {"kg·m^2/s^2", Unit::Energy::Joule },
232 {"kg*m^2/s^2", Unit::Energy::Joule },
233 {"kg·m2/s2", Unit::Energy::Joule },
234 {"kg*m2/s2", Unit::Energy::Joule },
235 {"W·s", Unit::Energy::Joule },
236 {"W*s", Unit::Energy::Joule },
238 {"μJ", Unit::Energy::Microjoule },
241 {"μN·mm", Unit::Energy::Nanojoule },
242 {"μN*mm", Unit::Energy::Nanojoule },
243 {"uN·mm", Unit::Energy::Nanojoule },
244 {"uN*mm", Unit::Energy::Nanojoule },
245 {"g·mm^2/s^2", Unit::Energy::Nanojoule },
246 {"g*mm^2/s^2", Unit::Energy::Nanojoule },
247 {"g·mm2/s2", Unit::Energy::Nanojoule },
248 {"g*mm2/s2", Unit::Energy::Nanojoule },
252 {"W·min", Unit::Energy::WattMinute },
253 {"W*min", Unit::Energy::WattMinute },
254 {"W·hr", Unit::Energy::WattHour },
255 {"W*hr", Unit::Energy::WattHour },
256 {"kW·min", Unit::Energy::KilowattMinute },
257 {"kW*min", Unit::Energy::KilowattMinute },
258 {"kW·hr", Unit::Energy::KilowattHour },
259 {"kW*hr", Unit::Energy::KilowattHour },
260 {"MW·min", Unit::Energy::MegawattMinute },
261 {"MW*min", Unit::Energy::MegawattMinute },
262 {"MW·hr", Unit::Energy::MegawattHour },
263 {"MW*hr", Unit::Energy::MegawattHour },
264 {"GW·min", Unit::Energy::GigawattMinute },
265 {"GW*min", Unit::Energy::GigawattMinute },
266 {"GW·hr", Unit::Energy::GigawattHour },
267 {"GW*hr", Unit::Energy::GigawattHour },
268 {"ft·lbf", Unit::Energy::FootPound },
269 {"ft*lbf", Unit::Energy::FootPound },
270 {"ft·lb", Unit::Energy::FootPound },
271 {"ft*lb", Unit::Energy::FootPound },
272 {"in·lbf", Unit::Energy::InchPound },
273 {"in*lbf", Unit::Energy::InchPound },
274 {"in·lb", Unit::Energy::InchPound },
275 {"in*lb", Unit::Energy::InchPound },
276 {"cal", Unit::Energy::Calorie },
278 {"μcal", Unit::Energy::Microcalorie },
280 {"ncal", Unit::Energy::Nanocalorie },
281 {"kcal", Unit::Energy::Kilocalorie },
283 {"Mcal", Unit::Energy::Megacalorie },
284 {"Gcal", Unit::Energy::Gigacalorie },
295};
296
297// clang-format on
298
299template <>
300template <typename NumericType>
301inline constexpr void Conversion<Unit::Energy, Unit::Energy::Joule>::FromStandard(
302 NumericType& /*value*/) noexcept {}
303
304template <>
305template <typename NumericType>
306inline constexpr void Conversion<Unit::Energy, Unit::Energy::Joule>::ToStandard(
307 NumericType& /*value*/) noexcept {}
308
309template <>
310template <typename NumericType>
311inline constexpr void Conversion<Unit::Energy, Unit::Energy::Millijoule>::FromStandard(
312 NumericType& value) noexcept {
313 value *= static_cast<NumericType>(1000.0L);
314}
315
316template <>
317template <typename NumericType>
318inline constexpr void Conversion<Unit::Energy, Unit::Energy::Millijoule>::ToStandard(
319 NumericType& value) noexcept {
320 value *= static_cast<NumericType>(0.001L);
321}
322
323template <>
324template <typename NumericType>
325inline constexpr void Conversion<Unit::Energy, Unit::Energy::Microjoule>::FromStandard(
326 NumericType& value) noexcept {
327 value *= static_cast<NumericType>(1000000.0L);
328}
329
330template <>
331template <typename NumericType>
332inline constexpr void Conversion<Unit::Energy, Unit::Energy::Microjoule>::ToStandard(
333 NumericType& value) noexcept {
334 value *= static_cast<NumericType>(0.000001L);
335}
336
337template <>
338template <typename NumericType>
339inline constexpr void Conversion<Unit::Energy, Unit::Energy::Nanojoule>::FromStandard(
340 NumericType& value) noexcept {
341 value *= static_cast<NumericType>(1000000000.0L);
342}
343
344template <>
345template <typename NumericType>
346inline constexpr void Conversion<Unit::Energy, Unit::Energy::Nanojoule>::ToStandard(
347 NumericType& value) noexcept {
348 value *= static_cast<NumericType>(0.000000001L);
349}
350
351template <>
352template <typename NumericType>
353inline constexpr void Conversion<Unit::Energy, Unit::Energy::Kilojoule>::FromStandard(
354 NumericType& value) noexcept {
355 value *= static_cast<NumericType>(0.001L);
356}
357
358template <>
359template <typename NumericType>
360inline constexpr void Conversion<Unit::Energy, Unit::Energy::Kilojoule>::ToStandard(
361 NumericType& value) noexcept {
362 value *= static_cast<NumericType>(1000.0L);
363}
364
365template <>
366template <typename NumericType>
367inline constexpr void Conversion<Unit::Energy, Unit::Energy::Megajoule>::FromStandard(
368 NumericType& value) noexcept {
369 value *= static_cast<NumericType>(0.000001L);
370}
371
372template <>
373template <typename NumericType>
374inline constexpr void Conversion<Unit::Energy, Unit::Energy::Megajoule>::ToStandard(
375 NumericType& value) noexcept {
376 value *= static_cast<NumericType>(1000000.0L);
377}
378
379template <>
380template <typename NumericType>
381inline constexpr void Conversion<Unit::Energy, Unit::Energy::Gigajoule>::FromStandard(
382 NumericType& value) noexcept {
383 value *= static_cast<NumericType>(0.000000001L);
384}
385
386template <>
387template <typename NumericType>
388inline constexpr void Conversion<Unit::Energy, Unit::Energy::Gigajoule>::ToStandard(
389 NumericType& value) noexcept {
390 value *= static_cast<NumericType>(1000000000.0L);
391}
392
393template <>
394template <typename NumericType>
395inline constexpr void Conversion<Unit::Energy, Unit::Energy::WattMinute>::FromStandard(
396 NumericType& value) noexcept {
397 value /= static_cast<NumericType>(60.0L);
398}
399
400template <>
401template <typename NumericType>
402inline constexpr void Conversion<Unit::Energy, Unit::Energy::WattMinute>::ToStandard(
403 NumericType& value) noexcept {
404 value *= static_cast<NumericType>(60.0L);
405}
406
407template <>
408template <typename NumericType>
409inline constexpr void Conversion<Unit::Energy, Unit::Energy::WattHour>::FromStandard(
410 NumericType& value) noexcept {
411 value /= static_cast<NumericType>(3600.0L);
412}
413
414template <>
415template <typename NumericType>
416inline constexpr void Conversion<Unit::Energy, Unit::Energy::WattHour>::ToStandard(
417 NumericType& value) noexcept {
418 value *= static_cast<NumericType>(3600.0L);
419}
420
421template <>
422template <typename NumericType>
423inline constexpr void Conversion<Unit::Energy, Unit::Energy::KilowattMinute>::FromStandard(
424 NumericType& value) noexcept {
425 value /= static_cast<NumericType>(60000.0L);
426}
427
428template <>
429template <typename NumericType>
430inline constexpr void Conversion<Unit::Energy, Unit::Energy::KilowattMinute>::ToStandard(
431 NumericType& value) noexcept {
432 value *= static_cast<NumericType>(60000.0L);
433}
434
435template <>
436template <typename NumericType>
437inline constexpr void Conversion<Unit::Energy, Unit::Energy::KilowattHour>::FromStandard(
438 NumericType& value) noexcept {
439 value /= static_cast<NumericType>(3600000.0L);
440}
441
442template <>
443template <typename NumericType>
444inline constexpr void Conversion<Unit::Energy, Unit::Energy::KilowattHour>::ToStandard(
445 NumericType& value) noexcept {
446 value *= static_cast<NumericType>(3600000.0L);
447}
448
449template <>
450template <typename NumericType>
451inline constexpr void Conversion<Unit::Energy, Unit::Energy::MegawattMinute>::FromStandard(
452 NumericType& value) noexcept {
453 value /= static_cast<NumericType>(60000000.0L);
454}
455
456template <>
457template <typename NumericType>
458inline constexpr void Conversion<Unit::Energy, Unit::Energy::MegawattMinute>::ToStandard(
459 NumericType& value) noexcept {
460 value *= static_cast<NumericType>(60000000.0L);
461}
462
463template <>
464template <typename NumericType>
465inline constexpr void Conversion<Unit::Energy, Unit::Energy::MegawattHour>::FromStandard(
466 NumericType& value) noexcept {
467 value /= static_cast<NumericType>(3600000000.0L);
468}
469
470template <>
471template <typename NumericType>
472inline constexpr void Conversion<Unit::Energy, Unit::Energy::MegawattHour>::ToStandard(
473 NumericType& value) noexcept {
474 value *= static_cast<NumericType>(3600000000.0L);
475}
476
477template <>
478template <typename NumericType>
479inline constexpr void Conversion<Unit::Energy, Unit::Energy::GigawattMinute>::FromStandard(
480 NumericType& value) noexcept {
481 value /= static_cast<NumericType>(60000000000.0L);
482}
483
484template <>
485template <typename NumericType>
486inline constexpr void Conversion<Unit::Energy, Unit::Energy::GigawattMinute>::ToStandard(
487 NumericType& value) noexcept {
488 value *= static_cast<NumericType>(60000000000.0L);
489}
490
491template <>
492template <typename NumericType>
493inline constexpr void Conversion<Unit::Energy, Unit::Energy::GigawattHour>::FromStandard(
494 NumericType& value) noexcept {
495 value /= static_cast<NumericType>(3600000000000.0L);
496}
497
498template <>
499template <typename NumericType>
500inline constexpr void Conversion<Unit::Energy, Unit::Energy::GigawattHour>::ToStandard(
501 NumericType& value) noexcept {
502 value *= static_cast<NumericType>(3600000000000.0L);
503}
504
505template <>
506template <typename NumericType>
507inline constexpr void Conversion<Unit::Energy, Unit::Energy::FootPound>::FromStandard(
508 NumericType& value) noexcept {
509 value /= (static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.45359237L)
510 * static_cast<NumericType>(9.80665L));
511}
512
513template <>
514template <typename NumericType>
515inline constexpr void Conversion<Unit::Energy, Unit::Energy::FootPound>::ToStandard(
516 NumericType& value) noexcept {
517 value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.45359237L)
518 * static_cast<NumericType>(9.80665L);
519}
520
521template <>
522template <typename NumericType>
523inline constexpr void Conversion<Unit::Energy, Unit::Energy::InchPound>::FromStandard(
524 NumericType& value) noexcept {
525 value /= (static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.45359237L)
526 * static_cast<NumericType>(9.80665L));
527}
528
529template <>
530template <typename NumericType>
531inline constexpr void Conversion<Unit::Energy, Unit::Energy::InchPound>::ToStandard(
532 NumericType& value) noexcept {
533 value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.45359237L)
534 * static_cast<NumericType>(9.80665L);
535}
536
537template <>
538template <typename NumericType>
539inline constexpr void Conversion<Unit::Energy, Unit::Energy::Calorie>::FromStandard(
540 NumericType& value) noexcept {
541 value /= static_cast<NumericType>(4.184L);
542}
543
544template <>
545template <typename NumericType>
546inline constexpr void Conversion<Unit::Energy, Unit::Energy::Calorie>::ToStandard(
547 NumericType& value) noexcept {
548 value *= static_cast<NumericType>(4.184L);
549}
550
551template <>
552template <typename NumericType>
553inline constexpr void Conversion<Unit::Energy, Unit::Energy::Millicalorie>::FromStandard(
554 NumericType& value) noexcept {
555 value /= static_cast<NumericType>(0.004184L);
556}
557
558template <>
559template <typename NumericType>
560inline constexpr void Conversion<Unit::Energy, Unit::Energy::Millicalorie>::ToStandard(
561 NumericType& value) noexcept {
562 value *= static_cast<NumericType>(0.004184L);
563}
564
565template <>
566template <typename NumericType>
567inline constexpr void Conversion<Unit::Energy, Unit::Energy::Microcalorie>::FromStandard(
568 NumericType& value) noexcept {
569 value /= static_cast<NumericType>(0.000004184L);
570}
571
572template <>
573template <typename NumericType>
574inline constexpr void Conversion<Unit::Energy, Unit::Energy::Microcalorie>::ToStandard(
575 NumericType& value) noexcept {
576 value *= static_cast<NumericType>(0.000004184L);
577}
578
579template <>
580template <typename NumericType>
581inline constexpr void Conversion<Unit::Energy, Unit::Energy::Nanocalorie>::FromStandard(
582 NumericType& value) noexcept {
583 value /= static_cast<NumericType>(0.000000004184L);
584}
585
586template <>
587template <typename NumericType>
588inline constexpr void Conversion<Unit::Energy, Unit::Energy::Nanocalorie>::ToStandard(
589 NumericType& value) noexcept {
590 value *= static_cast<NumericType>(0.000000004184L);
591}
592
593template <>
594template <typename NumericType>
595inline constexpr void Conversion<Unit::Energy, Unit::Energy::Kilocalorie>::FromStandard(
596 NumericType& value) noexcept {
597 value /= static_cast<NumericType>(4184.0L);
598}
599
600template <>
601template <typename NumericType>
602inline constexpr void Conversion<Unit::Energy, Unit::Energy::Kilocalorie>::ToStandard(
603 NumericType& value) noexcept {
604 value *= static_cast<NumericType>(4184.0L);
605}
606
607template <>
608template <typename NumericType>
609inline constexpr void Conversion<Unit::Energy, Unit::Energy::Megacalorie>::FromStandard(
610 NumericType& value) noexcept {
611 value /= static_cast<NumericType>(4184000.0L);
612}
613
614template <>
615template <typename NumericType>
616inline constexpr void Conversion<Unit::Energy, Unit::Energy::Megacalorie>::ToStandard(
617 NumericType& value) noexcept {
618 value *= static_cast<NumericType>(4184000.0L);
619}
620
621template <>
622template <typename NumericType>
623inline constexpr void Conversion<Unit::Energy, Unit::Energy::Gigacalorie>::FromStandard(
624 NumericType& value) noexcept {
625 value /= static_cast<NumericType>(4184000000.0L);
626}
627
628template <>
629template <typename NumericType>
630inline constexpr void Conversion<Unit::Energy, Unit::Energy::Gigacalorie>::ToStandard(
631 NumericType& value) noexcept {
632 value *= static_cast<NumericType>(4184000000.0L);
633}
634
635template <>
636template <typename NumericType>
637inline constexpr void Conversion<Unit::Energy, Unit::Energy::Electronvolt>::FromStandard(
638 NumericType& value) noexcept {
639 value /= static_cast<NumericType>(1.602176634e-19L);
640}
641
642template <>
643template <typename NumericType>
644inline constexpr void Conversion<Unit::Energy, Unit::Energy::Electronvolt>::ToStandard(
645 NumericType& value) noexcept {
646 value *= static_cast<NumericType>(1.602176634e-19L);
647}
648
649template <>
650template <typename NumericType>
651inline constexpr void Conversion<Unit::Energy, Unit::Energy::Millielectronvolt>::FromStandard(
652 NumericType& value) noexcept {
653 value /= static_cast<NumericType>(1.602176634e-22L);
654}
655
656template <>
657template <typename NumericType>
658inline constexpr void Conversion<Unit::Energy, Unit::Energy::Millielectronvolt>::ToStandard(
659 NumericType& value) noexcept {
660 value *= static_cast<NumericType>(1.602176634e-22L);
661}
662
663template <>
664template <typename NumericType>
665inline constexpr void Conversion<Unit::Energy, Unit::Energy::Microelectronvolt>::FromStandard(
666 NumericType& value) noexcept {
667 value /= static_cast<NumericType>(1.602176634e-25L);
668}
669
670template <>
671template <typename NumericType>
672inline constexpr void Conversion<Unit::Energy, Unit::Energy::Microelectronvolt>::ToStandard(
673 NumericType& value) noexcept {
674 value *= static_cast<NumericType>(1.602176634e-25L);
675}
676
677template <>
678template <typename NumericType>
679inline constexpr void Conversion<Unit::Energy, Unit::Energy::Nanoelectronvolt>::FromStandard(
680 NumericType& value) noexcept {
681 value /= static_cast<NumericType>(1.602176634e-28L);
682}
683
684template <>
685template <typename NumericType>
686inline constexpr void Conversion<Unit::Energy, Unit::Energy::Nanoelectronvolt>::ToStandard(
687 NumericType& value) noexcept {
688 value *= static_cast<NumericType>(1.602176634e-28L);
689}
690
691template <>
692template <typename NumericType>
693inline constexpr void Conversion<Unit::Energy, Unit::Energy::Kiloelectronvolt>::FromStandard(
694 NumericType& value) noexcept {
695 value /= static_cast<NumericType>(1.602176634e-16L);
696}
697
698template <>
699template <typename NumericType>
700inline constexpr void Conversion<Unit::Energy, Unit::Energy::Kiloelectronvolt>::ToStandard(
701 NumericType& value) noexcept {
702 value *= static_cast<NumericType>(1.602176634e-16L);
703}
704
705template <>
706template <typename NumericType>
707inline constexpr void Conversion<Unit::Energy, Unit::Energy::Megaelectronvolt>::FromStandard(
708 NumericType& value) noexcept {
709 value /= static_cast<NumericType>(1.602176634e-13L);
710}
711
712template <>
713template <typename NumericType>
714inline constexpr void Conversion<Unit::Energy, Unit::Energy::Megaelectronvolt>::ToStandard(
715 NumericType& value) noexcept {
716 value *= static_cast<NumericType>(1.602176634e-13L);
717}
718
719template <>
720template <typename NumericType>
721inline constexpr void Conversion<Unit::Energy, Unit::Energy::Gigaelectronvolt>::FromStandard(
722 NumericType& value) noexcept {
723 value /= static_cast<NumericType>(1.602176634e-10L);
724}
725
726template <>
727template <typename NumericType>
728inline constexpr void Conversion<Unit::Energy, Unit::Energy::Gigaelectronvolt>::ToStandard(
729 NumericType& value) noexcept {
730 value *= static_cast<NumericType>(1.602176634e-10L);
731}
732
733template <>
734template <typename NumericType>
735inline constexpr void Conversion<Unit::Energy, Unit::Energy::BritishThermalUnit>::FromStandard(
736 NumericType& value) noexcept {
737 value *= static_cast<NumericType>(1.8L)
738 / (static_cast<NumericType>(4.1868L) * static_cast<NumericType>(453.59237L));
739}
740
741template <>
742template <typename NumericType>
743inline constexpr void Conversion<Unit::Energy, Unit::Energy::BritishThermalUnit>::ToStandard(
744 NumericType& value) noexcept {
745 value *= static_cast<NumericType>(4.1868L) * static_cast<NumericType>(453.59237L)
746 / static_cast<NumericType>(1.8L);
747}
748
749template <typename NumericType>
750inline const std::map<Unit::Energy,
751 std::function<void(NumericType* values, const std::size_t size)>>
752 MapOfConversionsFromStandard<Unit::Energy, NumericType>{
754 Conversions<Unit::Energy, Unit::Energy::Joule>::FromStandard<NumericType> },
756 Conversions<Unit::Energy, Unit::Energy::Millijoule>::FromStandard<NumericType> },
758 Conversions<Unit::Energy, Unit::Energy::Microjoule>::FromStandard<NumericType> },
760 Conversions<Unit::Energy, Unit::Energy::Nanojoule>::FromStandard<NumericType> },
762 Conversions<Unit::Energy, Unit::Energy::Kilojoule>::FromStandard<NumericType> },
764 Conversions<Unit::Energy, Unit::Energy::Megajoule>::FromStandard<NumericType> },
766 Conversions<Unit::Energy, Unit::Energy::Gigajoule>::FromStandard<NumericType> },
768 Conversions<Unit::Energy, Unit::Energy::WattMinute>::FromStandard<NumericType> },
770 Conversions<Unit::Energy, Unit::Energy::WattHour>::FromStandard<NumericType> },
772 Conversions<Unit::Energy, Unit::Energy::KilowattMinute>::FromStandard<NumericType> },
774 Conversions<Unit::Energy, Unit::Energy::KilowattHour>::FromStandard<NumericType> },
776 Conversions<Unit::Energy, Unit::Energy::MegawattMinute>::FromStandard<NumericType> },
778 Conversions<Unit::Energy, Unit::Energy::MegawattHour>::FromStandard<NumericType> },
780 Conversions<Unit::Energy, Unit::Energy::GigawattMinute>::FromStandard<NumericType> },
782 Conversions<Unit::Energy, Unit::Energy::GigawattHour>::FromStandard<NumericType> },
784 Conversions<Unit::Energy, Unit::Energy::FootPound>::FromStandard<NumericType> },
786 Conversions<Unit::Energy, Unit::Energy::InchPound>::FromStandard<NumericType> },
788 Conversions<Unit::Energy, Unit::Energy::Calorie>::FromStandard<NumericType> },
790 Conversions<Unit::Energy, Unit::Energy::Millicalorie>::FromStandard<NumericType> },
792 Conversions<Unit::Energy, Unit::Energy::Microcalorie>::FromStandard<NumericType> },
794 Conversions<Unit::Energy, Unit::Energy::Nanocalorie>::FromStandard<NumericType> },
796 Conversions<Unit::Energy, Unit::Energy::Kilocalorie>::FromStandard<NumericType> },
798 Conversions<Unit::Energy, Unit::Energy::Megacalorie>::FromStandard<NumericType> },
800 Conversions<Unit::Energy, Unit::Energy::Gigacalorie>::FromStandard<NumericType> },
802 Conversions<Unit::Energy, Unit::Energy::Electronvolt>::FromStandard<NumericType> },
804 Conversions<Unit::Energy, Unit::Energy::Millielectronvolt>::FromStandard<NumericType> },
806 Conversions<Unit::Energy, Unit::Energy::Microelectronvolt>::FromStandard<NumericType> },
808 Conversions<Unit::Energy, Unit::Energy::Nanoelectronvolt>::FromStandard<NumericType> },
810 Conversions<Unit::Energy, Unit::Energy::Kiloelectronvolt>::FromStandard<NumericType> },
812 Conversions<Unit::Energy, Unit::Energy::Megaelectronvolt>::FromStandard<NumericType> },
814 Conversions<Unit::Energy, Unit::Energy::Gigaelectronvolt>::FromStandard<NumericType> },
816 Conversions<Unit::Energy, Unit::Energy::BritishThermalUnit>::FromStandard<NumericType>},
817};
818
819template <typename NumericType>
820inline const std::map<Unit::Energy,
821 std::function<void(NumericType* const values, const std::size_t size)>>
822 MapOfConversionsToStandard<Unit::Energy, NumericType>{
824 Conversions<Unit::Energy, Unit::Energy::Joule>::ToStandard<NumericType> },
826 Conversions<Unit::Energy, Unit::Energy::Millijoule>::ToStandard<NumericType> },
828 Conversions<Unit::Energy, Unit::Energy::Microjoule>::ToStandard<NumericType> },
830 Conversions<Unit::Energy, Unit::Energy::Nanojoule>::ToStandard<NumericType> },
832 Conversions<Unit::Energy, Unit::Energy::Kilojoule>::ToStandard<NumericType> },
834 Conversions<Unit::Energy, Unit::Energy::Megajoule>::ToStandard<NumericType> },
836 Conversions<Unit::Energy, Unit::Energy::Gigajoule>::ToStandard<NumericType> },
838 Conversions<Unit::Energy, Unit::Energy::WattMinute>::ToStandard<NumericType> },
840 Conversions<Unit::Energy, Unit::Energy::WattHour>::ToStandard<NumericType> },
842 Conversions<Unit::Energy, Unit::Energy::KilowattMinute>::ToStandard<NumericType> },
844 Conversions<Unit::Energy, Unit::Energy::KilowattHour>::ToStandard<NumericType> },
846 Conversions<Unit::Energy, Unit::Energy::MegawattMinute>::ToStandard<NumericType> },
848 Conversions<Unit::Energy, Unit::Energy::MegawattHour>::ToStandard<NumericType> },
850 Conversions<Unit::Energy, Unit::Energy::GigawattMinute>::ToStandard<NumericType> },
852 Conversions<Unit::Energy, Unit::Energy::GigawattHour>::ToStandard<NumericType> },
854 Conversions<Unit::Energy, Unit::Energy::FootPound>::ToStandard<NumericType> },
856 Conversions<Unit::Energy, Unit::Energy::InchPound>::ToStandard<NumericType> },
858 Conversions<Unit::Energy, Unit::Energy::Calorie>::ToStandard<NumericType> },
860 Conversions<Unit::Energy, Unit::Energy::Millicalorie>::ToStandard<NumericType> },
862 Conversions<Unit::Energy, Unit::Energy::Microcalorie>::ToStandard<NumericType> },
864 Conversions<Unit::Energy, Unit::Energy::Nanocalorie>::ToStandard<NumericType> },
866 Conversions<Unit::Energy, Unit::Energy::Kilocalorie>::ToStandard<NumericType> },
868 Conversions<Unit::Energy, Unit::Energy::Megacalorie>::ToStandard<NumericType> },
870 Conversions<Unit::Energy, Unit::Energy::Gigacalorie>::ToStandard<NumericType> },
872 Conversions<Unit::Energy, Unit::Energy::Electronvolt>::ToStandard<NumericType> },
874 Conversions<Unit::Energy, Unit::Energy::Millielectronvolt>::ToStandard<NumericType> },
876 Conversions<Unit::Energy, Unit::Energy::Microelectronvolt>::ToStandard<NumericType> },
878 Conversions<Unit::Energy, Unit::Energy::Nanoelectronvolt>::ToStandard<NumericType> },
880 Conversions<Unit::Energy, Unit::Energy::Kiloelectronvolt>::ToStandard<NumericType> },
882 Conversions<Unit::Energy, Unit::Energy::Megaelectronvolt>::ToStandard<NumericType> },
884 Conversions<Unit::Energy, Unit::Energy::Gigaelectronvolt>::ToStandard<NumericType> },
886 Conversions<Unit::Energy, Unit::Energy::BritishThermalUnit>::ToStandard<NumericType>},
887};
888
889} // namespace Internal
890
891} // namespace PhQ
892
893#endif // PHQ_UNIT_ENERGY_HPP
Energy
Energy units.
Definition Energy.hpp:53
@ Gigaelectronvolt
Gigaelectronvolt (GeV) energy unit.
@ Nanojoule
Nanojoule (nJ) energy unit.
@ InchPound
Inch-pound (in·lbf) energy unit.
@ Gigajoule
Gigajoule (GJ) energy unit.
@ MegawattMinute
Megawatt-minute (MW·min) energy unit.
@ BritishThermalUnit
British thermal unit (BTU) energy unit.
@ Nanocalorie
Nanocalorie (ncal) energy unit.
@ Joule
Joule (J) energy unit.
@ Microcalorie
Microcalorie (μcal) energy unit.
@ FootPound
Foot-pound (ft·lbf) energy unit.
@ Calorie
Calorie (cal) energy unit.
@ WattHour
Watt-hour (W·hr) energy unit.
@ Nanoelectronvolt
Nanoelectronvolt (neV) energy unit.
@ KilowattHour
Kilowatt-hour (kW·hr) energy unit.
@ Microjoule
Microjoule (μJ) energy unit.
@ KilowattMinute
Kilowatt-minute (kW·min) energy unit.
@ Millicalorie
Millicalorie (mcal) energy unit.
@ GigawattHour
Gigawatt-hour (GW·hr) energy unit.
@ GigawattMinute
Gigawatt-minute (GW·min) energy unit.
@ Megaelectronvolt
Megaelectronvolt (MeV) energy unit.
@ MegawattHour
Megawatt-hour (MW·hr) energy unit.
@ WattMinute
Watt-minute (W·min) energy unit.
@ Millielectronvolt
Millielectronvolt (meV) energy unit.
@ Microelectronvolt
Microelectronvolt (μeV) energy unit.
@ Gigacalorie
Gigacalorie (Gcal) energy unit.
@ Kiloelectronvolt
Kiloelectronvolt (keV) energy unit.
@ Megacalorie
Megacalorie (Mcal) energy unit.
@ Millijoule
Millijoule (mJ) energy unit.
@ Kilojoule
Kilojoule (kJ) energy unit.
@ Megajoule
Megajoule (MJ) energy unit.
@ Electronvolt
Electronvolt (eV) energy unit.
@ Kilocalorie
Kilocalorie (kcal) energy unit.
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)
@ FootPoundSecondRankine
Foot-pound-second-rankine (ft·lbf·s·°R) system.
@ MillimetreGramSecondKelvin
Millimetre-gram-second-kelvin (mm·g·s·K) system.
@ MetreKilogramSecondKelvin
Metre-kilogram-second-kelvin (m·kg·s·K) system.
@ InchPoundSecondRankine
Inch-pound-second-rankine (in·lbf·s·°R) system.
std::string_view Abbreviation(const Enumeration enumeration)
Returns the abbreviation of a given enumeration value. For example, PhQ::Abbreviation(PhQ::Unit::Time...
Definition Base.hpp:89