Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
IncompressibleNewtonianFluid.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_CONSTITUTIVE_MODEL_INCOMPRESSIBLE_NEWTONIAN_FLUID_HPP
26 #define PHQ_CONSTITUTIVE_MODEL_INCOMPRESSIBLE_NEWTONIAN_FLUID_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 #include <string>
32 
33 #include "../Base.hpp"
34 #include "../ConstitutiveModel.hpp"
35 #include "../DynamicViscosity.hpp"
36 #include "../Strain.hpp"
37 #include "../StrainRate.hpp"
38 #include "../Stress.hpp"
39 #include "../SymmetricDyad.hpp"
40 #include "../Unit/Frequency.hpp"
41 #include "../Unit/Pressure.hpp"
42 
43 namespace PhQ {
44 
45 /// \brief Constitutive model for an incompressible Newtonian fluid. This is the simplest
46 /// constitutive model for a fluid. The viscous stress tensor at a point is a linear function of
47 /// only the local strain rate tensor at that point.
48 template <typename NumericType = double>
50 public:
51  /// \brief Default constructor. Constructs an incompressible Newtonian fluid constitutive model
52  /// with an uninitialized dynamic viscosity.
54 
55  /// \brief Constructor. Constructs an incompressible Newtonian fluid constitutive model from a
56  /// given dynamic viscosity.
57  explicit constexpr IncompressibleNewtonianFluid(
60 
61  /// \brief Destructor. Destroys this incompressible Newtonian fluid constitutive model.
62  ~IncompressibleNewtonianFluid() noexcept override = default;
63 
64  /// \brief Copy constructor. Constructs an incompressible Newtonian fluid constitutive model by
65  /// copying another one.
67 
68  /// \brief Move constructor. Constructs an incompressible Newtonian fluid constitutive model by
69  /// moving another one.
70  constexpr IncompressibleNewtonianFluid(IncompressibleNewtonianFluid&& other) noexcept = default;
71 
72  /// \brief Copy assignment operator. Assigns this incompressible Newtonian fluid constitutive
73  /// model by copying another one.
74  IncompressibleNewtonianFluid& operator=(const IncompressibleNewtonianFluid& other) = default;
75 
76  /// \brief Move assignment operator. Assigns this incompressible Newtonian fluid constitutive
77  /// model by moving another one.
78  IncompressibleNewtonianFluid& operator=(IncompressibleNewtonianFluid&& other) noexcept = default;
79 
80  /// \brief Dynamic viscosity of this incompressible Newtonian fluid constitutive model.
81  [[nodiscard]] inline constexpr const PhQ::DynamicViscosity<NumericType>&
82  DynamicViscosity() const noexcept {
83  return dynamic_viscosity;
84  }
85 
86  /// \brief Returns this constitutive model's type.
87  [[nodiscard]] inline ConstitutiveModel::Type GetType() const noexcept override {
89  }
90 
91  /// \brief Returns the stress resulting from a given strain and strain rate. Since this is an
92  /// incompressible Newtonian fluid constitutive model, the strain does not contribute to the
93  /// stress and is ignored.
94  [[nodiscard]] inline PhQ::Stress<float> Stress(
95  const PhQ::Strain<float>& /*strain*/,
96  const PhQ::StrainRate<float>& strain_rate) const override {
97  return this->Stress(strain_rate);
98  }
99 
100  /// \brief Returns the stress resulting from a given strain and strain rate. Since this is an
101  /// incompressible Newtonian fluid constitutive model, the strain does not contribute to the
102  /// stress and is ignored.
103  [[nodiscard]] inline PhQ::Stress<double> Stress(
104  const PhQ::Strain<double>& /*strain*/,
105  const PhQ::StrainRate<double>& strain_rate) const override {
106  return this->Stress(strain_rate);
107  }
108 
109  /// \brief Returns the stress resulting from a given strain and strain rate. Since this is an
110  /// incompressible Newtonian fluid constitutive model, the strain does not contribute to the
111  /// stress and is ignored.
112  [[nodiscard]] inline PhQ::Stress<long double> Stress(
113  const PhQ::Strain<long double>& /*strain*/,
114  const PhQ::StrainRate<long double>& strain_rate) const override {
115  return this->Stress(strain_rate);
116  }
117 
118  /// \brief Returns the stress resulting from a given strain. Since this is an incompressible
119  /// Newtonian fluid constitutive model, the strain does not contribute to the stress, so this
120  /// always returns a stress of zero.
121  [[nodiscard]] inline PhQ::Stress<float> Stress(
122  const PhQ::Strain<float>& /*strain*/) const override {
123  return PhQ::Stress<float>::Zero();
124  }
125 
126  /// \brief Returns the stress resulting from a given strain. Since this is an incompressible
127  /// Newtonian fluid constitutive model, the strain does not contribute to the stress, so this
128  /// always returns a stress of zero.
129  [[nodiscard]] inline PhQ::Stress<double> Stress(
130  const PhQ::Strain<double>& /*strain*/) const override {
131  return PhQ::Stress<double>::Zero();
132  }
133 
134  /// \brief Returns the stress resulting from a given strain. Since this is an incompressible
135  /// Newtonian fluid constitutive model, the strain does not contribute to the stress, so this
136  /// always returns a stress of zero.
137  [[nodiscard]] inline PhQ::Stress<long double> Stress(
138  const PhQ::Strain<long double>& /*strain*/) const override {
140  }
141 
142  /// \brief Returns the stress resulting from a given strain rate.
143  [[nodiscard]] inline PhQ::Stress<float> Stress(
144  const PhQ::StrainRate<float>& strain_rate) const override {
145  // stress = 2 * dynamic_viscosity * strain_rate
146  return PhQ::Stress<float>{{static_cast<float>(2) * static_cast<float>(dynamic_viscosity.Value())
147  * static_cast<PhQ::SymmetricDyad<float>>(strain_rate.Value())},
148  Standard<PhQ::Unit::Pressure>};
149  }
150 
151  /// \brief Returns the stress resulting from a given strain rate.
152  [[nodiscard]] inline PhQ::Stress<double> Stress(
153  const PhQ::StrainRate<double>& strain_rate) const override {
154  // stress = 2 * dynamic_viscosity * strain_rate
155  return PhQ::Stress<double>{
156  {static_cast<double>(2) * static_cast<double>(dynamic_viscosity.Value())
157  * static_cast<PhQ::SymmetricDyad<double>>(strain_rate.Value())},
158  Standard<PhQ::Unit::Pressure>};
159  }
160 
161  /// \brief Returns the stress resulting from a given strain rate.
162  [[nodiscard]] inline PhQ::Stress<long double> Stress(
163  const PhQ::StrainRate<long double>& strain_rate) const override {
164  // stress = 2 * dynamic_viscosity * strain_rate
166  {static_cast<long double>(2) * static_cast<long double>(dynamic_viscosity.Value())
167  * static_cast<PhQ::SymmetricDyad<long double>>(strain_rate.Value())},
168  Standard<PhQ::Unit::Pressure>};
169  }
170 
171  /// \brief Returns the strain resulting from a given stress. Since this is an incompressible
172  /// Newtonian fluid constitutive model, stress does not depend on strain, so this always returns a
173  /// strain of zero.
174  [[nodiscard]] inline PhQ::Strain<float> Strain(
175  const PhQ::Stress<float>& /*stress*/) const override {
176  return PhQ::Strain<float>::Zero();
177  }
178 
179  /// \brief Returns the strain resulting from a given stress. Since this is an incompressible
180  /// Newtonian fluid constitutive model, stress does not depend on strain, so this always returns a
181  /// strain of zero.
182  [[nodiscard]] inline PhQ::Strain<double> Strain(
183  const PhQ::Stress<double>& /*stress*/) const override {
184  return PhQ::Strain<double>::Zero();
185  }
186 
187  /// \brief Returns the strain resulting from a given stress. Since this is an incompressible
188  /// Newtonian fluid constitutive model, stress does not depend on strain, so this always returns a
189  /// strain of zero.
190  [[nodiscard]] inline PhQ::Strain<long double> Strain(
191  const PhQ::Stress<long double>& /*stress*/) const override {
193  }
194 
195  /// \brief Returns the strain rate resulting from a given stress.
196  [[nodiscard]] inline PhQ::StrainRate<float> StrainRate(
197  const PhQ::Stress<float>& stress) const override {
198  // strain_rate = stress / (2 * dynamic_viscosity)
199  return PhQ::StrainRate<float>{
200  {static_cast<PhQ::SymmetricDyad<float>>(stress.Value())
201  / (static_cast<float>(2) * static_cast<float>(dynamic_viscosity.Value()))},
202  Standard<PhQ::Unit::Frequency>};
203  }
204 
205  /// \brief Returns the strain rate resulting from a given stress.
206  [[nodiscard]] inline PhQ::StrainRate<double> StrainRate(
207  const PhQ::Stress<double>& stress) const override {
208  // strain_rate = stress / (2 * dynamic_viscosity)
210  {static_cast<PhQ::SymmetricDyad<double>>(stress.Value())
211  / (static_cast<double>(2) * static_cast<double>(dynamic_viscosity.Value()))},
212  Standard<PhQ::Unit::Frequency>};
213  }
214 
215  /// \brief Returns the strain rate resulting from a given stress.
217  const PhQ::Stress<long double>& stress) const override {
218  // strain_rate = stress / (2 * dynamic_viscosity)
220  {static_cast<PhQ::SymmetricDyad<long double>>(stress.Value())
221  / (static_cast<long double>(2) * static_cast<long double>(dynamic_viscosity.Value()))},
222  Standard<PhQ::Unit::Frequency>};
223  }
224 
225  /// \brief Prints this incompressible Newtonian fluid constitutive model as a string.
226  [[nodiscard]] inline std::string Print() const override {
227  return {"Type = " + std::string{Abbreviation(this->GetType())}
228  + ", Dynamic Viscosity = " + dynamic_viscosity.Print()};
229  }
230 
231  /// \brief Serializes this incompressible Newtonian fluid constitutive model as a JSON message.
232  [[nodiscard]] inline std::string JSON() const override {
233  return {R"({"type":")" + SnakeCase(Abbreviation(this->GetType())) + R"(","dynamic_viscosity":)"
234  + dynamic_viscosity.JSON() + "}"};
235  }
236 
237  /// \brief Serializes this incompressible Newtonian fluid constitutive model as an XML message.
238  [[nodiscard]] inline std::string XML() const override {
239  return {"<type>" + SnakeCase(Abbreviation(this->GetType())) + "</type><dynamic_viscosity>"
240  + dynamic_viscosity.XML() + "</dynamic_viscosity>"};
241  }
242 
243  /// \brief Serializes this incompressible Newtonian fluid constitutive model as a YAML message.
244  [[nodiscard]] inline std::string YAML() const override {
245  return {"{type:\"" + SnakeCase(Abbreviation(this->GetType()))
246  + "\",dynamic_viscosity:" + dynamic_viscosity.YAML() + "}"};
247  }
248 
249 private:
250  /// \brief Dynamic viscosity of this incompressible Newtonian fluid constitutive model.
252 };
253 
254 template <typename NumericType>
255 inline constexpr bool operator==(
257  const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& right) noexcept {
258  return left.DynamicViscosity() == right.DynamicViscosity();
259 }
260 
261 template <typename NumericType>
262 inline constexpr bool operator!=(
264  const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& right) noexcept {
265  return left.DynamicViscosity() != right.DynamicViscosity();
266 }
267 
268 template <typename NumericType>
269 inline constexpr bool operator<(
271  const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& right) noexcept {
272  return left.DynamicViscosity() < right.DynamicViscosity();
273 }
274 
275 template <typename NumericType>
276 inline constexpr bool operator>(
278  const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& right) noexcept {
279  return left.DynamicViscosity() > right.DynamicViscosity();
280 }
281 
282 template <typename NumericType>
283 inline constexpr bool operator<=(
285  const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& right) noexcept {
286  return left.DynamicViscosity() <= right.DynamicViscosity();
287 }
288 
289 template <typename NumericType>
290 inline constexpr bool operator>=(
292  const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& right) noexcept {
293  return left.DynamicViscosity() >= right.DynamicViscosity();
294 }
295 
296 template <typename NumericType>
297 inline std::ostream& operator<<(
298  std::ostream& stream,
300  stream << model.Print();
301  return stream;
302 }
303 
304 } // namespace PhQ
305 
306 namespace std {
307 
308 template <typename NumericType>
309 struct hash<typename PhQ::ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>> {
310  size_t operator()(
312  const {
313  return hash<PhQ::DynamicViscosity<NumericType>>()(model.DynamicViscosity());
314  }
315 };
316 
317 } // namespace std
318 
319 #endif // PHQ_CONSTITUTIVE_MODEL_INCOMPRESSIBLE_NEWTONIAN_FLUID_HPP
Constitutive model for an incompressible Newtonian fluid. This is the simplest constitutive model for...
IncompressibleNewtonianFluid()
Default constructor. Constructs an incompressible Newtonian fluid constitutive model with an uninitia...
PhQ::StrainRate< double > StrainRate(const PhQ::Stress< double > &stress) const override
Returns the strain rate resulting from a given stress.
PhQ::Stress< long double > Stress(const PhQ::Strain< long double > &, const PhQ::StrainRate< long double > &strain_rate) const override
Returns the stress resulting from a given strain and strain rate. Since this is an incompressible New...
PhQ::StrainRate< long double > StrainRate(const PhQ::Stress< long double > &stress) const override
Returns the strain rate resulting from a given stress.
PhQ::Stress< long double > Stress(const PhQ::StrainRate< long double > &strain_rate) const override
Returns the stress resulting from a given strain rate.
PhQ::Strain< long double > Strain(const PhQ::Stress< long double > &) const override
Returns the strain resulting from a given stress. Since this is an incompressible Newtonian fluid con...
PhQ::Stress< long double > Stress(const PhQ::Strain< long double > &) const override
Returns the stress resulting from a given strain. Since this is an incompressible Newtonian fluid con...
PhQ::Strain< double > Strain(const PhQ::Stress< double > &) const override
Returns the strain resulting from a given stress. Since this is an incompressible Newtonian fluid con...
std::string Print() const override
Prints this incompressible Newtonian fluid constitutive model as a string.
std::string JSON() const override
Serializes this incompressible Newtonian fluid constitutive model as a JSON message.
PhQ::Stress< double > Stress(const PhQ::Strain< double > &, const PhQ::StrainRate< double > &strain_rate) const override
Returns the stress resulting from a given strain and strain rate. Since this is an incompressible New...
PhQ::Stress< float > Stress(const PhQ::Strain< float > &, const PhQ::StrainRate< float > &strain_rate) const override
Returns the stress resulting from a given strain and strain rate. Since this is an incompressible New...
PhQ::Stress< double > Stress(const PhQ::Strain< double > &) const override
Returns the stress resulting from a given strain. Since this is an incompressible Newtonian fluid con...
constexpr const PhQ::DynamicViscosity< NumericType > & DynamicViscosity() const noexcept
Dynamic viscosity of this incompressible Newtonian fluid constitutive model.
PhQ::Stress< float > Stress(const PhQ::Strain< float > &) const override
Returns the stress resulting from a given strain. Since this is an incompressible Newtonian fluid con...
PhQ::Stress< float > Stress(const PhQ::StrainRate< float > &strain_rate) const override
Returns the stress resulting from a given strain rate.
constexpr IncompressibleNewtonianFluid(const DynamicViscosity< NumericType > &dynamic_viscosity)
Constructor. Constructs an incompressible Newtonian fluid constitutive model from a given dynamic vis...
PhQ::Strain< float > Strain(const PhQ::Stress< float > &) const override
Returns the strain resulting from a given stress. Since this is an incompressible Newtonian fluid con...
PhQ::DynamicViscosity< NumericType > dynamic_viscosity
Dynamic viscosity of this incompressible Newtonian fluid constitutive model.
PhQ::Stress< double > Stress(const PhQ::StrainRate< double > &strain_rate) const override
Returns the stress resulting from a given strain rate.
ConstitutiveModel::Type GetType() const noexcept override
Returns this constitutive model's type.
PhQ::StrainRate< float > StrainRate(const PhQ::Stress< float > &stress) const override
Returns the strain rate resulting from a given stress.
~IncompressibleNewtonianFluid() noexcept override=default
Destructor. Destroys this incompressible Newtonian fluid constitutive model.
Abstract base class for a material's constitutive model, which is a model that defines the relationsh...
Type
Type of a material's constitutive model.
@ IncompressibleNewtonianFluid
Incompressible Newtonian fluid constitutive model.
virtual std::string XML() const =0
Serializes this constitutive model as an XML message.
virtual std::string YAML() const =0
Serializes this constitutive model as a YAML message.
constexpr const PhQ::SymmetricDyad< NumericType > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
Dynamic viscosity, also known as molecular dynamic viscosity. Dynamic viscosity is the relationship b...
Three-dimensional Euclidean strain rate symmetric dyadic tensor. Time rate of change of strain....
Definition: StrainRate.hpp:51
Three-dimensional Euclidean strain symmetric dyadic tensor. Contains six components in Cartesian coor...
Definition: Strain.hpp:68
static constexpr Strain< NumericType > Zero()
Statically creates a strain tensor of zero.
Definition: Strain.hpp:136
Three-dimensional Euclidean Cauchy stress symmetric dyadic tensor. Contains six components in Cartesi...
Definition: Stress.hpp:50
static constexpr Stress< NumericType > Zero()
Statically creates a stress tensor of zero.
Definition: Stress.hpp:105
Symmetric three-dimensional Euclidean dyadic tensor. Contains six components in Cartesian coordinates...
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 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::string SnakeCase(const std::string_view string)
Returns a copy of the given string in snake case: all characters are lowercase and all spaces are rep...
Definition: Base.hpp:263
std::string_view Abbreviation(const Enumeration enumeration)
Returns the abbreviation of a given enumeration value. For example, PhQ::Abbreviation(PhQ::Unit::Time...
Definition: Base.hpp:89
constexpr bool operator!=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)