-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIncompressibleNewtonianFluid.hpp
318 lines (273 loc) · 14.5 KB
/
IncompressibleNewtonianFluid.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// Copyright © 2020-2024 Alexandre Coderre-Chabot
//
// This file is part of Physical Quantities (PhQ), a C++ library of physical quantities, physical
// models, and units of measure for scientific computing.
//
// Physical Quantities is hosted at:
// https://github.com/acodcha/phq
//
// Physical Quantities is licensed under the MIT License:
// https://mit-license.org
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// - The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef PHQ_CONSTITUTIVE_MODEL_INCOMPRESSIBLE_NEWTONIAN_FLUID_HPP
#define PHQ_CONSTITUTIVE_MODEL_INCOMPRESSIBLE_NEWTONIAN_FLUID_HPP
#include <cstddef>
#include <functional>
#include <ostream>
#include <string>
#include "../Base.hpp"
#include "../ConstitutiveModel.hpp"
#include "../DynamicViscosity.hpp"
#include "../Strain.hpp"
#include "../StrainRate.hpp"
#include "../Stress.hpp"
#include "../SymmetricDyad.hpp"
#include "../Unit/Frequency.hpp"
#include "../Unit/Pressure.hpp"
namespace PhQ {
/// \brief Constitutive model for an incompressible Newtonian fluid. This is the simplest
/// constitutive model for a fluid. The viscous stress tensor at a point is a linear function of
/// only the local strain rate tensor at that point.
template <typename NumericType = double>
class ConstitutiveModel::IncompressibleNewtonianFluid : public ConstitutiveModel {
public:
/// \brief Default constructor. Constructs an incompressible Newtonian fluid constitutive model
/// with an uninitialized dynamic viscosity.
IncompressibleNewtonianFluid() : ConstitutiveModel() {}
/// \brief Constructor. Constructs an incompressible Newtonian fluid constitutive model from a
/// given dynamic viscosity.
explicit constexpr IncompressibleNewtonianFluid(
const DynamicViscosity<NumericType>& dynamic_viscosity)
: ConstitutiveModel(), dynamic_viscosity(dynamic_viscosity) {}
/// \brief Destructor. Destroys this incompressible Newtonian fluid constitutive model.
~IncompressibleNewtonianFluid() noexcept override = default;
/// \brief Copy constructor. Constructs an incompressible Newtonian fluid constitutive model by
/// copying another one.
constexpr IncompressibleNewtonianFluid(const IncompressibleNewtonianFluid& other) = default;
/// \brief Move constructor. Constructs an incompressible Newtonian fluid constitutive model by
/// moving another one.
constexpr IncompressibleNewtonianFluid(IncompressibleNewtonianFluid&& other) noexcept = default;
/// \brief Copy assignment operator. Assigns this incompressible Newtonian fluid constitutive
/// model by copying another one.
IncompressibleNewtonianFluid& operator=(const IncompressibleNewtonianFluid& other) = default;
/// \brief Move assignment operator. Assigns this incompressible Newtonian fluid constitutive
/// model by moving another one.
IncompressibleNewtonianFluid& operator=(IncompressibleNewtonianFluid&& other) noexcept = default;
/// \brief Dynamic viscosity of this incompressible Newtonian fluid constitutive model.
[[nodiscard]] inline constexpr const PhQ::DynamicViscosity<NumericType>&
DynamicViscosity() const noexcept {
return dynamic_viscosity;
}
/// \brief Returns this constitutive model's type.
[[nodiscard]] inline ConstitutiveModel::Type GetType() const noexcept override {
return ConstitutiveModel::Type::IncompressibleNewtonianFluid;
}
/// \brief Returns the stress resulting from a given strain and strain rate. Since this is an
/// incompressible Newtonian fluid constitutive model, the strain does not contribute to the
/// stress and is ignored.
[[nodiscard]] inline PhQ::Stress<float> Stress(
const PhQ::Strain<float>& /*strain*/,
const PhQ::StrainRate<float>& strain_rate) const override {
return this->Stress(strain_rate);
}
/// \brief Returns the stress resulting from a given strain and strain rate. Since this is an
/// incompressible Newtonian fluid constitutive model, the strain does not contribute to the
/// stress and is ignored.
[[nodiscard]] inline PhQ::Stress<double> Stress(
const PhQ::Strain<double>& /*strain*/,
const PhQ::StrainRate<double>& strain_rate) const override {
return this->Stress(strain_rate);
}
/// \brief Returns the stress resulting from a given strain and strain rate. Since this is an
/// incompressible Newtonian fluid constitutive model, the strain does not contribute to the
/// stress and is ignored.
[[nodiscard]] inline PhQ::Stress<long double> Stress(
const PhQ::Strain<long double>& /*strain*/,
const PhQ::StrainRate<long double>& strain_rate) const override {
return this->Stress(strain_rate);
}
/// \brief Returns the stress resulting from a given strain. Since this is an incompressible
/// Newtonian fluid constitutive model, the strain does not contribute to the stress, so this
/// always returns a stress of zero.
[[nodiscard]] inline PhQ::Stress<float> Stress(
const PhQ::Strain<float>& /*strain*/) const override {
return PhQ::Stress<float>::Zero();
}
/// \brief Returns the stress resulting from a given strain. Since this is an incompressible
/// Newtonian fluid constitutive model, the strain does not contribute to the stress, so this
/// always returns a stress of zero.
[[nodiscard]] inline PhQ::Stress<double> Stress(
const PhQ::Strain<double>& /*strain*/) const override {
return PhQ::Stress<double>::Zero();
}
/// \brief Returns the stress resulting from a given strain. Since this is an incompressible
/// Newtonian fluid constitutive model, the strain does not contribute to the stress, so this
/// always returns a stress of zero.
[[nodiscard]] inline PhQ::Stress<long double> Stress(
const PhQ::Strain<long double>& /*strain*/) const override {
return PhQ::Stress<long double>::Zero();
}
/// \brief Returns the stress resulting from a given strain rate.
[[nodiscard]] inline PhQ::Stress<float> Stress(
const PhQ::StrainRate<float>& strain_rate) const override {
// stress = 2 * dynamic_viscosity * strain_rate
return PhQ::Stress<float>{{static_cast<float>(2) * static_cast<float>(dynamic_viscosity.Value())
* static_cast<PhQ::SymmetricDyad<float>>(strain_rate.Value())},
Standard<PhQ::Unit::Pressure>};
}
/// \brief Returns the stress resulting from a given strain rate.
[[nodiscard]] inline PhQ::Stress<double> Stress(
const PhQ::StrainRate<double>& strain_rate) const override {
// stress = 2 * dynamic_viscosity * strain_rate
return PhQ::Stress<double>{
{static_cast<double>(2) * static_cast<double>(dynamic_viscosity.Value())
* static_cast<PhQ::SymmetricDyad<double>>(strain_rate.Value())},
Standard<PhQ::Unit::Pressure>};
}
/// \brief Returns the stress resulting from a given strain rate.
[[nodiscard]] inline PhQ::Stress<long double> Stress(
const PhQ::StrainRate<long double>& strain_rate) const override {
// stress = 2 * dynamic_viscosity * strain_rate
return PhQ::Stress<long double>{
{static_cast<long double>(2) * static_cast<long double>(dynamic_viscosity.Value())
* static_cast<PhQ::SymmetricDyad<long double>>(strain_rate.Value())},
Standard<PhQ::Unit::Pressure>};
}
/// \brief Returns the strain resulting from a given stress. Since this is an incompressible
/// Newtonian fluid constitutive model, stress does not depend on strain, so this always returns a
/// strain of zero.
[[nodiscard]] inline PhQ::Strain<float> Strain(
const PhQ::Stress<float>& /*stress*/) const override {
return PhQ::Strain<float>::Zero();
}
/// \brief Returns the strain resulting from a given stress. Since this is an incompressible
/// Newtonian fluid constitutive model, stress does not depend on strain, so this always returns a
/// strain of zero.
[[nodiscard]] inline PhQ::Strain<double> Strain(
const PhQ::Stress<double>& /*stress*/) const override {
return PhQ::Strain<double>::Zero();
}
/// \brief Returns the strain resulting from a given stress. Since this is an incompressible
/// Newtonian fluid constitutive model, stress does not depend on strain, so this always returns a
/// strain of zero.
[[nodiscard]] inline PhQ::Strain<long double> Strain(
const PhQ::Stress<long double>& /*stress*/) const override {
return PhQ::Strain<long double>::Zero();
}
/// \brief Returns the strain rate resulting from a given stress.
[[nodiscard]] inline PhQ::StrainRate<float> StrainRate(
const PhQ::Stress<float>& stress) const override {
// strain_rate = stress / (2 * dynamic_viscosity)
return PhQ::StrainRate<float>{
{static_cast<PhQ::SymmetricDyad<float>>(stress.Value())
/ (static_cast<float>(2) * static_cast<float>(dynamic_viscosity.Value()))},
Standard<PhQ::Unit::Frequency>};
}
/// \brief Returns the strain rate resulting from a given stress.
[[nodiscard]] inline PhQ::StrainRate<double> StrainRate(
const PhQ::Stress<double>& stress) const override {
// strain_rate = stress / (2 * dynamic_viscosity)
return PhQ::StrainRate<double>{
{static_cast<PhQ::SymmetricDyad<double>>(stress.Value())
/ (static_cast<double>(2) * static_cast<double>(dynamic_viscosity.Value()))},
Standard<PhQ::Unit::Frequency>};
}
/// \brief Returns the strain rate resulting from a given stress.
[[nodiscard]] inline PhQ::StrainRate<long double> StrainRate(
const PhQ::Stress<long double>& stress) const override {
// strain_rate = stress / (2 * dynamic_viscosity)
return PhQ::StrainRate<long double>{
{static_cast<PhQ::SymmetricDyad<long double>>(stress.Value())
/ (static_cast<long double>(2) * static_cast<long double>(dynamic_viscosity.Value()))},
Standard<PhQ::Unit::Frequency>};
}
/// \brief Prints this incompressible Newtonian fluid constitutive model as a string.
[[nodiscard]] inline std::string Print() const override {
return {"Type = " + std::string{Abbreviation(this->GetType())}
+ ", Dynamic Viscosity = " + dynamic_viscosity.Print()};
}
/// \brief Serializes this incompressible Newtonian fluid constitutive model as a JSON message.
[[nodiscard]] inline std::string JSON() const override {
return {R"({"type":")" + SnakeCase(Abbreviation(this->GetType())) + R"(","dynamic_viscosity":)"
+ dynamic_viscosity.JSON() + "}"};
}
/// \brief Serializes this incompressible Newtonian fluid constitutive model as an XML message.
[[nodiscard]] inline std::string XML() const override {
return {"<type>" + SnakeCase(Abbreviation(this->GetType())) + "</type><dynamic_viscosity>"
+ dynamic_viscosity.XML() + "</dynamic_viscosity>"};
}
/// \brief Serializes this incompressible Newtonian fluid constitutive model as a YAML message.
[[nodiscard]] inline std::string YAML() const override {
return {"{type:\"" + SnakeCase(Abbreviation(this->GetType()))
+ "\",dynamic_viscosity:" + dynamic_viscosity.YAML() + "}"};
}
private:
/// \brief Dynamic viscosity of this incompressible Newtonian fluid constitutive model.
PhQ::DynamicViscosity<NumericType> dynamic_viscosity;
};
template <typename NumericType>
inline constexpr bool operator==(
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& left,
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& right) noexcept {
return left.DynamicViscosity() == right.DynamicViscosity();
}
template <typename NumericType>
inline constexpr bool operator!=(
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& left,
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& right) noexcept {
return left.DynamicViscosity() != right.DynamicViscosity();
}
template <typename NumericType>
inline constexpr bool operator<(
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& left,
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& right) noexcept {
return left.DynamicViscosity() < right.DynamicViscosity();
}
template <typename NumericType>
inline constexpr bool operator>(
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& left,
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& right) noexcept {
return left.DynamicViscosity() > right.DynamicViscosity();
}
template <typename NumericType>
inline constexpr bool operator<=(
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& left,
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& right) noexcept {
return left.DynamicViscosity() <= right.DynamicViscosity();
}
template <typename NumericType>
inline constexpr bool operator>=(
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& left,
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& right) noexcept {
return left.DynamicViscosity() >= right.DynamicViscosity();
}
template <typename NumericType>
inline std::ostream& operator<<(
std::ostream& stream,
const typename ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>& model) {
stream << model.Print();
return stream;
}
} // namespace PhQ
namespace std {
template <typename NumericType>
struct hash<typename PhQ::ConstitutiveModel::IncompressibleNewtonianFluid<NumericType>> {
size_t operator()(const typename PhQ::ConstitutiveModel::
IncompressibleNewtonianFluid<NumericType>& model) const {
return hash<PhQ::DynamicViscosity<NumericType>>()(model.DynamicViscosity());
}
};
} // namespace std
#endif // PHQ_CONSTITUTIVE_MODEL_INCOMPRESSIBLE_NEWTONIAN_FLUID_HPP