Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
ScalarHeatFlux.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_HEAT_FLUX_HPP
26 #define PHQ_SCALAR_HEAT_FLUX_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionalScalar.hpp"
35 #include "Unit/EnergyFlux.hpp"
36 
37 namespace PhQ {
38 
39 // Forward declaration for class PhQ::ScalarHeatFlux.
40 template <typename NumericType>
41 class HeatFlux;
42 
43 // Forward declaration for class PhQ::ScalarHeatFlux.
44 template <typename NumericType>
45 class PlanarHeatFlux;
46 
47 /// \brief Scalar heat flux component or magnitude of a heat flux vector. For a three-dimensional
48 /// Euclidean heat flux vector, see PhQ::HeatFlux. For a two-dimensional Euclidean heat flux vector
49 /// in the XY plane, see PhQ::PlanarHeatFlux.
50 template <typename NumericType = double>
51 class ScalarHeatFlux : public DimensionalScalar<Unit::EnergyFlux, NumericType> {
52 public:
53  /// \brief Default constructor. Constructs a scalar heat flux with an uninitialized value.
54  ScalarHeatFlux() = default;
55 
56  /// \brief Constructor. Constructs a scalar heat flux with a given value expressed in a given
57  /// energy flux unit.
58  ScalarHeatFlux(const NumericType value, const Unit::EnergyFlux unit)
59  : DimensionalScalar<Unit::EnergyFlux, NumericType>(value, unit) {}
60 
61  /// \brief Constructor. Constructs a scalar heat flux from a given scalar thermal conductivity and
62  /// scalar temperature gradient using Fourier's law of heat conduction. Since heat flows opposite
63  /// the temperature gradient, the resulting scalar heat flux is negative.
64  constexpr ScalarHeatFlux(
65  const ScalarThermalConductivity<NumericType>& scalar_thermal_conductivity,
66  const ScalarTemperatureGradient<NumericType>& scalar_temperature_gradient)
67  : ScalarHeatFlux<NumericType>(
68  -scalar_thermal_conductivity.Value() * scalar_temperature_gradient.Value()) {}
69 
70  /// \brief Destructor. Destroys this scalar heat flux.
71  ~ScalarHeatFlux() noexcept = default;
72 
73  /// \brief Copy constructor. Constructs a scalar heat flux by copying another one.
74  constexpr ScalarHeatFlux(const ScalarHeatFlux<NumericType>& other) = default;
75 
76  /// \brief Copy constructor. Constructs a scalar heat flux by copying another one.
77  template <typename OtherNumericType>
78  explicit constexpr ScalarHeatFlux(const ScalarHeatFlux<OtherNumericType>& other)
79  : ScalarHeatFlux(static_cast<NumericType>(other.Value())) {}
80 
81  /// \brief Move constructor. Constructs a scalar heat flux by moving another one.
82  constexpr ScalarHeatFlux(ScalarHeatFlux<NumericType>&& other) noexcept = default;
83 
84  /// \brief Copy assignment operator. Assigns this scalar heat flux by copying another one.
86  const ScalarHeatFlux<NumericType>& other) = default;
87 
88  /// \brief Copy assignment operator. Assigns this scalar heat flux by copying another one.
89  template <typename OtherNumericType>
91  this->value = static_cast<NumericType>(other.Value());
92  return *this;
93  }
94 
95  /// \brief Move assignment operator. Assigns this scalar heat flux by moving another one.
97  ScalarHeatFlux<NumericType>&& other) noexcept = default;
98 
99  /// \brief Statically creates a scalar heat flux of zero.
100  [[nodiscard]] static constexpr ScalarHeatFlux<NumericType> Zero() {
101  return ScalarHeatFlux<NumericType>{static_cast<NumericType>(0)};
102  }
103 
104  /// \brief Statically creates a scalar heat flux with a given value expressed in a given energy
105  /// flux unit.
106  template <Unit::EnergyFlux Unit>
107  [[nodiscard]] static constexpr ScalarHeatFlux<NumericType> Create(const NumericType value) {
109  ConvertStatically<Unit::EnergyFlux, Unit, Standard<Unit::EnergyFlux>>(value)};
110  }
111 
113  const ScalarHeatFlux<NumericType>& scalar_heat_flux) const {
114  return ScalarHeatFlux<NumericType>{this->value + scalar_heat_flux.value};
115  }
116 
118  const ScalarHeatFlux<NumericType>& scalar_heat_flux) const {
119  return ScalarHeatFlux<NumericType>{this->value - scalar_heat_flux.value};
120  }
121 
122  constexpr ScalarHeatFlux<NumericType> operator*(const NumericType number) const {
123  return ScalarHeatFlux<NumericType>{this->value * number};
124  }
125 
127  const PlanarDirection<NumericType>& planar_direction) const;
128 
129  constexpr HeatFlux<NumericType> operator*(const Direction<NumericType>& direction) const;
130 
131  constexpr ScalarHeatFlux<NumericType> operator/(const NumericType number) const {
132  return ScalarHeatFlux<NumericType>{this->value / number};
133  }
134 
135  constexpr NumericType operator/(
136  const ScalarHeatFlux<NumericType>& scalar_heat_flux) const noexcept {
137  return this->value / scalar_heat_flux.value;
138  }
139 
140  constexpr void operator+=(const ScalarHeatFlux<NumericType>& scalar_heat_flux) noexcept {
141  this->value += scalar_heat_flux.value;
142  }
143 
144  constexpr void operator-=(const ScalarHeatFlux<NumericType>& scalar_heat_flux) noexcept {
145  this->value -= scalar_heat_flux.value;
146  }
147 
148  constexpr void operator*=(const NumericType number) noexcept {
149  this->value *= number;
150  }
151 
152  constexpr void operator/=(const NumericType number) noexcept {
153  this->value /= number;
154  }
155 
156 private:
157  /// \brief Constructor. Constructs a scalar heat flux with a given value expressed in the standard
158  /// energy flux unit.
159  explicit constexpr ScalarHeatFlux(const NumericType value)
160  : DimensionalScalar<Unit::EnergyFlux, NumericType>(value) {}
161 
162  template <typename OtherNumericType>
163  friend class PlanarHeatFlux;
164 
165  template <typename OtherNumericType>
166  friend class HeatFlux;
167 };
168 
169 template <typename NumericType>
170 inline constexpr bool operator==(
171  const ScalarHeatFlux<NumericType>& left, const ScalarHeatFlux<NumericType>& right) noexcept {
172  return left.Value() == right.Value();
173 }
174 
175 template <typename NumericType>
176 inline constexpr bool operator!=(
177  const ScalarHeatFlux<NumericType>& left, const ScalarHeatFlux<NumericType>& right) noexcept {
178  return left.Value() != right.Value();
179 }
180 
181 template <typename NumericType>
182 inline constexpr bool operator<(
183  const ScalarHeatFlux<NumericType>& left, const ScalarHeatFlux<NumericType>& right) noexcept {
184  return left.Value() < right.Value();
185 }
186 
187 template <typename NumericType>
188 inline constexpr bool operator>(
189  const ScalarHeatFlux<NumericType>& left, const ScalarHeatFlux<NumericType>& right) noexcept {
190  return left.Value() > right.Value();
191 }
192 
193 template <typename NumericType>
194 inline constexpr bool operator<=(
195  const ScalarHeatFlux<NumericType>& left, const ScalarHeatFlux<NumericType>& right) noexcept {
196  return left.Value() <= right.Value();
197 }
198 
199 template <typename NumericType>
200 inline constexpr bool operator>=(
201  const ScalarHeatFlux<NumericType>& left, const ScalarHeatFlux<NumericType>& right) noexcept {
202  return left.Value() >= right.Value();
203 }
204 
205 template <typename NumericType>
206 inline std::ostream& operator<<(
207  std::ostream& stream, const ScalarHeatFlux<NumericType>& scalar_heat_flux) {
208  stream << scalar_heat_flux.Print();
209  return stream;
210 }
211 
212 template <typename NumericType>
214  const NumericType number, const ScalarHeatFlux<NumericType>& scalar_heat_flux) {
215  return scalar_heat_flux * number;
216 }
217 
218 } // namespace PhQ
219 
220 namespace std {
221 
222 template <typename NumericType>
223 struct hash<PhQ::ScalarHeatFlux<NumericType>> {
224  inline size_t operator()(const PhQ::ScalarHeatFlux<NumericType>& scalar_heat_flux) const {
225  return hash<NumericType>()(scalar_heat_flux.Value());
226  }
227 };
228 
229 } // namespace std
230 
231 #endif // PHQ_SCALAR_HEAT_FLUX_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::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...
Three-dimensional Euclidean direction vector. Contains three components in Cartesian coordinates: x,...
Definition: Direction.hpp:115
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...
Two-dimensional Euclidean heat flux vector in the XY plane. Contains two components in Cartesian coor...
Scalar heat flux component or magnitude of a heat flux vector. For a three-dimensional Euclidean heat...
constexpr ScalarHeatFlux< NumericType > operator+(const ScalarHeatFlux< NumericType > &scalar_heat_flux) const
constexpr ScalarHeatFlux< NumericType > & operator=(const ScalarHeatFlux< OtherNumericType > &other)
Copy assignment operator. Assigns this scalar heat flux by copying another one.
static constexpr ScalarHeatFlux< NumericType > Zero()
Statically creates a scalar heat flux of zero.
constexpr ScalarHeatFlux< NumericType > & operator=(ScalarHeatFlux< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this scalar heat flux by moving another one.
constexpr NumericType operator/(const ScalarHeatFlux< NumericType > &scalar_heat_flux) const noexcept
constexpr ScalarHeatFlux(const NumericType value)
Constructor. Constructs a scalar heat flux with a given value expressed in the standard energy flux u...
constexpr void operator+=(const ScalarHeatFlux< NumericType > &scalar_heat_flux) noexcept
constexpr ScalarHeatFlux(const ScalarThermalConductivity< NumericType > &scalar_thermal_conductivity, const ScalarTemperatureGradient< NumericType > &scalar_temperature_gradient)
Constructor. Constructs a scalar heat flux from a given scalar thermal conductivity and scalar temper...
~ScalarHeatFlux() noexcept=default
Destructor. Destroys this scalar heat flux.
constexpr ScalarHeatFlux< NumericType > operator*(const NumericType number) const
ScalarHeatFlux(const NumericType value, const Unit::EnergyFlux unit)
Constructor. Constructs a scalar heat flux with a given value expressed in a given energy flux unit.
constexpr ScalarHeatFlux(ScalarHeatFlux< NumericType > &&other) noexcept=default
Move constructor. Constructs a scalar heat flux by moving another one.
constexpr ScalarHeatFlux< NumericType > operator-(const ScalarHeatFlux< NumericType > &scalar_heat_flux) const
constexpr void operator*=(const NumericType number) noexcept
constexpr ScalarHeatFlux< NumericType > & operator=(const ScalarHeatFlux< NumericType > &other)=default
Copy assignment operator. Assigns this scalar heat flux by copying another one.
ScalarHeatFlux()=default
Default constructor. Constructs a scalar heat flux with an uninitialized value.
constexpr void operator-=(const ScalarHeatFlux< NumericType > &scalar_heat_flux) noexcept
constexpr void operator/=(const NumericType number) noexcept
constexpr ScalarHeatFlux< NumericType > operator/(const NumericType number) const
static constexpr ScalarHeatFlux< NumericType > Create(const NumericType value)
Statically creates a scalar heat flux with a given value expressed in a given energy flux unit.
Scalar temperature gradient component or magnitude of a temperature gradient vector....
Scalar component or resultant of a three-dimensional Euclidean thermal conductivity symmetric dyadic ...
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)