Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
HeatCapacity.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_HEAT_CAPACITY_HPP
26 #define PHQ_UNIT_HEAT_CAPACITY_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 Heat capacity units.
53 enum class HeatCapacity : int8_t {
54  /// \brief Joule per kelvin (J/K) heat capacity unit.
56 
57  /// \brief Nanojoule per kelvin (nJ/K) heat capacity unit.
59 
60  /// \brief Foot-pound per degree Rankine (ft·lbf/°R) heat capacity unit.
62 
63  /// \brief Inch-pound per degree Rankine (in·lbf/°R) heat capacity unit.
65 };
66 
67 } // namespace Unit
68 
69 /// \brief Standard heat capacity unit: joule per kelvin (J/K).
70 template <>
71 inline constexpr const Unit::HeatCapacity Standard<Unit::HeatCapacity>{
73 
74 /// \brief Physical dimension set of heat capacity units.
75 template <>
76 inline constexpr const Dimensions RelatedDimensions<Unit::HeatCapacity>{
77  Dimensions{Dimension::Time{-2}, Dimension::Length{2}, Dimension::Mass{1},
79  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
80 };
81 
82 inline std::ostream& operator<<(std::ostream& stream, const Unit::HeatCapacity unit) {
83  stream << Abbreviation(unit);
84  return stream;
85 }
86 
87 namespace Internal {
88 
89 template <>
90 inline const std::map<UnitSystem, Unit::HeatCapacity> ConsistentUnits<Unit::HeatCapacity>{
95 };
96 
97 template <>
98 inline const std::map<Unit::HeatCapacity, UnitSystem> RelatedUnitSystems<Unit::HeatCapacity>{
103 };
104 
105 // clang-format off
106 
107 template <>
108 inline const std::map<Unit::HeatCapacity, std::string_view> Abbreviations<Unit::HeatCapacity>{
113 };
114 
115 template <>
116 inline const std::unordered_map<std::string_view, Unit::HeatCapacity> Spellings<Unit::HeatCapacity>{
120  {"kg·m^2/s^2/K", Unit::HeatCapacity::JoulePerKelvin },
121  {"kg*m^2/s^2/K", Unit::HeatCapacity::JoulePerKelvin },
122  {"kg·m2/s2/K", Unit::HeatCapacity::JoulePerKelvin },
123  {"kg*m2/s2/K", Unit::HeatCapacity::JoulePerKelvin },
124  {"kg·m^2/(s^2·K)", Unit::HeatCapacity::JoulePerKelvin },
125  {"kg*m^2/(s^2*K)", Unit::HeatCapacity::JoulePerKelvin },
126  {"kg·m2/(s2·K)", Unit::HeatCapacity::JoulePerKelvin },
127  {"kg*m2/(s2*K)", Unit::HeatCapacity::JoulePerKelvin },
133  {"g·mm^2/s^2/K", Unit::HeatCapacity::NanojoulePerKelvin },
134  {"g*mm^2/s^2/K", Unit::HeatCapacity::NanojoulePerKelvin },
135  {"g·mm2/s2/K", Unit::HeatCapacity::NanojoulePerKelvin },
137  {"g·mm^2/(s^2·K)", Unit::HeatCapacity::NanojoulePerKelvin },
138  {"g*mm^2/(s^2*K)", Unit::HeatCapacity::NanojoulePerKelvin },
139  {"g·mm2/(s2·K)", Unit::HeatCapacity::NanojoulePerKelvin },
140  {"g*mm2/(s2*K)", Unit::HeatCapacity::NanojoulePerKelvin },
157 };
158 
159 // clang-format on
160 
161 template <>
162 template <typename NumericType>
163 inline constexpr void
164 Conversion<Unit::HeatCapacity, Unit::HeatCapacity::JoulePerKelvin>::FromStandard(
165  NumericType& /*value*/) noexcept {}
166 
167 template <>
168 template <typename NumericType>
169 inline constexpr void
170 Conversion<Unit::HeatCapacity, Unit::HeatCapacity::JoulePerKelvin>::ToStandard(
171  NumericType& /*value*/) noexcept {}
172 
173 template <>
174 template <typename NumericType>
175 inline constexpr void
176 Conversion<Unit::HeatCapacity, Unit::HeatCapacity::NanojoulePerKelvin>::FromStandard(
177  NumericType& value) noexcept {
178  value *= static_cast<NumericType>(1000000000.0L);
179 }
180 
181 template <>
182 template <typename NumericType>
183 inline constexpr void
184 Conversion<Unit::HeatCapacity, Unit::HeatCapacity::NanojoulePerKelvin>::ToStandard(
185  NumericType& value) noexcept {
186  value *= static_cast<NumericType>(0.000000001L);
187 }
188 
189 template <>
190 template <typename NumericType>
191 inline constexpr void
192 Conversion<Unit::HeatCapacity, Unit::HeatCapacity::FootPoundPerRankine>::FromStandard(
193  NumericType& value) noexcept {
194  value /= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.45359237L)
195  * static_cast<NumericType>(9.80665L) * static_cast<NumericType>(1.8L);
196 }
197 
198 template <>
199 template <typename NumericType>
200 inline constexpr void
201 Conversion<Unit::HeatCapacity, Unit::HeatCapacity::FootPoundPerRankine>::ToStandard(
202  NumericType& value) noexcept {
203  value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.45359237L)
204  * static_cast<NumericType>(9.80665L) * static_cast<NumericType>(1.8L);
205 }
206 
207 template <>
208 template <typename NumericType>
209 inline constexpr void
210 Conversion<Unit::HeatCapacity, Unit::HeatCapacity::InchPoundPerRankine>::FromStandard(
211  NumericType& value) noexcept {
212  value /= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.45359237L)
213  * static_cast<NumericType>(9.80665L) * static_cast<NumericType>(1.8L);
214 }
215 
216 template <>
217 template <typename NumericType>
218 inline constexpr void
219 Conversion<Unit::HeatCapacity, Unit::HeatCapacity::InchPoundPerRankine>::ToStandard(
220  NumericType& value) noexcept {
221  value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.45359237L)
222  * static_cast<NumericType>(9.80665L) * static_cast<NumericType>(1.8L);
223 }
224 
225 template <typename NumericType>
226 inline const std::map<Unit::HeatCapacity,
227  std::function<void(NumericType* values, const std::size_t size)>>
228  MapOfConversionsFromStandard<Unit::HeatCapacity, NumericType>{
230  Conversions<Unit::HeatCapacity,
231  Unit::HeatCapacity::JoulePerKelvin>::FromStandard<NumericType> },
233  Conversions<Unit::HeatCapacity,
234  Unit::HeatCapacity::NanojoulePerKelvin>::FromStandard<NumericType> },
236  Conversions<Unit::HeatCapacity,
237  Unit::HeatCapacity::FootPoundPerRankine>::FromStandard<NumericType>},
239  Conversions<Unit::HeatCapacity,
240  Unit::HeatCapacity::InchPoundPerRankine>::FromStandard<NumericType>},
241 };
242 
243 template <typename NumericType>
244 inline const std::map<Unit::HeatCapacity,
245  std::function<void(NumericType* const values, const std::size_t size)>>
246  MapOfConversionsToStandard<Unit::HeatCapacity, NumericType>{
248  Conversions<Unit::HeatCapacity,
249  Unit::HeatCapacity::JoulePerKelvin>::ToStandard<NumericType> },
251  Conversions<Unit::HeatCapacity,
252  Unit::HeatCapacity::NanojoulePerKelvin>::ToStandard<NumericType> },
254  Conversions<Unit::HeatCapacity,
255  Unit::HeatCapacity::FootPoundPerRankine>::ToStandard<NumericType>},
257  Conversions<Unit::HeatCapacity,
258  Unit::HeatCapacity::InchPoundPerRankine>::ToStandard<NumericType>},
259 };
260 
261 } // namespace Internal
262 
263 } // namespace PhQ
264 
265 #endif // PHQ_UNIT_HEAT_CAPACITY_HPP
ElectricCurrent
Electric current units.
Mass
Mass units.
Definition: Mass.hpp:53
Length
Length units.
Definition: Length.hpp:53
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
HeatCapacity
Heat capacity units.
@ NanojoulePerKelvin
Nanojoule per kelvin (nJ/K) heat capacity unit.
@ InchPoundPerRankine
Inch-pound per degree Rankine (in·lbf/°R) heat capacity unit.
@ FootPoundPerRankine
Foot-pound per degree Rankine (ft·lbf/°R) heat capacity unit.
@ JoulePerKelvin
Joule per kelvin (J/K) heat capacity unit.
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)