Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
surface_tension_model.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2023-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_surface_tension_model_h
5#define lethe_surface_tension_model_h
6
8#include <core/phase_change.h>
9
10#include <algorithm>
11
12/**
13 * @brief Abstract class that allows to calculate the
14 * surface tension coefficient.
15 */
17{
18public:
19 /**
20 * @brief Instantiates and returns a pointer to a SurfaceTensionModel object
21 * by casting it to the proper child class
22 *
23 * @param material_interaction_parameters Parameters for the surface tension
24 * coefficient calculation
25 */
26 static std::shared_ptr<SurfaceTensionModel>
28 const Parameters::MaterialInteractions &material_interaction_parameters);
29
30 /**
31 * @brief is_constant_surface_tension_model Returns a boolean indicating if
32 * the model is a constant surface tension model.
33 * @return Boolean value of if the model corresponds to a constant surface
34 * tension model.
35 */
36 bool
41
42protected:
44};
45
46
47/**
48 * @brief Constant surface tension.
49 */
51{
52public:
53 /**
54 * @brief Default constructor
55 */
56 SurfaceTensionConstant(const double p_surface_tension_coefficient)
57 : surface_tension_coefficient(p_surface_tension_coefficient)
58 {
59 this->surface_tension_is_constant = true;
60 }
61
62 /**
63 * @brief value Calculates the surface tension coefficient
64 * @param fields_value Value of the various field on which the property may
65 * depend.
66 * @return value of the physical property calculated with the fields_value
67 */
68 double
69 value(const std::map<field, double> & /*fields_value*/) override
70 {
72 }
73
74 /**
75 * @brief vector_value Calculates the vector of surface tension coefficient.
76 * @param field_vectors Vectors of the fields on which the surface tension
77 * coefficient may depend.
78 * @param property_vector Vectors of the surface tension coefficient values
79 */
80 void
81 vector_value(const std::map<field, std::vector<double>> & /*field_vectors*/,
82 std::vector<double> &property_vector) override
83 {
84 std::ranges::fill(property_vector, surface_tension_coefficient);
85 }
86
87 /**
88 * @brief jacobian Calculates the jacobian (the partial derivative) of the
89 * surface tension coefficient with respect to a field
90 * @param field_values Value of the various fields on which the property may
91 * depend.
92 * @param id Indicator of the field with respect to which the jacobian
93 * should be calculated.
94 * @return value of the partial derivative of the surface tension coefficient
95 * with respect to the field.
96 */
97 double
98 jacobian(const std::map<field, double> & /*field_values*/,
99 field /*id*/) override
100 {
101 return 0;
102 }
103
104 /**
105 * @brief vector_jacobian Calculates the derivative of the surface tension
106 * coefficient with respect to a field.
107 * @param field_vectors Vector for the values of the fields used to evaluate
108 * the property.
109 * @param id Identifier of the field with respect to which a derivative should
110 * be calculated.
111 * @param jacobian vector of the value of the derivative of the surface
112 * tension coefficient with respect to the field id.
113 */
114 void
116 const std::map<field, std::vector<double>> & /*field_vectors*/,
117 const field /*id*/,
118 std::vector<double> &jacobian_vector) override
119 {
120 std::ranges::fill(jacobian_vector, 0);
121 }
122
123private:
125};
126
127/**
128 * @brief Linear surface tension. The surface tension is given by:
129 * sigma_0 + dsimga/dT * (T-T_0).
130 */
132{
133public:
134 /**
135 * @brief Default constructor
136 * @param p_surface_tension_parameters The parameters for the surface tension
137 * model, including the surface tension coefficient sigma_0 and surface
138 * tension gradient dsimga/dT at the reference temperature T_0
139 */
141 const Parameters::SurfaceTensionParameters &p_surface_tension_parameters)
143 p_surface_tension_parameters.surface_tension_coefficient)
144 , T_0(p_surface_tension_parameters.T_0)
146 p_surface_tension_parameters.surface_tension_gradient)
147 {
149 }
150
151 /**
152 * @brief value Calculates the surface tension coefficient
153 * @param field_vectors Vectors of the fields on which the surface tension
154 * depends. In this case, it depends on the temperature.
155 * @return value of the physical property calculated with the fields_value
156 */
157 double
158 value(const std::map<field, double> &fields_value) override
159 {
160 Assert(fields_value.find(field::temperature) != fields_value.end(),
161 PhysicialPropertyModelFieldUndefined("SurfaceTensionLinear",
162 "temperature"));
163 const double temperature = fields_value.at(field::temperature);
166 }
167
168 /**
169 * @brief vector_value Calculates the vector of surface tension coefficient.
170 * @param field_vectors Vectors of the fields on which the surface tension
171 * depends. In this case, it depends on the temperature.
172 * @param property_vector Vectors of the surface tension coefficient values
173 */
174 void
175 vector_value(const std::map<field, std::vector<double>> &field_vectors,
176 std::vector<double> &property_vector) override
177 {
178 Assert(field_vectors.find(field::temperature) != field_vectors.end(),
179 PhysicialPropertyModelFieldUndefined("SurfaceTensionLinear",
180 "temperature"));
181 const std::vector<double> &temperature =
182 field_vectors.at(field::temperature);
183 for (unsigned int i = 0; i < property_vector.size(); ++i)
184 property_vector[i] = surface_tension_coefficient +
186 }
187
188 /**
189 * @brief jacobian Calculates the jacobian (the partial derivative) of the
190 * surface tension coefficient with respect to a field
191 * @param field_values Value of the various fields on which the property may
192 * depend.
193 * @param id Indicator of the field with respect to which the jacobian
194 * should be calculated.
195 * @return value of the partial derivative of the surface tension coefficient
196 * with respect to the field.
197 */
198 double
199 jacobian(const std::map<field, double> & /*field_values*/, field id) override
200 {
201 if (id == field::temperature)
203 else
204 return 0;
205 }
206
207 /**
208 * @brief vector_jacobian Calculates the derivative of the surface tension
209 * coefficient with respect to a field.
210 * @param field_vectors Vector for the values of the fields used to evaluate
211 * the property.
212 * @param id Identifier of the field with respect to which a derivative should
213 * be calculated.
214 * @param jacobian vector of the value of the derivative of the surface
215 * tension coefficient with respect to the field id.
216 */
217 void
219 const std::map<field, std::vector<double>> & /*field_vectors*/,
220 const field id,
221 std::vector<double> &jacobian_vector) override
222 {
223 if (id == field::temperature)
224 std::ranges::fill(jacobian_vector, surface_tension_gradient);
225 else
226 std::ranges::fill(jacobian_vector, 0);
227 }
228
229protected:
231 const double T_0;
233};
234
235/**
236 * @brief Linear surface tension with phase change. The surface tension is given by:
237 * alpha_l*(sigma_0 + dsigma/dT * (T-T_0)).
238 */
240{
241public:
242 /**
243 * @brief Default constructor
244 * @param p_surface_tension_parameters The parameters for the surface tension
245 * model, including the surface tension coefficient sigma_0 and surface
246 * tension gradient dsimga/dT at the reference temperature T_0, and the
247 * solidus and liquidus temperatures T_solidus and T_liquidus respectively.
248 */
250 const Parameters::SurfaceTensionParameters &p_surface_tension_parameters)
251 : SurfaceTensionLinear(p_surface_tension_parameters)
252 , T_solidus(p_surface_tension_parameters.T_solidus)
253 , T_liquidus(p_surface_tension_parameters.T_liquidus)
254 {
256 }
257
258 /**
259 * @brief value Calculates the surface tension coefficient.
260 * @param field_vectors Vectors of the fields on which the surface tension
261 * depends. In this case, it depends on the temperature.
262 * @return value of the physical property calculated with the fields_value.
263 */
264 double
265 value(const std::map<field, double> &fields_value) override
266 {
267 Assert(fields_value.find(field::temperature) != fields_value.end(),
268 PhysicialPropertyModelFieldUndefined("SurfaceTensionPhaseChange",
269 "temperature"));
270 const double temperature = fields_value.at(field::temperature);
271
272 double surface_tension;
273
275 surface_tension = 0.0;
276 else if (temperature > T_liquidus)
277 surface_tension = surface_tension_coefficient +
279 else
280 {
281 const double l_frac =
283
284 surface_tension = (surface_tension_coefficient +
286 l_frac;
287 }
288 return surface_tension;
289 }
290
291 /**
292 * @brief vector_value Calculates the vector of surface tension coefficient.
293 * @param field_vectors Vectors of the fields on which the surface tension
294 * depends. In this case, it depends on the temperature.
295 * @param property_vector Vectors of the surface tension coefficient values.
296 */
297 void
298 vector_value(const std::map<field, std::vector<double>> &field_vectors,
299 std::vector<double> &property_vector) override
300 {
301 Assert(field_vectors.find(field::temperature) != field_vectors.end(),
302 PhysicialPropertyModelFieldUndefined("SurfaceTensionPhaseChange",
303 "temperature"));
304 const std::vector<double> &temperature =
305 field_vectors.at(field::temperature);
306 for (unsigned int i = 0; i < property_vector.size(); ++i)
307 if (temperature[i] < T_solidus)
308 property_vector[i] = 0.0;
309 else if (temperature[i] > T_liquidus)
310 property_vector[i] = surface_tension_coefficient +
312 else
313 {
314 const double l_frac =
316
317 property_vector[i] =
320 l_frac;
321 }
322 }
323
324 /**
325 * @brief jacobian Calculates the jacobian (the partial derivative) of the
326 * surface tension coefficient with respect to a field.
327 * @param field_values Value of the various fields on which the property may
328 * depend.
329 * @param id Indicator of the field with respect to which the jacobian
330 * should be calculated.
331 * @return value of the partial derivative of the surface tension coefficient
332 * with respect to the field.
333 */
334 double
335 jacobian(const std::map<field, double> &field_values, field id) override
336 {
337 if (id == field::temperature)
338 {
339 Assert(field_values.find(field::temperature) != field_values.end(),
340 PhysicialPropertyModelFieldUndefined("SurfaceTensionPhaseChange",
341 "temperature"));
342 const double temperature = field_values.at(field::temperature);
344 return 0;
345 else if (temperature > T_liquidus)
347 else
348 {
349 const double l_frac =
351 return surface_tension_gradient * l_frac;
352 }
353 }
354 else
355 return 0;
356 }
357
358 /**
359 * @brief vector_jacobian Calculates the derivative of the surface tension
360 * coefficient with respect to a field.
361 * @param field_vectors Vector for the values of the fields used to evaluate
362 * the property.
363 * @param id Identifier of the field with respect to which a derivative should
364 * be calculated.
365 * @param jacobian vector of the value of the derivative of the surface
366 * tension coefficient with respect to the field id.
367 */
368 void
369 vector_jacobian(const std::map<field, std::vector<double>> &field_vectors,
370 const field id,
371 std::vector<double> &jacobian_vector) override
372 {
373 if (id == field::temperature)
374 {
375 Assert(field_vectors.find(field::temperature) != field_vectors.end(),
376 PhysicialPropertyModelFieldUndefined("SurfaceTensionPhaseChange",
377 "temperature"));
378 const std::vector<double> &temperature =
379 field_vectors.at(field::temperature);
380 for (unsigned int i = 0; i < jacobian_vector.size(); ++i)
381 if (temperature[i] < T_solidus)
382 jacobian_vector[i] = 0.0;
383 else if (temperature[i] > T_liquidus)
384 jacobian_vector[i] = surface_tension_gradient;
385 else
386 {
387 const double l_frac = calculate_liquid_fraction(temperature[i],
388 T_solidus,
389 T_liquidus);
390 jacobian_vector[i] = surface_tension_gradient * l_frac;
391 }
392 }
393 else
394 std::ranges::fill(jacobian_vector, 0);
395 }
396
397private:
398 const double T_solidus;
399 const double T_liquidus;
400};
401
402#endif
InterfacePropertyModel()
class Default constructor. Set the model_depends_on to false for all variables.
std::map< field, bool > model_depends_on
MaterialInteractions - Class that defines physical properties due to interactions between two differe...
Definition parameters.h:757
void vector_value(const std::map< field, std::vector< double > > &, std::vector< double > &property_vector) override
vector_value Calculates the vector of surface tension coefficient.
double jacobian(const std::map< field, double > &, field) override
jacobian Calculates the jacobian (the partial derivative) of the surface tension coefficient with res...
void vector_jacobian(const std::map< field, std::vector< double > > &, const field, std::vector< double > &jacobian_vector) override
vector_jacobian Calculates the derivative of the surface tension coefficient with respect to a field.
double value(const std::map< field, double > &) override
value Calculates the surface tension coefficient
SurfaceTensionConstant(const double p_surface_tension_coefficient)
Default constructor.
void vector_jacobian(const std::map< field, std::vector< double > > &, const field id, std::vector< double > &jacobian_vector) override
vector_jacobian Calculates the derivative of the surface tension coefficient with respect to a field.
const double surface_tension_coefficient
double value(const std::map< field, double > &fields_value) override
value Calculates the surface tension coefficient
double jacobian(const std::map< field, double > &, field id) override
jacobian Calculates the jacobian (the partial derivative) of the surface tension coefficient with res...
SurfaceTensionLinear(const Parameters::SurfaceTensionParameters &p_surface_tension_parameters)
Default constructor.
void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
vector_value Calculates the vector of surface tension coefficient.
Abstract class that allows to calculate the surface tension coefficient.
static std::shared_ptr< SurfaceTensionModel > model_cast(const Parameters::MaterialInteractions &material_interaction_parameters)
Instantiates and returns a pointer to a SurfaceTensionModel object by casting it to the proper child ...
bool is_constant_surface_tension_model()
is_constant_surface_tension_model Returns a boolean indicating if the model is a constant surface ten...
void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
vector_value Calculates the vector of surface tension coefficient.
void vector_jacobian(const std::map< field, std::vector< double > > &field_vectors, const field id, std::vector< double > &jacobian_vector) override
vector_jacobian Calculates the derivative of the surface tension coefficient with respect to a field.
double jacobian(const std::map< field, double > &field_values, field id) override
jacobian Calculates the jacobian (the partial derivative) of the surface tension coefficient with res...
SurfaceTensionPhaseChange(const Parameters::SurfaceTensionParameters &p_surface_tension_parameters)
Default constructor.
double value(const std::map< field, double > &fields_value) override
value Calculates the surface tension coefficient.
@ temperature
Temperature scalar field from heat transfer.
double calculate_liquid_fraction(const double &T, const Parameters::PhaseChange &phase_change_parameters)
calculate_liquid_fraction Calculates the liquid fraction of a phase change material at a temperature ...
SurfaceTensionParameters - Defines parameters for surface tension models.
Definition parameters.h:521