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_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
35namespace PhQ {
36
37// Forward declaration for class PhQ::TemperatureDifference.
38template <typename NumericType>
39class Length;
40
41// Forward declaration for class PhQ::TemperatureDifference.
42template <typename NumericType>
43class LinearThermalExpansionCoefficient;
44
45// Forward declaration for class PhQ::TemperatureDifference.
46template <typename NumericType>
47class ScalarStrain;
48
49// Forward declaration for class PhQ::TemperatureDifference.
50template <typename NumericType>
51class ScalarTemperatureGradient;
52
53// Forward declaration for class PhQ::TemperatureDifference.
54template <typename NumericType>
55class Strain;
56
57// Forward declaration for class PhQ::TemperatureDifference.
58template <typename NumericType>
59class Temperature;
60
61// Forward declaration for class PhQ::TemperatureDifference.
62template <typename NumericType>
63class 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.
68template <typename NumericType = double>
69class TemperatureDifference : public DimensionalScalar<Unit::TemperatureDifference, NumericType> {
70public:
71 /// \brief Default constructor. Constructs a temperature difference with an uninitialized value.
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.
81 constexpr TemperatureDifference(
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
185private:
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
195template <typename NumericType>
196inline constexpr bool operator==(const TemperatureDifference<NumericType>& left,
197 const TemperatureDifference<NumericType>& right) noexcept {
198 return left.Value() == right.Value();
199}
200
201template <typename NumericType>
202inline constexpr bool operator!=(const TemperatureDifference<NumericType>& left,
203 const TemperatureDifference<NumericType>& right) noexcept {
204 return left.Value() != right.Value();
205}
206
207template <typename NumericType>
208inline constexpr bool operator<(const TemperatureDifference<NumericType>& left,
209 const TemperatureDifference<NumericType>& right) noexcept {
210 return left.Value() < right.Value();
211}
212
213template <typename NumericType>
214inline constexpr bool operator>(const TemperatureDifference<NumericType>& left,
215 const TemperatureDifference<NumericType>& right) noexcept {
216 return left.Value() > right.Value();
217}
218
219template <typename NumericType>
220inline constexpr bool operator<=(const TemperatureDifference<NumericType>& left,
221 const TemperatureDifference<NumericType>& right) noexcept {
222 return left.Value() <= right.Value();
223}
224
225template <typename NumericType>
226inline constexpr bool operator>=(const TemperatureDifference<NumericType>& left,
227 const TemperatureDifference<NumericType>& right) noexcept {
228 return left.Value() >= right.Value();
229}
230
231template <typename NumericType>
232inline std::ostream& operator<<(
233 std::ostream& stream, const TemperatureDifference<NumericType>& temperature_difference) {
234 stream << temperature_difference.Print();
235 return stream;
236}
237
238template <typename NumericType>
240 const NumericType number, const TemperatureDifference<NumericType>& temperature_difference) {
241 return temperature_difference * number;
242}
243
244} // namespace PhQ
245
246namespace std {
247
248template <typename NumericType>
249struct 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...
NumericType value
Value of this physical quantity expressed in its standard unit of measure.
constexpr NumericType Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr UnitType 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(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 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 TemperatureDifference< NumericType > & operator=(TemperatureDifference< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this temperature difference by moving another one.
constexpr void operator-=(const TemperatureDifference< NumericType > &temperature_difference) noexcept
constexpr TemperatureDifference< NumericType > operator-(const TemperatureDifference< NumericType > &temperature_difference) const
constexpr TemperatureDifference< NumericType > & operator=(const TemperatureDifference< OtherNumericType > &other)
Copy assignment operator. Assigns this temperature difference by copying another one.
constexpr TemperatureDifference< NumericType > operator+(const TemperatureDifference< NumericType > &temperature_difference) const
constexpr TemperatureDifference(TemperatureDifference< NumericType > &&other) noexcept=default
Move constructor. Constructs a temperature difference by moving another one.
static constexpr TemperatureDifference< NumericType > Zero()
Statically creates a temperature difference of absolute zero.
constexpr TemperatureDifference< NumericType > operator/(const NumericType number) const
constexpr TemperatureDifference< NumericType > operator*(const NumericType number) const
static constexpr TemperatureDifference< NumericType > Create(const NumericType value)
Statically creates a temperature difference with a given value expressed in a given temperature unit.
constexpr Temperature< NumericType > operator-(const Temperature< NumericType > &temperature) const
constexpr NumericType operator/(const TemperatureDifference< NumericType > &temperature_difference) const noexcept
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 > &other)=default
Copy assignment operator. Assigns this temperature difference by copying another one.
Temperature. For a temperature difference, see PhQ::TemperatureDifference. For the gradient of temper...
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,...
TemperatureDifference
Temperature difference units. Not to be confused with temperature units. For example,...
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, 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 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