Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
thermal_conductivity_model.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2021-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_conductivity_model_h
5#define lethe_thermal_conductivity_model_h
6
7#include <core/parameters.h>
8#include <core/phase_change.h>
10
11#include <algorithm>
12
13/**
14 * @brief Abstract class that allows to calculate the
15 * thermal conductivity on each quadrature point using the temperature of the
16 * fluid.
17 */
19{
20public:
21 /**
22 * @brief Instantiates and returns a pointer to a ThermalConductivityModel object by casting it to
23 * the proper child class
24 *
25 * @param material_properties Parameters for a material
26 */
27 static std::shared_ptr<ThermalConductivityModel>
28 model_cast(const Parameters::Material &material_properties);
29};
30
31
32/**
33 * @brief Constant thermal conductivity.
34 */
36{
37public:
38 /**
39 * @brief Default constructor
40 */
41 ConstantThermalConductivity(const double p_thermal_conductivity)
42 : thermal_conductivity(p_thermal_conductivity)
43 {}
44
45 /**
46 * @brief value Calculates the value the thermal conductivity
47 * @param fields_value Value of the various field on which the thermal conductivity depends.
48 * @return value of the thermal conductivity calculated with the fields_value.
49 */
50 double
51 value(const std::map<field, double> & /*fields_value*/) override
52 {
54 };
55
56 /**
57 * @brief vector_value Calculates the vector value of thermal conductivities
58 * @param field_vectors Vector of properties on which the thermal conductivities depend
59 * @param property_vector Values of the thermal conductivities
60 */
61 void
62 vector_value(const std::map<field, std::vector<double>> & /*field_vectors*/,
63 std::vector<double> &property_vector) override
64 {
65 property_vector.assign(property_vector.size(), thermal_conductivity);
66 }
67
68 /**
69 * @brief jacobian Calculates the jacobian (the partial derivative) of the thermal conductivity with respect to a field
70 * @param field_values Value of the various fields on which the property may depend.
71 * @param id Indicator of the field with respect to which the jacobian
72 * should be calculated
73 * @return value of the partial derivative of the thermal conductivity with respect to the field.
74 */
75
76 double
77 jacobian(const std::map<field, double> & /*field_values*/,
78 field /*id*/) override
79 {
80 return 0;
81 };
82
83 /**
84 * @brief vector_jacobian Calculate the derivative of the thermal conductivity with respect to a field
85 * @param field_vectors Vector for the values of the fields used to evaluate the property
86 * @param id Identifier of the field with respect to which a derivative should be calculated
87 * @param jacobian Vector of the value of the derivative of the thermal conductivity with respect to the field id
88 */
89
90 void
92 const std::map<field, std::vector<double>> & /*field_vectors*/,
93 const field /*id*/,
94 std::vector<double> &jacobian_vector) override
95 {
96 std::ranges::fill(jacobian_vector, 0);
97 };
98
99private:
101};
102
103
104/**
105 * @brief Implements a linear temperature-dependent thermal conductivity of the form k = A + BT
106 */
108{
109public:
110 /**
111 * @brief Default constructor
112 */
113 ThermalConductivityLinear(const double A, const double B)
114 : A(A)
115 , B(B)
116 {
118 }
119
120 /**
121 * @brief value Calculates the value the thermal conductivity
122 * @param fields_value Value of the various field on which the thermal conductivity depends.
123 * @return value of the thermal conductivity calculated with the fields_value.
124 */
125 double
126 value(const std::map<field, double> &fields_value) override
127 {
128 Assert(fields_value.find(field::temperature) != fields_value.end(),
129 PhysicialPropertyModelFieldUndefined("ThermalConductivityLinear",
130 "temperature"));
131 return A + B * fields_value.at(field::temperature);
132 };
133
134 /**
135 * @brief vector_value Calculates the vector value of thermal conductivities
136 * @param field_vectors Vector of properties on which the thermal conductivities depend
137 * @param property_vector Values of the thermal conductivities
138 */
139 void
140 vector_value(const std::map<field, std::vector<double>> &field_vectors,
141 std::vector<double> &property_vector) override
142 {
143 Assert(field_vectors.find(field::temperature) != field_vectors.end(),
144 PhysicialPropertyModelFieldUndefined("ThermalConductivityLinear",
145 "temperature"));
146 const std::vector<double> &T = field_vectors.at(field::temperature);
147 for (unsigned int i = 0; i < property_vector.size(); ++i)
148 property_vector[i] = A + B * T[i];
149 }
150
151 /**
152 * @brief jacobian Calculates the jacobian (the partial derivative) of the thermal conductivity with respect to a field
153 * @param field_values Value of the various fields on which the property may depend.
154 * @param id Indicator of the field with respect to which the jacobian
155 * should be calculated
156 * @return value of the partial derivative of the thermal conductivity with respect to the field.
157 */
158
159 double
160 jacobian(const std::map<field, double> & /*field_values*/,
161 field /*id*/) override
162 {
163 return B;
164 };
165
166 /**
167 * @brief vector_jacobian Calculate the derivative of the thermal conductivity with respect to a field
168 * @param field_vectors Vector for the values of the fields used to evaluate the property
169 * @param id Identifier of the field with respect to which a derivative should be calculated
170 * @param jacobian Vector of the value of the derivative of the thermal conductivity with respect to the field id
171 */
172
173 void
175 const std::map<field, std::vector<double>> & /*field_vectors*/,
176 const field /*id*/,
177 std::vector<double> &jacobian_vector) override
178 {
179 std::ranges::fill(jacobian_vector, B);
180 };
181
182private:
183 const double A;
184 const double B;
185};
186
187/**
188 * @brief Implements a phase-dependent thermal conductivity
189 */
191{
192public:
193 /**
194 * @brief Default constructor
195 */
197 const Parameters::PhaseChange phase_change_params)
198 : p_phase_change_params(phase_change_params)
201 , T_solidus(phase_change_params.T_solidus)
202 , T_liquidus(phase_change_params.T_liquidus)
203 {
205 }
206
207 /**
208 * @brief value Calculates the value of the thermal conductivity
209 * @param fields_value Value of the various field on which the thermal conductivity depends.
210 * @return value of the thermal conductivity calculated with the fields_value.
211 */
212 double
213 value(const std::map<field, double> &fields_value) override
214 {
215 Assert(fields_value.find(field::temperature) != fields_value.end(),
216 PhysicialPropertyModelFieldUndefined(
217 "ThermalConductivityPhaseChange", "temperature"));
218 double thermal_conductivity;
219 // Thermal conductivity of solid phase
220 if (fields_value.at(field::temperature) < T_solidus)
221 thermal_conductivity = thermal_conductivity_s;
222 // Thermal conductivity of liquid phase
223 else if (fields_value.at(field::temperature) > T_liquidus)
224 thermal_conductivity = thermal_conductivity_l;
225 // Mean value of the conductivities of the solid and liquid phases
226 else
227 {
228 const double l_frac =
231
232 thermal_conductivity = thermal_conductivity_l * l_frac +
233 thermal_conductivity_s * (1. - l_frac);
234 }
235
236 return thermal_conductivity;
237 };
238
239 /**
240 * @brief vector_value Calculates the vector value of thermal conductivities
241 * @param field_vectors Vector of properties on which the thermal conductivities depend
242 * @param property_vector Values of the thermal conductivities
243 */
244 void
245 vector_value(const std::map<field, std::vector<double>> &field_vectors,
246 std::vector<double> &property_vector) override
247 {
248 Assert(field_vectors.find(field::temperature) != field_vectors.end(),
249 PhysicialPropertyModelFieldUndefined(
250 "ThermalConductivityPhaseChange", "temperature"));
251 const std::vector<double> &T = field_vectors.at(field::temperature);
252 for (unsigned int i = 0; i < property_vector.size(); ++i)
253 {
254 // Thermal conductivity of solid phase
255 if (T[i] < T_solidus)
256 property_vector[i] = thermal_conductivity_s;
257 // Thermal conductivity of liquid phase
258 else if (T[i] > T_liquidus)
259 property_vector[i] = thermal_conductivity_l;
260 else
261 {
262 const double l_frac =
264
265 property_vector[i] = thermal_conductivity_l * l_frac +
266 thermal_conductivity_s * (1. - l_frac);
267 }
268 }
269 };
270
271 /**
272 * @brief jacobian Calculates the jacobian (the partial derivative) of the thermal conductivity with respect to a field
273 * @param field_values Value of the various fields on which the property may depend.
274 * @param id Indicator of the field with respect to which the jacobian
275 * should be calculated
276 * @return value of the partial derivative of the thermal conductivity with respect to the field.
277 */
278
279 double
280 jacobian(const std::map<field, double> &field_values, field id) override
281 {
282 if (id == field::temperature)
283 {
284 Assert(field_values.find(field::temperature) != field_values.end(),
285 PhysicialPropertyModelFieldUndefined(
286 "ThermalConductivityPhaseChange", "temperature"));
287 return this->numerical_jacobian(field_values, field::temperature);
288 }
289 else
290 return 0;
291 };
292
293 /**
294 * @brief vector_jacobian Calculate the derivative of the thermal conductivity with respect to a field
295 * @param field_vectors Vector for the values of the fields used to evaluate the property
296 * @param id Identifier of the field with respect to which a derivative should be calculated
297 * @param jacobian Vector of the value of the derivative of the thermal conductivity with respect to the field id
298 */
299
300 void
301 vector_jacobian(const std::map<field, std::vector<double>> &field_vectors,
302 const field id,
303 std::vector<double> &jacobian_vector) override
304 {
305 Assert(field_vectors.find(field::temperature) != field_vectors.end(),
306 PhysicialPropertyModelFieldUndefined(
307 "ThermalConductivityPhaseChange", "temperature"));
308 vector_numerical_jacobian(field_vectors, id, jacobian_vector);
309 };
310
311private:
315 const double T_solidus;
316 const double T_liquidus;
317};
318
319#endif
double jacobian(const std::map< field, double > &, field) override
jacobian Calculates the jacobian (the partial derivative) of the thermal conductivity with respect to...
void vector_value(const std::map< field, std::vector< double > > &, std::vector< double > &property_vector) override
vector_value Calculates the vector value of thermal conductivities
ConstantThermalConductivity(const double p_thermal_conductivity)
Default constructor.
double value(const std::map< field, double > &) override
value Calculates the value the thermal conductivity
void vector_jacobian(const std::map< field, std::vector< double > > &, const field, std::vector< double > &jacobian_vector) override
vector_jacobian Calculate the derivative of the thermal conductivity 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
double value(const std::map< field, double > &fields_value) override
value Calculates the value the thermal conductivity
ThermalConductivityLinear(const double A, const double B)
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 conductivities
void vector_jacobian(const std::map< field, std::vector< double > > &, const field, std::vector< double > &jacobian_vector) override
vector_jacobian Calculate the derivative of the thermal conductivity with respect to a field
double jacobian(const std::map< field, double > &, field) override
jacobian Calculates the jacobian (the partial derivative) of the thermal conductivity with respect to...
Abstract class that allows to calculate the thermal conductivity on each quadrature point using the t...
static std::shared_ptr< ThermalConductivityModel > model_cast(const Parameters::Material &material_properties)
Instantiates and returns a pointer to a ThermalConductivityModel object by casting it to the proper c...
double value(const std::map< field, double > &fields_value) override
value Calculates the value of the thermal conductivity
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 conductivities
double jacobian(const std::map< field, double > &field_values, field id) override
jacobian Calculates the jacobian (the partial derivative) of the thermal conductivity with respect to...
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 conductivity with respect to a field
ThermalConductivityPhaseChange(const Parameters::PhaseChange phase_change_params)
Default constructor.
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 ...
Phase change model for melting/freezing liquids The model assumes that the phase change occurs betwee...
Definition parameters.h:264