Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
EnergyFlux.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_FLUX_HPP
26 #define PHQ_UNIT_ENERGY_FLUX_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 
48 namespace PhQ {
49 
50 namespace Unit {
51 
52 /// \brief Energy flux units.
53 enum class EnergyFlux : int8_t {
54  /// \brief Watt per square metre (W/m^2) energy flux unit.
56 
57  /// \brief Nanowatt per square millimetre (nW/mm^2) energy flux unit.
59 
60  /// \brief Foot-pound per square foot per second (ft·lbf/ft^2/s) energy flux unit.
62 
63  /// \brief Inch-pound per square inch per second (in·lbf/in^2/s) energy flux unit.
65 };
66 
67 } // namespace Unit
68 
69 /// \brief Standard energy flux unit: watt per square metre (W/m^2).
70 template <>
71 inline constexpr const Unit::EnergyFlux Standard<Unit::EnergyFlux>{
73 
74 /// \brief Physical dimension set of energy flux units.
75 template <>
76 inline constexpr const Dimensions RelatedDimensions<Unit::EnergyFlux>{
77  Dimensions{Dimension::Time{-3}, Dimension::Length{0}, Dimension::Mass{1},
79  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
80 };
81 
82 inline std::ostream& operator<<(std::ostream& stream, const Unit::EnergyFlux unit) {
83  stream << Abbreviation(unit);
84  return stream;
85 }
86 
87 namespace Internal {
88 
89 template <>
90 inline const std::map<UnitSystem, Unit::EnergyFlux> ConsistentUnits<Unit::EnergyFlux>{
95 };
96 
97 template <>
98 inline const std::map<Unit::EnergyFlux, UnitSystem> RelatedUnitSystems<Unit::EnergyFlux>{
103 };
104 
105 // clang-format off
106 
107 template <>
108 inline const std::map<Unit::EnergyFlux, std::string_view> Abbreviations<Unit::EnergyFlux>{
113 };
114 
115 template <>
116 inline const std::unordered_map<std::string_view, Unit::EnergyFlux> Spellings<Unit::EnergyFlux>{
119  {"J/(m^2·s)", Unit::EnergyFlux::WattPerSquareMetre },
120  {"J/(m^2*s)", Unit::EnergyFlux::WattPerSquareMetre },
121  {"J/(m2·s)", Unit::EnergyFlux::WattPerSquareMetre },
172 };
173 
174 // clang-format on
175 
176 template <>
177 template <typename NumericType>
178 inline constexpr void
179 Conversion<Unit::EnergyFlux, Unit::EnergyFlux::WattPerSquareMetre>::FromStandard(
180  NumericType& /*value*/) noexcept {}
181 
182 template <>
183 template <typename NumericType>
184 inline constexpr void
185 Conversion<Unit::EnergyFlux, Unit::EnergyFlux::WattPerSquareMetre>::ToStandard(
186  NumericType& /*value*/) noexcept {}
187 
188 template <>
189 template <typename NumericType>
190 inline constexpr void
191 Conversion<Unit::EnergyFlux, Unit::EnergyFlux::NanowattPerSquareMillimetre>::FromStandard(
192  NumericType& value) noexcept {
193  value *= static_cast<NumericType>(1000.0L);
194 }
195 
196 template <>
197 template <typename NumericType>
198 inline constexpr void
199 Conversion<Unit::EnergyFlux, Unit::EnergyFlux::NanowattPerSquareMillimetre>::ToStandard(
200  NumericType& value) noexcept {
201  value *= static_cast<NumericType>(0.001L);
202 }
203 
204 template <>
205 template <typename NumericType>
206 inline constexpr void
207 Conversion<Unit::EnergyFlux, Unit::EnergyFlux::FootPoundPerSquareFootPerSecond>::FromStandard(
208  NumericType& value) noexcept {
209  value *= static_cast<NumericType>(0.3048L)
210  / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
211 }
212 
213 template <>
214 template <typename NumericType>
215 inline constexpr void
216 Conversion<Unit::EnergyFlux, Unit::EnergyFlux::FootPoundPerSquareFootPerSecond>::ToStandard(
217  NumericType& value) noexcept {
218  value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
219  / static_cast<NumericType>(0.3048L);
220 }
221 
222 template <>
223 template <typename NumericType>
224 inline constexpr void
225 Conversion<Unit::EnergyFlux, Unit::EnergyFlux::InchPoundPerSquareInchPerSecond>::FromStandard(
226  NumericType& value) noexcept {
227  value *= static_cast<NumericType>(0.0254L)
228  / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
229 }
230 
231 template <>
232 template <typename NumericType>
233 inline constexpr void
234 Conversion<Unit::EnergyFlux, Unit::EnergyFlux::InchPoundPerSquareInchPerSecond>::ToStandard(
235  NumericType& value) noexcept {
236  value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
237  / static_cast<NumericType>(0.0254L);
238 }
239 
240 template <typename NumericType>
241 inline const std::map<Unit::EnergyFlux,
242  std::function<void(NumericType* values, const std::size_t size)>>
243  MapOfConversionsFromStandard<Unit::EnergyFlux, NumericType>{
245  Conversions<Unit::EnergyFlux,
246  Unit::EnergyFlux::WattPerSquareMetre>::FromStandard<NumericType> },
248  Conversions<Unit::EnergyFlux,
249  Unit::EnergyFlux::NanowattPerSquareMillimetre>::FromStandard<NumericType> },
251  Conversions<Unit::EnergyFlux,
252  Unit::EnergyFlux::FootPoundPerSquareFootPerSecond>::FromStandard<NumericType>},
254  Conversions<Unit::EnergyFlux,
255  Unit::EnergyFlux::InchPoundPerSquareInchPerSecond>::FromStandard<NumericType>},
256 };
257 
258 template <typename NumericType>
259 inline const std::map<Unit::EnergyFlux,
260  std::function<void(NumericType* const values, const std::size_t size)>>
261  MapOfConversionsToStandard<Unit::EnergyFlux, NumericType>{
263  Conversions<Unit::EnergyFlux,
264  Unit::EnergyFlux::WattPerSquareMetre>::ToStandard<NumericType> },
266  Conversions<Unit::EnergyFlux,
267  Unit::EnergyFlux::NanowattPerSquareMillimetre>::ToStandard<NumericType> },
269  Conversions<Unit::EnergyFlux,
270  Unit::EnergyFlux::FootPoundPerSquareFootPerSecond>::ToStandard<NumericType>},
272  Conversions<Unit::EnergyFlux,
273  Unit::EnergyFlux::InchPoundPerSquareInchPerSecond>::ToStandard<NumericType>},
274 };
275 
276 } // namespace Internal
277 
278 } // namespace PhQ
279 
280 #endif // PHQ_UNIT_ENERGY_FLUX_HPP
ElectricCurrent
Electric current units.
Mass
Mass units.
Definition: Mass.hpp:53
Length
Length units.
Definition: Length.hpp:53
EnergyFlux
Energy flux units.
Definition: EnergyFlux.hpp:53
@ NanowattPerSquareMillimetre
Nanowatt per square millimetre (nW/mm^2) energy flux unit.
@ FootPoundPerSquareFootPerSecond
Foot-pound per square foot per second (ft·lbf/ft^2/s) energy flux unit.
@ InchPoundPerSquareInchPerSecond
Inch-pound per square inch per second (in·lbf/in^2/s) energy flux unit.
@ WattPerSquareMetre
Watt per square metre (W/m^2) energy flux unit.
SubstanceAmount
Amount of substance units.
Temperature
Temperature units. Not to be confused with temperature difference units. For example,...
Definition: Temperature.hpp:55
Time
Time units.
Definition: Time.hpp:53
Namespace that encompasses all of the Physical Quantities library's content.
@ 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
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)