Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
ThermalDiffusivity.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_THERMAL_DIFFUSIVITY_HPP
26 #define PHQ_THERMAL_DIFFUSIVITY_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionalScalar.hpp"
33 #include "MassDensity.hpp"
36 #include "Unit/Diffusivity.hpp"
37 
38 namespace PhQ {
39 
40 // Forward declaration for class PhQ::ThermalDiffusivity.
41 template <typename NumericType>
42 class PrandtlNumber;
43 
44 /// \brief Thermal diffusivity of a material. Measures the rate of heat transfer inside a material.
45 /// Equals the scalar thermal conductivity divided by the mass density and specific isobaric heat
46 /// capacity; see PhQ::ScalarThermalConductivity, PhQ::MassDensity, and
47 /// PhQ::SpecificIsobaricHeatCapacity. Also appears in the definition of the Prandtl number; see
48 /// PhQ::PrandtlNumber and PhQ::KinematicViscosity.
49 template <typename NumericType = double>
50 class ThermalDiffusivity : public DimensionalScalar<Unit::Diffusivity, NumericType> {
51 public:
52  /// \brief Default constructor. Constructs a thermal diffusivity with an uninitialized value.
53  ThermalDiffusivity() = default;
54 
55  /// \brief Constructor. Constructs a thermal diffusivity with a given value expressed in a given
56  /// diffusivity unit.
57  ThermalDiffusivity(const NumericType value, const Unit::Diffusivity unit)
58  : DimensionalScalar<Unit::Diffusivity, NumericType>(value, unit) {}
59 
60  /// \brief Constructor. Constructs a thermal diffusivity from a given scalar thermal conductivity,
61  /// specific isobaric heat capacity, and mass density using the definition of the thermal
62  /// diffusivity.
63  constexpr ThermalDiffusivity(
64  const ScalarThermalConductivity<NumericType>& scalar_thermal_conductivity,
65  const MassDensity<NumericType>& mass_density,
66  const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity)
67  : ThermalDiffusivity<NumericType>(
68  scalar_thermal_conductivity.Value()
69  / (mass_density.Value() * specific_isobaric_heat_capacity.Value())) {}
70 
71  /// \brief Constructor. Constructs a thermal diffusivity from a given kinematic viscosity and
72  /// Prandtl number using the definition of the Prandtl number.
73  constexpr ThermalDiffusivity(const KinematicViscosity<NumericType>& kinematic_viscosity,
74  const PrandtlNumber<NumericType>& prandtl_number);
75 
76  /// \brief Destructor. Destroys this thermal diffusivity.
77  ~ThermalDiffusivity() noexcept = default;
78 
79  /// \brief Copy constructor. Constructs a thermal diffusivity by copying another one.
80  constexpr ThermalDiffusivity(const ThermalDiffusivity<NumericType>& other) = default;
81 
82  /// \brief Copy constructor. Constructs a thermal diffusivity by copying another one.
83  template <typename OtherNumericType>
84  explicit constexpr ThermalDiffusivity(const ThermalDiffusivity<OtherNumericType>& other)
85  : ThermalDiffusivity(static_cast<NumericType>(other.Value())) {}
86 
87  /// \brief Move constructor. Constructs a thermal diffusivity by moving another one.
88  constexpr ThermalDiffusivity(ThermalDiffusivity<NumericType>&& other) noexcept = default;
89 
90  /// \brief Copy assignment operator. Assigns this thermal diffusivity by copying another one.
92  const ThermalDiffusivity<NumericType>& other) = default;
93 
94  /// \brief Copy assignment operator. Assigns this thermal diffusivity by copying another one.
95  template <typename OtherNumericType>
98  this->value = static_cast<NumericType>(other.Value());
99  return *this;
100  }
101 
102  /// \brief Move assignment operator. Assigns this thermal diffusivity by moving another one.
104  ThermalDiffusivity<NumericType>&& other) noexcept = default;
105 
106  /// \brief Statically creates a thermal diffusivity of zero.
107  [[nodiscard]] static constexpr ThermalDiffusivity<NumericType> Zero() {
108  return ThermalDiffusivity<NumericType>{static_cast<NumericType>(0)};
109  }
110 
111  /// \brief Statically creates a thermal diffusivity with a given value expressed in a given
112  /// diffusivity unit.
113  template <Unit::Diffusivity Unit>
114  [[nodiscard]] static constexpr ThermalDiffusivity<NumericType> Create(const NumericType value) {
116  ConvertStatically<Unit::Diffusivity, Unit, Standard<Unit::Diffusivity>>(value)};
117  }
118 
120  const ThermalDiffusivity<NumericType>& thermal_diffusivity) const {
121  return ThermalDiffusivity<NumericType>{this->value + thermal_diffusivity.value};
122  }
123 
125  const ThermalDiffusivity<NumericType>& thermal_diffusivity) const {
126  return ThermalDiffusivity<NumericType>{this->value - thermal_diffusivity.value};
127  }
128 
129  constexpr ThermalDiffusivity<NumericType> operator*(const NumericType number) const {
130  return ThermalDiffusivity<NumericType>{this->value * number};
131  }
132 
133  constexpr ThermalDiffusivity<NumericType> operator/(const NumericType number) const {
134  return ThermalDiffusivity<NumericType>{this->value / number};
135  }
136 
137  constexpr NumericType operator/(
138  const ThermalDiffusivity<NumericType>& thermal_diffusivity) const noexcept {
139  return this->value / thermal_diffusivity.value;
140  }
141 
142  constexpr void operator+=(const ThermalDiffusivity<NumericType>& thermal_diffusivity) noexcept {
143  this->value += thermal_diffusivity.value;
144  }
145 
146  constexpr void operator-=(const ThermalDiffusivity<NumericType>& thermal_diffusivity) noexcept {
147  this->value -= thermal_diffusivity.value;
148  }
149 
150  constexpr void operator*=(const NumericType number) noexcept {
151  this->value *= number;
152  }
153 
154  constexpr void operator/=(const NumericType number) noexcept {
155  this->value /= number;
156  }
157 
158 private:
159  /// \brief Constructor. Constructs a thermal diffusivity with a given value expressed in the
160  /// standard diffusivity unit.
161  explicit constexpr ThermalDiffusivity(const NumericType value)
162  : DimensionalScalar<Unit::Diffusivity, NumericType>(value) {}
163 };
164 
165 template <typename NumericType>
166 inline constexpr bool operator==(const ThermalDiffusivity<NumericType>& left,
167  const ThermalDiffusivity<NumericType>& right) noexcept {
168  return left.Value() == right.Value();
169 }
170 
171 template <typename NumericType>
172 inline constexpr bool operator!=(const ThermalDiffusivity<NumericType>& left,
173  const ThermalDiffusivity<NumericType>& right) noexcept {
174  return left.Value() != right.Value();
175 }
176 
177 template <typename NumericType>
178 inline constexpr bool operator<(const ThermalDiffusivity<NumericType>& left,
179  const ThermalDiffusivity<NumericType>& right) noexcept {
180  return left.Value() < right.Value();
181 }
182 
183 template <typename NumericType>
184 inline constexpr bool operator>(const ThermalDiffusivity<NumericType>& left,
185  const ThermalDiffusivity<NumericType>& right) noexcept {
186  return left.Value() > right.Value();
187 }
188 
189 template <typename NumericType>
190 inline constexpr bool operator<=(const ThermalDiffusivity<NumericType>& left,
191  const ThermalDiffusivity<NumericType>& right) noexcept {
192  return left.Value() <= right.Value();
193 }
194 
195 template <typename NumericType>
196 inline constexpr bool operator>=(const ThermalDiffusivity<NumericType>& left,
197  const ThermalDiffusivity<NumericType>& right) noexcept {
198  return left.Value() >= right.Value();
199 }
200 
201 template <typename NumericType>
202 inline std::ostream& operator<<(
203  std::ostream& stream, const ThermalDiffusivity<NumericType>& thermal_diffusivity) {
204  stream << thermal_diffusivity.Print();
205  return stream;
206 }
207 
208 template <typename NumericType>
210  const NumericType number, const ThermalDiffusivity<NumericType>& thermal_diffusivity) {
211  return thermal_diffusivity * number;
212 }
213 
214 template <typename NumericType>
216  const MassDensity<NumericType>& mass_density,
217  const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
218  const ThermalDiffusivity<NumericType>& thermal_diffusivity)
219  : ScalarThermalConductivity<NumericType>(
220  mass_density.Value() * specific_isobaric_heat_capacity.Value()
221  * thermal_diffusivity.Value()) {}
222 
223 template <typename NumericType>
225  const ScalarThermalConductivity<NumericType>& scalar_thermal_conductivity,
226  const ThermalDiffusivity<NumericType>& thermal_diffusivity,
227  const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity)
228  : MassDensity<NumericType>(
229  scalar_thermal_conductivity.Value()
230  / (thermal_diffusivity.Value() * specific_isobaric_heat_capacity.Value())) {}
231 
232 template <typename NumericType>
234  const ScalarThermalConductivity<NumericType>& scalar_thermal_conductivity,
235  const MassDensity<NumericType>& mass_density,
236  const ThermalDiffusivity<NumericType>& thermal_diffusivity)
237  : SpecificIsobaricHeatCapacity<NumericType>(
238  scalar_thermal_conductivity.Value() / (mass_density.Value() * thermal_diffusivity.Value())) {}
239 
240 } // namespace PhQ
241 
242 namespace std {
243 
244 template <typename NumericType>
245 struct hash<PhQ::ThermalDiffusivity<NumericType>> {
246  inline size_t operator()(const PhQ::ThermalDiffusivity<NumericType>& thermal_diffusivity) const {
247  return hash<NumericType>()(thermal_diffusivity.Value());
248  }
249 };
250 
251 } // namespace std
252 
253 #endif // PHQ_THERMAL_DIFFUSIVITY_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::Diffusivity 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...
Kinematic viscosity, also known as molecular kinematic viscosity. Defined as dynamic viscosity divide...
Mass density. Mass per unit volume; see PhQ::Mass and PhQ::Volume.
Definition: MassDensity.hpp:83
MassDensity()=default
Default constructor. Constructs a mass density with an uninitialized value.
Prandtl number of a fluid. Represents the ratio of the momentum diffusivity to the thermal diffusivit...
Scalar component or resultant of a three-dimensional Euclidean thermal conductivity symmetric dyadic ...
ScalarThermalConductivity()=default
Default constructor. Constructs a scalar thermal conductivity with an uninitialized value.
Mass-specific isobaric heat capacity, also known as mass-specific heat capacity at constant pressure,...
SpecificIsobaricHeatCapacity()=default
Default constructor. Constructs a specific isobaric heat capacity with an uninitialized value.
Thermal diffusivity of a material. Measures the rate of heat transfer inside a material....
constexpr ThermalDiffusivity(const NumericType value)
Constructor. Constructs a thermal diffusivity with a given value expressed in the standard diffusivit...
constexpr void operator-=(const ThermalDiffusivity< NumericType > &thermal_diffusivity) noexcept
constexpr ThermalDiffusivity< NumericType > operator+(const ThermalDiffusivity< NumericType > &thermal_diffusivity) const
constexpr ThermalDiffusivity< NumericType > operator*(const NumericType number) const
constexpr ThermalDiffusivity(const ScalarThermalConductivity< NumericType > &scalar_thermal_conductivity, const MassDensity< NumericType > &mass_density, const SpecificIsobaricHeatCapacity< NumericType > &specific_isobaric_heat_capacity)
Constructor. Constructs a thermal diffusivity from a given scalar thermal conductivity,...
constexpr void operator*=(const NumericType number) noexcept
static constexpr ThermalDiffusivity< NumericType > Zero()
Statically creates a thermal diffusivity of zero.
constexpr void operator+=(const ThermalDiffusivity< NumericType > &thermal_diffusivity) noexcept
constexpr void operator/=(const NumericType number) noexcept
static constexpr ThermalDiffusivity< NumericType > Create(const NumericType value)
Statically creates a thermal diffusivity with a given value expressed in a given diffusivity unit.
constexpr NumericType operator/(const ThermalDiffusivity< NumericType > &thermal_diffusivity) const noexcept
constexpr ThermalDiffusivity< NumericType > operator-(const ThermalDiffusivity< NumericType > &thermal_diffusivity) const
constexpr ThermalDiffusivity< NumericType > & operator=(const ThermalDiffusivity< NumericType > &other)=default
Copy assignment operator. Assigns this thermal diffusivity by copying another one.
~ThermalDiffusivity() noexcept=default
Destructor. Destroys this thermal diffusivity.
constexpr ThermalDiffusivity< NumericType > & operator=(const ThermalDiffusivity< OtherNumericType > &other)
Copy assignment operator. Assigns this thermal diffusivity by copying another one.
constexpr ThermalDiffusivity< NumericType > operator/(const NumericType number) const
constexpr ThermalDiffusivity< NumericType > & operator=(ThermalDiffusivity< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this thermal diffusivity by moving another one.
ThermalDiffusivity(const NumericType value, const Unit::Diffusivity unit)
Constructor. Constructs a thermal diffusivity with a given value expressed in a given diffusivity uni...
ThermalDiffusivity()=default
Default constructor. Constructs a thermal diffusivity with an uninitialized value.
constexpr ThermalDiffusivity(ThermalDiffusivity< NumericType > &&other) noexcept=default
Move constructor. Constructs a thermal diffusivity by moving another one.
Diffusivity
Diffusivity units.
Definition: Diffusivity.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)