Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
SpecificEnergy.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_SPECIFIC_ENERGY_HPP
26 #define PHQ_UNIT_SPECIFIC_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 
48 namespace PhQ {
49 
50 namespace Unit {
51 
52 /// \brief Mass-specific energy units.
53 enum class SpecificEnergy : int8_t {
54  /// \brief Joule per kilogram (J/kg) specific energy unit.
56 
57  /// \brief Nanojoule per gram (nJ/g) specific energy unit.
59 
60  /// \brief Foot-pound per slug (ft·lbf/slug) specific energy unit.
62 
63  /// \brief Inch-pound per slinch (in·lbf/slinch) specific energy unit.
65 };
66 
67 } // namespace Unit
68 
69 /// \brief Standard mass-specific energy unit: joule per kilogram (J/kg).
70 template <>
71 inline constexpr const Unit::SpecificEnergy Standard<Unit::SpecificEnergy>{
73 
74 /// \brief Physical dimension set of mass-specific energy units.
75 template <>
76 inline constexpr const Dimensions RelatedDimensions<Unit::SpecificEnergy>{
77  Dimensions{Dimension::Time{-2}, Dimension::Length{2}, Dimension::Mass{0},
79  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
80 };
81 
82 inline std::ostream& operator<<(std::ostream& stream, const Unit::SpecificEnergy unit) {
83  stream << Abbreviation(unit);
84  return stream;
85 }
86 
87 namespace Internal {
88 
89 template <>
90 inline const std::map<UnitSystem, Unit::SpecificEnergy> ConsistentUnits<Unit::SpecificEnergy>{
95 };
96 
97 template <>
98 inline const std::map<Unit::SpecificEnergy, UnitSystem> RelatedUnitSystems<Unit::SpecificEnergy>{
103 };
104 
105 // clang-format off
106 
107 template <>
108 inline const std::map<Unit::SpecificEnergy, std::string_view> Abbreviations<Unit::SpecificEnergy>{
111  {Unit::SpecificEnergy::FootPoundPerSlug, "ft·lbf/slug" },
112  {Unit::SpecificEnergy::InchPoundPerSlinch, "in·lbf/slinch"},
113 };
114 
115 template <>
116 inline const std::unordered_map<std::string_view, Unit::SpecificEnergy> Spellings<
136  {"ft·lbf/slug", Unit::SpecificEnergy::FootPoundPerSlug },
137  {"ft*lbf/slug", Unit::SpecificEnergy::FootPoundPerSlug },
138  {"lbf·ft/slug", Unit::SpecificEnergy::FootPoundPerSlug },
139  {"lbf*ft/slug", Unit::SpecificEnergy::FootPoundPerSlug },
140  {"ft·lb/slug", Unit::SpecificEnergy::FootPoundPerSlug },
142  {"lb·ft/slug", Unit::SpecificEnergy::FootPoundPerSlug },
146  {"in·lbf/slinch", Unit::SpecificEnergy::InchPoundPerSlinch},
147  {"in*lbf/slinch", Unit::SpecificEnergy::InchPoundPerSlinch},
148  {"lbf·in/slinch", Unit::SpecificEnergy::InchPoundPerSlinch},
149  {"lbf*in/slinch", Unit::SpecificEnergy::InchPoundPerSlinch},
150  {"in·lb/slinch", Unit::SpecificEnergy::InchPoundPerSlinch},
152  {"lb·in/slinch", Unit::SpecificEnergy::InchPoundPerSlinch},
156 };
157 
158 // clang-format on
159 
160 template <>
161 template <typename NumericType>
162 inline constexpr void
163 Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::JoulePerKilogram>::FromStandard(
164  NumericType& /*value*/) noexcept {}
165 
166 template <>
167 template <typename NumericType>
168 inline constexpr void
169 Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::JoulePerKilogram>::ToStandard(
170  NumericType& /*value*/) noexcept {}
171 
172 template <>
173 template <typename NumericType>
174 inline constexpr void
175 Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::NanojoulePerGram>::FromStandard(
176  NumericType& value) noexcept {
177  value *= static_cast<NumericType>(1000000.0L);
178 }
179 
180 template <>
181 template <typename NumericType>
182 inline constexpr void
183 Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::NanojoulePerGram>::ToStandard(
184  NumericType& value) noexcept {
185  value *= static_cast<NumericType>(0.000001L);
186 }
187 
188 template <>
189 template <typename NumericType>
190 inline constexpr void
191 Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::FootPoundPerSlug>::FromStandard(
192  NumericType& value) noexcept {
193  value /= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L);
194 }
195 
196 template <>
197 template <typename NumericType>
198 inline constexpr void
199 Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::FootPoundPerSlug>::ToStandard(
200  NumericType& value) noexcept {
201  value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L);
202 }
203 
204 template <>
205 template <typename NumericType>
206 inline constexpr void
207 Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::InchPoundPerSlinch>::FromStandard(
208  NumericType& value) noexcept {
209  value /= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L);
210 }
211 
212 template <>
213 template <typename NumericType>
214 inline constexpr void
215 Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::InchPoundPerSlinch>::ToStandard(
216  NumericType& value) noexcept {
217  value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L);
218 }
219 
220 template <typename NumericType>
221 inline const std::map<Unit::SpecificEnergy,
222  std::function<void(NumericType* values, const std::size_t size)>>
223  MapOfConversionsFromStandard<Unit::SpecificEnergy, NumericType>{
225  Conversions<Unit::SpecificEnergy,
226  Unit::SpecificEnergy::JoulePerKilogram>::FromStandard<NumericType> },
228  Conversions<Unit::SpecificEnergy,
229  Unit::SpecificEnergy::NanojoulePerGram>::FromStandard<NumericType> },
231  Conversions<Unit::SpecificEnergy,
232  Unit::SpecificEnergy::FootPoundPerSlug>::FromStandard<NumericType> },
234  Conversions<Unit::SpecificEnergy,
235  Unit::SpecificEnergy::InchPoundPerSlinch>::FromStandard<NumericType>},
236 };
237 
238 template <typename NumericType>
239 inline const std::map<Unit::SpecificEnergy,
240  std::function<void(NumericType* const values, const std::size_t size)>>
241  MapOfConversionsToStandard<Unit::SpecificEnergy, NumericType>{
243  Conversions<Unit::SpecificEnergy,
244  Unit::SpecificEnergy::JoulePerKilogram>::ToStandard<NumericType> },
246  Conversions<Unit::SpecificEnergy,
247  Unit::SpecificEnergy::NanojoulePerGram>::ToStandard<NumericType> },
249  Conversions<Unit::SpecificEnergy,
250  Unit::SpecificEnergy::FootPoundPerSlug>::ToStandard<NumericType> },
252  Conversions<Unit::SpecificEnergy,
253  Unit::SpecificEnergy::InchPoundPerSlinch>::ToStandard<NumericType>},
254 };
255 
256 } // namespace Internal
257 
258 } // namespace PhQ
259 
260 #endif // PHQ_UNIT_SPECIFIC_ENERGY_HPP
ElectricCurrent
Electric current units.
Mass
Mass units.
Definition: Mass.hpp:53
Length
Length units.
Definition: Length.hpp:53
SubstanceAmount
Amount of substance units.
SpecificEnergy
Mass-specific energy units.
@ NanojoulePerGram
Nanojoule per gram (nJ/g) specific energy unit.
@ JoulePerKilogram
Joule per kilogram (J/kg) specific energy unit.
@ FootPoundPerSlug
Foot-pound per slug (ft·lbf/slug) specific energy unit.
@ InchPoundPerSlinch
Inch-pound per slinch (in·lbf/slinch) specific energy unit.
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)