Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Loading...
Searching...
No Matches
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
48namespace PhQ {
49
50namespace 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.
55enum 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.
67};
68
69} // namespace Unit
70
71/// \brief Standard temperature difference unit: kelvin (K).
72template <>
73inline constexpr const Unit::TemperatureDifference Standard<Unit::TemperatureDifference>{
75
76/// \brief Physical dimension set of temperature difference units.
77template <>
78inline constexpr const Dimensions RelatedDimensions<Unit::TemperatureDifference>{
79 Dimensions{Dimension::Time{0}, Dimension::Length{0}, Dimension::Mass{0},
80 Dimension::ElectricCurrent{0}, Dimension::Temperature{1},
81 Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
82};
83
84inline std::ostream& operator<<(std::ostream& stream, const Unit::TemperatureDifference unit) {
85 stream << Abbreviation(unit);
86 return stream;
87}
88
89namespace Internal {
90
91template <>
92inline const std::map<UnitSystem, Unit::TemperatureDifference>
93 ConsistentUnits<Unit::TemperatureDifference>{
98};
99
100template <>
101inline const std::map<Unit::TemperatureDifference, UnitSystem>
102 RelatedUnitSystems<Unit::TemperatureDifference>{};
103
104// clang-format off
105
106template <>
107inline const std::map<Unit::TemperatureDifference, std::string_view>
108 Abbreviations<Unit::TemperatureDifference>{
113};
114
115template <>
116inline const std::unordered_map<std::string_view, Unit::TemperatureDifference>
117 Spellings<Unit::TemperatureDifference>{
130};
131
132// clang-format on
133
134template <>
135template <typename NumericType>
136inline constexpr void Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Kelvin>::
137 FromStandard(NumericType& /*value*/) noexcept {}
138
139template <>
140template <typename NumericType>
141inline constexpr void Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Kelvin>::
142 ToStandard(NumericType& /*value*/) noexcept {}
143
144template <>
145template <typename NumericType>
146inline constexpr void
147Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Celsius>::FromStandard(
148 NumericType& /*value*/) noexcept {}
149
150template <>
151template <typename NumericType>
152inline constexpr void
153Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Celsius>::ToStandard(
154 NumericType& /*value*/) noexcept {}
155
156template <>
157template <typename NumericType>
158inline constexpr void
159Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Rankine>::FromStandard(
160 NumericType& value) noexcept {
161 value *= static_cast<NumericType>(1.8L);
162}
163
164template <>
165template <typename NumericType>
166inline constexpr void
167Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Rankine>::ToStandard(
168 NumericType& value) noexcept {
169 value /= static_cast<NumericType>(1.8L);
170}
171
172template <>
173template <typename NumericType>
174inline constexpr void
175Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Fahrenheit>::FromStandard(
176 NumericType& value) noexcept {
177 value *= static_cast<NumericType>(1.8L);
178}
179
180template <>
181template <typename NumericType>
182inline constexpr void
183Conversion<Unit::TemperatureDifference, Unit::TemperatureDifference::Fahrenheit>::ToStandard(
184 NumericType& value) noexcept {
185 value /= static_cast<NumericType>(1.8L);
186}
187
188template <typename NumericType>
189inline const std::map<Unit::TemperatureDifference,
190 std::function<void(NumericType* values, const std::size_t size)>>
191 MapOfConversionsFromStandard<Unit::TemperatureDifference, NumericType>{
193 Conversions<Unit::TemperatureDifference, Unit::TemperatureDifference::Kelvin>::
194 FromStandard<NumericType>},
196 Conversions<Unit::TemperatureDifference, Unit::TemperatureDifference::Celsius>::
197 FromStandard<NumericType>},
199 Conversions<Unit::TemperatureDifference, Unit::TemperatureDifference::Rankine>::
200 FromStandard<NumericType>},
202 Conversions<Unit::TemperatureDifference, Unit::TemperatureDifference::Fahrenheit>::
203 FromStandard<NumericType>},
204};
205
206template <typename NumericType>
207inline const std::map<Unit::TemperatureDifference,
208 std::function<void(NumericType* const values, const std::size_t size)>>
209 MapOfConversionsToStandard<Unit::TemperatureDifference, NumericType>{
211 Conversions<Unit::TemperatureDifference, Unit::TemperatureDifference::Kelvin>::
212 ToStandard<NumericType>},
214 Conversions<Unit::TemperatureDifference, Unit::TemperatureDifference::Celsius>::
215 ToStandard<NumericType>},
217 Conversions<Unit::TemperatureDifference, Unit::TemperatureDifference::Rankine>::
218 ToStandard<NumericType>},
220 Conversions<Unit::TemperatureDifference, Unit::TemperatureDifference::Fahrenheit>::
221 ToStandard<NumericType>},
222};
223
224} // namespace Internal
225
226} // namespace PhQ
227
228#endif // PHQ_UNIT_TEMPERATURE_DIFFERENCE_HPP
@ Celsius
Degree Celsius (°C) temperature unit.
@ Rankine
Degree Rankine (°R) temperature unit.
@ Kelvin
Kelvin (K) temperature unit.
@ Fahrenheit
Degree Fahrenheit (°F) temperature unit.
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.
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)
@ 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