Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
TemperatureDifference.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_TEMPERATURE_DIFFERENCE_HPP
26 #define PHQ_UNIT_TEMPERATURE_DIFFERENCE_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 Temperature difference units. Not to be confused with temperature units. For example, a
53 /// temperature difference of +20 °C corresponds to a temperature difference of +36 °F, whereas a
54 /// temperature of 20 °C corresponds to a temperature of 68 °F.
55 enum class TemperatureDifference : int8_t {
56  /// \brief Kelvin (K) temperature difference unit.
57  Kelvin,
58 
59  /// \brief Degree Celsius (°C) temperature difference unit.
60  Celsius,
61 
62  /// \brief Degree Rankine (°R) temperature difference unit.
63  Rankine,
64 
65  /// \brief Degree Fahrenheit (°F) temperature difference unit.
66  Fahrenheit,
67 };
68 
69 } // namespace Unit
70 
71 /// \brief Standard temperature difference unit: kelvin (K).
72 template <>
73 inline constexpr const Unit::TemperatureDifference Standard<Unit::TemperatureDifference>{
75 
76 /// \brief Physical dimension set of temperature difference units.
77 template <>
78 inline constexpr const Dimensions RelatedDimensions<Unit::TemperatureDifference>{
81  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
82 };
83 
84 inline std::ostream& operator<<(std::ostream& stream, const Unit::TemperatureDifference unit) {
85  stream << Abbreviation(unit);
86  return stream;
87 }
88 
89 namespace Internal {
90 
91 template <>
92 inline const std::map<UnitSystem, Unit::TemperatureDifference>
93  ConsistentUnits<Unit::TemperatureDifference>{
98 };
99 
100 template <>
101 inline const std::map<Unit::TemperatureDifference, UnitSystem>
102  RelatedUnitSystems<Unit::TemperatureDifference>{};
103 
104 // clang-format off
105 
106 template <>
107 inline const std::map<Unit::TemperatureDifference, std::string_view>
108  Abbreviations<Unit::TemperatureDifference>{
113 };
114 
115 template <>
116 inline const std::unordered_map<std::string_view, Unit::TemperatureDifference>
117  Spellings<Unit::TemperatureDifference>{
130 };
131 
132 // clang-format on
133 
134 template <>
135 template <typename NumericType>
136 inline constexpr void
137 Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Kelvin>::FromStandard(
138  NumericType& /*value*/) noexcept {}
139 
140 template <>
141 template <typename NumericType>
142 inline constexpr void
143 Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Kelvin>::ToStandard(
144  NumericType& /*value*/) noexcept {}
145 
146 template <>
147 template <typename NumericType>
148 inline constexpr void
149 Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Celsius>::FromStandard(
150  NumericType& /*value*/) noexcept {}
151 
152 template <>
153 template <typename NumericType>
154 inline constexpr void
155 Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Celsius>::ToStandard(
156  NumericType& /*value*/) noexcept {}
157 
158 template <>
159 template <typename NumericType>
160 inline constexpr void
161 Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Rankine>::FromStandard(
162  NumericType& value) noexcept {
163  value *= static_cast<NumericType>(1.8L);
164 }
165 
166 template <>
167 template <typename NumericType>
168 inline constexpr void
169 Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Rankine>::ToStandard(
170  NumericType& value) noexcept {
171  value /= static_cast<NumericType>(1.8L);
172 }
173 
174 template <>
175 template <typename NumericType>
176 inline constexpr void
177 Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Fahrenheit>::FromStandard(
178  NumericType& value) noexcept {
179  value *= static_cast<NumericType>(1.8L);
180 }
181 
182 template <>
183 template <typename NumericType>
184 inline constexpr void
185 Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Fahrenheit>::ToStandard(
186  NumericType& value) noexcept {
187  value /= static_cast<NumericType>(1.8L);
188 }
189 
190 template <typename NumericType>
191 inline const std::map<Unit::TemperatureDifference,
192  std::function<void(NumericType* values, const std::size_t size)>>
193  MapOfConversionsFromStandard<Unit::TemperatureDifference, NumericType>{
195  Conversions<Unit::TemperatureDifference,
196  Unit::TemperatureDifference::Kelvin>::FromStandard<NumericType> },
198  Conversions<Unit::TemperatureDifference,
199  Unit::TemperatureDifference::Celsius>::FromStandard<NumericType> },
201  Conversions<Unit::TemperatureDifference,
202  Unit::TemperatureDifference::Rankine>::FromStandard<NumericType> },
204  Conversions<Unit::TemperatureDifference,
205  Unit::TemperatureDifference::Fahrenheit>::FromStandard<NumericType>},
206 };
207 
208 template <typename NumericType>
209 inline const std::map<Unit::TemperatureDifference,
210  std::function<void(NumericType* const values, const std::size_t size)>>
211  MapOfConversionsToStandard<Unit::TemperatureDifference, NumericType>{
213  Conversions<Unit::TemperatureDifference,
214  Unit::TemperatureDifference::Kelvin>::ToStandard<NumericType> },
216  Conversions<Unit::TemperatureDifference,
217  Unit::TemperatureDifference::Celsius>::ToStandard<NumericType> },
219  Conversions<Unit::TemperatureDifference,
220  Unit::TemperatureDifference::Rankine>::ToStandard<NumericType> },
222  Conversions<Unit::TemperatureDifference,
223  Unit::TemperatureDifference::Fahrenheit>::ToStandard<NumericType>},
224 };
225 
226 } // namespace Internal
227 
228 } // namespace PhQ
229 
230 #endif // PHQ_UNIT_TEMPERATURE_DIFFERENCE_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
TemperatureDifference
Temperature difference units. Not to be confused with temperature units. For example,...
@ Celsius
Degree Celsius (°C) temperature difference unit.
@ Rankine
Degree Rankine (°R) temperature difference unit.
@ Kelvin
Kelvin (K) temperature difference unit.
@ Fahrenheit
Degree Fahrenheit (°F) temperature difference 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)