Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
HeatFlux.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_HEAT_FLUX_HPP
26 #define PHQ_HEAT_FLUX_HPP
27 
28 #include <array>
29 #include <cstddef>
30 #include <functional>
31 #include <ostream>
32 
33 #include "DimensionalVector.hpp"
34 #include "Direction.hpp"
35 #include "PlanarHeatFlux.hpp"
36 #include "ScalarHeatFlux.hpp"
38 #include "TemperatureGradient.hpp"
39 #include "ThermalConductivity.hpp"
40 #include "Unit/EnergyFlux.hpp"
41 #include "Vector.hpp"
42 
43 namespace PhQ {
44 
45 /// \brief Three-dimensional Euclidean heat flux vector. Contains three components in Cartesian
46 /// coordinates: x, y, and z. For a two-dimensional Euclidean heat flux vector in the XY plane, see
47 /// PhQ::PlanarHeatFlux. For scalar heat flux components or for the magnitude of a heat flux vector,
48 /// see PhQ::ScalarHeatFlux.
49 template <typename NumericType = double>
50 class HeatFlux : public DimensionalVector<Unit::EnergyFlux, NumericType> {
51 public:
52  /// \brief Default constructor. Constructs a heat flux vector with an uninitialized value.
53  HeatFlux() = default;
54 
55  /// \brief Constructor. Constructs a heat flux vector with a given value expressed in a given
56  /// energy flux unit.
58  : DimensionalVector<Unit::EnergyFlux, NumericType>(value, unit) {}
59 
60  /// \brief Constructor. Constructs a heat flux vector from a given set of scalar heat flux
61  /// components.
64  : HeatFlux<NumericType>({x.Value(), y.Value(), z.Value()}) {}
65 
66  /// \brief Constructor. Constructs a heat flux vector from a given scalar heat flux magnitude and
67  /// direction.
68  constexpr HeatFlux(
69  const ScalarHeatFlux<NumericType>& scalar_heat_flux, const Direction<NumericType>& direction)
70  : HeatFlux<NumericType>(scalar_heat_flux.Value() * direction.Value()) {}
71 
72  /// \brief Constructor. Constructs a heat flux vector from a given planar heat flux vector in the
73  /// XY plane. This heat flux vector's z-component is initialized to zero.
74  explicit constexpr HeatFlux(const PlanarHeatFlux<NumericType>& planar_heat_flux)
75  : HeatFlux<NumericType>(Vector<NumericType>{planar_heat_flux.Value()}) {}
76 
77  /// \brief Constructor. Constructs a heat flux vector from a given scalar thermal conductivity and
78  /// temperature gradient vector using Fourier's law of heat conduction. Since heat flows opposite
79  /// the temperature gradient, the resulting heat flux direction is opposite the temperature
80  /// gradient direction.
81  constexpr HeatFlux(const ScalarThermalConductivity<NumericType>& scalar_thermal_conductivity,
82  const TemperatureGradient<NumericType>& temperature_gradient)
83  : HeatFlux<NumericType>(-scalar_thermal_conductivity.Value() * temperature_gradient.Value()) {}
84 
85  /// \brief Constructor. Constructs a heat flux vector from a given thermal conductivity tensor and
86  /// temperature gradient vector using Fourier's law of heat conduction. Since heat flows opposite
87  /// the temperature gradient, the resulting heat flux direction is opposite the temperature
88  /// gradient direction.
89  constexpr HeatFlux(const ThermalConductivity<NumericType>& thermal_conductivity,
90  const TemperatureGradient<NumericType>& temperature_gradient)
91  : HeatFlux<NumericType>(-1.0 * thermal_conductivity.Value() * temperature_gradient.Value()) {}
92 
93  /// \brief Destructor. Destroys this heat flux vector.
94  ~HeatFlux() noexcept = default;
95 
96  /// \brief Copy constructor. Constructs a heat flux vector by copying another one.
97  constexpr HeatFlux(const HeatFlux<NumericType>& other) = default;
98 
99  /// \brief Copy constructor. Constructs a heat flux vector by copying another one.
100  template <typename OtherNumericType>
101  explicit constexpr HeatFlux(const HeatFlux<OtherNumericType>& other)
102  : HeatFlux(static_cast<Vector<NumericType>>(other.Value())) {}
103 
104  /// \brief Move constructor. Constructs a heat flux vector by moving another one.
105  constexpr HeatFlux(HeatFlux<NumericType>&& other) noexcept = default;
106 
107  /// \brief Copy assignment operator. Assigns this heat flux vector by copying another one.
108  constexpr HeatFlux<NumericType>& operator=(const HeatFlux<NumericType>& other) = default;
109 
110  /// \brief Copy assignment operator. Assigns this heat flux vector by copying another one.
111  template <typename OtherNumericType>
113  this->value = static_cast<Vector<NumericType>>(other.Value());
114  return *this;
115  }
116 
117  /// \brief Move assignment operator. Assigns this heat flux vector by moving another one.
118  constexpr HeatFlux<NumericType>& operator=(HeatFlux<NumericType>&& other) noexcept = default;
119 
120  /// \brief Statically creates a heat flux vector of zero.
121  [[nodiscard]] static constexpr HeatFlux<NumericType> Zero() {
123  }
124 
125  /// \brief Statically creates a heat flux vector from the given x, y, and z Cartesian components
126  /// expressed in a given energy flux unit.
127  template <Unit::EnergyFlux Unit>
128  [[nodiscard]] static constexpr HeatFlux<NumericType> Create(
129  const NumericType x, const NumericType y, const NumericType z) {
130  return HeatFlux<NumericType>{
131  ConvertStatically<Unit::EnergyFlux, Unit, Standard<Unit::EnergyFlux>>(
132  Vector<NumericType>{x, y, z})};
133  }
134 
135  /// \brief Statically creates a heat flux vector from the given x, y, and z Cartesian components
136  /// expressed in a given energy flux unit.
137  template <Unit::EnergyFlux Unit>
138  [[nodiscard]] static constexpr HeatFlux<NumericType> Create(
139  const std::array<NumericType, 3>& x_y_z) {
140  return HeatFlux<NumericType>{
141  ConvertStatically<Unit::EnergyFlux, Unit, Standard<Unit::EnergyFlux>>(
142  Vector<NumericType>{x_y_z})};
143  }
144 
145  /// \brief Statically creates a heat flux vector with a given value expressed in a given energy
146  /// flux unit.
147  template <Unit::EnergyFlux Unit>
148  [[nodiscard]] static constexpr HeatFlux<NumericType> Create(const Vector<NumericType>& value) {
149  return HeatFlux<NumericType>{
150  ConvertStatically<Unit::EnergyFlux, Unit, Standard<Unit::EnergyFlux>>(value)};
151  }
152 
153  /// \brief Returns the x Cartesian component of this heat flux vector.
154  [[nodiscard]] constexpr ScalarHeatFlux<NumericType> x() const noexcept {
155  return ScalarHeatFlux<NumericType>{this->value.x()};
156  }
157 
158  /// \brief Returns the y Cartesian component of this heat flux vector.
159  [[nodiscard]] constexpr ScalarHeatFlux<NumericType> y() const noexcept {
160  return ScalarHeatFlux<NumericType>{this->value.y()};
161  }
162 
163  /// \brief Returns the z Cartesian component of this heat flux vector.
164  [[nodiscard]] constexpr ScalarHeatFlux<NumericType> z() const noexcept {
165  return ScalarHeatFlux<NumericType>{this->value.z()};
166  }
167 
168  /// \brief Returns the magnitude of this heat flux vector.
169  [[nodiscard]] ScalarHeatFlux<NumericType> Magnitude() const {
171  }
172 
173  /// \brief Returns the direction of this heat flux vector.
174  [[nodiscard]] PhQ::Direction<NumericType> Direction() const {
175  return this->value.Direction();
176  }
177 
178  /// \brief Returns the angle between this heat flux vector and another one.
179  [[nodiscard]] PhQ::Angle<NumericType> Angle(const HeatFlux<NumericType>& heat_flux) const {
180  return PhQ::Angle<NumericType>{*this, heat_flux};
181  }
182 
183  constexpr HeatFlux<NumericType> operator+(const HeatFlux<NumericType>& heat_flux) const {
184  return HeatFlux<NumericType>{this->value + heat_flux.value};
185  }
186 
187  constexpr HeatFlux<NumericType> operator-(const HeatFlux<NumericType>& heat_flux) const {
188  return HeatFlux<NumericType>{this->value - heat_flux.value};
189  }
190 
191  constexpr HeatFlux<NumericType> operator*(const NumericType number) const {
192  return HeatFlux<NumericType>{this->value * number};
193  }
194 
195  constexpr HeatFlux<NumericType> operator/(const NumericType number) const {
196  return HeatFlux<NumericType>{this->value / number};
197  }
198 
199  constexpr void operator+=(const HeatFlux<NumericType>& heat_flux) noexcept {
200  this->value += heat_flux.value;
201  }
202 
203  constexpr void operator-=(const HeatFlux<NumericType>& heat_flux) noexcept {
204  this->value -= heat_flux.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 heat flux vector with a given value expressed in the standard
217  /// energy flux unit.
218  explicit constexpr HeatFlux(const Vector<NumericType>& value)
219  : DimensionalVector<Unit::EnergyFlux, NumericType>(value) {}
220 };
221 
222 template <typename NumericType>
223 inline constexpr bool operator==(
224  const HeatFlux<NumericType>& left, const HeatFlux<NumericType>& right) noexcept {
225  return left.Value() == right.Value();
226 }
227 
228 template <typename NumericType>
229 inline constexpr bool operator!=(
230  const HeatFlux<NumericType>& left, const HeatFlux<NumericType>& right) noexcept {
231  return left.Value() != right.Value();
232 }
233 
234 template <typename NumericType>
235 inline constexpr bool operator<(
236  const HeatFlux<NumericType>& left, const HeatFlux<NumericType>& right) noexcept {
237  return left.Value() < right.Value();
238 }
239 
240 template <typename NumericType>
241 inline constexpr bool operator>(
242  const HeatFlux<NumericType>& left, const HeatFlux<NumericType>& right) noexcept {
243  return left.Value() > right.Value();
244 }
245 
246 template <typename NumericType>
247 inline constexpr bool operator<=(
248  const HeatFlux<NumericType>& left, const HeatFlux<NumericType>& right) noexcept {
249  return left.Value() <= right.Value();
250 }
251 
252 template <typename NumericType>
253 inline constexpr bool operator>=(
254  const HeatFlux<NumericType>& left, const HeatFlux<NumericType>& right) noexcept {
255  return left.Value() >= right.Value();
256 }
257 
258 template <typename NumericType>
259 inline std::ostream& operator<<(std::ostream& stream, const HeatFlux<NumericType>& heat_flux) {
260  stream << heat_flux.Print();
261  return stream;
262 }
263 
264 template <typename NumericType>
266  const NumericType number, const HeatFlux<NumericType>& heat_flux) {
267  return heat_flux * number;
268 }
269 
270 template <typename NumericType>
272  : Direction<NumericType>(heat_flux.Value()) {}
273 
274 template <typename NumericType>
276  const HeatFlux<NumericType>& heat_flux_1, const HeatFlux<NumericType>& heat_flux_2)
277  : Angle<NumericType>(heat_flux_1.Value(), heat_flux_2.Value()) {}
278 
279 template <typename NumericType>
281  const ScalarHeatFlux<NumericType>& scalar_heat_flux) const {
282  return HeatFlux<NumericType>{scalar_heat_flux, *this};
283 }
284 
285 template <typename NumericType>
287  const Direction<NumericType>& direction) const {
288  return HeatFlux<NumericType>{*this, direction};
289 }
290 
291 template <typename NumericType>
293  : PlanarHeatFlux(PlanarVector<NumericType>{heat_flux.Value()}) {}
294 
295 } // namespace PhQ
296 
297 namespace std {
298 
299 template <typename NumericType>
300 struct hash<PhQ::HeatFlux<NumericType>> {
301  inline size_t operator()(const PhQ::HeatFlux<NumericType>& heat_flux) const {
302  return hash<PhQ::Vector<NumericType>>()(heat_flux.Value());
303  }
304 };
305 
306 } // namespace std
307 
308 #endif // PHQ_HEAT_FLUX_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::EnergyFlux 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
Three-dimensional Euclidean heat flux vector. Contains three components in Cartesian coordinates: x,...
Definition: HeatFlux.hpp:50
constexpr void operator+=(const HeatFlux< NumericType > &heat_flux) noexcept
Definition: HeatFlux.hpp:199
PhQ::Direction< NumericType > Direction() const
Returns the direction of this heat flux vector.
Definition: HeatFlux.hpp:174
HeatFlux()=default
Default constructor. Constructs a heat flux vector with an uninitialized value.
constexpr HeatFlux(const ScalarThermalConductivity< NumericType > &scalar_thermal_conductivity, const TemperatureGradient< NumericType > &temperature_gradient)
Constructor. Constructs a heat flux vector from a given scalar thermal conductivity and temperature g...
Definition: HeatFlux.hpp:81
HeatFlux(const Vector< NumericType > &value, const Unit::EnergyFlux unit)
Constructor. Constructs a heat flux vector with a given value expressed in a given energy flux unit.
Definition: HeatFlux.hpp:57
constexpr HeatFlux(const Vector< NumericType > &value)
Constructor. Constructs a heat flux vector with a given value expressed in the standard energy flux u...
Definition: HeatFlux.hpp:218
constexpr HeatFlux(const ThermalConductivity< NumericType > &thermal_conductivity, const TemperatureGradient< NumericType > &temperature_gradient)
Constructor. Constructs a heat flux vector from a given thermal conductivity tensor and temperature g...
Definition: HeatFlux.hpp:89
ScalarHeatFlux< NumericType > Magnitude() const
Returns the magnitude of this heat flux vector.
Definition: HeatFlux.hpp:169
constexpr HeatFlux(const ScalarHeatFlux< NumericType > &scalar_heat_flux, const Direction< NumericType > &direction)
Constructor. Constructs a heat flux vector from a given scalar heat flux magnitude and direction.
Definition: HeatFlux.hpp:68
constexpr HeatFlux< NumericType > & operator=(HeatFlux< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this heat flux vector by moving another one.
~HeatFlux() noexcept=default
Destructor. Destroys this heat flux vector.
constexpr HeatFlux< NumericType > & operator=(const HeatFlux< OtherNumericType > &other)
Copy assignment operator. Assigns this heat flux vector by copying another one.
Definition: HeatFlux.hpp:112
constexpr void operator-=(const HeatFlux< NumericType > &heat_flux) noexcept
Definition: HeatFlux.hpp:203
constexpr HeatFlux(const PlanarHeatFlux< NumericType > &planar_heat_flux)
Constructor. Constructs a heat flux vector from a given planar heat flux vector in the XY plane....
Definition: HeatFlux.hpp:74
constexpr HeatFlux< NumericType > operator*(const NumericType number) const
Definition: HeatFlux.hpp:191
constexpr HeatFlux(HeatFlux< NumericType > &&other) noexcept=default
Move constructor. Constructs a heat flux vector by moving another one.
HeatFlux(const ScalarHeatFlux< NumericType > &x, const ScalarHeatFlux< NumericType > &y, const ScalarHeatFlux< NumericType > &z)
Constructor. Constructs a heat flux vector from a given set of scalar heat flux components.
Definition: HeatFlux.hpp:62
constexpr HeatFlux< NumericType > operator+(const HeatFlux< NumericType > &heat_flux) const
Definition: HeatFlux.hpp:183
static constexpr HeatFlux< NumericType > Zero()
Statically creates a heat flux vector of zero.
Definition: HeatFlux.hpp:121
constexpr HeatFlux< NumericType > operator/(const NumericType number) const
Definition: HeatFlux.hpp:195
constexpr ScalarHeatFlux< NumericType > x() const noexcept
Returns the x Cartesian component of this heat flux vector.
Definition: HeatFlux.hpp:154
PhQ::Angle< NumericType > Angle(const HeatFlux< NumericType > &heat_flux) const
Returns the angle between this heat flux vector and another one.
Definition: HeatFlux.hpp:179
constexpr void operator/=(const NumericType number) noexcept
Definition: HeatFlux.hpp:211
static constexpr HeatFlux< NumericType > Create(const std::array< NumericType, 3 > &x_y_z)
Statically creates a heat flux vector from the given x, y, and z Cartesian components expressed in a ...
Definition: HeatFlux.hpp:138
constexpr HeatFlux< NumericType > & operator=(const HeatFlux< NumericType > &other)=default
Copy assignment operator. Assigns this heat flux vector by copying another one.
constexpr void operator*=(const NumericType number) noexcept
Definition: HeatFlux.hpp:207
constexpr ScalarHeatFlux< NumericType > z() const noexcept
Returns the z Cartesian component of this heat flux vector.
Definition: HeatFlux.hpp:164
static constexpr HeatFlux< NumericType > Create(const NumericType x, const NumericType y, const NumericType z)
Statically creates a heat flux vector from the given x, y, and z Cartesian components expressed in a ...
Definition: HeatFlux.hpp:128
static constexpr HeatFlux< NumericType > Create(const Vector< NumericType > &value)
Statically creates a heat flux vector with a given value expressed in a given energy flux unit.
Definition: HeatFlux.hpp:148
constexpr HeatFlux< NumericType > operator-(const HeatFlux< NumericType > &heat_flux) const
Definition: HeatFlux.hpp:187
constexpr ScalarHeatFlux< NumericType > y() const noexcept
Returns the y Cartesian component of this heat flux vector.
Definition: HeatFlux.hpp:159
Two-dimensional Euclidean heat flux vector in the XY plane. Contains two components in Cartesian coor...
PlanarHeatFlux()=default
Default constructor. Constructs a planar heat flux vector with an uninitialized value.
Two-dimensional Euclidean vector in the XY plane. Contains two components in Cartesian coordinates: x...
Scalar heat flux component or magnitude of a heat flux vector. For a three-dimensional Euclidean heat...
constexpr ScalarHeatFlux< NumericType > operator*(const NumericType number) const
Scalar component or resultant of a three-dimensional Euclidean thermal conductivity symmetric dyadic ...
Three-dimensional Euclidean temperature gradient vector. Contains three components in Cartesian coord...
Three-dimensional Euclidean Cauchy thermal conductivity symmetric dyadic tensor. Contains six compone...
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
EnergyFlux
Energy flux units.
Definition: EnergyFlux.hpp:53
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)