Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
PlanarTemperatureGradient.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_PLANAR_TEMPERATURE_GRADIENT_HPP
26 #define PHQ_PLANAR_TEMPERATURE_GRADIENT_HPP
27 
28 #include <array>
29 #include <cstddef>
30 #include <functional>
31 #include <ostream>
32 
33 #include "Angle.hpp"
35 #include "PlanarDirection.hpp"
36 #include "PlanarVector.hpp"
39 
40 namespace PhQ {
41 
42 /// \brief Two-dimensional Euclidean temperature gradient vector in the XY plane. Contains two
43 /// components in Cartesian coordinates: x and y. For a three-dimensional Euclidean temperature
44 /// gradient vector, see PhQ::TemperatureGradient. For scalar temperature gradient components or for
45 /// the magnitude of a temperature gradient vector, see PhQ::ScalarTemperatureGradient.
46 template <typename NumericType = double>
48  : public DimensionalPlanarVector<Unit::TemperatureGradient, NumericType> {
49 public:
50  /// \brief Default constructor. Constructs a planar temperature gradient vector with an
51  /// uninitialized value.
53 
54  /// \brief Constructor. Constructs a planar temperature gradient vector with a given value
55  /// expressed in a given temperature gradient unit.
58  : DimensionalPlanarVector<Unit::TemperatureGradient, NumericType>(value, unit) {}
59 
60  /// \brief Constructor. Constructs a planar temperature gradient vector from a given set of scalar
61  /// temperature gradient components.
64  : PlanarTemperatureGradient<NumericType>({x.Value(), y.Value()}) {}
65 
66  /// \brief Constructor. Constructs a planar temperature gradient vector from a given scalar
67  /// temperature gradient magnitude and planar direction.
69  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient,
70  const PlanarDirection<NumericType>& planar_direction)
71  : PlanarTemperatureGradient<NumericType>(
72  scalar_temperature_gradient.Value() * planar_direction.Value()) {}
73 
74  /// \brief Constructor. Constructs a planar temperature gradient vector from a given temperature
75  /// gradient vector by projecting the temperature gradient vector onto the XY plane.
76  explicit constexpr PlanarTemperatureGradient(
77  const TemperatureGradient<NumericType>& temperature_gradient);
78 
79  /// \brief Destructor. Destroys this planar temperature gradient vector.
80  ~PlanarTemperatureGradient() noexcept = default;
81 
82  /// \brief Copy constructor. Constructs a planar temperature gradient vector by copying another
83  /// one.
85  const PlanarTemperatureGradient<NumericType>& other) = default;
86 
87  /// \brief Copy constructor. Constructs a planar temperature gradient vector by copying another
88  /// one.
89  template <typename OtherNumericType>
90  explicit constexpr PlanarTemperatureGradient(
91  const PlanarTemperatureGradient<OtherNumericType>& other)
92  : PlanarTemperatureGradient(static_cast<PlanarVector<NumericType>>(other.Value())) {}
93 
94  /// \brief Move constructor. Constructs a planar temperature gradient vector by moving another
95  /// one.
97  PlanarTemperatureGradient<NumericType>&& other) noexcept = default;
98 
99  /// \brief Copy assignment operator. Assigns this planar temperature gradient vector by copying
100  /// another one.
102  const PlanarTemperatureGradient<NumericType>& other) = default;
103 
104  /// \brief Copy assignment operator. Assigns this planar temperature gradient vector by copying
105  /// another one.
106  template <typename OtherNumericType>
109  this->value = static_cast<PlanarVector<NumericType>>(other.Value());
110  return *this;
111  }
112 
113  /// \brief Move assignment operator. Assigns this planar temperature gradient vector by moving
114  /// another one.
116  PlanarTemperatureGradient<NumericType>&& other) noexcept = default;
117 
118  /// \brief Statically creates a planar temperature gradient vector of zero.
119  [[nodiscard]] static constexpr PlanarTemperatureGradient<NumericType> Zero() {
121  }
122 
123  /// \brief Statically creates a planar temperature gradient vector from the given x and y
124  /// Cartesian components expressed in a given temperature gradient unit.
125  template <Unit::TemperatureGradient Unit>
126  [[nodiscard]] static constexpr PlanarTemperatureGradient<NumericType> Create(
127  const NumericType x, const NumericType y) {
129  ConvertStatically<Unit::TemperatureGradient, Unit, Standard<Unit::TemperatureGradient>>(
131  }
132 
133  /// \brief Statically creates a planar temperature gradient vector from the given x and y
134  /// Cartesian components expressed in a given temperature gradient unit.
135  template <Unit::TemperatureGradient Unit>
136  [[nodiscard]] static constexpr PlanarTemperatureGradient<NumericType> Create(
137  const std::array<NumericType, 2>& x_y) {
139  ConvertStatically<Unit::TemperatureGradient, Unit, Standard<Unit::TemperatureGradient>>(
141  }
142 
143  /// \brief Statically creates a planar temperature gradient vector with a given value expressed in
144  /// a given temperature gradient unit.
145  template <Unit::TemperatureGradient Unit>
146  [[nodiscard]] static constexpr PlanarTemperatureGradient<NumericType> Create(
149  ConvertStatically<Unit::TemperatureGradient, Unit, Standard<Unit::TemperatureGradient>>(
150  value)};
151  }
152 
153  /// \brief Returns the x Cartesian component of this planar temperature gradient vector.
154  [[nodiscard]] constexpr ScalarTemperatureGradient<NumericType> x() const noexcept {
156  }
157 
158  /// \brief Returns the y Cartesian component of this planar temperature gradient vector.
159  [[nodiscard]] constexpr ScalarTemperatureGradient<NumericType> y() const noexcept {
161  }
162 
163  /// \brief Returns the magnitude of this planar temperature gradient vector.
166  }
167 
168  /// \brief Returns the direction of this planar temperature gradient vector.
170  return this->value.PlanarDirection();
171  }
172 
173  /// \brief Returns the angle between this planar temperature gradient vector and another one.
175  const PlanarTemperatureGradient<NumericType>& planar_temperature_gradient) const {
176  return PhQ::Angle<NumericType>{*this, planar_temperature_gradient};
177  }
178 
180  const PlanarTemperatureGradient<NumericType>& planar_temperature_gradient) const {
181  return PlanarTemperatureGradient<NumericType>{this->value + planar_temperature_gradient.value};
182  }
183 
185  const PlanarTemperatureGradient<NumericType>& planar_temperature_gradient) const {
186  return PlanarTemperatureGradient<NumericType>{this->value - planar_temperature_gradient.value};
187  }
188 
189  constexpr PlanarTemperatureGradient<NumericType> operator*(const NumericType number) const {
190  return PlanarTemperatureGradient<NumericType>{this->value * number};
191  }
192 
193  constexpr PlanarTemperatureGradient<NumericType> operator/(const NumericType number) const {
194  return PlanarTemperatureGradient<NumericType>{this->value / number};
195  }
196 
197  constexpr void operator+=(
198  const PlanarTemperatureGradient<NumericType>& planar_temperature_gradient) noexcept {
199  this->value += planar_temperature_gradient.value;
200  }
201 
202  constexpr void operator-=(
203  const PlanarTemperatureGradient<NumericType>& planar_temperature_gradient) noexcept {
204  this->value -= planar_temperature_gradient.value;
205  }
206 
207  constexpr void operator*=(const NumericType number) noexcept {
208  this->value *= number;
209  }
210 
211  constexpr void operator/=(const NumericType number) noexcept {
212  this->value /= number;
213  }
214 
215 private:
216  /// \brief Constructor. Constructs a planar temperature gradient vector with a given value
217  /// expressed in the standard temperature gradient unit.
220 };
221 
222 template <typename NumericType>
223 inline constexpr bool operator==(const PlanarTemperatureGradient<NumericType>& left,
224  const PlanarTemperatureGradient<NumericType>& right) noexcept {
225  return left.Value() == right.Value();
226 }
227 
228 template <typename NumericType>
229 inline constexpr bool operator!=(const PlanarTemperatureGradient<NumericType>& left,
230  const PlanarTemperatureGradient<NumericType>& right) noexcept {
231  return left.Value() != right.Value();
232 }
233 
234 template <typename NumericType>
235 inline constexpr bool operator<(const PlanarTemperatureGradient<NumericType>& left,
236  const PlanarTemperatureGradient<NumericType>& right) noexcept {
237  return left.Value() < right.Value();
238 }
239 
240 template <typename NumericType>
241 inline constexpr bool operator>(const PlanarTemperatureGradient<NumericType>& left,
242  const PlanarTemperatureGradient<NumericType>& right) noexcept {
243  return left.Value() > right.Value();
244 }
245 
246 template <typename NumericType>
247 inline constexpr bool operator<=(const PlanarTemperatureGradient<NumericType>& left,
248  const PlanarTemperatureGradient<NumericType>& right) noexcept {
249  return left.Value() <= right.Value();
250 }
251 
252 template <typename NumericType>
253 inline constexpr bool operator>=(const PlanarTemperatureGradient<NumericType>& left,
254  const PlanarTemperatureGradient<NumericType>& right) noexcept {
255  return left.Value() >= right.Value();
256 }
257 
258 template <typename NumericType>
259 inline std::ostream& operator<<(
260  std::ostream& stream,
261  const PlanarTemperatureGradient<NumericType>& planar_temperature_gradient) {
262  stream << planar_temperature_gradient.Print();
263  return stream;
264 }
265 
266 template <typename NumericType>
268  const NumericType number,
269  const PlanarTemperatureGradient<NumericType>& planar_temperature_gradient) {
270  return planar_temperature_gradient * number;
271 }
272 
273 template <typename NumericType>
275  const PlanarTemperatureGradient<NumericType>& planar_temperature_gradient)
276  : PlanarDirection<NumericType>(planar_temperature_gradient.Value()) {}
277 
278 template <typename NumericType>
280  const PlanarTemperatureGradient<NumericType>& planar_temperature_gradient_1,
281  const PlanarTemperatureGradient<NumericType>& planar_temperature_gradient_2)
282  : Angle<NumericType>(
283  planar_temperature_gradient_1.Value(), planar_temperature_gradient_2.Value()) {}
284 
285 template <typename NumericType>
287  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient) const {
288  return PlanarTemperatureGradient<NumericType>{scalar_temperature_gradient, *this};
289 }
290 
291 template <typename NumericType>
294  const PlanarDirection<NumericType>& planar_direction) const {
295  return PlanarTemperatureGradient<NumericType>{*this, planar_direction};
296 }
297 
298 } // namespace PhQ
299 
300 namespace std {
301 
302 template <typename NumericType>
303 struct hash<PhQ::PlanarTemperatureGradient<NumericType>> {
304  inline size_t operator()(
305  const PhQ::PlanarTemperatureGradient<NumericType>& planar_temperature_gradient) const {
306  return hash<PhQ::PlanarVector<NumericType>>()(planar_temperature_gradient.Value());
307  }
308 };
309 
310 } // namespace std
311 
312 #endif // PHQ_PLANAR_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.
Abstract base class that represents any dimensional planar vector physical quantity....
PhQ::PlanarVector< double > value
Value of this physical quantity expressed in its standard unit of measure.
constexpr const PhQ::PlanarVector< double > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr Unit::TemperatureGradient 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...
two-dimensional Euclidean direction vector in the XY plane. Contains two components in Cartesian coor...
constexpr PlanarAcceleration< NumericType > operator*(const ScalarAcceleration< NumericType > &scalar_acceleration) const
constexpr PlanarDirection()
Default constructor. Initializes a planar direction to the zero planar vector.
Two-dimensional Euclidean temperature gradient vector in the XY plane. Contains two components in Car...
constexpr PlanarTemperatureGradient(PlanarTemperatureGradient< NumericType > &&other) noexcept=default
Move constructor. Constructs a planar temperature gradient vector by moving another one.
PhQ::PlanarDirection< NumericType > PlanarDirection() const
Returns the direction of this planar temperature gradient vector.
~PlanarTemperatureGradient() noexcept=default
Destructor. Destroys this planar temperature gradient vector.
constexpr PlanarTemperatureGradient< NumericType > & operator=(const PlanarTemperatureGradient< NumericType > &other)=default
Copy assignment operator. Assigns this planar temperature gradient vector by copying another one.
constexpr PlanarTemperatureGradient(const ScalarTemperatureGradient< NumericType > &scalar_temperature_gradient, const PlanarDirection< NumericType > &planar_direction)
Constructor. Constructs a planar temperature gradient vector from a given scalar temperature gradient...
PlanarTemperatureGradient(const PlanarVector< NumericType > &value, const Unit::TemperatureGradient unit)
Constructor. Constructs a planar temperature gradient vector with a given value expressed in a given ...
constexpr ScalarTemperatureGradient< NumericType > y() const noexcept
Returns the y Cartesian component of this planar temperature gradient vector.
PhQ::Angle< NumericType > Angle(const PlanarTemperatureGradient< NumericType > &planar_temperature_gradient) const
Returns the angle between this planar temperature gradient vector and another one.
constexpr PlanarTemperatureGradient< NumericType > operator-(const PlanarTemperatureGradient< NumericType > &planar_temperature_gradient) const
constexpr PlanarTemperatureGradient< NumericType > operator*(const NumericType number) const
constexpr PlanarTemperatureGradient< NumericType > & operator=(const PlanarTemperatureGradient< OtherNumericType > &other)
Copy assignment operator. Assigns this planar temperature gradient vector by copying another one.
constexpr PlanarTemperatureGradient< NumericType > operator+(const PlanarTemperatureGradient< NumericType > &planar_temperature_gradient) const
static constexpr PlanarTemperatureGradient< NumericType > Create(const NumericType x, const NumericType y)
Statically creates a planar temperature gradient vector from the given x and y Cartesian components e...
PlanarTemperatureGradient(const ScalarTemperatureGradient< NumericType > &x, const ScalarTemperatureGradient< NumericType > &y)
Constructor. Constructs a planar temperature gradient vector from a given set of scalar temperature g...
constexpr void operator+=(const PlanarTemperatureGradient< NumericType > &planar_temperature_gradient) noexcept
ScalarTemperatureGradient< NumericType > Magnitude() const
Returns the magnitude of this planar temperature gradient vector.
constexpr PlanarTemperatureGradient(const PlanarVector< NumericType > &value)
Constructor. Constructs a planar temperature gradient vector with a given value expressed in the stan...
static constexpr PlanarTemperatureGradient< NumericType > Create(const std::array< NumericType, 2 > &x_y)
Statically creates a planar temperature gradient vector from the given x and y Cartesian components e...
constexpr void operator/=(const NumericType number) noexcept
static constexpr PlanarTemperatureGradient< NumericType > Create(const PlanarVector< NumericType > &value)
Statically creates a planar temperature gradient vector with a given value expressed in a given tempe...
constexpr PlanarTemperatureGradient< NumericType > operator/(const NumericType number) const
constexpr PlanarTemperatureGradient< NumericType > & operator=(PlanarTemperatureGradient< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this planar temperature gradient vector by moving another one.
PlanarTemperatureGradient()=default
Default constructor. Constructs a planar temperature gradient vector with an uninitialized value.
constexpr void operator-=(const PlanarTemperatureGradient< NumericType > &planar_temperature_gradient) noexcept
constexpr ScalarTemperatureGradient< NumericType > x() const noexcept
Returns the x Cartesian component of this planar temperature gradient vector.
constexpr void operator*=(const NumericType number) noexcept
static constexpr PlanarTemperatureGradient< NumericType > Zero()
Statically creates a planar temperature gradient vector of zero.
Two-dimensional Euclidean vector in the XY plane. Contains two components in Cartesian coordinates: x...
constexpr NumericType x() const noexcept
Returns this two-dimensional planar vector's x Cartesian component.
static constexpr PlanarVector< NumericType > Zero()
Statically creates a two-dimensional planar vector with its x and y Cartesian components initialized ...
PhQ::PlanarDirection< NumericType > PlanarDirection() const
Returns the planar direction of this two-dimensional planar vector.
NumericType Magnitude() const noexcept
Returns the magnitude (also known as the L2 norm) of this two-dimensional planar vector.
constexpr NumericType y() const noexcept
Returns this two-dimensional planar vector's y Cartesian component.
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
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)