Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
ScalarTemperatureGradient.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_SCALAR_TEMPERATURE_GRADIENT_HPP
26 #define PHQ_SCALAR_TEMPERATURE_GRADIENT_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionalScalar.hpp"
33 #include "Length.hpp"
36 
37 namespace PhQ {
38 
39 // Forward declaration for class PhQ::ScalarTemperatureGradient.
40 template <typename NumericType>
41 class Direction;
42 
43 // Forward declaration for class PhQ::ScalarTemperatureGradient.
44 template <typename NumericType>
45 class PlanarDirection;
46 
47 // Forward declaration for class PhQ::ScalarTemperatureGradient.
48 template <typename NumericType>
49 class PlanarTemperatureGradient;
50 
51 // Forward declaration for class PhQ::ScalarTemperatureGradient.
52 template <typename NumericType>
54 
55 /// \brief Scalar temperature gradient component or magnitude of a temperature gradient vector. For
56 /// a three-dimensional Euclidean temperature gradient vector, see PhQ::TemperatureGradient. For a
57 /// two-dimensional Euclidean temperature gradient vector in the XY plane, see
58 /// PhQ::PlanarTemperatureGradient.
59 template <typename NumericType = double>
60 class ScalarTemperatureGradient : public DimensionalScalar<Unit::TemperatureGradient, NumericType> {
61 public:
62  /// \brief Default constructor. Constructs a scalar temperature gradient with an uninitialized
63  /// value.
65 
66  /// \brief Constructor. Constructs a scalar temperature gradient with a given value expressed in a
67  /// given temperature gradient unit.
69  : DimensionalScalar<Unit::TemperatureGradient, NumericType>(value, unit) {}
70 
71  /// \brief Constructor. Constructs a scalar temperature gradient from a given temperature
72  /// difference and length using the definition of temperature gradient.
74  const TemperatureDifference<NumericType>& temperature_difference,
75  const Length<NumericType>& length)
76  : ScalarTemperatureGradient<NumericType>(temperature_difference.Value() / length.Value()) {}
77 
78  /// \brief Destructor. Destroys this scalar temperature gradient.
79  ~ScalarTemperatureGradient() noexcept = default;
80 
81  /// \brief Copy constructor. Constructs a scalar temperature gradient by copying another one.
83  const ScalarTemperatureGradient<NumericType>& other) = default;
84 
85  /// \brief Copy constructor. Constructs a scalar temperature gradient by copying another one.
86  template <typename OtherNumericType>
87  explicit constexpr ScalarTemperatureGradient(
88  const ScalarTemperatureGradient<OtherNumericType>& other)
89  : ScalarTemperatureGradient(static_cast<NumericType>(other.Value())) {}
90 
91  /// \brief Move constructor. Constructs a scalar temperature gradient by moving another one.
93  ScalarTemperatureGradient<NumericType>&& other) noexcept = default;
94 
95  /// \brief Copy assignment operator. Assigns this scalar temperature gradient by copying another
96  /// one.
98  const ScalarTemperatureGradient<NumericType>& other) = default;
99 
100  /// \brief Copy assignment operator. Assigns this scalar temperature gradient by copying another
101  /// one.
102  template <typename OtherNumericType>
105  this->value = static_cast<NumericType>(other.Value());
106  return *this;
107  }
108 
109  /// \brief Move assignment operator. Assigns this scalar temperature gradient by moving another
110  /// one.
112  ScalarTemperatureGradient<NumericType>&& other) noexcept = default;
113 
114  /// \brief Statically creates a scalar temperature gradient of zero.
115  [[nodiscard]] static constexpr ScalarTemperatureGradient<NumericType> Zero() {
116  return ScalarTemperatureGradient<NumericType>{static_cast<NumericType>(0)};
117  }
118 
119  /// \brief Statically creates a scalar temperature gradient with a given value expressed in a
120  /// given temperature gradient unit.
121  template <Unit::TemperatureGradient Unit>
122  [[nodiscard]] static constexpr ScalarTemperatureGradient<NumericType> Create(
123  const NumericType value) {
125  ConvertStatically<Unit::TemperatureGradient, Unit, Standard<Unit::TemperatureGradient>>(
126  value)};
127  }
128 
130  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient) const {
131  return ScalarTemperatureGradient<NumericType>{this->value + scalar_temperature_gradient.value};
132  }
133 
135  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient) const {
136  return ScalarTemperatureGradient<NumericType>{this->value - scalar_temperature_gradient.value};
137  }
138 
139  constexpr ScalarTemperatureGradient<NumericType> operator*(const NumericType number) const {
140  return ScalarTemperatureGradient<NumericType>{this->value * number};
141  }
142 
144  return TemperatureDifference<NumericType>{*this, length};
145  }
146 
148  const PlanarDirection<NumericType>& planar_direction) const;
149 
151  const Direction<NumericType>& direction) const;
152 
153  constexpr ScalarTemperatureGradient<NumericType> operator/(const NumericType number) const {
154  return ScalarTemperatureGradient<NumericType>{this->value / number};
155  }
156 
157  constexpr NumericType operator/(
158  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient) const noexcept {
159  return this->value / scalar_temperature_gradient.value;
160  }
161 
162  constexpr void operator+=(
163  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient) noexcept {
164  this->value += scalar_temperature_gradient.value;
165  }
166 
167  constexpr void operator-=(
168  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient) noexcept {
169  this->value -= scalar_temperature_gradient.value;
170  }
171 
172  constexpr void operator*=(const NumericType number) noexcept {
173  this->value *= number;
174  }
175 
176  constexpr void operator/=(const NumericType number) noexcept {
177  this->value /= number;
178  }
179 
180 private:
181  /// \brief Constructor. Constructs a scalar temperature gradient with a given value expressed in
182  /// the standard temperature gradient unit.
183  explicit constexpr ScalarTemperatureGradient(const NumericType value)
184  : DimensionalScalar<Unit::TemperatureGradient, NumericType>(value) {}
185 
186  template <typename OtherNumericType>
188 
189  template <typename OtherNumericType>
190  friend class TemperatureGradient;
191 };
192 
193 template <typename NumericType>
194 inline constexpr bool operator==(const ScalarTemperatureGradient<NumericType>& left,
195  const ScalarTemperatureGradient<NumericType>& right) noexcept {
196  return left.Value() == right.Value();
197 }
198 
199 template <typename NumericType>
200 inline constexpr bool operator!=(const ScalarTemperatureGradient<NumericType>& left,
201  const ScalarTemperatureGradient<NumericType>& right) noexcept {
202  return left.Value() != right.Value();
203 }
204 
205 template <typename NumericType>
206 inline constexpr bool operator<(const ScalarTemperatureGradient<NumericType>& left,
207  const ScalarTemperatureGradient<NumericType>& right) noexcept {
208  return left.Value() < right.Value();
209 }
210 
211 template <typename NumericType>
212 inline constexpr bool operator>(const ScalarTemperatureGradient<NumericType>& left,
213  const ScalarTemperatureGradient<NumericType>& right) noexcept {
214  return left.Value() > right.Value();
215 }
216 
217 template <typename NumericType>
218 inline constexpr bool operator<=(const ScalarTemperatureGradient<NumericType>& left,
219  const ScalarTemperatureGradient<NumericType>& right) noexcept {
220  return left.Value() <= right.Value();
221 }
222 
223 template <typename NumericType>
224 inline constexpr bool operator>=(const ScalarTemperatureGradient<NumericType>& left,
225  const ScalarTemperatureGradient<NumericType>& right) noexcept {
226  return left.Value() >= right.Value();
227 }
228 
229 template <typename NumericType>
230 inline std::ostream& operator<<(
231  std::ostream& stream,
232  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient) {
233  stream << scalar_temperature_gradient.Print();
234  return stream;
235 }
236 
237 template <typename NumericType>
239  const NumericType number,
240  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient) {
241  return scalar_temperature_gradient * number;
242 }
243 
244 template <typename NumericType>
246  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient,
247  const Length<NumericType>& length)
248  : TemperatureDifference<NumericType>(scalar_temperature_gradient.Value() * length.Value()) {}
249 
250 template <typename NumericType>
251 inline constexpr ScalarTemperatureGradient<NumericType>
252 TemperatureDifference<NumericType>::operator/(const Length<NumericType>& length) const {
253  return ScalarTemperatureGradient<NumericType>{*this, length};
254 }
255 
256 } // namespace PhQ
257 
258 namespace std {
259 
260 template <typename NumericType>
261 struct hash<PhQ::ScalarTemperatureGradient<NumericType>> {
262  inline size_t operator()(
263  const PhQ::ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient) const {
264  return hash<NumericType>()(scalar_temperature_gradient.Value());
265  }
266 };
267 
268 } // namespace std
269 
270 #endif // PHQ_SCALAR_TEMPERATURE_GRADIENT_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::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...
Three-dimensional Euclidean direction vector. Contains three components in Cartesian coordinates: x,...
Definition: Direction.hpp:115
Length, distance, or physical size. Can also represent a scalar component or magnitude of a position ...
Definition: Length.hpp:111
two-dimensional Euclidean direction vector in the XY plane. Contains two components in Cartesian coor...
Two-dimensional Euclidean temperature gradient vector in the XY plane. Contains two components in Car...
Scalar temperature gradient component or magnitude of a temperature gradient vector....
constexpr ScalarTemperatureGradient< NumericType > operator*(const NumericType number) const
constexpr ScalarTemperatureGradient(ScalarTemperatureGradient< NumericType > &&other) noexcept=default
Move constructor. Constructs a scalar temperature gradient by moving another one.
constexpr ScalarTemperatureGradient< NumericType > operator+(const ScalarTemperatureGradient< NumericType > &scalar_temperature_gradient) const
constexpr void operator-=(const ScalarTemperatureGradient< NumericType > &scalar_temperature_gradient) noexcept
constexpr void operator+=(const ScalarTemperatureGradient< NumericType > &scalar_temperature_gradient) noexcept
constexpr ScalarTemperatureGradient(const TemperatureDifference< NumericType > &temperature_difference, const Length< NumericType > &length)
Constructor. Constructs a scalar temperature gradient from a given temperature difference and length ...
~ScalarTemperatureGradient() noexcept=default
Destructor. Destroys this scalar temperature gradient.
constexpr void operator*=(const NumericType number) noexcept
constexpr ScalarTemperatureGradient< NumericType > operator-(const ScalarTemperatureGradient< NumericType > &scalar_temperature_gradient) const
constexpr ScalarTemperatureGradient(const NumericType value)
Constructor. Constructs a scalar temperature gradient with a given value expressed in the standard te...
ScalarTemperatureGradient(const NumericType value, const Unit::TemperatureGradient unit)
Constructor. Constructs a scalar temperature gradient with a given value expressed in a given tempera...
constexpr void operator/=(const NumericType number) noexcept
constexpr ScalarTemperatureGradient< NumericType > & operator=(const ScalarTemperatureGradient< NumericType > &other)=default
Copy assignment operator. Assigns this scalar temperature gradient by copying another one.
constexpr ScalarTemperatureGradient< NumericType > operator/(const NumericType number) const
constexpr TemperatureDifference< NumericType > operator*(const Length< NumericType > &length) const
static constexpr ScalarTemperatureGradient< NumericType > Create(const NumericType value)
Statically creates a scalar temperature gradient with a given value expressed in a given temperature ...
constexpr ScalarTemperatureGradient< NumericType > & operator=(ScalarTemperatureGradient< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this scalar temperature gradient by moving another one.
ScalarTemperatureGradient()=default
Default constructor. Constructs a scalar temperature gradient with an uninitialized value.
constexpr ScalarTemperatureGradient< NumericType > & operator=(const ScalarTemperatureGradient< OtherNumericType > &other)
Copy assignment operator. Assigns this scalar temperature gradient by copying another one.
static constexpr ScalarTemperatureGradient< NumericType > Zero()
Statically creates a scalar temperature gradient of zero.
constexpr NumericType operator/(const ScalarTemperatureGradient< NumericType > &scalar_temperature_gradient) const noexcept
Temperature difference. Not to be confused with temperature; see PhQ::Temperature....
TemperatureDifference()=default
Default constructor. Constructs a temperature difference with an uninitialized value.
Three-dimensional Euclidean temperature gradient vector. Contains three components in Cartesian coord...
TemperatureGradient
Temperature gradient units.
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 Dyad< NumericType > operator/(const Dyad< NumericType > &dyad, const OtherNumericType number)
Definition: Dyad.hpp:696
constexpr bool operator!=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)