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_TEMPERATURE_GRADIENT_HPP
26 #define PHQ_TEMPERATURE_GRADIENT_HPP
27 
28 #include <array>
29 #include <cstddef>
30 #include <functional>
31 #include <ostream>
32 
33 #include "Angle.hpp"
34 #include "DimensionalVector.hpp"
35 #include "Direction.hpp"
39 #include "Vector.hpp"
40 
41 namespace PhQ {
42 
43 /// \brief Three-dimensional Euclidean temperature gradient vector. Contains three components in
44 /// Cartesian coordinates: x, y, and z. For a two-dimensional Euclidean temperature gradient vector
45 /// in the XY plane, see PhQ::PlanarTemperatureGradient. For scalar temperature gradient components
46 /// or for the magnitude of a temperature gradient vector, see PhQ::ScalarTemperatureGradient.
47 template <typename NumericType = double>
48 class TemperatureGradient : public DimensionalVector<Unit::TemperatureGradient, NumericType> {
49 public:
50  /// \brief Default constructor. Constructs a temperature gradient vector with an uninitialized
51  /// value.
52  TemperatureGradient() = default;
53 
54  /// \brief Constructor. Constructs a temperature gradient vector with a given value expressed in a
55  /// given temperature gradient unit.
57  : DimensionalVector<Unit::TemperatureGradient, NumericType>(value, unit) {}
58 
59  /// \brief Constructor. Constructs a temperature gradient vector from a given set of scalar
60  /// temperature gradient components.
64  : TemperatureGradient<NumericType>({x.Value(), y.Value(), z.Value()}) {}
65 
66  /// \brief Constructor. Constructs a temperature gradient vector from a given scalar temperature
67  /// gradient magnitude and direction.
69  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient,
70  const Direction<NumericType>& direction)
71  : TemperatureGradient<NumericType>(scalar_temperature_gradient.Value() * direction.Value()) {}
72 
73  /// \brief Constructor. Constructs a temperature gradient vector from a given planar temperature
74  /// gradient vector in the XY plane. This temperature gradient vector's z-component is initialized
75  /// to zero.
76  explicit constexpr TemperatureGradient(
77  const PlanarTemperatureGradient<NumericType>& planar_temperature_gradient)
78  : TemperatureGradient<NumericType>(Vector<NumericType>{planar_temperature_gradient.Value()}) {}
79 
80  /// \brief Destructor. Destroys this temperature gradient vector.
81  ~TemperatureGradient() noexcept = default;
82 
83  /// \brief Copy constructor. Constructs a temperature gradient vector by copying another one.
84  constexpr TemperatureGradient(const TemperatureGradient<NumericType>& other) = default;
85 
86  /// \brief Copy constructor. Constructs a temperature gradient vector by copying another one.
87  template <typename OtherNumericType>
88  explicit constexpr TemperatureGradient(const TemperatureGradient<OtherNumericType>& other)
89  : TemperatureGradient(static_cast<Vector<NumericType>>(other.Value())) {}
90 
91  /// \brief Move constructor. Constructs a temperature gradient vector by moving another one.
92  constexpr TemperatureGradient(TemperatureGradient<NumericType>&& other) noexcept = default;
93 
94  /// \brief Copy assignment operator. Assigns this temperature gradient vector by copying another
95  /// one.
97  const TemperatureGradient<NumericType>& other) = default;
98 
99  /// \brief Copy assignment operator. Assigns this temperature gradient vector by copying another
100  /// one.
101  template <typename OtherNumericType>
104  this->value = static_cast<Vector<NumericType>>(other.Value());
105  return *this;
106  }
107 
108  /// \brief Move assignment operator. Assigns this temperature gradient vector by moving another
109  /// one.
111  TemperatureGradient<NumericType>&& other) noexcept = default;
112 
113  /// \brief Statically creates a temperature gradient vector of zero.
114  [[nodiscard]] static constexpr TemperatureGradient<NumericType> Zero() {
116  }
117 
118  /// \brief Statically creates a temperature gradient vector from the given x, y, and z Cartesian
119  /// components expressed in a given temperature gradient unit.
120  template <Unit::TemperatureGradient Unit>
121  [[nodiscard]] static constexpr TemperatureGradient<NumericType> Create(
122  const NumericType x, const NumericType y, const NumericType z) {
124  ConvertStatically<Unit::TemperatureGradient, Unit, Standard<Unit::TemperatureGradient>>(
125  Vector<NumericType>{x, y, z})};
126  }
127 
128  /// \brief Statically creates a temperature gradient vector from the given x, y, and z Cartesian
129  /// components expressed in a given temperature gradient unit.
130  template <Unit::TemperatureGradient Unit>
131  [[nodiscard]] static constexpr TemperatureGradient<NumericType> Create(
132  const std::array<NumericType, 3>& x_y_z) {
134  ConvertStatically<Unit::TemperatureGradient, Unit, Standard<Unit::TemperatureGradient>>(
135  Vector<NumericType>{x_y_z})};
136  }
137 
138  /// \brief Statically creates a temperature gradient vector with a given value expressed in a
139  /// given temperature gradient unit.
140  template <Unit::TemperatureGradient Unit>
141  [[nodiscard]] static constexpr TemperatureGradient<NumericType> Create(
142  const Vector<NumericType>& value) {
144  ConvertStatically<Unit::TemperatureGradient, Unit, Standard<Unit::TemperatureGradient>>(
145  value)};
146  }
147 
148  /// \brief Returns the x Cartesian component of this temperature gradient vector.
149  [[nodiscard]] constexpr ScalarTemperatureGradient<NumericType> x() const noexcept {
151  }
152 
153  /// \brief Returns the y Cartesian component of this temperature gradient vector.
154  [[nodiscard]] constexpr ScalarTemperatureGradient<NumericType> y() const noexcept {
156  }
157 
158  /// \brief Returns the z Cartesian component of this temperature gradient vector.
159  [[nodiscard]] constexpr ScalarTemperatureGradient<NumericType> z() const noexcept {
161  }
162 
163  /// \brief Returns the magnitude of this temperature gradient vector.
166  }
167 
168  /// \brief Returns the direction of this temperature gradient vector.
169  [[nodiscard]] PhQ::Direction<NumericType> Direction() const {
170  return this->value.Direction();
171  }
172 
173  /// \brief Returns the angle between this temperature gradient vector and another one.
175  const TemperatureGradient<NumericType>& temperature_gradient) const {
176  return PhQ::Angle<NumericType>{*this, temperature_gradient};
177  }
178 
180  const TemperatureGradient<NumericType>& temperature_gradient) const {
181  return TemperatureGradient<NumericType>{this->value + temperature_gradient.value};
182  }
183 
185  const TemperatureGradient<NumericType>& temperature_gradient) const {
186  return TemperatureGradient<NumericType>{this->value - temperature_gradient.value};
187  }
188 
189  constexpr TemperatureGradient<NumericType> operator*(const NumericType number) const {
190  return TemperatureGradient<NumericType>{this->value * number};
191  }
192 
193  constexpr TemperatureGradient<NumericType> operator/(const NumericType number) const {
194  return TemperatureGradient<NumericType>{this->value / number};
195  }
196 
197  constexpr void operator+=(const TemperatureGradient<NumericType>& temperature_gradient) noexcept {
198  this->value += temperature_gradient.value;
199  }
200 
201  constexpr void operator-=(const TemperatureGradient<NumericType>& temperature_gradient) noexcept {
202  this->value -= temperature_gradient.value;
203  }
204 
205  constexpr void operator*=(const NumericType number) noexcept {
206  this->value *= number;
207  }
208 
209  constexpr void operator/=(const NumericType number) noexcept {
210  this->value /= number;
211  }
212 
213 private:
214  /// \brief Constructor. Constructs a temperature gradient vector with a given value expressed in
215  /// the standard temperature gradient unit.
216  explicit constexpr TemperatureGradient(const Vector<NumericType>& value)
217  : DimensionalVector<Unit::TemperatureGradient, NumericType>(value) {}
218 };
219 
220 template <typename NumericType>
221 inline constexpr bool operator==(const TemperatureGradient<NumericType>& left,
222  const TemperatureGradient<NumericType>& right) noexcept {
223  return left.Value() == right.Value();
224 }
225 
226 template <typename NumericType>
227 inline constexpr bool operator!=(const TemperatureGradient<NumericType>& left,
228  const TemperatureGradient<NumericType>& right) noexcept {
229  return left.Value() != right.Value();
230 }
231 
232 template <typename NumericType>
233 inline constexpr bool operator<(const TemperatureGradient<NumericType>& left,
234  const TemperatureGradient<NumericType>& right) noexcept {
235  return left.Value() < right.Value();
236 }
237 
238 template <typename NumericType>
239 inline constexpr bool operator>(const TemperatureGradient<NumericType>& left,
240  const TemperatureGradient<NumericType>& right) noexcept {
241  return left.Value() > right.Value();
242 }
243 
244 template <typename NumericType>
245 inline constexpr bool operator<=(const TemperatureGradient<NumericType>& left,
246  const TemperatureGradient<NumericType>& right) noexcept {
247  return left.Value() <= right.Value();
248 }
249 
250 template <typename NumericType>
251 inline constexpr bool operator>=(const TemperatureGradient<NumericType>& left,
252  const TemperatureGradient<NumericType>& right) noexcept {
253  return left.Value() >= right.Value();
254 }
255 
256 template <typename NumericType>
257 inline std::ostream& operator<<(
258  std::ostream& stream, const TemperatureGradient<NumericType>& temperature_gradient) {
259  stream << temperature_gradient.Print();
260  return stream;
261 }
262 
263 template <typename NumericType>
265  const NumericType number, const TemperatureGradient<NumericType>& temperature_gradient) {
266  return temperature_gradient * number;
267 }
268 
269 template <typename NumericType>
271  const TemperatureGradient<NumericType>& temperature_gradient)
272  : Direction<NumericType>(temperature_gradient.Value()) {}
273 
274 template <typename NumericType>
275 inline Angle<NumericType>::Angle(const TemperatureGradient<NumericType>& temperature_gradient_1,
276  const TemperatureGradient<NumericType>& temperature_gradient_2)
277  : Angle<NumericType>(temperature_gradient_1.Value(), temperature_gradient_2.Value()) {}
278 
279 template <typename NumericType>
281  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient) const {
282  return TemperatureGradient<NumericType>{scalar_temperature_gradient, *this};
283 }
284 
285 template <typename NumericType>
287  const Direction<NumericType>& direction) const {
288  return TemperatureGradient<NumericType>{*this, direction};
289 }
290 
291 template <typename NumericType>
293  const TemperatureGradient<NumericType>& temperature_gradient)
294  : PlanarTemperatureGradient(PlanarVector<NumericType>{temperature_gradient.Value()}) {}
295 
296 } // namespace PhQ
297 
298 namespace std {
299 
300 template <typename NumericType>
301 struct hash<PhQ::TemperatureGradient<NumericType>> {
302  inline size_t operator()(
303  const PhQ::TemperatureGradient<NumericType>& temperature_gradient) const {
304  return hash<PhQ::Vector<NumericType>>()(temperature_gradient.Value());
305  }
306 };
307 
308 } // namespace std
309 
310 #endif // PHQ_TEMPERATURE_GRADIENT_HPP
Plane angle between two lines or dihedral angle between two planes.
Definition: Angle.hpp:130
Angle()=default
Default constructor. Constructs an angle with an uninitialized value.
constexpr const PhQ::PlanarVector< NumericType > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
Abstract base class that represents any dimensional vector physical quantity. Such a physical quantit...
std::string Print() const
Prints this physical quantity as a string. This physical quantity's value is expressed in its standar...
static constexpr Unit::TemperatureGradient Unit()
Standard unit of measure for this physical quantity. This physical quantity's value is stored interna...
PhQ::Vector< double > value
Value of this physical quantity expressed in its standard unit of measure.
constexpr const PhQ::Vector< double > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
Three-dimensional Euclidean direction vector. Contains three components in Cartesian coordinates: x,...
Definition: Direction.hpp:115
constexpr Direction()
Default constructor. Initializes a direction to the zero vector.
Definition: Direction.hpp:118
constexpr Acceleration< NumericType > operator*(const ScalarAcceleration< NumericType > &scalar_acceleration) const
Two-dimensional Euclidean temperature gradient vector in the XY plane. Contains two components in Car...
PlanarTemperatureGradient()=default
Default constructor. Constructs a planar temperature gradient vector with an uninitialized value.
Two-dimensional Euclidean vector in the XY plane. Contains two components in Cartesian coordinates: x...
Scalar temperature gradient component or magnitude of a temperature gradient vector....
constexpr ScalarTemperatureGradient< NumericType > operator*(const NumericType number) const
Three-dimensional Euclidean temperature gradient vector. Contains three components in Cartesian coord...
~TemperatureGradient() noexcept=default
Destructor. Destroys this temperature gradient vector.
PhQ::Direction< NumericType > Direction() const
Returns the direction of this temperature gradient vector.
static constexpr TemperatureGradient< NumericType > Create(const std::array< NumericType, 3 > &x_y_z)
Statically creates a temperature gradient vector from the given x, y, and z Cartesian components expr...
TemperatureGradient()=default
Default constructor. Constructs a temperature gradient vector with an uninitialized value.
constexpr TemperatureGradient(const PlanarTemperatureGradient< NumericType > &planar_temperature_gradient)
Constructor. Constructs a temperature gradient vector from a given planar temperature gradient vector...
constexpr TemperatureGradient< NumericType > operator/(const NumericType number) const
constexpr void operator-=(const TemperatureGradient< NumericType > &temperature_gradient) noexcept
static constexpr TemperatureGradient< NumericType > Create(const Vector< NumericType > &value)
Statically creates a temperature gradient vector with a given value expressed in a given temperature ...
constexpr void operator+=(const TemperatureGradient< NumericType > &temperature_gradient) noexcept
constexpr TemperatureGradient< NumericType > operator-(const TemperatureGradient< NumericType > &temperature_gradient) const
constexpr TemperatureGradient(const Vector< NumericType > &value)
Constructor. Constructs a temperature gradient vector with a given value expressed in the standard te...
ScalarTemperatureGradient< NumericType > Magnitude() const
Returns the magnitude of this temperature gradient vector.
constexpr TemperatureGradient(const ScalarTemperatureGradient< NumericType > &scalar_temperature_gradient, const Direction< NumericType > &direction)
Constructor. Constructs a temperature gradient vector from a given scalar temperature gradient magnit...
constexpr void operator/=(const NumericType number) noexcept
constexpr ScalarTemperatureGradient< NumericType > x() const noexcept
Returns the x Cartesian component of this temperature gradient vector.
constexpr void operator*=(const NumericType number) noexcept
constexpr TemperatureGradient< NumericType > operator*(const NumericType number) const
constexpr TemperatureGradient< NumericType > operator+(const TemperatureGradient< NumericType > &temperature_gradient) const
TemperatureGradient(const Vector< NumericType > &value, const Unit::TemperatureGradient unit)
Constructor. Constructs a temperature gradient vector with a given value expressed in a given tempera...
constexpr ScalarTemperatureGradient< NumericType > z() const noexcept
Returns the z Cartesian component of this temperature gradient vector.
constexpr TemperatureGradient< NumericType > & operator=(TemperatureGradient< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this temperature gradient vector by moving another one.
PhQ::Angle< NumericType > Angle(const TemperatureGradient< NumericType > &temperature_gradient) const
Returns the angle between this temperature gradient vector and another one.
constexpr TemperatureGradient< NumericType > & operator=(const TemperatureGradient< NumericType > &other)=default
Copy assignment operator. Assigns this temperature gradient vector by copying another one.
constexpr TemperatureGradient(TemperatureGradient< NumericType > &&other) noexcept=default
Move constructor. Constructs a temperature gradient vector by moving another one.
TemperatureGradient(const ScalarTemperatureGradient< NumericType > &x, const ScalarTemperatureGradient< NumericType > &y, const ScalarTemperatureGradient< NumericType > &z)
Constructor. Constructs a temperature gradient vector from a given set of scalar temperature gradient...
constexpr TemperatureGradient< NumericType > & operator=(const TemperatureGradient< OtherNumericType > &other)
Copy assignment operator. Assigns this temperature gradient vector by copying another one.
static constexpr TemperatureGradient< NumericType > Zero()
Statically creates a temperature gradient vector of zero.
static constexpr TemperatureGradient< NumericType > Create(const NumericType x, const NumericType y, const NumericType z)
Statically creates a temperature gradient vector from the given x, y, and z Cartesian components expr...
constexpr ScalarTemperatureGradient< NumericType > y() const noexcept
Returns the y Cartesian component of this temperature gradient vector.
Three-dimensional Euclidean vector. Contains three components in Cartesian coordinates: x,...
Definition: Vector.hpp:60
NumericType Magnitude() const noexcept
Returns the magnitude (also known as the L2 norm) of this three-dimensional vector.
Definition: Vector.hpp:209
static constexpr Vector< NumericType > Zero()
Statically creates a three-dimensional vector with its x, y, and z Cartesian components initialized t...
Definition: Vector.hpp:126
constexpr NumericType x() const noexcept
Returns this three-dimensional vector's x Cartesian component.
Definition: Vector.hpp:139
PhQ::Direction< NumericType > Direction() const
Returns the direction of this three-dimensional vector.
Definition: Direction.hpp:377
constexpr NumericType y() const noexcept
Returns this three-dimensional vector's y Cartesian component.
Definition: Vector.hpp:144
constexpr NumericType z() const noexcept
Returns this three-dimensional vector's z Cartesian component.
Definition: Vector.hpp:149
TemperatureGradient
Temperature gradient units.
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)