Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
PrandtlNumber.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_PRANDTL_NUMBER_HPP
26 #define PHQ_PRANDTL_NUMBER_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionlessScalar.hpp"
33 #include "DynamicViscosity.hpp"
34 #include "KinematicViscosity.hpp"
37 #include "ThermalDiffusivity.hpp"
38 
39 namespace PhQ {
40 
41 /// \brief Prandtl number of a fluid. Represents the ratio of the momentum diffusivity to the
42 /// thermal diffusivity of a fluid. See also PhQ::KinematicViscosity,
43 /// PhQ::SpecificIsobaricHeatCapacity, PhQ::DynamicViscosity, PhQ::ScalarThermalConductivity, and
44 /// PhQ::ThermalDiffusivity.
45 template <typename NumericType = double>
46 class PrandtlNumber : public DimensionlessScalar<NumericType> {
47 public:
48  /// \brief Default constructor. Constructs a Prandtl number with an uninitialized value.
49  PrandtlNumber() = default;
50 
51  /// \brief Constructor. Constructs a Prandtl number with a given value.
52  explicit constexpr PrandtlNumber(const NumericType value)
53  : DimensionlessScalar<NumericType>(value) {}
54 
55  /// \brief Constructor. Constructs a Prandtl number from a given kinematic viscosity and thermal
56  /// diffusivity using the definition of the Prandtl number.
57  constexpr PrandtlNumber(const KinematicViscosity<NumericType>& kinematic_viscosity,
58  const ThermalDiffusivity<NumericType>& thermal_diffusivity)
59  : PrandtlNumber<NumericType>(kinematic_viscosity.Value() / thermal_diffusivity.Value()) {}
60 
61  /// \brief Constructor. Constructs a Prandtl number from a given specific isobaric heat capacity,
62  /// dynamic viscosity, and scalar thermal conductivity using the definition of the Prandtl number.
63  constexpr PrandtlNumber(
64  const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
65  const DynamicViscosity<NumericType>& dynamic_viscosity,
66  const ScalarThermalConductivity<NumericType>& scalar_thermal_conductivity)
67  : PrandtlNumber<NumericType>(specific_isobaric_heat_capacity.Value() * dynamic_viscosity.Value()
68  / scalar_thermal_conductivity.Value()) {}
69 
70  /// \brief Destructor. Destroys this Prandtl number.
71  ~PrandtlNumber() noexcept = default;
72 
73  /// \brief Copy constructor. Constructs a Prandtl number by copying another one.
74  constexpr PrandtlNumber(const PrandtlNumber<NumericType>& other) = default;
75 
76  /// \brief Copy constructor. Constructs a Prandtl number by copying another one.
77  template <typename OtherNumericType>
78  explicit constexpr PrandtlNumber(const PrandtlNumber<OtherNumericType>& other)
79  : PrandtlNumber(static_cast<NumericType>(other.Value())) {}
80 
81  /// \brief Move constructor. Constructs a Prandtl number by moving another one.
82  constexpr PrandtlNumber(PrandtlNumber<NumericType>&& other) noexcept = default;
83 
84  /// \brief Copy assignment operator. Assigns this Prandtl number by copying another one.
86  const PrandtlNumber<NumericType>& other) = default;
87 
88  /// \brief Copy assignment operator. Assigns this Prandtl number 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 Prandtl number by moving another one.
97  PrandtlNumber<NumericType>&& other) noexcept = default;
98 
99  /// \brief Statically creates a Prandtl number of zero.
100  [[nodiscard]] static constexpr PrandtlNumber<NumericType> Zero() {
101  return PrandtlNumber<NumericType>{static_cast<NumericType>(0)};
102  }
103 
105  const PhQ::ScalarThermalConductivity<NumericType>& scalar_thermal_conductivity,
106  const PhQ::SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity) const {
108  *this, scalar_thermal_conductivity, specific_isobaric_heat_capacity};
109  }
110 
112  const PhQ::ThermalDiffusivity<NumericType>& thermal_diffusivity) const {
113  return PhQ::KinematicViscosity<NumericType>{*this, thermal_diffusivity};
114  }
115 
116  [[nodiscard]] constexpr PhQ::SpecificIsobaricHeatCapacity<NumericType>
118  const PhQ::ScalarThermalConductivity<NumericType>& scalar_thermal_conductivity,
119  const PhQ::DynamicViscosity<NumericType>& dynamic_viscosity) const {
121  *this, scalar_thermal_conductivity, dynamic_viscosity};
122  }
123 
125  const PhQ::SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
126  const PhQ::DynamicViscosity<NumericType>& dynamic_viscosity) const {
128  specific_isobaric_heat_capacity, dynamic_viscosity, *this};
129  }
130 
132  const PhQ::KinematicViscosity<NumericType>& kinematic_viscosity) const {
133  return PhQ::ThermalDiffusivity<NumericType>{kinematic_viscosity, *this};
134  }
135 
137  const PrandtlNumber<NumericType>& prandtl_number) const {
138  return PrandtlNumber<NumericType>{this->value + prandtl_number.value};
139  }
140 
142  const PrandtlNumber<NumericType>& prandtl_number) const {
143  return PrandtlNumber<NumericType>{this->value - prandtl_number.value};
144  }
145 
146  constexpr PrandtlNumber<NumericType> operator*(const NumericType number) const {
147  return PrandtlNumber<NumericType>{this->value * number};
148  }
149 
150  constexpr PrandtlNumber<NumericType> operator/(const NumericType number) const {
151  return PrandtlNumber<NumericType>{this->value / number};
152  }
153 
154  constexpr NumericType operator/(const PrandtlNumber<NumericType>& prandtl_number) const noexcept {
155  return this->value / prandtl_number.value;
156  }
157 
158  constexpr void operator+=(const PrandtlNumber<NumericType>& prandtl_number) noexcept {
159  this->value += prandtl_number.value;
160  }
161 
162  constexpr void operator-=(const PrandtlNumber<NumericType>& prandtl_number) noexcept {
163  this->value -= prandtl_number.value;
164  }
165 
166  constexpr void operator*=(const NumericType number) noexcept {
167  this->value *= number;
168  }
169 
170  constexpr void operator/=(const NumericType number) noexcept {
171  this->value /= number;
172  }
173 };
174 
175 template <typename NumericType>
176 inline constexpr bool operator==(
177  const PrandtlNumber<NumericType>& left, const PrandtlNumber<NumericType>& right) noexcept {
178  return left.Value() == right.Value();
179 }
180 
181 template <typename NumericType>
182 inline constexpr bool operator!=(
183  const PrandtlNumber<NumericType>& left, const PrandtlNumber<NumericType>& right) noexcept {
184  return left.Value() != right.Value();
185 }
186 
187 template <typename NumericType>
188 inline constexpr bool operator<(
189  const PrandtlNumber<NumericType>& left, const PrandtlNumber<NumericType>& right) noexcept {
190  return left.Value() < right.Value();
191 }
192 
193 template <typename NumericType>
194 inline constexpr bool operator>(
195  const PrandtlNumber<NumericType>& left, const PrandtlNumber<NumericType>& right) noexcept {
196  return left.Value() > right.Value();
197 }
198 
199 template <typename NumericType>
200 inline constexpr bool operator<=(
201  const PrandtlNumber<NumericType>& left, const PrandtlNumber<NumericType>& right) noexcept {
202  return left.Value() <= right.Value();
203 }
204 
205 template <typename NumericType>
206 inline constexpr bool operator>=(
207  const PrandtlNumber<NumericType>& left, const PrandtlNumber<NumericType>& right) noexcept {
208  return left.Value() >= right.Value();
209 }
210 
211 template <typename NumericType>
212 inline std::ostream& operator<<(
213  std::ostream& stream, const PrandtlNumber<NumericType>& prandtl_number) {
214  stream << prandtl_number.Print();
215  return stream;
216 }
217 
218 template <typename NumericType>
220  const NumericType number, const PrandtlNumber<NumericType>& prandtl_number) {
221  return PrandtlNumber<NumericType>{number * prandtl_number.Value()};
222 }
223 
224 template <typename NumericType>
226  const KinematicViscosity<NumericType>& kinematic_viscosity,
227  const PrandtlNumber<NumericType>& prandtl_number)
228  : ThermalDiffusivity<NumericType>(kinematic_viscosity.Value() / prandtl_number.Value()) {}
229 
230 template <typename NumericType>
232  const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
233  const DynamicViscosity<NumericType>& dynamic_viscosity,
234  const PrandtlNumber<NumericType>& prandtl_number)
235  : ScalarThermalConductivity<NumericType>(specific_isobaric_heat_capacity.Value()
236  * dynamic_viscosity.Value() / prandtl_number.Value()) {}
237 
238 template <typename NumericType>
240  const PrandtlNumber<NumericType>& prandtl_number,
241  const ScalarThermalConductivity<NumericType>& scalar_thermal_conductivity,
242  const DynamicViscosity<NumericType>& dynamic_viscosity)
243  : SpecificIsobaricHeatCapacity<NumericType>(
244  prandtl_number.Value() * scalar_thermal_conductivity.Value() / dynamic_viscosity.Value()) {}
245 
246 template <typename NumericType>
248  const PrandtlNumber<NumericType>& prandtl_number,
249  const ScalarThermalConductivity<NumericType>& scalar_thermal_conductivity,
250  const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity)
251  : DynamicViscosity<NumericType>(prandtl_number.Value() * scalar_thermal_conductivity.Value()
252  / specific_isobaric_heat_capacity.Value()) {}
253 
254 template <typename NumericType>
256  const PrandtlNumber<NumericType>& prandtl_number,
257  const ThermalDiffusivity<NumericType>& thermal_diffusivity)
258  : KinematicViscosity<NumericType>(prandtl_number.Value() * thermal_diffusivity.Value()) {}
259 
260 } // namespace PhQ
261 
262 namespace std {
263 
264 template <typename NumericType>
265 struct hash<PhQ::PrandtlNumber<NumericType>> {
266  inline size_t operator()(const PhQ::PrandtlNumber<NumericType>& prandtl_number) const {
267  return hash<NumericType>()(prandtl_number.Value());
268  }
269 };
270 
271 } // namespace std
272 
273 #endif // PHQ_PRANDTL_NUMBER_HPP
Abstract base class that represents any dimensionless scalar physical quantity. Such a physical quant...
constexpr double Value() const noexcept
Value of this physical quantity.
double value
Value of this physical quantity.
std::string Print() const
Prints this physical quantity as a string.
Dynamic viscosity, also known as molecular dynamic viscosity. Dynamic viscosity is the relationship b...
DynamicViscosity()=default
Default constructor. Constructs a dynamic viscosity with an uninitialized value.
Kinematic viscosity, also known as molecular kinematic viscosity. Defined as dynamic viscosity divide...
KinematicViscosity()=default
Default constructor. Constructs a kinematic viscosity with an uninitialized value.
Prandtl number of a fluid. Represents the ratio of the momentum diffusivity to the thermal diffusivit...
constexpr PhQ::DynamicViscosity< NumericType > DynamicViscosity(const PhQ::ScalarThermalConductivity< NumericType > &scalar_thermal_conductivity, const PhQ::SpecificIsobaricHeatCapacity< NumericType > &specific_isobaric_heat_capacity) const
constexpr PhQ::ThermalDiffusivity< NumericType > ThermalDiffusivity(const PhQ::KinematicViscosity< NumericType > &kinematic_viscosity) const
static constexpr PrandtlNumber< NumericType > Zero()
Statically creates a Prandtl number of zero.
constexpr PrandtlNumber(const KinematicViscosity< NumericType > &kinematic_viscosity, const ThermalDiffusivity< NumericType > &thermal_diffusivity)
Constructor. Constructs a Prandtl number from a given kinematic viscosity and thermal diffusivity usi...
constexpr PrandtlNumber< NumericType > operator*(const NumericType number) const
constexpr PhQ::SpecificIsobaricHeatCapacity< NumericType > SpecificIsobaricHeatCapacity(const PhQ::ScalarThermalConductivity< NumericType > &scalar_thermal_conductivity, const PhQ::DynamicViscosity< NumericType > &dynamic_viscosity) const
constexpr PrandtlNumber< NumericType > & operator=(const PrandtlNumber< OtherNumericType > &other)
Copy assignment operator. Assigns this Prandtl number by copying another one.
constexpr void operator*=(const NumericType number) noexcept
PrandtlNumber()=default
Default constructor. Constructs a Prandtl number with an uninitialized value.
constexpr void operator-=(const PrandtlNumber< NumericType > &prandtl_number) noexcept
constexpr void operator/=(const NumericType number) noexcept
constexpr PrandtlNumber(PrandtlNumber< NumericType > &&other) noexcept=default
Move constructor. Constructs a Prandtl number by moving another one.
constexpr PrandtlNumber< NumericType > operator/(const NumericType number) const
constexpr PhQ::ScalarThermalConductivity< NumericType > ScalarThermalConductivity(const PhQ::SpecificIsobaricHeatCapacity< NumericType > &specific_isobaric_heat_capacity, const PhQ::DynamicViscosity< NumericType > &dynamic_viscosity) const
constexpr PrandtlNumber< NumericType > operator-(const PrandtlNumber< NumericType > &prandtl_number) const
constexpr PrandtlNumber< NumericType > & operator=(PrandtlNumber< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this Prandtl number by moving another one.
constexpr void operator+=(const PrandtlNumber< NumericType > &prandtl_number) noexcept
constexpr PhQ::KinematicViscosity< NumericType > KinematicViscosity(const PhQ::ThermalDiffusivity< NumericType > &thermal_diffusivity) const
~PrandtlNumber() noexcept=default
Destructor. Destroys this Prandtl number.
constexpr NumericType operator/(const PrandtlNumber< NumericType > &prandtl_number) const noexcept
constexpr PrandtlNumber< NumericType > operator+(const PrandtlNumber< NumericType > &prandtl_number) const
constexpr PrandtlNumber(const SpecificIsobaricHeatCapacity< NumericType > &specific_isobaric_heat_capacity, const DynamicViscosity< NumericType > &dynamic_viscosity, const ScalarThermalConductivity< NumericType > &scalar_thermal_conductivity)
Constructor. Constructs a Prandtl number from a given specific isobaric heat capacity,...
constexpr PrandtlNumber(const NumericType value)
Constructor. Constructs a Prandtl number with a given value.
constexpr PrandtlNumber< NumericType > & operator=(const PrandtlNumber< NumericType > &other)=default
Copy assignment operator. Assigns this Prandtl number by copying another one.
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....
ThermalDiffusivity()=default
Default constructor. Constructs a thermal diffusivity with an uninitialized value.
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)