Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
heat_transfer_scratch_data.cc
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#include <core/bdf.h>
5#include <core/utilities.h>
6
8
9template <int dim>
10void
12{
13 // Initialize size of arrays
14 this->n_q_points = fe_values_T.get_quadrature().size();
15 this->n_dofs = fe_values_T.get_fe().n_dofs_per_cell();
16
17 // Initialize arrays related to quadrature
18 this->JxW.reinit(n_q_points);
19
20 // Forcing term array
21 this->source = std::vector<double>(n_q_points);
22
23 // Initialize arrays related to velocity and pressure
24 // Velocity
25 this->velocity_values = std::vector<Tensor<1, dim>>(n_q_points);
26 this->velocity_gradient_values = std::vector<Tensor<2, dim>>(n_q_points);
27 this->shear_rate_values = std::vector<double>(n_q_points);
28 // Pressure
29 this->pressure_values = std::vector<double>(n_q_points);
30
31 // Initialize arrays related to temperature
32 this->present_temperature_values = std::vector<double>(n_q_points);
33 this->temperature_gradients = std::vector<Tensor<1, dim>>(n_q_points);
34 this->present_temperature_laplacians = std::vector<double>(n_q_points);
35
36 // Initial arrays for physical properties
37 this->specific_heat = std::vector<double>(n_q_points);
38 this->grad_specific_heat_temperature = std::vector<double>(n_q_points);
39 this->thermal_conductivity = std::vector<double>(n_q_points);
40 this->density = std::vector<double>(n_q_points);
41 this->dynamic_viscosity = std::vector<double>(n_q_points);
42
43 // Velocity for BDF schemes
45 std::vector<std::vector<double>>(maximum_number_of_previous_solutions(),
46 std::vector<double>(n_q_points));
48 std::vector<std::vector<Tensor<1, dim>>>(
50 std::vector<Tensor<1, dim>>(n_q_points));
51
52 // Initialize arrays related to shape functions
53 // Velocity shape functions
54 this->phi_T.reinit(TableIndices<2>(n_q_points, n_dofs));
55 this->grad_phi_T.reinit(TableIndices<2>(n_q_points, n_dofs));
56 this->hess_phi_T.reinit(TableIndices<2>(n_q_points, n_dofs));
57 this->laplacian_phi_T.reinit(TableIndices<2>(n_q_points, n_dofs));
58
59 // Physical properties
60 fields.insert(
61 std::pair<field, std::vector<double>>(field::temperature, n_q_points));
62 fields.insert(
63 std::pair<field, std::vector<double>>(field::temperature_p1, n_q_points));
64 fields.insert(
65 std::pair<field, std::vector<double>>(field::temperature_p2, n_q_points));
66 fields.insert(
67 std::pair<field, std::vector<double>>(field::shear_rate, n_q_points));
68 fields.insert(
69 std::pair<field, std::vector<double>>(field::pressure, n_q_points));
70}
71
72template <int dim>
73void
75 const FiniteElement<dim> &fe,
76 const Quadrature<dim> &quadrature,
77 const Mapping<dim> &mapping,
78 const Parameters::CLS_PhaseFilter &phase_filter_parameters)
79{
80 gather_cls = true;
81 fe_values_cls = std::make_shared<FEValues<dim>>(
82 mapping, fe, quadrature, update_values | update_gradients);
83
84 // Allocate CLS values
85 filtered_phase_values = std::vector<double>(this->n_q_points);
87 std::vector<Tensor<1, dim>>(this->n_q_points);
88
89 phase_gradient_values = std::vector<Tensor<1, dim>>(this->n_q_points);
90
91 // Allocate physical properties
92 specific_heat_0 = std::vector<double>(n_q_points);
93 density_0 = std::vector<double>(n_q_points);
94 thermal_conductivity_0 = std::vector<double>(n_q_points);
95 dynamic_viscosity_0 = std::vector<double>(n_q_points);
96 grad_specific_heat_temperature_0 = std::vector<double>(n_q_points);
97
98 specific_heat_1 = std::vector<double>(n_q_points);
99 density_1 = std::vector<double>(n_q_points);
100 thermal_conductivity_1 = std::vector<double>(n_q_points);
101 dynamic_viscosity_1 = std::vector<double>(n_q_points);
102 grad_specific_heat_temperature_1 = std::vector<double>(n_q_points);
103
104 // Create filter
105 filter = ConservativeLevelSetFilterBase::model_cast(phase_filter_parameters);
106}
107
108template <int dim>
109void
111 const FiniteElement<dim> &fe,
112 const Quadrature<dim> &quadrature,
113 const Mapping<dim> &mapping,
114 const std::shared_ptr<ConservativeLevelSetFilterBase> &filter)
115{
116 gather_cls = true;
117 fe_values_cls = std::make_shared<FEValues<dim>>(
118 mapping, fe, quadrature, update_values | update_gradients);
119
120 // Allocate CLS values
121 filtered_phase_values = std::vector<double>(this->n_q_points);
123 std::vector<Tensor<1, dim>>(this->n_q_points);
124
125 phase_gradient_values = std::vector<Tensor<1, dim>>(this->n_q_points);
126
127 // Allocate physical properties
128 specific_heat_0 = std::vector<double>(n_q_points);
129 density_0 = std::vector<double>(n_q_points);
130 thermal_conductivity_0 = std::vector<double>(n_q_points);
131 dynamic_viscosity_0 = std::vector<double>(n_q_points);
132 grad_specific_heat_temperature_0 = std::vector<double>(n_q_points);
133
134 specific_heat_1 = std::vector<double>(n_q_points);
135 density_1 = std::vector<double>(n_q_points);
136 thermal_conductivity_1 = std::vector<double>(n_q_points);
137 dynamic_viscosity_1 = std::vector<double>(n_q_points);
138 grad_specific_heat_temperature_1 = std::vector<double>(n_q_points);
139
140 // Create filter
141 this->filter = filter;
142}
143
144template <int dim>
145void
147 const FiniteElement<dim> &fe,
148 const Quadrature<dim> &quadrature,
149 const Mapping<dim> &mapping)
150{
153 std::make_shared<FEValues<dim>>(mapping, fe, quadrature, update_values);
154
155 // Allocate time-harmonic Maxwell values
157 std::vector<Tensor<1, dim>>(this->n_q_points);
159 std::vector<Tensor<1, dim>>(this->n_q_points);
161 std::vector<Tensor<1, dim>>(this->n_q_points);
163 std::vector<Tensor<1, dim>>(this->n_q_points);
164
165 // Allocate physical properties
166 this->electric_conductivity = std::vector<double>(this->n_q_points);
167 this->magnetic_permeability_imag = std::vector<double>(this->n_q_points);
168 this->electric_permittivity_imag = std::vector<double>(this->n_q_points);
169
170 // Define extractors for the time-harmonic Maxwell fields
171 this->extractor_E_real = FEValuesExtractors::Vector(0);
172 this->extractor_E_imag = FEValuesExtractors::Vector(dim);
173 this->extractor_H_real = FEValuesExtractors::Vector(2 * dim);
174 this->extractor_H_imag = FEValuesExtractors::Vector(3 * dim);
175}
176
177template <int dim>
178void
180{
183 this->fields);
184
185 if (properties_manager.field_is_required(field::temperature_p1))
188 this->fields);
189
190 if (properties_manager.field_is_required(field::temperature_p2))
193 this->fields);
194
195 if (properties_manager.field_is_required(field::shear_rate))
196 {
197 for (unsigned int q = 0; q < n_q_points; ++q)
198 {
199 // Calculate shear rate (at each q)
200 const Tensor<2, dim> shear_rate_tensor =
202 transpose(velocity_gradient_values[q]);
203
204 // Calculate the shear rate magnitude
206 calculate_shear_rate_magnitude(shear_rate_tensor);
207 }
208
210 }
211
212 if (properties_manager.field_is_required(field::pressure))
213 {
215 }
216
217 if (material_id < 1 || properties_manager.get_number_of_solids() < 1)
218 {
219 switch (properties_manager.get_number_of_fluids())
220 {
221 case 1:
222 {
223 const auto density_model = properties_manager.get_density();
224 const auto specific_heat_model =
225 properties_manager.get_specific_heat();
226 const auto thermal_conductivity_model =
227 properties_manager.get_thermal_conductivity();
228 const auto rheology_model = properties_manager.get_rheology();
229
230 density_model->vector_value(fields, density);
231 specific_heat_model->vector_value(fields, specific_heat);
232 specific_heat_model->vector_jacobian(
234 thermal_conductivity_model->vector_value(fields,
236 rheology_model->get_dynamic_viscosity_vector(
237 density_model->get_density_ref(), fields, dynamic_viscosity);
238
240 {
241 const auto electric_conductivity_model =
242 properties_manager.get_electric_conductivity();
243 const auto magnetic_permeability_model =
244 properties_manager.get_magnetic_permeability_imag();
245 const auto electric_permittivity_model =
246 properties_manager.get_electric_permittivity_imag();
247
248 electric_conductivity_model->vector_value(
250 magnetic_permeability_model->vector_value(
252 electric_permittivity_model->vector_value(
254 }
255
256 break;
257 }
258 case 2:
259 {
260 const auto density_models =
261 properties_manager.get_density_vector();
262 const auto specific_heat_models =
263 properties_manager.get_specific_heat_vector();
264 const auto thermal_conductivity_models =
265 properties_manager.get_thermal_conductivity_vector();
266 const auto rheology_models =
267 properties_manager.get_rheology_vector();
268
269 density_models[0]->vector_value(fields, density_0);
270 specific_heat_models[0]->vector_value(fields, specific_heat_0);
271 thermal_conductivity_models[0]->vector_value(
273 rheology_models[0]->get_dynamic_viscosity_vector(
274 density_models[0]->get_density_ref(),
275 fields,
277 specific_heat_models[0]->vector_jacobian(
279
280 density_models[1]->vector_value(fields, density_1);
281 specific_heat_models[1]->vector_value(fields, specific_heat_1);
282 thermal_conductivity_models[1]->vector_value(
284 rheology_models[1]->get_dynamic_viscosity_vector(
285 density_models[1]->get_density_ref(),
286 fields,
288 specific_heat_models[1]->vector_jacobian(
290
291 // Blend the physical properties using the CLS field
292 for (unsigned int q = 0; q < this->n_q_points; ++q)
293 {
294 auto filtered_phase_value = this->filtered_phase_values[q];
295
296 density[q] = calculate_point_property(filtered_phase_value,
297 this->density_0[q],
298 this->density_1[q]);
299
300 specific_heat[q] =
301 calculate_point_property(filtered_phase_value,
302 this->specific_heat_0[q],
303 this->specific_heat_1[q]);
304
306 calculate_point_property(filtered_phase_value,
307 this->thermal_conductivity_0[q],
308 this->thermal_conductivity_1[q]);
309
311 calculate_point_property(filtered_phase_value,
312 this->dynamic_viscosity_0[q],
313 this->dynamic_viscosity_1[q]);
314
316 filtered_phase_value,
319 }
320 }
321 break;
322 default:
323 throw std::runtime_error("Unsupported number of fluids (>2)");
324 }
325 }
326 else
327 {
328 const auto density_model = properties_manager.get_density(0, material_id);
329 const auto specific_heat_model =
330 properties_manager.get_specific_heat(0, material_id);
331 const auto thermal_conductivity_model =
332 properties_manager.get_thermal_conductivity(0, material_id);
333 const auto rheology_model =
334 properties_manager.get_rheology(0, material_id);
335
336 density_model->vector_value(fields, density);
337 specific_heat_model->vector_value(fields, specific_heat);
338 specific_heat_model->vector_jacobian(fields,
341 thermal_conductivity_model->vector_value(fields, thermal_conductivity);
342 rheology_model->get_dynamic_viscosity_vector(
343 density_model->get_density_ref(), fields, dynamic_viscosity);
344
346 {
347 const auto electric_conductivity_model =
348 properties_manager.get_electric_conductivity(0, material_id);
349 const auto magnetic_permeability_model =
350 properties_manager.get_magnetic_permeability_imag(0, material_id);
351 const auto electric_permittivity_model =
352 properties_manager.get_electric_permittivity_imag(0, material_id);
353
354 electric_conductivity_model->vector_value(fields,
356 magnetic_permeability_model->vector_value(fields,
358 electric_permittivity_model->vector_value(fields,
360 }
361 }
362}
363
364template class HeatTransferScratchData<2>;
365template class HeatTransferScratchData<3>;
unsigned int maximum_number_of_previous_solutions()
Get the maximum number of previous time steps supposed by the BDF schemes implemented in Lethe.
Definition bdf.h:84
static std::shared_ptr< ConservativeLevelSetFilterBase > model_cast(const Parameters::CLS_PhaseFilter &phase_filter_parameters)
Instantiate and return a pointer to a ConservativeLevelSetFilterBase object by casting it to the prop...
Definition cls_filter.cc:7
Class that stores the information required by the assembly procedure for a heat transfer advection-di...
std::vector< double > filtered_phase_values
std::vector< double > thermal_conductivity_1
std::vector< Tensor< 1, dim > > electric_field_real_values
std::vector< Tensor< 1, dim > > temperature_gradients
std::vector< double > grad_specific_heat_temperature_0
FEValuesExtractors::Vector extractor_H_imag
std::vector< Tensor< 2, dim > > velocity_gradient_values
std::vector< double > grad_specific_heat_temperature
std::shared_ptr< ConservativeLevelSetFilterBase > filter
std::map< field, std::vector< double > > fields
std::vector< double > grad_specific_heat_temperature_1
FEValuesExtractors::Vector extractor_E_imag
void enable_cls(const FiniteElement< dim > &fe, const Quadrature< dim > &quadrature, const Mapping< dim > &mapping, const Parameters::CLS_PhaseFilter &phase_filter_parameters)
enable_cls Enables the collection of the CLS data by the scratch.
std::vector< Tensor< 1, dim > > magnetic_field_real_values
void calculate_physical_properties()
Calculates the physical properties. This method calculates the physical properties that may be requir...
std::vector< double > pressure_values
Pressure field for physical property models requiring them.
std::vector< double > electric_conductivity
std::vector< double > thermal_conductivity_0
std::vector< double > dynamic_viscosity_0
std::vector< double > present_temperature_values
std::vector< double > shear_rate_values
std::vector< double > dynamic_viscosity
void enable_time_harmonic_maxwell(const FiniteElement< dim > &fe, const Quadrature< dim > &quadrature, const Mapping< dim > &mapping)
enable_time_harmonic_maxwell Enables the collection of the time-harmonic Maxwell data by the scratch ...
std::vector< Tensor< 1, dim > > filtered_phase_gradient_values
std::vector< Tensor< 1, dim > > electric_field_imag_values
PhysicalPropertiesManager properties_manager
Table< 2, Tensor< 2, dim > > hess_phi_T
dealii::types::material_id material_id
std::vector< double > present_temperature_laplacians
std::vector< double > specific_heat_1
FEValuesExtractors::Vector extractor_H_real
std::vector< Tensor< 1, dim > > phase_gradient_values
std::vector< double > electric_permittivity_imag
std::vector< double > dynamic_viscosity_1
Table< 2, Tensor< 1, dim > > grad_phi_T
std::vector< double > thermal_conductivity
std::shared_ptr< FEValues< dim > > fe_values_cls
std::vector< Tensor< 1, dim > > velocity_values
std::shared_ptr< FEValues< dim > > fe_values_time_harmonic_maxwell
FEValuesExtractors::Vector extractor_E_real
std::vector< Tensor< 1, dim > > magnetic_field_imag_values
std::vector< double > specific_heat_0
std::vector< std::vector< Tensor< 1, dim > > > previous_temperature_gradients
std::vector< double > magnetic_permeability_imag
void allocate() override
Allocates the memory for the scratch.
std::vector< std::vector< double > > previous_temperature_values
double calculate_point_property(const double phase, const double property0, const double property1)
Calculate the equivalent properties for a given phase. Method called in quadrature points loops in CL...
Definition utilities.h:307
void set_field_vector(const field &id, const std::vector< double > &data, std::map< field, std::vector< double > > &fields)
double calculate_shear_rate_magnitude(const Tensor< 2, dim > shear_rate)
Calculates the magnitude of the shear rate tensor given as input.
Parameters for the phase filtration.