Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
rheological_model.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2021-2024 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
5
6std::shared_ptr<RheologicalModel>
8{
9 if (material_properties.rheological_model ==
11 return std::make_shared<Newtonian>(material_properties.kinematic_viscosity);
12 else if (material_properties.rheological_model ==
14 return std::make_shared<PowerLaw>(
19 else if (material_properties.rheological_model ==
21 return std::make_shared<Carreau>(
29
30 else // (fluid_properties.rheological_model ==
31 // Parameters::Fluid::RheologicalModel::phase_change)
32 return std::make_shared<PhaseChangeRheology>(
33 material_properties.phase_change_parameters);
34}
35
36double
37Newtonian::value(const std::map<field, double> & /*field_values*/)
38{
40}
41
42double
43PowerLaw::value(const std::map<field, double> &field_values)
44{
45 Assert(field_values.contains(field::shear_rate),
46 PhysicialPropertyModelFieldUndefined("PowerLaw", "shear_rate"));
47 const double shear_rate_magnitude = field_values.at(field::shear_rate);
48
49 return calculate_kinematic_viscosity(shear_rate_magnitude);
50}
51
52void
54 const std::map<field, std::vector<double>> &field_vectors,
55 std::vector<double> &property_vector)
56{
57 Assert(field_vectors.contains(field::shear_rate),
58 PhysicialPropertyModelFieldUndefined("PowerLaw", "shear_rate"));
59 const auto shear_rate_magnitude = field_vectors.at(field::shear_rate);
60
61 for (unsigned int i = 0; i < shear_rate_magnitude.size(); ++i)
62 property_vector[i] = calculate_kinematic_viscosity(shear_rate_magnitude[i]);
63}
64
65double
66PowerLaw::jacobian(const std::map<field, double> &field_values, const field id)
67{
68 const double shear_rate_magnitude = field_values.at(field::shear_rate);
69 if (id == field::shear_rate)
70 {
71 Assert(field_values.contains(field::shear_rate),
72 PhysicialPropertyModelFieldUndefined("PowerLaw", "shear_rate"));
73 return calculate_derivative(shear_rate_magnitude);
74 }
75 else
76 return 0;
77}
78
79void
81 const std::map<field, std::vector<double>> &field_vectors,
82 const field id,
83 std::vector<double> &jacobian_vector)
84{
85 Assert(field_vectors.contains(field::shear_rate),
86 PhysicialPropertyModelFieldUndefined("PowerLaw", "shear_rate"));
87 const auto shear_rate_magnitude = field_vectors.at(field::shear_rate);
88
89 if (id == field::shear_rate)
90 for (unsigned int i = 0; i < shear_rate_magnitude.size(); ++i)
91 jacobian_vector[i] = calculate_derivative(shear_rate_magnitude[i]);
92 else
93 std::ranges::fill(jacobian_vector, 0);
94}
95
96double
97Carreau::value(const std::map<field, double> &field_values)
98{
99 Assert(field_values.contains(field::shear_rate),
100 PhysicialPropertyModelFieldUndefined("Carreau", "shear_rate"));
101 const double shear_rate_magnitude = field_values.at(field::shear_rate);
102
103 return calculate_kinematic_viscosity(shear_rate_magnitude);
104}
105
106void
107Carreau::vector_value(const std::map<field, std::vector<double>> &field_vectors,
108 std::vector<double> &property_vector)
109{
110 Assert(field_vectors.contains(field::shear_rate),
111 PhysicialPropertyModelFieldUndefined("Carreau", "shear_rate"));
112 const auto shear_rate_magnitude = field_vectors.at(field::shear_rate);
113
114 for (unsigned int i = 0; i < shear_rate_magnitude.size(); ++i)
115 {
116 property_vector[i] =
117 calculate_kinematic_viscosity(shear_rate_magnitude[i]);
118 }
119}
120
121double
122Carreau::jacobian(const std::map<field, double> &field_values, const field id)
123{
124 if (id == field::shear_rate)
125 {
126 Assert(field_values.contains(field::shear_rate),
127 PhysicialPropertyModelFieldUndefined("Carreau", "shear_rate"));
128 return this->numerical_jacobian(field_values, field::shear_rate);
129 }
130 else
131 return 0;
132}
133
134void
136 const std::map<field, std::vector<double>> &field_vectors,
137 const field id,
138 std::vector<double> &jacobian_vector)
139{
140 if (id == field::shear_rate)
141 {
142 Assert(field_vectors.contains(field::shear_rate),
143 PhysicialPropertyModelFieldUndefined("Carreau", "shear_rate"));
144 this->vector_numerical_jacobian(field_vectors,
146 jacobian_vector);
147 }
148 else
149 std::ranges::fill(jacobian_vector, 0);
150}
151
152
153
154double
155PhaseChangeRheology::value(const std::map<field, double> &field_values)
156{
157 Assert(field_values.contains(field::temperature),
158 PhysicialPropertyModelFieldUndefined("PhaseChangeRheology",
159 "temperature"));
160 const double temperature = field_values.at(field::temperature);
161
163}
164
165void
167 const std::map<field, std::vector<double>> &field_vectors,
168 std::vector<double> &property_vector)
169{
170 Assert(field_vectors.contains(field::temperature),
171 PhysicialPropertyModelFieldUndefined("PhaseChangeRheology",
172 "temperature"));
173 const std::vector<double> &temperature_vec =
174 field_vectors.at(field::temperature);
175
176 for (unsigned int i = 0; i < temperature_vec.size(); ++i)
177 {
178 property_vector[i] = kinematic_viscosity(temperature_vec[i]);
179 }
180}
181
182double
183PhaseChangeRheology::jacobian(const std::map<field, double> &field_values,
184 const field id)
185{
186 if (id == field::temperature)
187 {
188 Assert(field_values.contains(field::temperature),
189 PhysicialPropertyModelFieldUndefined("PhaseChangeRheology",
190 "temperature"));
191 return this->numerical_jacobian(field_values, field::temperature);
192 }
193 else
194 return 0;
195}
196
197void
199 const std::map<field, std::vector<double>> &field_vectors,
200 const field id,
201 std::vector<double> &jacobian_vector)
202{
203 Assert(field_vectors.contains(field::temperature),
204 PhysicialPropertyModelFieldUndefined("PhaseChangeRheology",
205 "temperature"));
206 vector_numerical_jacobian(field_vectors, id, jacobian_vector);
207}
208
209/**
210 * @brief Calculates the kinematic viscosity used in PSPG and SUPG stabilizations.
211 * @param[in] field_values Value of the various fields on which the property may
212 * depend.
213 */
214double
216 [[maybe_unused]] const std::map<field, double> &field_values)
217{
218 return param.kinematic_viscosity_l;
219}
220
221/**
222 * @brief Calculates the vector values of the kinematic viscosity used in PSPG and SUPG stabilizations.
223 * @param[in] field_vectors Value of the fields on which the property may
224 * depend on.
225 * @param[out] property_vector Vector of computed viscosities.
226 */
227void
229 [[maybe_unused]] const std::map<field, std::vector<double>> &field_vectors,
230 std::vector<double> &property_vector)
231{
232 std::ranges::fill(property_vector, param.kinematic_viscosity_l);
233}
234
235/**
236 * @brief Calculates the dynamic viscosity used in PSPG and SUPG stabilization.
237 * @param[in] p_density_ref The density of the fluid at the reference state
238 * @param[in] field_values Value of the various fields on which the property may
239 * depend.
240 */
241double
243 const double &p_density_ref,
244 [[maybe_unused]] const std::map<field, double> &field_values)
245{
246 return param.kinematic_viscosity_l * p_density_ref;
247}
248
249/**
250 * @brief Calculates the vector values of the dynamic viscosity used in PSPG and SUPG stabilizations.
251 * @param[in] p_density_ref The density of the fluid at the reference state
252 * @param[in] field_vectors Value of the fields on which the property may
253 * depend on.
254 * @param[out] property_vector Vector of computed viscosities.
255 */
256void
258 const double &p_density_ref,
259 [[maybe_unused]] const std::map<field, std::vector<double>> &field_vectors,
260 std::vector<double> &property_vector)
261{
262 std::ranges::fill(property_vector,
263 param.kinematic_viscosity_l * p_density_ref);
264}
void vector_jacobian(const std::map< field, std::vector< double > > &field_vectors, const field id, std::vector< double > &jacobian_vector) override
vector_jacobian Calculate the derivative of the with respect to a field
void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
vector_value Calculates the vector values of the viscosity.
double jacobian(const std::map< field, double > &field_values, field id) override
jacobian Calculates the jacobian (the partial derivative) of the viscosity with respect to a field
double value(const std::map< field, double > &field_values) override
Returns the non-Newtonian viscosity.
double calculate_kinematic_viscosity(const double shear_rate_magnitude) const
double value(const std::map< field, double > &field_values) override
Returns the kinematic viscosity.
double kinematic_viscosity
Material - Class that defines the physical property of a material. Generally a material will be a flu...
Definition parameters.h:594
enum Parameters::Material::RheologicalModel rheological_model
PhaseChange phase_change_parameters
Definition parameters.h:649
NonNewtonian non_newtonian_parameters
Definition parameters.h:659
double jacobian(const std::map< field, double > &field_values, field id) override
jacobian Calculates the jacobian (the partial derivative) of the kinematic viscosity with respect to ...
virtual void get_dynamic_viscosity_for_stabilization_vector(const double &p_density_ref, const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
Calculates the vector values of the dynamic viscosity used in PSPG and SUPG stabilization terms.
Parameters::PhaseChange param
void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
vector_value Calculates the vector values of the kinematic viscosity.
double kinematic_viscosity(const double T) const
kinematic_viscosity Calculates the kinematic viscosity from the temperature using the liquid fraction
double get_kinematic_viscosity_for_stabilization(const std::map< field, double > &field_values) override
Calculates the kinematic viscosity used in PSPG and SUPG stabilization terms.
void vector_jacobian(const std::map< field, std::vector< double > > &field_vectors, const field id, std::vector< double > &jacobian_vector) override
vector_jacobian Calculate the derivative of the with respect to a field
void get_kinematic_viscosity_for_stabilization_vector(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
Calculates the vector values of the kinematic viscosity used in PSPG and SUPG stabilization terms.
virtual double get_dynamic_viscosity_for_stabilization(const double &p_density_ref, const std::map< field, double > &field_values) override
Calculates the dynamic viscosity used in PSPG and SUPG stabilization terms.
double value(const std::map< field, double > &field_values) override
Returns the kinematic viscosity.
void vector_numerical_jacobian(const std::map< field, std::vector< double > > &field_vectors, const field id, std::vector< double > &jacobian_vector)
vector_numerical_jacobian Calculates the vector of jacobian through forward finite difference (Euler)...
double numerical_jacobian(const std::map< field, double > &field_values, const field id)
numerical_jacobian Calculates the jacobian through a forward finite difference (Euler) approximation....
double calculate_kinematic_viscosity(const double shear_rate_magnitude) const
void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
vector_value Calculates the vector values of the kinematic viscosity.
double jacobian(const std::map< field, double > &field_values, field id) override
jacobian Calculates the jacobian (the partial derivative) of the kinematic viscosity with respect to ...
double calculate_derivative(const double shear_rate_magnitude) const
double value(const std::map< field, double > &field_values) override
Returns the non-Newtonian kinematic viscosity.
void vector_jacobian(const std::map< field, std::vector< double > > &field_vectors, const field id, std::vector< double > &jacobian_vector) override
vector_jacobian Calculate the derivative of the with respect to a field
static std::shared_ptr< RheologicalModel > model_cast(const Parameters::Material &material_properties)
Instantiates and returns a pointer to a RheologicalModel object by casting it to the proper child cla...
@ temperature
Temperature scalar field from heat transfer.
PowerLawParameters powerlaw_parameters
Definition parameters.h:400
CarreauParameters carreau_parameters
Definition parameters.h:399