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
KinematicViscosity.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_KINEMATIC_VISCOSITY_HPP
26#define PHQ_KINEMATIC_VISCOSITY_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
32#include "DimensionalScalar.hpp"
33#include "Unit/Diffusivity.hpp"
34
35namespace PhQ {
36
37// Forward declaration for class PhQ::KinematicViscosity.
38template <typename NumericType>
40
41// Forward declaration for class PhQ::KinematicViscosity.
42template <typename NumericType>
43class Length;
44
45// Forward declaration for class PhQ::KinematicViscosity.
46template <typename NumericType>
47class MassDensity;
48
49// Forward declaration for class PhQ::KinematicViscosity.
50template <typename NumericType>
51class PrandtlNumber;
52
53// Forward declaration for class PhQ::KinematicViscosity.
54template <typename NumericType>
55class ReynoldsNumber;
56
57// Forward declaration for class PhQ::KinematicViscosity.
58template <typename NumericType>
59class Speed;
60
61// Forward declaration for class PhQ::KinematicViscosity.
62template <typename NumericType>
63class ThermalDiffusivity;
64
65/// \brief Kinematic viscosity, also known as molecular kinematic viscosity. Defined as dynamic
66/// viscosity divided by mass density; see PhQ::DynamicViscosity and PhQ::MassDensity. Also appears
67/// in the definition of the Prandtl number; see PhQ::PrandtlNumber and
68/// PhQ::ThermalDiffusivity.
69template <typename NumericType = double>
70class KinematicViscosity : public DimensionalScalar<Unit::Diffusivity, NumericType> {
71public:
72 /// \brief Default constructor. Constructs a kinematic viscosity with an uninitialized value.
73 KinematicViscosity() = default;
74
75 /// \brief Constructor. Constructs a kinematic viscosity with a given value expressed in a given
76 /// diffusivity unit.
77 KinematicViscosity(const NumericType value, const Unit::Diffusivity unit)
78 : DimensionalScalar<Unit::Diffusivity, NumericType>(value, unit) {}
79
80 /// \brief Constructor. Constructs a kinematic viscosity from a given dynamic viscosity and mass
81 /// density using the definition of kinematic viscosity.
82 constexpr KinematicViscosity(const DynamicViscosity<NumericType>& dynamic_viscosity,
83 const MassDensity<NumericType>& mass_density);
84
85 /// \brief Constructor. Constructs a kinematic viscosity from a given speed, length, and Reynolds
86 /// number using the definition of the Reynolds number.
87 constexpr KinematicViscosity(const Speed<NumericType>& speed, const Length<NumericType>& length,
88 const ReynoldsNumber<NumericType>& reynolds_number);
89
90 /// \brief Constructor. Constructs a kinematic viscosity from a given Prandtl number and thermal
91 /// diffusivity using the definition of Prandtl number.
92 constexpr KinematicViscosity(const PrandtlNumber<NumericType>& prandtl_number,
93 const ThermalDiffusivity<NumericType>& thermal_diffusivity);
94
95 /// \brief Destructor. Destroys this kinematic viscosity.
96 ~KinematicViscosity() noexcept = default;
97
98 /// \brief Copy constructor. Constructs a kinematic viscosity by copying another one.
99 constexpr KinematicViscosity(const KinematicViscosity<NumericType>& other) = default;
100
101 /// \brief Copy constructor. Constructs a kinematic viscosity by copying another one.
102 template <typename OtherNumericType>
103 explicit constexpr KinematicViscosity(const KinematicViscosity<OtherNumericType>& other)
104 : KinematicViscosity(static_cast<NumericType>(other.Value())) {}
105
106 /// \brief Move constructor. Constructs a kinematic viscosity by moving another one.
107 constexpr KinematicViscosity(KinematicViscosity<NumericType>&& other) noexcept = default;
108
109 /// \brief Copy assignment operator. Assigns this kinematic viscosity by copying another one.
111 const KinematicViscosity<NumericType>& other) = default;
112
113 /// \brief Copy assignment operator. Assigns this kinematic viscosity by copying another one.
114 template <typename OtherNumericType>
117 this->value = static_cast<NumericType>(other.Value());
118 return *this;
119 }
120
121 /// \brief Move assignment operator. Assigns this kinematic viscosity by moving another one.
123 KinematicViscosity<NumericType>&& other) noexcept = default;
124
125 /// \brief Statically creates a kinematic viscosity of zero.
126 [[nodiscard]] static constexpr KinematicViscosity<NumericType> Zero() {
127 return KinematicViscosity<NumericType>{static_cast<NumericType>(0)};
128 }
129
130 /// \brief Statically creates a kinematic viscosity with a given value expressed in a given
131 /// diffusivity unit.
132 template <Unit::Diffusivity Unit>
133 [[nodiscard]] static constexpr KinematicViscosity<NumericType> Create(const NumericType value) {
135 ConvertStatically<Unit::Diffusivity, Unit, Standard<Unit::Diffusivity>>(value)};
136 }
137
139 const KinematicViscosity<NumericType>& kinematic_viscosity) const {
140 return KinematicViscosity<NumericType>{this->value + kinematic_viscosity.value};
141 }
142
144 const KinematicViscosity<NumericType>& kinematic_viscosity) const {
145 return KinematicViscosity<NumericType>{this->value - kinematic_viscosity.value};
146 }
147
148 constexpr KinematicViscosity<NumericType> operator*(const NumericType number) const {
149 return KinematicViscosity<NumericType>{this->value * number};
150 }
151
153 const MassDensity<NumericType>& mass_density) const;
154
155 constexpr KinematicViscosity<NumericType> operator/(const NumericType number) const {
156 return KinematicViscosity<NumericType>{this->value / number};
157 }
158
159 constexpr NumericType operator/(
160 const KinematicViscosity<NumericType>& kinematic_viscosity) const noexcept {
161 return this->value / kinematic_viscosity.value;
162 }
163
164 constexpr void operator+=(const KinematicViscosity<NumericType>& kinematic_viscosity) noexcept {
165 this->value += kinematic_viscosity.value;
166 }
167
168 constexpr void operator-=(const KinematicViscosity<NumericType>& kinematic_viscosity) noexcept {
169 this->value -= kinematic_viscosity.value;
170 }
171
172 constexpr void operator*=(const NumericType number) noexcept {
173 this->value *= number;
174 }
175
176 constexpr void operator/=(const NumericType number) noexcept {
177 this->value /= number;
178 }
179
180private:
181 /// \brief Constructor. Constructs a kinematic viscosity with a given value expressed in the
182 /// standard diffusivity unit.
183 explicit constexpr KinematicViscosity(const NumericType value)
184 : DimensionalScalar<Unit::Diffusivity, NumericType>(value) {}
185};
186
187template <typename NumericType>
188inline constexpr bool operator==(const KinematicViscosity<NumericType>& left,
189 const KinematicViscosity<NumericType>& right) noexcept {
190 return left.Value() == right.Value();
191}
192
193template <typename NumericType>
194inline constexpr bool operator!=(const KinematicViscosity<NumericType>& left,
195 const KinematicViscosity<NumericType>& right) noexcept {
196 return left.Value() != right.Value();
197}
198
199template <typename NumericType>
200inline constexpr bool operator<(const KinematicViscosity<NumericType>& left,
201 const KinematicViscosity<NumericType>& right) noexcept {
202 return left.Value() < right.Value();
203}
204
205template <typename NumericType>
206inline constexpr bool operator>(const KinematicViscosity<NumericType>& left,
207 const KinematicViscosity<NumericType>& right) noexcept {
208 return left.Value() > right.Value();
209}
210
211template <typename NumericType>
212inline constexpr bool operator<=(const KinematicViscosity<NumericType>& left,
213 const KinematicViscosity<NumericType>& right) noexcept {
214 return left.Value() <= right.Value();
215}
216
217template <typename NumericType>
218inline constexpr bool operator>=(const KinematicViscosity<NumericType>& left,
219 const KinematicViscosity<NumericType>& right) noexcept {
220 return left.Value() >= right.Value();
221}
222
223template <typename NumericType>
224inline std::ostream& operator<<(
225 std::ostream& stream, const KinematicViscosity<NumericType>& kinematic_viscosity) {
226 stream << kinematic_viscosity.Print();
227 return stream;
228}
229
230template <typename NumericType>
232 const NumericType number, const KinematicViscosity<NumericType>& kinematic_viscosity) {
233 return kinematic_viscosity * number;
234}
235
236} // namespace PhQ
237
238namespace std {
239
240template <typename NumericType>
241struct hash<PhQ::KinematicViscosity<NumericType>> {
242 inline size_t operator()(const PhQ::KinematicViscosity<NumericType>& kinematic_viscosity) const {
243 return hash<NumericType>()(kinematic_viscosity.Value());
244 }
245};
246
247} // namespace std
248
249#endif // PHQ_KINEMATIC_VISCOSITY_HPP
Abstract base class that represents any dimensional scalar physical quantity. Such a physical quantit...
NumericType value
Value of this physical quantity expressed in its standard unit of measure.
constexpr NumericType Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr UnitType 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...
Dynamic viscosity, also known as molecular dynamic viscosity. Dynamic viscosity is the relationship b...
Kinematic viscosity, also known as molecular kinematic viscosity. Defined as dynamic viscosity divide...
constexpr KinematicViscosity< NumericType > operator*(const NumericType number) const
constexpr KinematicViscosity< NumericType > & operator=(const KinematicViscosity< OtherNumericType > &other)
Copy assignment operator. Assigns this kinematic viscosity by copying another one.
constexpr void operator-=(const KinematicViscosity< NumericType > &kinematic_viscosity) noexcept
constexpr KinematicViscosity< NumericType > operator-(const KinematicViscosity< NumericType > &kinematic_viscosity) const
constexpr NumericType operator/(const KinematicViscosity< NumericType > &kinematic_viscosity) const noexcept
constexpr KinematicViscosity< NumericType > operator/(const NumericType number) const
constexpr KinematicViscosity< NumericType > operator+(const KinematicViscosity< NumericType > &kinematic_viscosity) const
constexpr void operator/=(const NumericType number) noexcept
static constexpr KinematicViscosity< NumericType > Create(const NumericType value)
Statically creates a kinematic viscosity with a given value expressed in a given diffusivity unit.
constexpr KinematicViscosity(const NumericType value)
Constructor. Constructs a kinematic viscosity with a given value expressed in the standard diffusivit...
~KinematicViscosity() noexcept=default
Destructor. Destroys this kinematic viscosity.
constexpr KinematicViscosity(KinematicViscosity< NumericType > &&other) noexcept=default
Move constructor. Constructs a kinematic viscosity by moving another one.
constexpr void operator*=(const NumericType number) noexcept
static constexpr KinematicViscosity< NumericType > Zero()
Statically creates a kinematic viscosity of zero.
KinematicViscosity(const NumericType value, const Unit::Diffusivity unit)
Constructor. Constructs a kinematic viscosity with a given value expressed in a given diffusivity uni...
constexpr void operator+=(const KinematicViscosity< NumericType > &kinematic_viscosity) noexcept
KinematicViscosity()=default
Default constructor. Constructs a kinematic viscosity with an uninitialized value.
constexpr KinematicViscosity< NumericType > & operator=(const KinematicViscosity< NumericType > &other)=default
Copy assignment operator. Assigns this kinematic viscosity by copying another one.
constexpr KinematicViscosity< NumericType > & operator=(KinematicViscosity< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this kinematic viscosity by moving another one.
Length, distance, or physical size. Can also represent a scalar component or magnitude of a position ...
Definition Length.hpp:111
Mass density. Mass per unit volume; see PhQ::Mass and PhQ::Volume.
Prandtl number of a fluid. Represents the ratio of the momentum diffusivity to the thermal diffusivit...
Reynolds number of a fluid flow. Measures the local turbulence of a fluid flow. Represents the ratio ...
Scalar velocity component or magnitude of a velocity vector. For a three-dimensional Euclidean veloci...
Definition Speed.hpp:100
Thermal diffusivity of a material. Measures the rate of heat transfer inside a material....
DynamicViscosity
Dynamic viscosity units.
MassDensity
Mass density units.
Length
Length units.
Definition Length.hpp:53
Diffusivity
Diffusivity units.
Speed
Speed units.
Definition Speed.hpp:53
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