Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
TemperatureGradient.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_GRADIENT_HPP
26 #define PHQ_UNIT_TEMPERATURE_GRADIENT_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 gradient units.
53 enum class TemperatureGradient : int8_t {
54  /// \brief Kelvin per metre (K/m) temperature gradient unit.
56 
57  /// \brief Kelvin per millimetre (K/mm) temperature gradient unit.
59 
60  /// \brief Degree Celsius per metre (°C/m) temperature gradient unit.
62 
63  /// \brief Degree Celsius per millimetre (°C/mm) temperature gradient unit.
65 
66  /// \brief Degree Rankine per foot (°R/ft) temperature gradient unit.
68 
69  /// \brief Degree Rankine per inch (°R/in) temperature gradient unit.
71 
72  /// \brief Degree Fahrenheit per foot (°F/ft) temperature gradient unit.
74 
75  /// \brief Degree Fahrenheit per inch (°F/in) temperature gradient unit.
77 };
78 
79 } // namespace Unit
80 
81 /// \brief Standard temperature gradient unit: kelvin per metre (K/m).
82 template <>
83 inline constexpr const Unit::TemperatureGradient Standard<Unit::TemperatureGradient>{
85 
86 /// \brief Physical dimension set of temperature gradient units.
87 template <>
88 inline constexpr const Dimensions RelatedDimensions<Unit::TemperatureGradient>{
89  Dimensions{Dimension::Time{0}, Dimension::Length{-1}, Dimension::Mass{0},
91  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
92 };
93 
94 inline std::ostream& operator<<(std::ostream& stream, const Unit::TemperatureGradient unit) {
95  stream << Abbreviation(unit);
96  return stream;
97 }
98 
99 namespace Internal {
100 
101 template <>
102 inline const std::map<UnitSystem, Unit::TemperatureGradient>
103  ConsistentUnits<Unit::TemperatureGradient>{
108 };
109 
110 template <>
111 inline const std::map<Unit::TemperatureGradient, UnitSystem>
112  RelatedUnitSystems<Unit::TemperatureGradient>{
117 };
118 
119 // clang-format off
120 
121 template <>
122 inline const std::map<Unit::TemperatureGradient, std::string_view>
123  Abbreviations<Unit::TemperatureGradient>{
132 };
133 
134 template <>
135 inline const std::unordered_map<std::string_view, Unit::TemperatureGradient>
136  Spellings<Unit::TemperatureGradient>{
161 };
162 
163 // clang-format on
164 
165 template <>
166 template <typename NumericType>
167 inline constexpr void
168 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::KelvinPerMetre>::FromStandard(
169  NumericType& /*value*/) noexcept {}
170 
171 template <>
172 template <typename NumericType>
173 inline constexpr void
174 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::KelvinPerMetre>::ToStandard(
175  NumericType& /*value*/) noexcept {}
176 
177 template <>
178 template <typename NumericType>
179 inline constexpr void
180 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::KelvinPerMillimetre>::FromStandard(
181  NumericType& value) noexcept {
182  value *= static_cast<NumericType>(0.001L);
183 }
184 
185 template <>
186 template <typename NumericType>
187 inline constexpr void
188 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::KelvinPerMillimetre>::ToStandard(
189  NumericType& value) noexcept {
190  value *= static_cast<NumericType>(1000.0L);
191 }
192 
193 template <>
194 template <typename NumericType>
195 inline constexpr void
196 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::CelsiusPerMetre>::FromStandard(
197  NumericType& /*value*/) noexcept {}
198 
199 template <>
200 template <typename NumericType>
201 inline constexpr void
202 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::CelsiusPerMetre>::ToStandard(
203  NumericType& /*value*/) noexcept {}
204 
205 template <>
206 template <typename NumericType>
207 inline constexpr void
208 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::CelsiusPerMillimetre>::
209  FromStandard(NumericType& value) noexcept {
210  value *= static_cast<NumericType>(0.001L);
211 }
212 
213 template <>
214 template <typename NumericType>
215 inline constexpr void
216 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::CelsiusPerMillimetre>::ToStandard(
217  NumericType& value) noexcept {
218  value *= static_cast<NumericType>(1000.0L);
219 }
220 
221 template <>
222 template <typename NumericType>
223 inline constexpr void
224 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::RankinePerFoot>::FromStandard(
225  NumericType& value) noexcept {
226  value *= static_cast<NumericType>(1.8L) * static_cast<NumericType>(0.3048L);
227 }
228 
229 template <>
230 template <typename NumericType>
231 inline constexpr void
232 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::RankinePerFoot>::ToStandard(
233  NumericType& value) noexcept {
234  value /= (static_cast<NumericType>(1.8L) * static_cast<NumericType>(0.3048L));
235 }
236 
237 template <>
238 template <typename NumericType>
239 inline constexpr void
240 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::RankinePerInch>::FromStandard(
241  NumericType& value) noexcept {
242  value *= static_cast<NumericType>(1.8L) * static_cast<NumericType>(0.0254L);
243 }
244 
245 template <>
246 template <typename NumericType>
247 inline constexpr void
248 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::RankinePerInch>::ToStandard(
249  NumericType& value) noexcept {
250  value /= (static_cast<NumericType>(1.8L) * static_cast<NumericType>(0.0254L));
251 }
252 
253 template <>
254 template <typename NumericType>
255 inline constexpr void
256 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::FahrenheitPerFoot>::FromStandard(
257  NumericType& value) noexcept {
258  value *= static_cast<NumericType>(1.8L) * static_cast<NumericType>(0.3048L);
259 }
260 
261 template <>
262 template <typename NumericType>
263 inline constexpr void
264 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::FahrenheitPerFoot>::ToStandard(
265  NumericType& value) noexcept {
266  value /= (static_cast<NumericType>(1.8L) * static_cast<NumericType>(0.3048L));
267 }
268 
269 template <>
270 template <typename NumericType>
271 inline constexpr void
272 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::FahrenheitPerInch>::FromStandard(
273  NumericType& value) noexcept {
274  value *= static_cast<NumericType>(1.8L) * static_cast<NumericType>(0.0254L);
275 }
276 
277 template <>
278 template <typename NumericType>
279 inline constexpr void
280 Conversion<Unit::TemperatureGradient, Unit::TemperatureGradient::FahrenheitPerInch>::ToStandard(
281  NumericType& value) noexcept {
282  value /= (static_cast<NumericType>(1.8L) * static_cast<NumericType>(0.0254L));
283 }
284 
285 template <typename NumericType>
286 inline const std::map<Unit::TemperatureGradient,
287  std::function<void(NumericType* values, const std::size_t size)>>
288  MapOfConversionsFromStandard<Unit::TemperatureGradient, NumericType>{
290  Conversions<Unit::TemperatureGradient,
291  Unit::TemperatureGradient::KelvinPerMetre>::FromStandard<NumericType> },
293  Conversions<Unit::TemperatureGradient,
294  Unit::TemperatureGradient::KelvinPerMillimetre>::FromStandard<NumericType> },
296  Conversions<Unit::TemperatureGradient,
297  Unit::TemperatureGradient::CelsiusPerMetre>::FromStandard<NumericType> },
299  Conversions<Unit::TemperatureGradient,
300  Unit::TemperatureGradient::CelsiusPerMillimetre>::FromStandard<NumericType>},
302  Conversions<Unit::TemperatureGradient,
303  Unit::TemperatureGradient::RankinePerFoot>::FromStandard<NumericType> },
305  Conversions<Unit::TemperatureGradient,
306  Unit::TemperatureGradient::RankinePerInch>::FromStandard<NumericType> },
308  Conversions<Unit::TemperatureGradient,
309  Unit::TemperatureGradient::FahrenheitPerFoot>::FromStandard<NumericType> },
311  Conversions<Unit::TemperatureGradient,
312  Unit::TemperatureGradient::FahrenheitPerInch>::FromStandard<NumericType> },
313 };
314 
315 template <typename NumericType>
316 inline const std::map<Unit::TemperatureGradient,
317  std::function<void(NumericType* const values, const std::size_t size)>>
318  MapOfConversionsToStandard<Unit::TemperatureGradient, NumericType>{
320  Conversions<Unit::TemperatureGradient,
321  Unit::TemperatureGradient::KelvinPerMetre>::ToStandard<NumericType> },
323  Conversions<Unit::TemperatureGradient,
324  Unit::TemperatureGradient::KelvinPerMillimetre>::ToStandard<NumericType> },
326  Conversions<Unit::TemperatureGradient,
327  Unit::TemperatureGradient::CelsiusPerMetre>::ToStandard<NumericType> },
329  Conversions<Unit::TemperatureGradient,
330  Unit::TemperatureGradient::CelsiusPerMillimetre>::ToStandard<NumericType>},
332  Conversions<Unit::TemperatureGradient,
333  Unit::TemperatureGradient::RankinePerFoot>::ToStandard<NumericType> },
335  Conversions<Unit::TemperatureGradient,
336  Unit::TemperatureGradient::RankinePerInch>::ToStandard<NumericType> },
338  Conversions<Unit::TemperatureGradient,
339  Unit::TemperatureGradient::FahrenheitPerFoot>::ToStandard<NumericType> },
341  Conversions<Unit::TemperatureGradient,
342  Unit::TemperatureGradient::FahrenheitPerInch>::ToStandard<NumericType> },
343 };
344 
345 } // namespace Internal
346 
347 } // namespace PhQ
348 
349 #endif // PHQ_UNIT_TEMPERATURE_GRADIENT_HPP
ElectricCurrent
Electric current units.
TemperatureGradient
Temperature gradient units.
@ RankinePerInch
Degree Rankine per inch (°R/in) temperature gradient unit.
@ FahrenheitPerInch
Degree Fahrenheit per inch (°F/in) temperature gradient unit.
@ CelsiusPerMetre
Degree Celsius per metre (°C/m) temperature gradient unit.
@ FahrenheitPerFoot
Degree Fahrenheit per foot (°F/ft) temperature gradient unit.
@ RankinePerFoot
Degree Rankine per foot (°R/ft) temperature gradient unit.
@ CelsiusPerMillimetre
Degree Celsius per millimetre (°C/mm) temperature gradient unit.
@ KelvinPerMetre
Kelvin per metre (K/m) temperature gradient unit.
@ KelvinPerMillimetre
Kelvin per millimetre (K/mm) temperature gradient unit.
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)