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