Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
specific_heat_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_specific_heat_model_h
5#define lethe_specific_heat_model_h
6
7#include <core/parameters.h>
8#include <core/phase_change.h>
10
11#include <algorithm>
12
13using namespace dealii;
14
15/**
16 * @brief Abstract class for calculating the specific heat of materials on
17 * quadrature points using the temperature of the fluid.
18 */
20{
21public:
22 /**
23 * @brief Instantiates and returns a pointer to a SpecificHeatModel object
24 * by casting it to the proper child class.
25 *
26 * @param[in] material_properties Property parameters of a material (fluid or
27 * solid).
28 *
29 * @return Casted SpecificHeatModel object.
30 */
31 static std::shared_ptr<SpecificHeatModel>
32 model_cast(const Parameters::Material &material_properties);
33};
34
35
36/**
37 * @brief Constant specific heat model.
38 */
40{
41public:
42 /**
43 * @brief Constructor of the constant specific heat model.
44 *
45 * @param[in] p_specific_heat Constant specific heat value.
46 */
47 ConstantSpecificHeat(const double p_specific_heat)
48 : specific_heat(p_specific_heat)
49 {}
50
51 /**
52 * @brief Compute specific heat value.
53 *
54 * @param[in] field_values Value of the various field on which the specific
55 * heat may depend. The map stores a single value per field.
56 *
57 * @note Here, the @p field_values parameter is ignored since the specific
58 * heat remains constant.
59 *
60 * @return Specific heat value.
61 */
62 double
63 value(const std::map<field, double> &field_values) override
64 {
65 (void)field_values;
66 return specific_heat;
67 };
68
69 /**
70 * @brief vector_value Compute specific heat values.
71 *
72 * @param[in] field_vectors Vectors of the fields on which the specific heat
73 * may depend. The map stores a vector of values per field.
74 *
75 * @param[out] property_vector Vector of computed specific heat values.
76 *
77 * @note Here, the @p field_vectors parameter is ignored since the specific
78 * heat remains constant.
79 */
80 void
81 vector_value(const std::map<field, std::vector<double>> &field_vectors,
82 std::vector<double> &property_vector) override
83 {
84 (void)field_vectors;
85 std::ranges::fill(property_vector, specific_heat);
86 }
87
88 /**
89 * @brief Compute the jacobian (the partial derivative) of the specific heat
90 * with respect to a specified field.
91 *
92 * @param[in] field_values Values of the various fields on which the specific
93 * heat may depend. The map stores a single value per field.
94 *
95 * @param[in] id Indicator of the field with respect to which the jacobian
96 * should be computed.
97 *
98 * @note Here, the @p field_values and @p id parameters are ignored since the
99 * specific heat remains constant.
100 *
101 * @return Value of the derivative of the specific heat with respect to the
102 * specified field. Since the specific heat remains constant, this function
103 * returns zero.
104 */
105 double
106 jacobian(const std::map<field, double> &field_values, field id) override
107 {
108 (void)field_values;
109 (void)id;
110 return 0;
111 };
112
113 /**
114 * @brief Computes the derivative of the specific heat with respect to
115 * specified fields.
116 *
117 * @param[in] field_vectors Vector of values of the fields used to evaluate
118 * the specific heat. The map stores a vector of values per field.
119 *
120 * @param[in] id Identifier of the field with respect to which a derivative
121 * should be computed.
122 *
123 * @param[out] jacobian Vector of computed derivative values of the specific
124 * heat
125 * with respect to the field of the specified @p id. In this case, it returns
126 * a vector of zeros since the specific heat remains constant.
127 *
128 * @note Here, the @p field_vectors and @p id parameters are ignored since the
129 * specific heat remains constant.
130 *
131 */
132 void
133 vector_jacobian(const std::map<field, std::vector<double>> &field_vectors,
134 const field id,
135 std::vector<double> &jacobian_vector) override
136 {
137 (void)field_vectors;
138 (void)id;
139 std::ranges::fill(jacobian_vector, 0);
140 };
141
142private:
143 const double specific_heat;
144};
145
146
147/**
148 * @brief Phase change specific heat model.
149 *
150 * The phase change specific heat \f$(c^{*}_\mathrm{p})\f$ model takes into
151 * account the phase change of a material by considering the latent heat into
152 * the specific heat over a phase change temperature interval determined by
153 * \f$\left[T_\mathrm{s},T_\mathrm{l}\right]\f$ where \f$T_\mathrm{s}\f$ is the
154 * solidus temperature and \f$T_\mathrm{l}\f$ is the liquidus temperature.
155 *
156 * The specific heat is evaluated as:
157 * \f$ c^{*}_\mathrm{p}(T) =
158 * \begin{cases}
159 * C_\mathrm{p,s} & \text{if} \; T<T_\mathrm{s}\\
160 * \frac{C_\mathrm{p,s}+C_\mathrm{p,l}}{2}+\frac{h_\mathrm{l}}
161 * {T_\mathrm{l}-T_\mathrm{s}} & \text{if} \;
162 * T\in[T_\mathrm{s},T_\mathrm{l}]\\ C_\mathrm{p,l} & \text{if} \;
163 * T>T_\mathrm{l} \end{cases} \f$
164 *
165 * where \f$C_\mathrm{p,s}\f$ and \f$C_\mathrm{p,l}\f$ are the solid and liquid
166 * specific heat, respectively, and \f$h_\mathrm{l}\f$ is the latent enthalpy
167 * (enthalpy related to the phase change).
168 */
170{
171public:
172 /**
173 * @brief Constructor of the phase change specific heat model.
174 *
175 * @param[in] p_phase_change_parameters Set of parameters of the phase change
176 * model.
177 */
179 const Parameters::PhaseChange p_phase_change_parameters)
180 : param(p_phase_change_parameters)
181 {
185 }
186
187 /**
188 * @brief Compute the specific heat of the isothermal ideal gas.
189 *
190 * @param[in] field_values Values of the various fields on which the property
191 * may depend. In this case, the specific heat depends on temperature.
192 * The map stores a single value per field.
193 *
194 * @return Value of the specific heat computed with the @p field_values.
195 */
196 double
197 value(const std::map<field, double> &field_values) override
198 {
199 Assert(field_values.find(field::temperature) != field_values.end(),
200 PhysicialPropertyModelFieldUndefined("PhaseChangeSpecificHeat",
201 "temperature"));
202 Assert(field_values.find(field::temperature_p1) != field_values.end(),
203 PhysicialPropertyModelFieldUndefined("PhaseChangeSpecificHeat",
204 "temperature_p1"));
205 Assert(field_values.find(field::temperature_p2) != field_values.end(),
206 PhysicialPropertyModelFieldUndefined("PhaseChangeSpecificHeat",
207 "temperature_p2"));
208 double temperature = field_values.at(field::temperature);
209 double temperature_p1 = field_values.at(field::temperature_p1);
210 double temperature_p2 = field_values.at(field::temperature_p2);
211
212
213 // Gather information required from the simulation control to have the time
214 // history
215 std::shared_ptr<SimulationControl> simulation_control =
217
218 // Time stepping information
219 auto method = simulation_control->get_assembly_method();
220 // Vector for the BDF coefficients
221 const Vector<double> &bdf_coefs =
222 simulation_control->get_bdf_coefficients();
223
224 switch (method)
225 {
227 {
228 // Clipping to ensure a minimal temperature difference
230 temperature = std::max(temperature, temperature_p1 + 1e-6);
231 else
232 temperature_p1 = std::max(temperature_p1, temperature + 1e-6);
233
234 const double enthalpy_current = enthalpy(temperature);
235 const double enthalpy_p1 = enthalpy(temperature_p1);
236 const double dH =
237 bdf_coefs[0] * enthalpy_current + bdf_coefs[1] * enthalpy_p1;
238 const double dT =
239 bdf_coefs[0] * temperature + bdf_coefs[1] * temperature_p1;
240 return dH / dT;
241 }
242
244 {
245 // Clipping to ensure a minimal temperature difference
247 temperature = std::max(temperature, temperature_p2 + 1e-6);
248 else
249 temperature_p2 = std::max(temperature_p2, temperature + 1e-6);
250
251 const double enthalpy_current = enthalpy(temperature);
252 const double enthalpy_p1 = enthalpy(temperature_p1);
253 const double enthalpy_p2 = enthalpy(temperature_p2);
254 const double dH = bdf_coefs[0] * enthalpy_current +
255 bdf_coefs[1] * enthalpy_p1 +
256 bdf_coefs[2] * enthalpy_p2;
257 const double dT = bdf_coefs[0] * temperature +
258 bdf_coefs[1] * temperature_p1 +
259 bdf_coefs[2] * temperature_p2;
260 return dH / dT;
261 }
262
263 default:
264 throw(std::runtime_error(
265 "Other time integration schemes are not supported by the phase change model"));
266 }
267 }
268
269 /**
270 * @brief Compute a vector of specific heat values for an isothermal ideal gas.
271 *
272 * @param[in] field_vectors Vectors of the fields on which the specific heat
273 * may depend. In this case, the specific heat depends on temperature. The map
274 * stores a vector of values per field.
275 *
276 * @param[out] property_vector Vectors of computed specific heat values.
277 */
278 void
279 vector_value(const std::map<field, std::vector<double>> &field_vectors,
280 std::vector<double> &property_vector) override
281 {
282 Assert(field_vectors.find(field::temperature) != field_vectors.end(),
283 PhysicialPropertyModelFieldUndefined("PhaseChangeSpecificHeat",
284 "temperature"));
285 Assert(field_vectors.find(field::temperature_p1) != field_vectors.end(),
286 PhysicialPropertyModelFieldUndefined("PhaseChangeSpecificHeat",
287 "temperature_p1"));
288 Assert(field_vectors.find(field::temperature_p2) != field_vectors.end(),
289 PhysicialPropertyModelFieldUndefined("PhaseChangeSpecificHeat",
290 "temperature_p2"));
291 const std::vector<double> &temperature_vec =
292 field_vectors.at(field::temperature);
293 const std::vector<double> &p1_temperature_vec =
294 field_vectors.at(field::temperature_p1);
295 const std::vector<double> &p2_temperature_vec =
296 field_vectors.at(field::temperature_p2);
297
298 const unsigned int n_values = temperature_vec.size();
299
300 Assert(n_values == p2_temperature_vec.size(),
301 SizeOfFields(n_values, p2_temperature_vec.size()));
302 Assert(n_values == p1_temperature_vec.size(),
303 SizeOfFields(n_values, p1_temperature_vec.size()));
304 Assert(n_values == property_vector.size(),
305 SizeOfFields(n_values, property_vector.size()));
306
307 // Gather information required from the simulation control to have the time
308 // history
309 std::shared_ptr<SimulationControl> simulation_control =
311 std::vector<double> time_steps_vector =
312 simulation_control->get_time_steps_vector();
313
314 auto method = simulation_control->get_assembly_method();
315 const Vector<double> &bdf_coefs =
316 simulation_control->get_bdf_coefficients();
317
318 for (unsigned int i = 0; i < n_values; ++i)
319 {
320 double temperature = temperature_vec[i];
321 double temperature_p1 = p1_temperature_vec[i];
322 double temperature_p2 = p2_temperature_vec[i];
323
324 switch (method)
325 {
327 {
328 // Clipping to ensure a minimal temperature difference
330 temperature = std::max(temperature, temperature_p1 + 1e-6);
331 else
332 temperature_p1 = std::max(temperature_p1, temperature + 1e-6);
333
334 const double enthalpy_current = enthalpy(temperature);
335 const double enthalpy_p1 = enthalpy(temperature_p1);
336 const double dH =
337 bdf_coefs[0] * enthalpy_current + bdf_coefs[1] * enthalpy_p1;
338 const double dT =
339 bdf_coefs[0] * temperature + bdf_coefs[1] * temperature_p1;
340
341 // The division does not need a tolerance to avoid a division by
342 // 0 since the temperature is clipped
343 property_vector[i] = dH / dT;
344
345 break;
346 }
347
349 {
350 // Clipping to ensure a minimal temperature difference
352 temperature = std::max(temperature, temperature_p2 + 1e-6);
353 else
354 temperature_p2 = std::max(temperature_p2, temperature + 1e-6);
355
356 const double enthalpy_current = enthalpy(temperature);
357 const double enthalpy_p1 = enthalpy(temperature_p1);
358 const double enthalpy_p2 = enthalpy(temperature_p2);
359 const double dH = bdf_coefs[0] * enthalpy_current +
360 bdf_coefs[1] * enthalpy_p1 +
361 bdf_coefs[2] * enthalpy_p2;
362 const double dT = bdf_coefs[0] * temperature +
363 bdf_coefs[1] * temperature_p1 +
364 bdf_coefs[2] * temperature_p2;
365 property_vector[i] = dH / (dT + 1e-8);
366 break;
367 }
368
369 default:
370 throw(std::runtime_error(
371 "Other time integration schemes are not supported by the phase change model"));
372 }
373 }
374 }
375
376 /**
377 * @brief Compute the jacobian (the partial derivative) of the specific heat
378 * with respect to a specified field.
379 *
380 * @param[in] field_values Values of the various fields on which the specific
381 * heat may depend. The map stores a single value per field.
382 *
383 * @param[in] id Indicator of the field with respect to which the jacobian
384 * should be computed.
385 *
386 * @return Value of the derivative of the specific heat with respect to the
387 * specified field.
388 */
389 double
390 jacobian(const std::map<field, double> &field_values, field id) override
391 {
392 if (id == field::temperature)
393 {
394 Assert(field_values.find(field::temperature) != field_values.end(),
395 PhysicialPropertyModelFieldUndefined(
396 "EvaporationModelTemperature", "temperature"));
397 return numerical_jacobian(field_values, field::temperature);
398 }
399 else
400 return 0;
401 };
402
403 /**
404 * @brief Compute the derivative of the specific heat with respect to a field
405 * for an isothermal ideal gas.
406 *
407 * @param[in] field_vectors Vector of values of the fields used to evaluate
408 * the specific heat. The map stores a vector of values per field.
409 *
410 * @param[in] id Identifier of the field with respect to which a derivative
411 * should be computed.
412 *
413 * @param[out] jacobian Vector of computed derivative values of the specific
414 * heat with respect to the field of the specified @p id.
415 */
416 void
417 vector_jacobian(const std::map<field, std::vector<double>> &field_vectors,
418 const field id,
419 std::vector<double> &jacobian_vector) override
420 {
421 Assert(field_vectors.find(field::temperature) != field_vectors.end(),
422 PhysicialPropertyModelFieldUndefined("EvaporationModelTemperature",
423 "temperature"));
424 vector_numerical_jacobian(field_vectors, id, jacobian_vector);
425 };
426
427 /**
428 * @brief Compute the enthalpy of a phase change material for a temperature
429 * \f$T\f$.
430 *
431 * The enthalpy \f$(H)\f$ is defined:
432 *
433 * - In pure liquid \f$(T>T_\mathrm{l})\f$ as:\n
434 * \f$H(T) = c_\mathrm{p,s} T_\mathrm{s} + 0.5(c_\mathrm{p,s}+c_\mathrm{p,l})
435 * (T_\mathrm{l}-T_\mathrm{s}) + h_\mathrm{l} + c_\mathrm{p,l}
436 * (T-T_\mathrm{l})\f$\n\n
437 *
438 * - In liquid-solid mixture \f$(T_\mathrm{s} \leq T \leq T_\mathrm{l})\f$
439 * as:\n
440 *\f$H(T) = c_\mathrm{p,s} T_\mathrm{s} + 0.5(c_\mathrm{p,s}+c_\mathrm{p,l})
441 * (T_\mathrm{l}-T_\mathrm{s}) + \alpha_\mathrm{l} h_\mathrm{l}\f$\n
442 * where \f$\alpha_\mathrm{l} = \frac{T-T_\mathrm{s}}{T_\mathrm{l}-
443 * T_\mathrm{s}}\f$ is the liquid fraction.\n\n
444 *
445 * - In pure solid \f$(T<T_\mathrm{s})\f$ as:\n
446 * \f$H(T) = c_\mathrm{p,s} T\f$
447 *
448 * @param[in] T temperature at which the enthalpy is computed.
449 *
450 * @return Value of the enthalpy evaluated at \f$T\f$.
451 */
452
453 inline double
454 enthalpy(const double T)
455 {
456 if (T > param.T_liquidus)
457 return (param.cp_s * param.T_solidus +
458 0.5 * (param.cp_l + param.cp_s) *
459 (param.T_liquidus - param.T_solidus) +
460 param.latent_enthalpy + (T - param.T_liquidus) * param.cp_l);
461 else if (T > param.T_solidus)
462 {
464 return (param.cp_s * param.T_solidus +
465 0.5 * (param.cp_l + param.cp_s) * (T - param.T_solidus) +
466 param.latent_enthalpy * liquid_fraction);
467 }
468 else
469 return param.cp_s * T;
470 }
471
472private:
475};
476
477#endif
void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
vector_value Compute specific heat values.
double value(const std::map< field, double > &field_values) override
Compute specific heat value.
double jacobian(const std::map< field, double > &field_values, field id) override
Compute the jacobian (the partial derivative) of the specific heat with respect to a specified field.
ConstantSpecificHeat(const double p_specific_heat)
Constructor of the constant specific heat model.
void vector_jacobian(const std::map< field, std::vector< double > > &field_vectors, const field id, std::vector< double > &jacobian_vector) override
Computes the derivative of the specific heat with respect to specified fields.
Material - Class that defines the physical property of a material. Generally a material will be a flu...
Definition parameters.h:594
void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector) override
Compute a vector of specific heat values for an isothermal ideal gas.
PhaseChangeSpecificHeat(const Parameters::PhaseChange p_phase_change_parameters)
Constructor of the phase change specific heat model.
double enthalpy(const double T)
Compute the enthalpy of a phase change material for a temperature .
void vector_jacobian(const std::map< field, std::vector< double > > &field_vectors, const field id, std::vector< double > &jacobian_vector) override
Compute the derivative of the specific heat with respect to a field for an isothermal ideal gas.
const Parameters::PhaseChange param
double jacobian(const std::map< field, double > &field_values, field id) override
Compute the jacobian (the partial derivative) of the specific heat with respect to a specified field.
double value(const std::map< field, double > &field_values) override
Compute the specific heat of the isothermal ideal gas.
std::shared_ptr< SimulationControl > simulation_control
std::shared_ptr< SimulationControl > & get_simulation_control()
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 for calculating the specific heat of materials on quadrature points using the temperat...
static std::shared_ptr< SpecificHeatModel > model_cast(const Parameters::Material &material_properties)
Instantiates and returns a pointer to a SpecificHeatModel object by casting it to the proper child cl...
@ 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 ...
Phase change model for melting/freezing liquids The model assumes that the phase change occurs betwee...
Definition parameters.h:264