Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
ReciprocalTemperature.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_RECIPROCAL_TEMPERATURE_HPP
26 #define PHQ_UNIT_RECIPROCAL_TEMPERATURE_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 Reciprocal temperature units. Reciprocal temperature is the inverse of temperature.
53 enum class ReciprocalTemperature : int8_t {
54  /// \brief Per kelvin (/K) reciprocal temperature unit.
55  PerKelvin,
56 
57  /// \brief Per degree Celsius (/°C) reciprocal temperature unit.
58  PerCelsius,
59 
60  /// \brief Per degree Rankine (/°R) reciprocal temperature unit.
61  PerRankine,
62 
63  /// \brief Per degree Fahrenheit (/°F) reciprocal temperature unit.
65 };
66 
67 } // namespace Unit
68 
69 /// \brief Standard reciprocal temperature unit: per kelvin (/K).
70 template <>
71 inline constexpr const Unit::ReciprocalTemperature Standard<Unit::ReciprocalTemperature>{
73 
74 /// \brief Physical dimension set of reciprocal temperature units.
75 template <>
76 inline constexpr const Dimensions RelatedDimensions<Unit::ReciprocalTemperature>{
79  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
80 };
81 
82 inline std::ostream& operator<<(std::ostream& stream, const Unit::ReciprocalTemperature unit) {
83  stream << Abbreviation(unit);
84  return stream;
85 }
86 
87 namespace Internal {
88 
89 template <>
90 inline const std::map<UnitSystem, Unit::ReciprocalTemperature>
91  ConsistentUnits<Unit::ReciprocalTemperature>{
96 };
97 
98 template <>
99 inline const std::map<Unit::ReciprocalTemperature, UnitSystem>
100  RelatedUnitSystems<Unit::ReciprocalTemperature>{};
101 
102 // clang-format off
103 
104 template <>
105 inline const std::map<Unit::ReciprocalTemperature, std::string_view>
106  Abbreviations<Unit::ReciprocalTemperature>{
111 };
112 
113 template <>
114 inline const std::unordered_map<std::string_view, Unit::ReciprocalTemperature>
115  Spellings<Unit::ReciprocalTemperature>{
140 };
141 
142 // clang-format on
143 
144 template <>
145 template <typename NumericType>
146 inline constexpr void
147 Conversion<Unit::ReciprocalTemperature, Unit::ReciprocalTemperature::PerKelvin>::FromStandard(
148  NumericType& /*value*/) noexcept {}
149 
150 template <>
151 template <typename NumericType>
152 inline constexpr void
153 Conversion<Unit::ReciprocalTemperature, Unit::ReciprocalTemperature::PerKelvin>::ToStandard(
154  NumericType& /*value*/) noexcept {}
155 
156 template <>
157 template <typename NumericType>
158 inline constexpr void
159 Conversion<Unit::ReciprocalTemperature, Unit::ReciprocalTemperature::PerCelsius>::FromStandard(
160  NumericType& /*value*/) noexcept {}
161 
162 template <>
163 template <typename NumericType>
164 inline constexpr void
165 Conversion<Unit::ReciprocalTemperature, Unit::ReciprocalTemperature::PerCelsius>::ToStandard(
166  NumericType& /*value*/) noexcept {}
167 
168 template <>
169 template <typename NumericType>
170 inline constexpr void
171 Conversion<Unit::ReciprocalTemperature, Unit::ReciprocalTemperature::PerRankine>::FromStandard(
172  NumericType& value) noexcept {
173  value /= static_cast<NumericType>(1.8L);
174 }
175 
176 template <>
177 template <typename NumericType>
178 inline constexpr void
179 Conversion<Unit::ReciprocalTemperature, Unit::ReciprocalTemperature::PerRankine>::ToStandard(
180  NumericType& value) noexcept {
181  value *= static_cast<NumericType>(1.8L);
182 }
183 
184 template <>
185 template <typename NumericType>
186 inline constexpr void
187 Conversion<Unit::ReciprocalTemperature, Unit::ReciprocalTemperature::PerFahrenheit>::FromStandard(
188  NumericType& value) noexcept {
189  value /= static_cast<NumericType>(1.8L);
190 }
191 
192 template <>
193 template <typename NumericType>
194 inline constexpr void
195 Conversion<Unit::ReciprocalTemperature, Unit::ReciprocalTemperature::PerFahrenheit>::ToStandard(
196  NumericType& value) noexcept {
197  value *= static_cast<NumericType>(1.8L);
198 }
199 
200 template <typename NumericType>
201 inline const std::map<Unit::ReciprocalTemperature,
202  std::function<void(NumericType* values, const std::size_t size)>>
203  MapOfConversionsFromStandard<Unit::ReciprocalTemperature, NumericType>{
205  Conversions<Unit::ReciprocalTemperature,
206  Unit::ReciprocalTemperature::PerKelvin>::FromStandard<NumericType> },
208  Conversions<Unit::ReciprocalTemperature,
209  Unit::ReciprocalTemperature::PerCelsius>::FromStandard<NumericType> },
211  Conversions<Unit::ReciprocalTemperature,
212  Unit::ReciprocalTemperature::PerRankine>::FromStandard<NumericType> },
214  Conversions<Unit::ReciprocalTemperature,
215  Unit::ReciprocalTemperature::PerFahrenheit>::FromStandard<NumericType>},
216 };
217 
218 template <typename NumericType>
219 inline const std::map<Unit::ReciprocalTemperature,
220  std::function<void(NumericType* const values, const std::size_t size)>>
221  MapOfConversionsToStandard<Unit::ReciprocalTemperature, NumericType>{
223  Conversions<Unit::ReciprocalTemperature,
224  Unit::ReciprocalTemperature::PerKelvin>::ToStandard<NumericType> },
226  Conversions<Unit::ReciprocalTemperature,
227  Unit::ReciprocalTemperature::PerCelsius>::ToStandard<NumericType> },
229  Conversions<Unit::ReciprocalTemperature,
230  Unit::ReciprocalTemperature::PerRankine>::ToStandard<NumericType> },
232  Conversions<Unit::ReciprocalTemperature,
233  Unit::ReciprocalTemperature::PerFahrenheit>::ToStandard<NumericType>},
234 };
235 
236 } // namespace Internal
237 
238 } // namespace PhQ
239 
240 #endif // PHQ_UNIT_RECIPROCAL_TEMPERATURE_HPP
ReciprocalTemperature
Reciprocal temperature units. Reciprocal temperature is the inverse of temperature.
@ PerKelvin
Per kelvin (/K) reciprocal temperature unit.
@ PerCelsius
Per degree Celsius (/°C) reciprocal temperature unit.
@ PerFahrenheit
Per degree Fahrenheit (/°F) reciprocal temperature unit.
@ PerRankine
Per degree Rankine (/°R) reciprocal temperature unit.
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
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)