Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
thermal_expansion_model.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2022-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_thermal_expansion_model_h
5#define lethe_thermal_expansion_model_h
6
7#include <core/phase_change.h>
9
10#include <algorithm>
11
12/**
13 * @brief Abstract class that allows to calculate the
14 * thermal expansion coefficient (with unit of inverse temperature)
15 */
17{
18public:
19 /**
20 * @brief Instantiates and returns a pointer to a ThermalExpansionModel object by casting it to
21 * the proper child class
22 *
23 * @param material_properties Parameters for a material
24 */
25 static std::shared_ptr<ThermalExpansionModel>
26 model_cast(const Parameters::Material &material_properties);
27};
28
29
30/**
31 * @brief Constant thermal expansion coefficient.
32 */
34{
35public:
36 /**
37 * @brief Default constructor
38 */
39 ConstantThermalExpansion(const double p_thermal_expansion)
40 : thermal_expansion(p_thermal_expansion)
41 {}
42
43 /**
44 * @brief value Calculates the thermale expansion
45 * @param fields_value Value of the various field on which the property may depend.
46 * @return value of the physical property calculated with the fields_value
47 */
48 double
49 value(const std::map<field, double> & /*fields_value*/) override
50 {
51 return thermal_expansion;
52 };
53
54 /**
55 * @brief vector_value Calculates the vector of thermal expansion.
56 * @param field_vectors Vectors of the fields on which the thermal expansion may depend.
57 * @param property_vector Vectors of the thermal expansion values
58 */
59 void
60 vector_value(const std::map<field, std::vector<double>> & /*field_vectors*/,
61 std::vector<double> &property_vector) override
62 {
63 std::ranges::fill(property_vector, thermal_expansion);
64 }
65
66 /**
67 * @brief jacobian Calculates the jacobian (the partial derivative) of the thermal expansion with respect to a field
68 * @param field_values Value of the various fields on which the property may depend.
69 * @param id Indicator of the field with respect to which the jacobian
70 * should be calculated.
71 * @return value of the partial derivative of the thermal expansion with respect to the field.
72 */
73
74 double
75 jacobian(const std::map<field, double> & /*field_values*/,
76 field /*id*/) override
77 {
78 return 0;
79 };
80
81 /**
82 * @brief vector_jacobian Calculates the derivative of the thermal expansion with respect to a field.
83 * @param field_vectors Vector for the values of the fields used to evaluate the property.
84 * @param id Identifier of the field with respect to which a derivative should be calculated.
85 * @param jacobian vector of the value of the derivative of the thermal expansion with respect to the field id.
86 */
87
88 void
90 const std::map<field, std::vector<double>> & /*field_vectors*/,
91 const field /*id*/,
92 std::vector<double> &jacobian_vector) override
93 {
94 std::ranges::fill(jacobian_vector, 0);
95 };
96
97private:
98 const double thermal_expansion;
99};
100
101/**
102 * @brief Implements a phase-dependent thermal expansion coefficient
103 */
105{
106public:
107 /**
108 * @brief Default constructor
109 */
111 : p_phase_change_params(phase_change_params)
112 {
114 }
115
116 /**
117 * @brief value Calculates the value of the thermal expansion coefficient
118 * @param fields_value Value of the various field on which the thermal expansion coefficient depends.
119 * @return value of the thermal expansion coefficient calculated with the fields_value.
120 */
121 double
122 value(const std::map<field, double> &fields_value) override
123 {
124 Assert(fields_value.find(field::temperature) != fields_value.end(),
125 PhysicialPropertyModelFieldUndefined("ThermalExpansionPhaseChange",
126 "temperature"));
127 if (fields_value.at(field::temperature) > p_phase_change_params.T_liquidus)
128 return p_phase_change_params.thermal_expansion_l;
129 else
130 return p_phase_change_params.thermal_expansion_s;
131 };
132
133 /**
134 * @brief vector_value Calculates the vector value of thermal expansion coefficients
135 * @param field_vectors Vector of properties on which the thermal expansion coefficients depend
136 * @param property_vector Values of the thermal expansion coefficients
137 */
138 void
139 vector_value(const std::map<field, std::vector<double>> &field_vectors,
140 std::vector<double> &property_vector) override
141 {
142 Assert(field_vectors.find(field::temperature) != field_vectors.end(),
143 PhysicialPropertyModelFieldUndefined("ThermalExpansionPhaseChange",
144 "temperature"));
145 const std::vector<double> &T = field_vectors.at(field::temperature);
146 for (unsigned int i = 0; i < property_vector.size(); ++i)
147 {
148 // Thermal expansion of solid phase
149 if (T[i] > p_phase_change_params.T_liquidus)
150 property_vector[i] = p_phase_change_params.thermal_expansion_l;
151 else
152 property_vector[i] = p_phase_change_params.thermal_expansion_s;
153 // Thermal expansion of liquid phase
154 }
155 };
156
157 /**
158 * @brief jacobian Calculates the jacobian (the partial derivative) of the thermal expansion with respect to a field
159 * @param field_values Value of the various fields on which the property may depend.
160 * @param id Indicator of the field with respect to which the jacobian
161 * should be calculated
162 * @return value of the partial derivative of the thermal expansion with respect to the field.
163 */
164
165 double
166 jacobian(const std::map<field, double> &field_values, field id) override
167 {
168 if (id == field::temperature)
169 {
170 Assert(field_values.find(field::temperature) != field_values.end(),
171 PhysicialPropertyModelFieldUndefined(
172 "ThermalExpansionPhaseChange", "temperature"));
173 return this->numerical_jacobian(field_values, field::temperature);
174 }
175 else
176 return 0;
177 };
178
179 /**
180 * @brief vector_jacobian Calculate the derivative of the thermal expansion with respect to a field
181 * @param field_vectors Vector for the values of the fields used to evaluate the property
182 * @param id Identifier of the field with respect to which a derivative should be calculated
183 * @param jacobian Vector of the value of the derivative of the thermal expansion with respect to the field id
184 */
185
186 void
187 vector_jacobian(const std::map<field, std::vector<double>> &field_vectors,
188 const field id,
189 std::vector<double> &jacobian_vector) override
190 {
191 Assert(field_vectors.find(field::temperature) != field_vectors.end(),
192 PhysicialPropertyModelFieldUndefined("ThermalExpansionPhaseChange",
193 "temperature"));
194 vector_numerical_jacobian(field_vectors, id, jacobian_vector);
195 };
196
197private:
199};
200
201#endif
ConstantThermalExpansion(const double p_thermal_expansion)
Default constructor.
double jacobian(const std::map< field, double > &, field) override
jacobian Calculates the jacobian (the partial derivative) of the thermal expansion with respect to a ...
double value(const std::map< field, double > &) override
value Calculates the thermale expansion
void vector_value(const std::map< field, std::vector< double > > &, std::vector< double > &property_vector) override
vector_value Calculates the vector of thermal expansion.
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 thermal expansion with respect to a field.
Material - Class that defines the physical property of a material. Generally a material will be a flu...
Definition parameters.h:594
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....
PhysicalPropertyModel()
Default constructor. Set the model_depends_on to false for all variables.
std::map< field, bool > model_depends_on
Abstract class that allows to calculate the thermal expansion coefficient (with unit of inverse tempe...
static std::shared_ptr< ThermalExpansionModel > model_cast(const Parameters::Material &material_properties)
Instantiates and returns a pointer to a ThermalExpansionModel object by casting it to the proper chil...
double jacobian(const std::map< field, double > &field_values, field id) override
jacobian Calculates the jacobian (the partial derivative) of the thermal expansion with respect to a ...
Parameters::PhaseChange p_phase_change_params
ThermalExpansionPhaseChange(const Parameters::PhaseChange phase_change_params)
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 value of thermal expansion coefficients
double value(const std::map< field, double > &fields_value) override
value Calculates the value of the thermal expansion coefficient
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 thermal expansion with respect to a field
Phase change model for melting/freezing liquids The model assumes that the phase change occurs betwee...
Definition parameters.h:264