Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
mobility_cahn_hilliard_model.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2023-2024 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_mobility_cahn_hilliard_model_h
5#define lethe_mobility_cahn_hilliard_model_h
6
8
9/**
10 * @brief Implementation of the computation of the mobility
11 * for Cahn-Hilliard equations.
12 */
14{
15public:
16 /**
17 * @brief Instantiate and return a pointer to a MobilityCahnHilliardModel
18 * object by casting it to the proper child class.
19 *
20 * @param[in] material_interaction_parameters Parameters for the mobility
21 * calculation.
22 */
23 static std::shared_ptr<MobilityCahnHilliardModel>
25 const Parameters::MaterialInteractions &material_interaction_parameters);
26
27 /**
28 * @brief Pure virtual method to access the mobility constant.
29 * @return Value of the mobility constant.
30 */
31 virtual double
33
34 /**
35 * @brief Definition of a virtual destructor for the class.
36 */
37 ~MobilityCahnHilliardModel() override = default;
38};
39
40/**
41 * @brief Constant mobility model.
42 *
43 * The mobility function is the following : \f$M(\phi) = D \f$ where D is the
44 * mobility constant.
45 */
47{
48public:
49 /**
50 * @brief Default constructor
51 *
52 * @param[in] p_mobility_cahn_hilliard_constant the user defined mobility
53 * constant.
54 */
56 const double p_mobility_cahn_hilliard_constant)
57 : mobility_cahn_hilliard_constant(p_mobility_cahn_hilliard_constant)
58 {}
59
60 /**
61 * @brief Destructor of derived class.
62 */
64
65 /**
66 * @brief Return the mobility constant, though it returns the same
67 * value as the value method, it is implemented here for generality.
68 *
69 * @return Value of the mobility constant.
70 */
71 double
76
77 /**
78 * @brief Compute the mobility.
79 * @param[in] fields_value Value of the various field on which the mobility
80 * may depend.
81 * @return Value of the mobility.
82 */
83 double
84 value([[maybe_unused]] const std::map<field, double> &fields_value) override
85 {
87 }
88
89 /**
90 * @brief Calculate the vector of mobility_cahn_hilliard.
91 * @param[in] field_vectors Vectors of the fields on which the mobility
92 * may depend.
93 * @param[out] property_vector Vectors of the mobility values
94 */
95 void
97 [[maybe_unused]] const std::map<field, std::vector<double>> &field_vectors,
98 std::vector<double> &property_vector) override
99 {
100 std::ranges::fill(property_vector, mobility_cahn_hilliard_constant);
101 }
102
103 /**
104 * @brief Calculate the jacobian (the partial derivative) of the
105 * mobility with respect to a field.
106 * @param[in] field_values Value of the various fields on which the mobility
107 * may depend.
108 * @param[in] id Indicator of the field with respect to which the jacobian
109 * should be calculated.
110 * @return Value of the partial derivative of the mobility with respect to
111 * the field.
112 */
113 double
114 jacobian([[maybe_unused]] const std::map<field, double> &field_values,
115 [[maybe_unused]] field id) override
116 {
117 return 0;
118 }
119
120 /**
121 * @brief Calculate the derivative of the mobility with respect to a field.
122 * @param[in] field_vectors Vector for the values of the fields used to
123 * evaluate the mobility.
124 * @param[in] id Identifier of the field with respect to which a derivative
125 * should be calculated.
126 * @param[out] jacobian_vector Vector of the value of the derivative of the
127 * mobility with respect to the field id.
128 */
129 void
131 [[maybe_unused]] const std::map<field, std::vector<double>> &field_vectors,
132 [[maybe_unused]] const field id,
133 std::vector<double> &jacobian_vector) override
134 {
135 std::ranges::fill(jacobian_vector, 0);
136 }
137
138private:
140};
141
142/**
143 * @brief Quartic mobility model.
144 *
145 * The mobility function is the following : \f$M(\phi) = D(1-\phi^2)^2 \f$
146 * where D is the mobility constant.
147 */
149{
150public:
151 /**
152 * @brief Default constructor.
153 *
154 * @param[in] p_mobility_cahn_hilliard_constant the user defined mobility
155 * constant.
156 */
158 const double p_mobility_cahn_hilliard_constant)
159 : mobility_cahn_hilliard_constant(p_mobility_cahn_hilliard_constant)
160 {
162 }
163
164 /**
165 * @brief Destructor of derived class.
166 */
168
169 /**
170 * @brief Return the mobility constant.
171 * @return Value of the mobility constant.
172 */
173 double
175 {
177 }
178
179 /**
180 * @brief Calculate the mobility.
181 * @param[in] fields_value Value of the various fields on which the mobility
182 * may depend.
183 * @return Value of the mobility calculated with the fields_value.
184 */
185 double
186 value(const std::map<field, double> &fields_value) override
187 {
188 Assert(fields_value.contains(field::phase_order_cahn_hilliard),
189 PhysicialPropertyModelFieldUndefined(
190 "MobilityCahnHilliardModelQuartic", "phase_order_cahn_hilliard"));
191 const double &phase_order_cahn_hilliard =
192 fields_value.at(field::phase_order_cahn_hilliard);
193
194 // The phase order values are clamped to avoid unphysical mobilities in the
195 // bulk phases.
197 std::pow((1 - std::min(1.0,
200 2);
201 }
202
203 /**
204 * @brief Calculate the vector of mobility.
205 * @param[in] field_vectors Vectors of the fields on which the mobility
206 * may depend.
207 * @param[out] property_vector Vector of the mobility values.
208 */
209 void
210 vector_value(const std::map<field, std::vector<double>> &field_vectors,
211 std::vector<double> &property_vector) override
212 {
213 Assert(field_vectors.contains(field::phase_order_cahn_hilliard),
214 PhysicialPropertyModelFieldUndefined(
215 "MobilityCahnHilliardModelQuartic", "phase_order_cahn_hilliard"));
216 const std::vector<double> &phase_order_cahn_hilliard =
217 field_vectors.at(field::phase_order_cahn_hilliard);
218 for (unsigned int i = 0; i < property_vector.size(); ++i)
219 {
220 property_vector[i] =
222 std::pow((1 - std::min(1.0,
225 2);
226 }
227 }
228
229 /**
230 * @brief Calculate the jacobian (the partial derivative) of the
231 * mobility with respect to a field.
232 * @param[in] fields_value Value of the various fields on which the mobility
233 * may depend.
234 * @param[in] id Indicator of the field with respect to which the Jacobian
235 * should be calculated.
236 * @return Value of the partial derivative of the mobility with respect to
237 * the field.
238 */
239
240 double
241 jacobian(const std::map<field, double> &fields_value,
242 [[maybe_unused]] field id) override
243 {
244 Assert(fields_value.contains(field::phase_order_cahn_hilliard),
245 PhysicialPropertyModelFieldUndefined(
246 "MobilityCahnHilliardModelQuartic", "phase_order_cahn_hilliard"));
247 const double &phase_order_cahn_hilliard =
248 fields_value.at(field::phase_order_cahn_hilliard);
249
250 return -4 *
251 (std::max(-1.0, std::min(phase_order_cahn_hilliard, 0.0)) +
252 std::min(1.0, std::max(phase_order_cahn_hilliard, 0.0))) *
254 (1 -
255 std::min(1.0,
257 }
258
259 /**
260 * @brief Calculate the derivative of the mobility with respect to a field.
261 * @param[in] fields_vectors Vector for the values of the fields used to
262 * evaluate the mobility.
263 * @param[in] id Identifier of the field with respect to which a derivative
264 * should be calculated.
265 * @param[out] jacobian_vector Vector of the values of the derivatives of the
266 * mobility with respect to the field id.
267 */
268
269 void
270 vector_jacobian(const std::map<field, std::vector<double>> &fields_vectors,
271 [[maybe_unused]] const field id,
272 std::vector<double> &jacobian_vector) override
273 {
274 Assert(fields_vectors.contains(field::phase_order_cahn_hilliard),
275 PhysicialPropertyModelFieldUndefined(
276 "MobilityCahnHilliardModelQuartic", "phase_order_cahn_hilliard"));
277 const std::vector<double> &phase_order_cahn_hilliard =
278 fields_vectors.at(field::phase_order_cahn_hilliard);
279 for (unsigned int i = 0; i < jacobian_vector.size(); ++i)
280 jacobian_vector[i] =
281 -4 *
282 (std::max(-1.0, std::min(phase_order_cahn_hilliard[i], 0.0)) +
283 std::min(1.0, std::max(phase_order_cahn_hilliard[i], 0.0))) *
285 (1 -
286 std::min(1.0,
288 }
289
290private:
292};
293
294#endif
InterfacePropertyModel()
class Default constructor. Set the model_depends_on to false for all variables.
std::map< field, bool > model_depends_on
double jacobian(const std::map< field, double > &field_values, field id) override
Calculate the jacobian (the partial derivative) of the mobility with respect to a field.
double value(const std::map< field, double > &fields_value) override
Compute the mobility.
void vector_jacobian(const std::map< field, std::vector< double > > &field_vectors, const field id, std::vector< double > &jacobian_vector) override
Calculate the derivative of the mobility with respect to a field.
MobilityCahnHilliardModelConstant(const double p_mobility_cahn_hilliard_constant)
Default constructor.
~MobilityCahnHilliardModelConstant() override=default
Destructor of derived class.
double get_mobility_constant() override
Return the mobility constant, though it returns the same value as the value method,...
void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
Calculate the vector of mobility_cahn_hilliard.
double jacobian(const std::map< field, double > &fields_value, field id) override
Calculate the jacobian (the partial derivative) of the mobility with respect to a field.
void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
Calculate the vector of mobility.
double get_mobility_constant() override
Return the mobility constant.
MobilityCahnHilliardModelQuartic(const double p_mobility_cahn_hilliard_constant)
Default constructor.
void vector_jacobian(const std::map< field, std::vector< double > > &fields_vectors, const field id, std::vector< double > &jacobian_vector) override
Calculate the derivative of the mobility with respect to a field.
double value(const std::map< field, double > &fields_value) override
Calculate the mobility.
~MobilityCahnHilliardModelQuartic() override=default
Destructor of derived class.
Implementation of the computation of the mobility for Cahn-Hilliard equations.
~MobilityCahnHilliardModel() override=default
Definition of a virtual destructor for the class.
virtual double get_mobility_constant()=0
Pure virtual method to access the mobility constant.
static std::shared_ptr< MobilityCahnHilliardModel > model_cast(const Parameters::MaterialInteractions &material_interaction_parameters)
Instantiate and return a pointer to a MobilityCahnHilliardModel object by casting it to the proper ch...
MaterialInteractions - Class that defines physical properties due to interactions between two differe...
Definition parameters.h:757