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_TEMPERATURE_DIFFERENCE_HPP
26 #define PHQ_TEMPERATURE_DIFFERENCE_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionalScalar.hpp"
34 
35 namespace PhQ {
36 
37 // Forward declaration for class PhQ::TemperatureDifference.
38 template <typename NumericType>
39 class Length;
40 
41 // Forward declaration for class PhQ::TemperatureDifference.
42 template <typename NumericType>
43 class LinearThermalExpansionCoefficient;
44 
45 // Forward declaration for class PhQ::TemperatureDifference.
46 template <typename NumericType>
47 class ScalarStrain;
48 
49 // Forward declaration for class PhQ::TemperatureDifference.
50 template <typename NumericType>
51 class ScalarTemperatureGradient;
52 
53 // Forward declaration for class PhQ::TemperatureDifference.
54 template <typename NumericType>
55 class Strain;
56 
57 // Forward declaration for class PhQ::TemperatureDifference.
58 template <typename NumericType>
59 class Temperature;
60 
61 // Forward declaration for class PhQ::TemperatureDifference.
62 template <typename NumericType>
63 class VolumetricThermalExpansionCoefficient;
64 
65 /// \brief Temperature difference. Not to be confused with temperature; see PhQ::Temperature. For
66 /// example, a temperature difference of 20 kelvin is very different from a temperature of 20
67 /// kelvin.
68 template <typename NumericType = double>
69 class TemperatureDifference : public DimensionalScalar<Unit::TemperatureDifference, NumericType> {
70 public:
71  /// \brief Default constructor. Constructs a temperature difference with an uninitialized value.
72  TemperatureDifference() = default;
73 
74  /// \brief Constructor. Constructs a temperature difference with a given value expressed in a
75  /// given temperature unit.
77  : DimensionalScalar<Unit::TemperatureDifference, NumericType>(value, unit) {}
78 
79  /// \brief Constructor. Constructs a temperature difference from a given scalar temperature
80  /// gradient and length using the definition of temperature gradient.
82  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient,
83  const Length<NumericType>& length);
84 
85  /// \brief Destructor. Destroys this temperature difference.
86  ~TemperatureDifference() noexcept = default;
87 
88  /// \brief Copy constructor. Constructs a temperature difference by copying another one.
89  constexpr TemperatureDifference(const TemperatureDifference<NumericType>& other) = default;
90 
91  /// \brief Copy constructor. Constructs a temperature difference by copying another one.
92  template <typename OtherNumericType>
93  explicit constexpr TemperatureDifference(const TemperatureDifference<OtherNumericType>& other)
94  : TemperatureDifference(static_cast<NumericType>(other.Value())) {}
95 
96  /// \brief Move constructor. Constructs a temperature difference by moving another one.
97  constexpr TemperatureDifference(TemperatureDifference<NumericType>&& other) noexcept = default;
98 
99  /// \brief Copy assignment operator. Assigns this temperature difference by copying another one.
101  const TemperatureDifference<NumericType>& other) = default;
102 
103  /// \brief Copy assignment operator. Assigns this temperature difference by copying another one.
104  template <typename OtherNumericType>
107  this->value = static_cast<NumericType>(other.Value());
108  return *this;
109  }
110 
111  /// \brief Move assignment operator. Assigns this temperature difference by moving another one.
113  TemperatureDifference<NumericType>&& other) noexcept = default;
114 
115  /// \brief Statically creates a temperature difference of absolute zero.
116  [[nodiscard]] static constexpr TemperatureDifference<NumericType> Zero() {
117  return TemperatureDifference<NumericType>{static_cast<NumericType>(0)};
118  }
119 
120  /// \brief Statically creates a temperature difference with a given value expressed in a given
121  /// temperature unit.
122  template <Unit::TemperatureDifference Unit>
123  [[nodiscard]] static constexpr TemperatureDifference<NumericType> Create(
124  const NumericType value) {
126  ConvertStatically<Unit::TemperatureDifference, Unit, Standard<Unit::TemperatureDifference>>(
127  value)};
128  }
129 
130  constexpr Temperature<NumericType> operator+(const Temperature<NumericType>& temperature) const;
131 
133  const TemperatureDifference<NumericType>& temperature_difference) const {
134  return TemperatureDifference<NumericType>{this->value + temperature_difference.value};
135  }
136 
137  constexpr Temperature<NumericType> operator-(const Temperature<NumericType>& temperature) const;
138 
140  const TemperatureDifference<NumericType>& temperature_difference) const {
141  return TemperatureDifference<NumericType>{this->value - temperature_difference.value};
142  }
143 
144  constexpr TemperatureDifference<NumericType> operator*(const NumericType number) const {
145  return TemperatureDifference<NumericType>{this->value * number};
146  }
147 
149  const LinearThermalExpansionCoefficient<NumericType>& linear_thermal_expansion_coefficient)
150  const;
151 
153  volumetric_thermal_expansion_coefficient) const;
154 
155  constexpr TemperatureDifference<NumericType> operator/(const NumericType number) const {
156  return TemperatureDifference<NumericType>{this->value / number};
157  }
158 
160  const Length<NumericType>& length) const;
161 
162  constexpr NumericType operator/(
163  const TemperatureDifference<NumericType>& temperature_difference) const noexcept {
164  return this->value / temperature_difference.value;
165  }
166 
167  constexpr void operator+=(
168  const TemperatureDifference<NumericType>& temperature_difference) noexcept {
169  this->value += temperature_difference.value;
170  }
171 
172  constexpr void operator-=(
173  const TemperatureDifference<NumericType>& temperature_difference) noexcept {
174  this->value -= temperature_difference.value;
175  }
176 
177  constexpr void operator*=(const NumericType number) noexcept {
178  this->value *= number;
179  }
180 
181  constexpr void operator/=(const NumericType number) noexcept {
182  this->value /= number;
183  }
184 
185 private:
186  /// \brief Constructor. Constructs a temperature difference with a given value expressed in the
187  /// standard temperature difference unit.
188  explicit constexpr TemperatureDifference(const NumericType value)
190 
191  template <typename OtherNumericType>
192  friend class Temperature;
193 };
194 
195 template <typename NumericType>
196 inline constexpr bool operator==(const TemperatureDifference<NumericType>& left,
197  const TemperatureDifference<NumericType>& right) noexcept {
198  return left.Value() == right.Value();
199 }
200 
201 template <typename NumericType>
202 inline constexpr bool operator!=(const TemperatureDifference<NumericType>& left,
203  const TemperatureDifference<NumericType>& right) noexcept {
204  return left.Value() != right.Value();
205 }
206 
207 template <typename NumericType>
208 inline constexpr bool operator<(const TemperatureDifference<NumericType>& left,
209  const TemperatureDifference<NumericType>& right) noexcept {
210  return left.Value() < right.Value();
211 }
212 
213 template <typename NumericType>
214 inline constexpr bool operator>(const TemperatureDifference<NumericType>& left,
215  const TemperatureDifference<NumericType>& right) noexcept {
216  return left.Value() > right.Value();
217 }
218 
219 template <typename NumericType>
220 inline constexpr bool operator<=(const TemperatureDifference<NumericType>& left,
221  const TemperatureDifference<NumericType>& right) noexcept {
222  return left.Value() <= right.Value();
223 }
224 
225 template <typename NumericType>
226 inline constexpr bool operator>=(const TemperatureDifference<NumericType>& left,
227  const TemperatureDifference<NumericType>& right) noexcept {
228  return left.Value() >= right.Value();
229 }
230 
231 template <typename NumericType>
232 inline std::ostream& operator<<(
233  std::ostream& stream, const TemperatureDifference<NumericType>& temperature_difference) {
234  stream << temperature_difference.Print();
235  return stream;
236 }
237 
238 template <typename NumericType>
240  const NumericType number, const TemperatureDifference<NumericType>& temperature_difference) {
241  return temperature_difference * number;
242 }
243 
244 } // namespace PhQ
245 
246 namespace std {
247 
248 template <typename NumericType>
249 struct hash<PhQ::TemperatureDifference<NumericType>> {
250  inline size_t operator()(
251  const PhQ::TemperatureDifference<NumericType>& temperature_difference) const {
252  return hash<NumericType>()(temperature_difference.Value());
253  }
254 };
255 
256 } // namespace std
257 
258 #endif // PHQ_TEMPERATURE_DIFFERENCE_HPP
Abstract base class that represents any dimensional scalar physical quantity. Such a physical quantit...
double value
Value of this physical quantity expressed in its standard unit of measure.
constexpr double Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr Unit::TemperatureDifference Unit()
Standard unit of measure for this physical quantity. This physical quantity's value is stored interna...
std::string Print() const
Prints this physical quantity as a string. This physical quantity's value is expressed in its standar...
Length, distance, or physical size. Can also represent a scalar component or magnitude of a position ...
Definition: Length.hpp:111
Linear thermal expansion coefficient. Not to be confused with the volumetric thermal expansion coeffi...
Scalar component or resultant of a three-dimensional Euclidean strain symmetric dyadic tensor....
Scalar temperature gradient component or magnitude of a temperature gradient vector....
Three-dimensional Euclidean strain symmetric dyadic tensor. Contains six components in Cartesian coor...
Definition: Strain.hpp:68
Temperature difference. Not to be confused with temperature; see PhQ::Temperature....
constexpr void operator+=(const TemperatureDifference< NumericType > &temperature_difference) noexcept
constexpr TemperatureDifference< NumericType > operator/(const NumericType number) const
static constexpr TemperatureDifference< NumericType > Zero()
Statically creates a temperature difference of absolute zero.
constexpr TemperatureDifference< NumericType > operator*(const NumericType number) const
constexpr TemperatureDifference(const NumericType value)
Constructor. Constructs a temperature difference with a given value expressed in the standard tempera...
constexpr void operator/=(const NumericType number) noexcept
~TemperatureDifference() noexcept=default
Destructor. Destroys this temperature difference.
constexpr TemperatureDifference< NumericType > & operator=(const TemperatureDifference< OtherNumericType > &other)
Copy assignment operator. Assigns this temperature difference by copying another one.
constexpr ScalarStrain< NumericType > operator*(const LinearThermalExpansionCoefficient< NumericType > &linear_thermal_expansion_coefficient) const
constexpr Temperature< NumericType > operator+(const Temperature< NumericType > &temperature) const
TemperatureDifference(const NumericType value, const Unit::TemperatureDifference unit)
Constructor. Constructs a temperature difference with a given value expressed in a given temperature ...
constexpr Temperature< NumericType > operator-(const Temperature< NumericType > &temperature) const
constexpr void operator-=(const TemperatureDifference< NumericType > &temperature_difference) noexcept
constexpr TemperatureDifference< NumericType > & operator=(TemperatureDifference< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this temperature difference by moving another one.
constexpr ScalarTemperatureGradient< NumericType > operator/(const Length< NumericType > &length) const
constexpr TemperatureDifference(TemperatureDifference< NumericType > &&other) noexcept=default
Move constructor. Constructs a temperature difference by moving another one.
static constexpr TemperatureDifference< NumericType > Create(const NumericType value)
Statically creates a temperature difference with a given value expressed in a given temperature unit.
constexpr TemperatureDifference(const ScalarTemperatureGradient< NumericType > &scalar_temperature_gradient, const Length< NumericType > &length)
Constructor. Constructs a temperature difference from a given scalar temperature gradient and length ...
constexpr TemperatureDifference< NumericType > & operator=(const TemperatureDifference< NumericType > &other)=default
Copy assignment operator. Assigns this temperature difference by copying another one.
constexpr NumericType operator/(const TemperatureDifference< NumericType > &temperature_difference) const noexcept
constexpr Strain< NumericType > operator*(const VolumetricThermalExpansionCoefficient< NumericType > &volumetric_thermal_expansion_coefficient) const
TemperatureDifference()=default
Default constructor. Constructs a temperature difference with an uninitialized value.
constexpr void operator*=(const NumericType number) noexcept
constexpr TemperatureDifference< NumericType > operator+(const TemperatureDifference< NumericType > &temperature_difference) const
constexpr TemperatureDifference< NumericType > operator-(const TemperatureDifference< NumericType > &temperature_difference) const
Temperature. For a temperature difference, see PhQ::TemperatureDifference. For the gradient of temper...
Definition: Temperature.hpp:41
Volumetric thermal expansion coefficient. Not to be confused with the linear thermal expansion coeffi...
Length
Length units.
Definition: Length.hpp:53
Temperature
Temperature units. Not to be confused with temperature difference units. For example,...
Definition: Temperature.hpp:55
TemperatureDifference
Temperature difference units. Not to be confused with temperature units. For example,...
Namespace that encompasses all of the Physical Quantities library's content.
constexpr bool operator<(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator<=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr Acceleration< NumericType > operator*(const NumericType number, const Acceleration< NumericType > &acceleration)
constexpr bool operator>(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator==(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator>=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator!=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)