Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Loading...
Searching...
No Matches
ReynoldsNumber.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_REYNOLDS_NUMBER_HPP
26#define PHQ_REYNOLDS_NUMBER_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
33#include "DynamicViscosity.hpp"
35#include "Length.hpp"
36#include "MassDensity.hpp"
37#include "Speed.hpp"
38
39namespace PhQ {
40
41/// \brief Reynolds number of a fluid flow. Measures the local turbulence of a fluid flow.
42/// Represents the ratio of local inertial forces to local viscous forces in a fluid flow. See also
43/// PhQ::MassDensity, PhQ::Speed, PhQ::Length, PhQ::DynamicViscosity, and PhQ::KinematicViscosity.
44template <typename NumericType = double>
45class ReynoldsNumber : public DimensionlessScalar<NumericType> {
46public:
47 /// \brief Default constructor. Constructs a Reynolds number with an uninitialized value.
48 ReynoldsNumber() = default;
49
50 /// \brief Constructor. Constructs a Reynolds number with a given value.
51 explicit constexpr ReynoldsNumber(const NumericType value)
52 : DimensionlessScalar<NumericType>(value) {}
53
54 /// \brief Constructor. Constructs a Reynolds number from a given mass density, speed, length, and
55 /// dynamic viscosity using the definition of the Reynolds number.
56 constexpr ReynoldsNumber(
57 const MassDensity<NumericType>& mass_density, const Speed<NumericType>& speed,
58 const Length<NumericType>& length, const DynamicViscosity<NumericType>& dynamic_viscosity)
59 : ReynoldsNumber<NumericType>(
60 mass_density.Value() * speed.Value() * length.Value() / dynamic_viscosity.Value()) {}
61
62 /// \brief Constructor. Constructs a Reynolds number from a given speed, length, and kinematic
63 /// viscosity using the definition of the Reynolds number.
64 constexpr ReynoldsNumber(const Speed<NumericType>& speed, const Length<NumericType>& length,
65 const KinematicViscosity<NumericType>& kinematic_viscosity)
66 : ReynoldsNumber<NumericType>(speed.Value() * length.Value() / kinematic_viscosity.Value()) {}
67
68 /// \brief Destructor. Destroys this Reynolds number.
69 ~ReynoldsNumber() noexcept = default;
70
71 /// \brief Copy constructor. Constructs a Reynolds number by copying another one.
72 constexpr ReynoldsNumber(const ReynoldsNumber<NumericType>& other) = default;
73
74 /// \brief Copy constructor. Constructs a Reynolds number by copying another one.
75 template <typename OtherNumericType>
76 explicit constexpr ReynoldsNumber(const ReynoldsNumber<OtherNumericType>& other)
77 : ReynoldsNumber(static_cast<NumericType>(other.Value())) {}
78
79 /// \brief Move constructor. Constructs a Reynolds number by moving another one.
80 constexpr ReynoldsNumber(ReynoldsNumber<NumericType>&& other) noexcept = default;
81
82 /// \brief Copy assignment operator. Assigns this Reynolds number by copying another one.
84 const ReynoldsNumber<NumericType>& other) = default;
85
86 /// \brief Copy assignment operator. Assigns this Reynolds number by copying another one.
87 template <typename OtherNumericType>
89 this->value = static_cast<NumericType>(other.Value());
90 return *this;
91 }
92
93 /// \brief Move assignment operator. Assigns this Reynolds number by moving another one.
95 ReynoldsNumber<NumericType>&& other) noexcept = default;
96
97 /// \brief Statically creates a Reynolds number of zero.
98 [[nodiscard]] static constexpr ReynoldsNumber<NumericType> Zero() {
99 return ReynoldsNumber<NumericType>{static_cast<NumericType>(0)};
100 }
101
103 const PhQ::MassDensity<NumericType>& mass_density, const PhQ::Speed<NumericType>& speed,
104 const PhQ::Length<NumericType>& length) const {
105 return PhQ::DynamicViscosity<NumericType>{mass_density, speed, length, *this};
106 }
107
109 const PhQ::Speed<NumericType>& speed, const PhQ::Length<NumericType>& length) const {
110 return PhQ::KinematicViscosity<NumericType>{speed, length, *this};
111 }
112
113 [[nodiscard]] constexpr PhQ::Length<NumericType> Length(
114 const PhQ::DynamicViscosity<NumericType>& dynamic_viscosity,
115 const PhQ::MassDensity<NumericType>& mass_density,
116 const PhQ::Speed<NumericType>& speed) const {
117 return PhQ::Length<NumericType>{*this, dynamic_viscosity, mass_density, speed};
118 }
119
120 [[nodiscard]] constexpr PhQ::Length<NumericType> Length(
121 const PhQ::KinematicViscosity<NumericType>& kinematic_viscosity,
122 const PhQ::Speed<NumericType>& speed) const {
123 return PhQ::Length<NumericType>{*this, kinematic_viscosity, speed};
124 }
125
127 const PhQ::DynamicViscosity<NumericType>& dynamic_viscosity,
128 const PhQ::Speed<NumericType>& speed, const PhQ::Length<NumericType>& length) const {
129 return PhQ::MassDensity<NumericType>{*this, dynamic_viscosity, speed, length};
130 }
131
132 [[nodiscard]] constexpr PhQ::Speed<NumericType> Speed(
133 const PhQ::DynamicViscosity<NumericType>& dynamic_viscosity,
134 const PhQ::MassDensity<NumericType>& mass_density,
135 const PhQ::Length<NumericType>& length) const {
136 return PhQ::Speed<NumericType>{*this, dynamic_viscosity, mass_density, length};
137 }
138
139 [[nodiscard]] constexpr PhQ::Speed<NumericType> Speed(
140 const PhQ::KinematicViscosity<NumericType>& kinematic_viscosity,
141 const PhQ::Length<NumericType>& length) const {
142 return PhQ::Speed<NumericType>{*this, kinematic_viscosity, length};
143 }
144
146 const ReynoldsNumber<NumericType>& reynolds_number) const {
147 return ReynoldsNumber<NumericType>{this->value + reynolds_number.value};
148 }
149
151 const ReynoldsNumber<NumericType>& reynolds_number) const {
152 return ReynoldsNumber<NumericType>{this->value - reynolds_number.value};
153 }
154
155 constexpr ReynoldsNumber<NumericType> operator*(const NumericType number) const {
156 return ReynoldsNumber<NumericType>{this->value * number};
157 }
158
159 constexpr ReynoldsNumber<NumericType> operator/(const NumericType number) const {
160 return ReynoldsNumber<NumericType>{this->value / number};
161 }
162
163 constexpr NumericType operator/(
164 const ReynoldsNumber<NumericType>& reynolds_number) const noexcept {
165 return this->value / reynolds_number.value;
166 }
167
168 constexpr void operator+=(const ReynoldsNumber<NumericType>& reynolds_number) noexcept {
169 this->value += reynolds_number.value;
170 }
171
172 constexpr void operator-=(const ReynoldsNumber<NumericType>& reynolds_number) noexcept {
173 this->value -= reynolds_number.value;
174 }
175
176 constexpr void operator*=(const NumericType number) noexcept {
177 this->value *= number;
178 }
179
180 constexpr void operator/=(const NumericType number) noexcept {
181 this->value /= number;
182 }
183};
184
185template <typename NumericType>
186inline constexpr bool operator==(
187 const ReynoldsNumber<NumericType>& left, const ReynoldsNumber<NumericType>& right) noexcept {
188 return left.Value() == right.Value();
189}
190
191template <typename NumericType>
192inline constexpr bool operator!=(
193 const ReynoldsNumber<NumericType>& left, const ReynoldsNumber<NumericType>& right) noexcept {
194 return left.Value() != right.Value();
195}
196
197template <typename NumericType>
198inline constexpr bool operator<(
199 const ReynoldsNumber<NumericType>& left, const ReynoldsNumber<NumericType>& right) noexcept {
200 return left.Value() < right.Value();
201}
202
203template <typename NumericType>
204inline constexpr bool operator>(
205 const ReynoldsNumber<NumericType>& left, const ReynoldsNumber<NumericType>& right) noexcept {
206 return left.Value() > right.Value();
207}
208
209template <typename NumericType>
210inline constexpr bool operator<=(
211 const ReynoldsNumber<NumericType>& left, const ReynoldsNumber<NumericType>& right) noexcept {
212 return left.Value() <= right.Value();
213}
214
215template <typename NumericType>
216inline constexpr bool operator>=(
217 const ReynoldsNumber<NumericType>& left, const ReynoldsNumber<NumericType>& right) noexcept {
218 return left.Value() >= right.Value();
219}
220
221template <typename NumericType>
222inline std::ostream& operator<<(
223 std::ostream& stream, const ReynoldsNumber<NumericType>& reynolds_number) {
224 stream << reynolds_number.Print();
225 return stream;
226}
227
228template <typename NumericType>
230 const NumericType number, const ReynoldsNumber<NumericType>& reynolds_number) {
231 return ReynoldsNumber<NumericType>{number * reynolds_number.Value()};
232}
233
234template <typename NumericType>
236 const ReynoldsNumber<NumericType>& reynolds_number,
237 const DynamicViscosity<NumericType>& dynamic_viscosity,
238 const MassDensity<NumericType>& mass_density, const Speed<NumericType>& speed)
239 : Length<NumericType>(reynolds_number.Value() * dynamic_viscosity.Value()
240 / (mass_density.Value() * speed.Value())) {}
241
242template <typename NumericType>
244 const ReynoldsNumber<NumericType>& reynolds_number,
245 const KinematicViscosity<NumericType>& kinematic_viscosity, const Speed<NumericType>& speed)
246 : Length<NumericType>(reynolds_number.Value() * kinematic_viscosity.Value() / speed.Value()) {}
247
248template <typename NumericType>
250 const ReynoldsNumber<NumericType>& reynolds_number,
251 const DynamicViscosity<NumericType>& dynamic_viscosity,
252 const MassDensity<NumericType>& mass_density, const Length<NumericType>& length)
253 : Speed<NumericType>(reynolds_number.Value() * dynamic_viscosity.Value()
254 / (mass_density.Value() * length.Value())) {}
255
256template <typename NumericType>
258 const ReynoldsNumber<NumericType>& reynolds_number,
259 const KinematicViscosity<NumericType>& kinematic_viscosity, const Length<NumericType>& length)
260 : Speed<NumericType>(reynolds_number.Value() * kinematic_viscosity.Value() / length.Value()) {}
261
262template <typename NumericType>
264 const ReynoldsNumber<NumericType>& reynolds_number,
265 const DynamicViscosity<NumericType>& dynamic_viscosity, const Speed<NumericType>& speed,
266 const Length<NumericType>& length)
267 : MassDensity<NumericType>(
268 reynolds_number.Value() * dynamic_viscosity.Value() / (speed.Value() * length.Value())) {}
269
270template <typename NumericType>
272 const Speed<NumericType>& speed, const Length<NumericType>& length,
273 const ReynoldsNumber<NumericType>& reynolds_number)
274 : KinematicViscosity<NumericType>(speed.Value() * length.Value() / reynolds_number.Value()) {}
275
276template <typename NumericType>
278 const MassDensity<NumericType>& mass_density, const Speed<NumericType>& speed,
279 const Length<NumericType>& length, const ReynoldsNumber<NumericType>& reynolds_number)
280 : DynamicViscosity<NumericType>(
281 mass_density.Value() * speed.Value() * length.Value() / reynolds_number.Value()) {}
282
283} // namespace PhQ
284
285namespace std {
286
287template <typename NumericType>
288struct hash<PhQ::ReynoldsNumber<NumericType>> {
289 inline size_t operator()(const PhQ::ReynoldsNumber<NumericType>& reynolds_number) const {
290 return hash<NumericType>()(reynolds_number.Value());
291 }
292};
293
294} // namespace std
295
296#endif // PHQ_REYNOLDS_NUMBER_HPP
Abstract base class that represents any dimensionless scalar physical quantity. Such a physical quant...
constexpr NumericType Value() const noexcept
Value of this physical quantity.
NumericType 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.
Length, distance, or physical size. Can also represent a scalar component or magnitude of a position ...
Definition Length.hpp:111
Length()=default
Default constructor. Constructs a length with an uninitialized value.
Mass density. Mass per unit volume; see PhQ::Mass and PhQ::Volume.
MassDensity()=default
Default constructor. Constructs a mass density with an uninitialized value.
Reynolds number of a fluid flow. Measures the local turbulence of a fluid flow. Represents the ratio ...
constexpr PhQ::Speed< NumericType > Speed(const PhQ::KinematicViscosity< NumericType > &kinematic_viscosity, const PhQ::Length< NumericType > &length) const
constexpr PhQ::DynamicViscosity< NumericType > DynamicViscosity(const PhQ::MassDensity< NumericType > &mass_density, const PhQ::Speed< NumericType > &speed, const PhQ::Length< NumericType > &length) const
constexpr ReynoldsNumber< NumericType > operator+(const ReynoldsNumber< NumericType > &reynolds_number) const
constexpr PhQ::Speed< NumericType > Speed(const PhQ::DynamicViscosity< NumericType > &dynamic_viscosity, const PhQ::MassDensity< NumericType > &mass_density, const PhQ::Length< NumericType > &length) const
constexpr ReynoldsNumber< NumericType > & operator=(const ReynoldsNumber< NumericType > &other)=default
Copy assignment operator. Assigns this Reynolds number by copying another one.
constexpr ReynoldsNumber< NumericType > operator*(const NumericType number) const
constexpr ReynoldsNumber< NumericType > & operator=(const ReynoldsNumber< OtherNumericType > &other)
Copy assignment operator. Assigns this Reynolds number by copying another one.
constexpr ReynoldsNumber< NumericType > & operator=(ReynoldsNumber< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this Reynolds number by moving another one.
constexpr void operator*=(const NumericType number) noexcept
constexpr void operator+=(const ReynoldsNumber< NumericType > &reynolds_number) noexcept
constexpr ReynoldsNumber(const Speed< NumericType > &speed, const Length< NumericType > &length, const KinematicViscosity< NumericType > &kinematic_viscosity)
Constructor. Constructs a Reynolds number from a given speed, length, and kinematic viscosity using t...
constexpr ReynoldsNumber< NumericType > operator-(const ReynoldsNumber< NumericType > &reynolds_number) const
constexpr ReynoldsNumber(ReynoldsNumber< NumericType > &&other) noexcept=default
Move constructor. Constructs a Reynolds number by moving another one.
constexpr PhQ::MassDensity< NumericType > MassDensity(const PhQ::DynamicViscosity< NumericType > &dynamic_viscosity, const PhQ::Speed< NumericType > &speed, const PhQ::Length< NumericType > &length) const
static constexpr ReynoldsNumber< NumericType > Zero()
Statically creates a Reynolds number of zero.
~ReynoldsNumber() noexcept=default
Destructor. Destroys this Reynolds number.
constexpr ReynoldsNumber(const MassDensity< NumericType > &mass_density, const Speed< NumericType > &speed, const Length< NumericType > &length, const DynamicViscosity< NumericType > &dynamic_viscosity)
Constructor. Constructs a Reynolds number from a given mass density, speed, length,...
constexpr NumericType operator/(const ReynoldsNumber< NumericType > &reynolds_number) const noexcept
constexpr PhQ::KinematicViscosity< NumericType > KinematicViscosity(const PhQ::Speed< NumericType > &speed, const PhQ::Length< NumericType > &length) const
constexpr ReynoldsNumber< NumericType > operator/(const NumericType number) const
constexpr void operator/=(const NumericType number) noexcept
constexpr ReynoldsNumber(const NumericType value)
Constructor. Constructs a Reynolds number with a given value.
constexpr PhQ::Length< NumericType > Length(const PhQ::KinematicViscosity< NumericType > &kinematic_viscosity, const PhQ::Speed< NumericType > &speed) const
constexpr PhQ::Length< NumericType > Length(const PhQ::DynamicViscosity< NumericType > &dynamic_viscosity, const PhQ::MassDensity< NumericType > &mass_density, const PhQ::Speed< NumericType > &speed) const
constexpr void operator-=(const ReynoldsNumber< NumericType > &reynolds_number) noexcept
ReynoldsNumber()=default
Default constructor. Constructs a Reynolds number with an uninitialized value.
Scalar velocity component or magnitude of a velocity vector. For a three-dimensional Euclidean veloci...
Definition Speed.hpp:100
Speed()=default
Default constructor. Constructs a speed with an uninitialized value.
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, 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 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