Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
heat_transfer_assemblers.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>
7#include <core/utilities.h>
8
9#include <solvers/copy_data.h>
12
14 EmissivityError,
15 double,
16 << "Emissivity : " << arg1
17 << " cannot be larger than 1.0 (black body) or smaller than 0.0");
18
19template <int dim>
20void
22 const HeatTransferScratchData<dim> &scratch_data,
24{
25 // Gather physical properties in case of mono fluids simulations (to be
26 // modified by cell in case of multiple fluids simulations)
27 const std::vector<double> &density = scratch_data.density;
28 const std::vector<double> &specific_heat = scratch_data.specific_heat;
29 const std::vector<double> &thermal_conductivity =
30 scratch_data.thermal_conductivity;
31
32 // Loop and quadrature information
33 const auto &JxW_vec = scratch_data.JxW;
34 const unsigned int n_q_points = scratch_data.n_q_points;
35 const double h = scratch_data.cell_size;
36 const unsigned int n_dofs = scratch_data.n_dofs;
37
38 // Vector for the BDF coefficients
39 // The coefficients are stored in the following fashion :
40 // 0 - n+1
41 // 1 - n
42 // 2 - n-1
43 // 3 - n-2
44 std::vector<double> time_steps_vector =
45 this->simulation_control->get_time_steps_vector();
46
47 // Time steps and inverse time steps which is used for numerous calculations
48 const double dt = time_steps_vector[0];
49 const double sdt = 1. / dt;
50
51 // Copy data elements
52 auto &strong_jacobian_vec = copy_data.strong_jacobian;
53 auto &local_matrix = copy_data.local_matrix;
54
55 // assembling local matrix and right hand side
56 for (unsigned int q = 0; q < n_q_points; ++q)
57 {
58 const double rho_cp = density[q] * specific_heat[q];
59 const double alpha = thermal_conductivity[q] / (rho_cp + DBL_MIN);
60
61 const auto method = this->simulation_control->get_assembly_method();
62
63 // Store JxW in local variable for faster access
64 const double JxW = JxW_vec[q];
65
66 const auto velocity = scratch_data.velocity_values[q];
67
68 // Calculation of the magnitude of the velocity for the stabilization
69 // parameter
70 const double u_mag = std::max(velocity.norm(), 1e-12);
71
72 // Calculation of the SUPG stabilization parameter. The
73 // stabilization parameter used is different if the simulation is
74 // steady or unsteady. In the unsteady case it includes the value
75 // of the time step
76 const double tau =
77 is_steady(method) ?
78 1. / std::sqrt(std::pow(2. * u_mag / h, 2) +
79 9 * std::pow(4 * alpha / (h * h), 2)) :
80 1. / std::sqrt(std::pow(sdt, 2) + std::pow(2. * u_mag / h, 2) +
81 9 * std::pow(4 * alpha / (h * h), 2));
82
83 for (unsigned int j = 0; j < n_dofs; ++j)
84 {
85 strong_jacobian_vec[q][j] +=
86 rho_cp * velocity * scratch_data.grad_phi_T[q][j] -
87 thermal_conductivity[q] * scratch_data.laplacian_phi_T[q][j];
88 }
89
90 for (unsigned int i = 0; i < n_dofs; ++i)
91 {
92 const auto phi_T_i = scratch_data.phi_T[q][i];
93 const auto grad_phi_T_i = scratch_data.grad_phi_T[q][i];
94
95 for (unsigned int j = 0; j < n_dofs; ++j)
96 {
97 const Tensor<1, dim> grad_phi_T_j = scratch_data.grad_phi_T[q][j];
98
99 // Weak form for : - k * laplacian T + rho * cp *
100 // u * gradT - f -
101 // tau:grad(u) =0
102 // Hypothesis : incompressible newtonian fluid
103 // so tau:grad(u) =
104 // mu*(grad(u)+transpose(grad(u)).transpose(grad(u))
105 local_matrix(i, j) +=
106 (thermal_conductivity[q] * grad_phi_T_i * grad_phi_T_j +
107 rho_cp * phi_T_i * velocity * grad_phi_T_j) *
108 JxW;
109
110 // Addition to the cell matrix for SUPG stabilization
111 local_matrix(i, j) += tau * strong_jacobian_vec[q][j] *
112 (grad_phi_T_i * velocity) * JxW;
113 }
114 }
115
116 } // end loop on quadrature points
117}
118
119template <int dim>
120void
122 const HeatTransferScratchData<dim> &scratch_data,
123 StabilizedMethodsCopyData &copy_data)
124{
125 const auto method = this->simulation_control->get_assembly_method();
126 const unsigned int n_q_points = scratch_data.n_q_points;
127 const double h = scratch_data.cell_size;
128 const unsigned int n_dofs = scratch_data.n_dofs;
129
130 const std::vector<double> &density = scratch_data.density;
131 const std::vector<double> &specific_heat = scratch_data.specific_heat;
132 const std::vector<double> &thermal_conductivity =
133 scratch_data.thermal_conductivity;
134
135 // Time steps and inverse time steps which is used for stabilization
136 // constant
137 std::vector<double> time_steps_vector =
138 this->simulation_control->get_time_steps_vector();
139 const double dt = time_steps_vector[0];
140 const double sdt = 1. / dt;
141
142 // Copy data elements
143 auto &strong_residual_vec = copy_data.strong_residual;
144 auto &local_rhs = copy_data.local_rhs;
145
146 // assembling right hand side
147 for (unsigned int q = 0; q < n_q_points; ++q)
148 {
149 const Tensor<1, dim> temperature_gradient =
150 scratch_data.temperature_gradients[q];
151 const double temperature_laplacian =
152 scratch_data.present_temperature_laplacians[q];
153
154 // Gather physical properties in case of mono fluids simulations (to be
155 // modified by cell in case of multiple fluids simulations)
156 double rho_cp = density[q] * specific_heat[q];
157 double alpha = thermal_conductivity[q] / (rho_cp + DBL_MIN);
158
159 // Store JxW in local variable for faster access
160 const double JxW = scratch_data.fe_values_T.JxW(q);
161
162 const auto velocity = scratch_data.velocity_values[q];
163
164 // Calculation of the magnitude of the velocity for the
165 // stabilization parameter
166 const double u_mag = std::max(velocity.norm(), 1e-12);
167
168 // Calculation of the SUPG stabilization parameter. The
169 // stabilization parameter used is different if the simulation is
170 // steady or unsteady. In the unsteady case it includes the value
171 // of the time step
172 const double tau =
173 is_steady(method) ?
174 1. / std::sqrt(std::pow(2. * u_mag / h, 2) +
175 9 * std::pow(4 * alpha / (h * h), 2)) :
176 1. / std::sqrt(std::pow(sdt, 2) + std::pow(2. * u_mag / h, 2) +
177 9 * std::pow(4 * alpha / (h * h), 2));
178
179 // Calculate the strong residual for GLS stabilization
180 strong_residual_vec[q] +=
181 rho_cp * velocity * temperature_gradient -
182 thermal_conductivity[q] * temperature_laplacian -
183 scratch_data.source[q];
184
185 for (unsigned int i = 0; i < n_dofs; ++i)
186 {
187 const auto phi_T_i = scratch_data.phi_T[q][i];
188 const auto grad_phi_T_i = scratch_data.grad_phi_T[q][i];
189
190 // rhs for : - k * laplacian T + rho * cp * u * grad T - f
191 // -grad(u)*grad(u) = 0
192 local_rhs(i) -=
193 (thermal_conductivity[q] * grad_phi_T_i * temperature_gradient +
194 rho_cp * phi_T_i * velocity * temperature_gradient -
195 scratch_data.source[q] * phi_T_i) *
196 JxW;
197
198 // Apply SUPG
199 local_rhs(i) -=
200 tau * (strong_residual_vec[q] * (grad_phi_T_i * velocity)) * JxW;
201 }
202
203 } // end loop on quadrature points
204}
205
206template class HeatTransferAssemblerCore<2>;
207template class HeatTransferAssemblerCore<3>;
208
209template <int dim>
210void
212 const HeatTransferScratchData<dim> &scratch_data,
213 StabilizedMethodsCopyData &copy_data)
214{
215 // Loop and quadrature information
216 const auto &JxW = scratch_data.JxW;
217 const unsigned int n_q_points = scratch_data.n_q_points;
218 const unsigned int n_dofs = scratch_data.n_dofs;
219
220 const std::vector<double> &density = scratch_data.density;
221 const std::vector<double> &specific_heat = scratch_data.specific_heat;
222 const std::vector<double> &grad_specific_heat_temperature =
224
225 // Copy data elements
226 auto &strong_residual = copy_data.strong_residual;
227 auto &strong_jacobian = copy_data.strong_jacobian;
228 auto &local_matrix = copy_data.local_matrix;
229
230 const double h = scratch_data.cell_size;
231
232 // Time stepping information
233 const auto method = this->simulation_control->get_assembly_method();
234 // Vector for the BDF coefficients
235 const Vector<double> &bdf_coefs =
236 this->simulation_control->get_bdf_coefficients();
237 std::vector<double> temperature(1 + number_of_previous_solutions(method));
238
239 // Loop over the quadrature points
240 for (unsigned int q = 0; q < n_q_points; ++q)
241 {
242 const double rho = density[q];
243 const double rho_cp = rho * specific_heat[q];
244 double dT_dt = 0;
245
246 temperature[0] = scratch_data.present_temperature_values[q];
247 for (unsigned int p = 0; p < number_of_previous_solutions(method); ++p)
248 temperature[p + 1] = scratch_data.previous_temperature_values[p][q];
249
250 for (unsigned int p = 0; p < number_of_previous_solutions(method) + 1;
251 ++p)
252 {
253 strong_residual[q] += rho_cp * bdf_coefs[p] * temperature[p];
254 dT_dt += bdf_coefs[p] * temperature[p];
255 }
256
257 for (unsigned int j = 0; j < n_dofs; ++j)
258 {
259 strong_jacobian[q][j] +=
260 rho_cp * bdf_coefs[0] * scratch_data.phi_T[q][j];
261 }
262
263 const double tau_ggls =
264 std::pow(h, scratch_data.fe_values_T.get_fe().degree + 1) / 6. /
265 (rho_cp + DBL_MIN);
266
267 for (unsigned int i = 0; i < n_dofs; ++i)
268 {
269 const double phi_T_i = scratch_data.phi_T[q][i];
270 const auto grad_phi_T_i = scratch_data.grad_phi_T[q][i];
271
272 for (unsigned int j = 0; j < n_dofs; ++j)
273 {
274 const double phi_T_j = scratch_data.phi_T[q][j];
275 const auto grad_phi_T_j = scratch_data.grad_phi_T[q][j];
276
277 local_matrix(i, j) +=
278 rho_cp * phi_T_j * phi_T_i * bdf_coefs[0] * JxW[q];
279
280 local_matrix(i, j) += rho * grad_specific_heat_temperature[q] *
281 phi_T_j * phi_T_i * dT_dt * JxW[q];
282
283 if (GGLS)
284 {
285 local_matrix(i, j) += rho_cp * rho_cp * tau_ggls *
286 (grad_phi_T_i * grad_phi_T_j) *
287 bdf_coefs[0] * JxW[q];
288 }
289 }
290 }
291 } // end loop on quadrature points
292}
293
294template <int dim>
295void
297 const HeatTransferScratchData<dim> &scratch_data,
298 StabilizedMethodsCopyData &copy_data)
299{
300 // Gather physical properties in case of mono fluids simulations (to be
301 // modified by cell in case of multiple fluids simulations)
302 const std::vector<double> &density = scratch_data.density;
303 const std::vector<double> &specific_heat = scratch_data.specific_heat;
304
305 // Loop and quadrature information
306 const auto &JxW = scratch_data.JxW;
307 const unsigned int n_q_points = scratch_data.n_q_points;
308 const unsigned int n_dofs = scratch_data.n_dofs;
309 const double h = scratch_data.cell_size;
310
311 // Copy data elements
312 auto &strong_residual = copy_data.strong_residual;
313 auto &local_rhs = copy_data.local_rhs;
314
315 // Time stepping information
316 const auto method = this->simulation_control->get_assembly_method();
317 // Vector for the BDF coefficients
318 const Vector<double> &bdf_coefs =
319 this->simulation_control->get_bdf_coefficients();
320 std::vector<double> temperature(1 + number_of_previous_solutions(method));
321 std::vector<Tensor<1, dim>> temperature_gradient(
322 1 + number_of_previous_solutions(method));
323
324 // Loop over the quadrature points
325 for (unsigned int q = 0; q < n_q_points; ++q)
326 {
327 const double rho_cp = density[q] * specific_heat[q];
328
329 const double tau_ggls =
330 std::pow(h, scratch_data.fe_values_T.get_fe().degree + 1) / 6. /
331 (rho_cp + DBL_MIN);
332
333 temperature[0] = scratch_data.present_temperature_values[q];
334 temperature_gradient[0] = scratch_data.temperature_gradients[q];
335
336 for (unsigned int p = 0; p < number_of_previous_solutions(method); ++p)
337 {
338 temperature[p + 1] = scratch_data.previous_temperature_values[p][q];
339 temperature_gradient[p + 1] =
340 scratch_data.previous_temperature_gradients[p][q];
341 }
342
343 for (unsigned int p = 0; p < number_of_previous_solutions(method) + 1;
344 ++p)
345 {
346 strong_residual[q] += rho_cp * bdf_coefs[p] * temperature[p];
347 }
348
349 for (unsigned int i = 0; i < n_dofs; ++i)
350 {
351 const double phi_T_i = scratch_data.phi_T[q][i];
352 const auto grad_phi_T_i = scratch_data.grad_phi_T[q][i];
353 double local_rhs_i = 0;
354 for (unsigned int p = 0; p < number_of_previous_solutions(method) + 1;
355 ++p)
356 {
357 local_rhs_i -= rho_cp * bdf_coefs[p] * (temperature[p] * phi_T_i);
358
359 if (GGLS)
360 {
361 // ?? why rho_cp * rho_cp
362 local_rhs_i -= rho_cp * rho_cp * tau_ggls * grad_phi_T_i *
363 bdf_coefs[p] * temperature_gradient[p];
364 }
365 }
366 local_rhs(i) += local_rhs_i * JxW[q];
367 }
368 } // end loop on quadrature points
369}
370
371template class HeatTransferAssemblerBDF<2>;
372template class HeatTransferAssemblerBDF<3>;
373
374template <int dim>
375void
377 const HeatTransferScratchData<dim> &scratch_data,
378 StabilizedMethodsCopyData &copy_data)
379{
380 if (!scratch_data.is_boundary_cell)
381 return;
382
383 auto &local_matrix = copy_data.local_matrix;
384 const double Stefan_Boltzmann_constant =
385 this->boundary_conditions_ht.Stefan_Boltzmann_constant;
386
387 for (unsigned int f = 0; f < scratch_data.n_faces; ++f)
388 {
389 if (this->boundary_conditions_ht.type.at(
390 scratch_data.boundary_face_id[f]) ==
392 {
393 // Robin boundary condition, loop on faces (Newton's cooling law +
394 // Stefan-Boltzmann law) implementation similar to deal.ii step-7
395 Function<dim> &h_function = *(this->boundary_conditions_ht.h.at(
396 scratch_data.boundary_face_id[f]));
397 Function<dim> &emissivity_function =
398 *(this->boundary_conditions_ht.emissivity.at(
399 scratch_data.boundary_face_id[f]));
400 for (unsigned int q = 0; q < scratch_data.n_faces_q_points; ++q)
401 {
402 const double T_face = scratch_data.temperature_face_value[f][q];
403 const double JxW = scratch_data.face_JxW[f][q];
404 const double h =
405 h_function.value(scratch_data.quadrature_points[q]);
406 const double emissivity =
407 emissivity_function.value(scratch_data.quadrature_points[q]);
408 AssertThrow(emissivity <= 1.0 && emissivity >= 0.0,
409 EmissivityError(emissivity));
410 for (unsigned int i = 0; i < scratch_data.n_dofs; ++i)
411 {
412 const double phi_face_T_i = scratch_data.phi_face_T[f][q][i];
413
414 for (unsigned int j = 0; j < scratch_data.n_dofs; ++j)
415 {
416 const double phi_face_T_j =
417 scratch_data.phi_face_T[f][q][j];
418 local_matrix(i, j) +=
419 (h + 4.0 * Stefan_Boltzmann_constant * emissivity *
420 T_face * T_face * T_face) *
421 phi_face_T_i * phi_face_T_j * JxW;
422 }
423 }
424 }
425 }
426 }
427}
428
429template <int dim>
430void
432 const HeatTransferScratchData<dim> &scratch_data,
433 StabilizedMethodsCopyData &copy_data)
434{
435 if (!scratch_data.is_boundary_cell)
436 return;
437
438 auto &local_rhs = copy_data.local_rhs;
439 const double Stefan_Boltzmann_constant =
440 this->boundary_conditions_ht.Stefan_Boltzmann_constant;
441
442 // Robin boundary condition, loop on faces (Newton's cooling law +
443 // Stefan-Boltzmann law) Convection-radiation-flux BC is a combination of
444 // convection and radiation. If the Stefan-Boltzmann constant (with default
445 // value = 0) is set to 0, only the convection component is considered,
446 // whereas if the convection coefficient, h (with default value = 0), is set
447 // to 0, only the radiation component is considered. Otherwise, both the
448 // convection and radiation are significant on the boundary implementation
449 // similar to deal.ii step-7
450 for (unsigned int f = 0; f < scratch_data.n_faces; ++f)
451 {
452 if (this->boundary_conditions_ht.type.at(
453 scratch_data.boundary_face_id[f]) ==
455 {
456 Function<dim> &h_function = *(this->boundary_conditions_ht.h.at(
457 scratch_data.boundary_face_id[f]));
458 Function<dim> &T_inf_function =
459 *(this->boundary_conditions_ht.Tinf.at(
460 scratch_data.boundary_face_id[f]));
461 Function<dim> &emissivity_function =
462 *(this->boundary_conditions_ht.emissivity.at(
463 scratch_data.boundary_face_id[f]));
464 Function<dim> &heat_flux_bc_function =
465 *(this->boundary_conditions_ht.heat_flux_bc.at(
466 scratch_data.boundary_face_id[f]));
467 for (unsigned int q = 0; q < scratch_data.n_faces_q_points; ++q)
468 {
469 const double T_face = scratch_data.temperature_face_value[f][q];
470 const double JxW = scratch_data.face_JxW[f][q];
471 const double h =
472 h_function.value(scratch_data.quadrature_points[q]);
473 const double T_inf =
474 T_inf_function.value(scratch_data.quadrature_points[q]);
475 const double emissivity =
476 emissivity_function.value(scratch_data.quadrature_points[q]);
477 AssertThrow(emissivity <= 1.0 && emissivity >= 0.0,
478 EmissivityError(emissivity));
479 const double heat_flux_bc =
480 heat_flux_bc_function.value(scratch_data.quadrature_points[q]);
481 for (unsigned int i = 0; i < scratch_data.n_dofs; ++i)
482 {
483 const double phi_face_T_i = scratch_data.phi_face_T[f][q][i];
484 local_rhs(i) -= phi_face_T_i *
485 (h * (T_face - T_inf) +
486 Stefan_Boltzmann_constant * emissivity *
487 (T_face * T_face * T_face * T_face -
488 T_inf * T_inf * T_inf * T_inf) +
489 heat_flux_bc) *
490 JxW;
491 }
492 }
493 }
494 }
495}
496
499
500template <int dim>
501void
507
508template <int dim>
509void
511 const HeatTransferScratchData<dim> &scratch_data,
512 StabilizedMethodsCopyData &copy_data)
513{
514 const unsigned int n_q_points = scratch_data.n_q_points;
515 const unsigned int n_dofs = scratch_data.n_dofs;
516
517 const std::vector<double> &dynamic_viscosity_vector =
518 scratch_data.dynamic_viscosity;
519
520 // Time steps and inverse time steps which is used for stabilization
521 // constant
522 std::vector<double> time_steps_vector =
523 this->simulation_control->get_time_steps_vector();
524
525 // Copy data elements
526 auto &local_rhs = copy_data.local_rhs;
527
528 // assembling right hand side
529 for (unsigned int q = 0; q < n_q_points; ++q)
530 {
531 // Gather physical properties in case of mono fluids simulations (to be
532 // modified by cell in case of multiple fluids simulations)
533 const double dynamic_viscosity = dynamic_viscosity_vector[q];
534
535 // Store JxW in local variable for faster access
536 const double JxW = scratch_data.fe_values_T.JxW(q);
537
538 const auto velocity_gradient_fd =
539 scratch_data.velocity_gradient_values[q];
540
541 for (unsigned int i = 0; i < n_dofs; ++i)
542 {
543 const auto phi_T_i = scratch_data.phi_T[q][i];
544
545 local_rhs(i) -= (-dynamic_viscosity * phi_T_i *
546 scalar_product(velocity_gradient_fd +
547 transpose(velocity_gradient_fd),
548 transpose(velocity_gradient_fd))) *
549 JxW;
550 }
551 }
552}
553
556
557template <int dim>
558void
564
565template <int dim>
566void
568 const HeatTransferScratchData<dim> &scratch_data,
569 StabilizedMethodsCopyData &copy_data)
570{
571 const unsigned int n_q_points = scratch_data.n_q_points;
572 const unsigned int n_dofs = scratch_data.n_dofs;
573
574 const std::vector<double> &dynamic_viscosity_vector =
575 scratch_data.dynamic_viscosity;
576
577 double viscous_dissipation_coefficient(0.);
578
579 // Time steps and inverse time steps which is used for stabilization
580 // constant
581 std::vector<double> time_steps_vector =
582 this->simulation_control->get_time_steps_vector();
583
584 // Copy data elements
585 auto &local_rhs = copy_data.local_rhs;
586
587 // assembling right hand side
588 for (unsigned int q = 0; q < n_q_points; ++q)
589 {
590 // Gather physical properties in case of mono fluids simulations (to be
591 // modified by cell in case of multiple fluids simulations)
592 const double dynamic_viscosity = dynamic_viscosity_vector[q];
593
594 // Store JxW in local variable for faster access
595 const double JxW = scratch_data.fe_values_T.JxW(q);
596
597 const auto velocity_gradient_fd =
598 scratch_data.velocity_gradient_values[q];
599
600 // Manage viscous dissipation application on specified fluid
601 const double filtered_phase_value_q =
602 scratch_data.filtered_phase_values[q];
603 if (this->viscous_dissipative_fluid ==
605 {
606 // if phase = 0, no viscous dissipation
607 // if phase = 1, maximum viscous dissipation
608 viscous_dissipation_coefficient = filtered_phase_value_q;
609 }
610 else if (this->viscous_dissipative_fluid ==
612 {
613 // if phase = 1, no viscous dissipation
614 // if phase = 0, maximum viscous dissipation
615 viscous_dissipation_coefficient = 1. - filtered_phase_value_q;
616 }
617 else if (this->viscous_dissipative_fluid ==
619 {
620 // maximum viscous dissipation everywhere
621 viscous_dissipation_coefficient = 1.;
622 }
623 else
624 {
625 throw(
626 std::runtime_error("Invalid viscous dissipative fluid. "
627 "Options are 'fluid_0', 'fluid_1' or 'both'."));
628 }
629
630 // assemble the rhs
631 for (unsigned int i = 0; i < n_dofs; ++i)
632 {
633 const auto phi_T_i = scratch_data.phi_T[q][i];
634
635 local_rhs(i) -= viscous_dissipation_coefficient *
636 (-dynamic_viscosity * phi_T_i *
637 scalar_product(velocity_gradient_fd +
638 transpose(velocity_gradient_fd),
639 transpose(velocity_gradient_fd))) *
640 JxW;
641 }
642 }
643}
644
647
648template <int dim>
649void
651 const HeatTransferScratchData<dim> &scratch_data,
652 StabilizedMethodsCopyData &copy_data)
653{
654 // Gather physical properties in case of mono fluids simulations (to be
655 // modified by cell in case of multiple fluids simulations)
656 const std::vector<double> &density = scratch_data.density;
657 const std::vector<double> &specific_heat = scratch_data.specific_heat;
658
659 // Loop and quadrature information
660 const auto &JxW_vec = scratch_data.JxW;
661 const unsigned int n_q_points = scratch_data.n_q_points;
662 const double h = scratch_data.cell_size;
663 const unsigned int n_dofs = scratch_data.n_dofs;
664
665 // Copy data elements
666 auto &local_matrix = copy_data.local_matrix;
667
668 // assembling local matrix and right hand side
669 for (unsigned int q = 0; q < n_q_points; ++q)
670 {
671 const double rho_cp = density[q] * specific_heat[q];
672
673 const auto method = this->simulation_control->get_assembly_method();
674
675 // Store JxW in local variable for faster access
676 const double JxW = JxW_vec[q];
677
678 const auto velocity = scratch_data.velocity_values[q];
679
680 // Calculation of the magnitude of the velocity for the stabilization
681 // parameter
682 const double u_mag = std::max(velocity.norm(), 1e-12);
683
684 // Temperature gradient information for DCDD stabilization
685 Tensor<1, dim> dcdd_temperature_gradient =
686 is_steady(method) ? scratch_data.temperature_gradients[q] :
687 scratch_data.previous_temperature_gradients[0][q];
688
689 // Implementation of a Discontinuity-Capturing Directional Dissipation
690 // (DCDD) shock capturing scheme. For more information see Tezduyar,
691 // T. E. (2003). Computation of moving boundaries and interfaces and
692 // stabilization parameters. International Journal for Numerical
693 // Methods in Fluids, 43(5), 555-575. Our implementation is based on
694 // equations (70) and (79), which are adapted for the heat transfer
695 // solver.
696
697 // In Tezduyar 2003, this is denoted r in equation (67). The velocity is
698 // replaced by the temperature.
699 Tensor<1, dim> temperature_gradient_unit_vector =
700 dcdd_temperature_gradient / (dcdd_temperature_gradient.norm() + 1e-12);
701
702 // In Tezduyar 2003, this is denoted s in equation (67)
703 Tensor<1, dim> velocity_unit_vector =
704 velocity / (velocity.norm() + 1e-12);
705
706 // Directionality tensor describing [rr - (r⋅s)^2*ss]
707 Tensor<2, dim> dir_tensor =
708 outer_product(temperature_gradient_unit_vector,
709 temperature_gradient_unit_vector) -
710 (Utilities::fixed_power<2>(scalar_product(
711 temperature_gradient_unit_vector, velocity_unit_vector)) *
712 outer_product(velocity_unit_vector, velocity_unit_vector));
713
714 // Calculate the artificial viscosity of the shock capture as in equation
715 // (79) of Tezduyar 2003
716 const double nu_dcdd = 0.5 * h * h * u_mag *
717 dcdd_temperature_gradient.norm() /
718 scratch_data.global_delta_T_ref;
719
720 for (unsigned int i = 0; i < n_dofs; ++i)
721 {
722 const auto grad_phi_T_i = scratch_data.grad_phi_T[q][i];
723
724 for (unsigned int j = 0; j < n_dofs; ++j)
725 {
726 const Tensor<1, dim> grad_phi_T_j = scratch_data.grad_phi_T[q][j];
727
728 // DCDD shock capturing
729 local_matrix(i, j) +=
730 rho_cp * nu_dcdd *
731 (scalar_product(grad_phi_T_i, dir_tensor * grad_phi_T_j)) * JxW;
732 }
733 }
734
735 } // end loop on quadrature points
736}
737
738template <int dim>
739void
741 const HeatTransferScratchData<dim> &scratch_data,
742 StabilizedMethodsCopyData &copy_data)
743{
744 const auto method = this->simulation_control->get_assembly_method();
745 const unsigned int n_q_points = scratch_data.n_q_points;
746 const double h = scratch_data.cell_size;
747 const unsigned int n_dofs = scratch_data.n_dofs;
748
749 const std::vector<double> &density = scratch_data.density;
750 const std::vector<double> &specific_heat = scratch_data.specific_heat;
751
752 // Copy data elements
753 auto &local_rhs = copy_data.local_rhs;
754
755 // assembling right hand side
756 for (unsigned int q = 0; q < n_q_points; ++q)
757 {
758 const Tensor<1, dim> temperature_gradient =
759 scratch_data.temperature_gradients[q];
760
761 // Gather physical properties in case of mono fluids simulations (to be
762 // modified by cell in case of multiple fluids simulations)
763 double rho_cp = density[q] * specific_heat[q];
764
765 // Store JxW in local variable for faster access
766 const double JxW = scratch_data.fe_values_T.JxW(q);
767
768 const auto velocity = scratch_data.velocity_values[q];
769
770 // Calculation of the magnitude of the velocity for the
771 // stabilization parameter
772 const double u_mag = std::max(velocity.norm(), 1e-12);
773
774 // Temperature gradient information for DCDD stabilization
775 Tensor<1, dim> dcdd_temperature_gradient =
776 is_steady(method) ? scratch_data.temperature_gradients[q] :
777 scratch_data.previous_temperature_gradients[0][q];
778
779 // Implementation of a Discontinuity-Capturing Directional Dissipation
780 // (DCDD) shock capturing scheme. For more information see Tezduyar,
781 // T. E. (2003). Computation of moving boundaries and interfaces and
782 // stabilization parameters. International Journal for Numerical
783 // Methods in Fluids, 43(5), 555-575. Our implementation is based on
784 // equations (70) and (79), which are adapted for the heat transfer
785 // solver.
786
787 // In Tezduyar 2003, this is denoted r in equation (67)
788 Tensor<1, dim> temperature_gradient_unit_vector =
789 dcdd_temperature_gradient / (dcdd_temperature_gradient.norm() + 1e-12);
790
791 // In Tezduyar 2003, this is denoted s in equation (67)
792 Tensor<1, dim> velocity_unit_vector =
793 velocity / (velocity.norm() + 1e-12);
794
795 // Directionality tensor [rr - (r⋅s)^2*ss]
796 Tensor<2, dim> dir_tensor =
797 outer_product(temperature_gradient_unit_vector,
798 temperature_gradient_unit_vector) -
799 (Utilities::fixed_power<2>(scalar_product(
800 temperature_gradient_unit_vector, velocity_unit_vector)) *
801 outer_product(velocity_unit_vector, velocity_unit_vector));
802
803 // Calculate the artificial viscosity of the shock capture as in equation
804 // (79) of Tezduyar 2003
805 const double nu_dcdd = 0.5 * h * h * u_mag *
806 dcdd_temperature_gradient.norm() /
807 scratch_data.global_delta_T_ref;
808
809 for (unsigned int i = 0; i < n_dofs; ++i)
810 {
811 const auto grad_phi_T_i = scratch_data.grad_phi_T[q][i];
812
813 // DCDD shock capturing
814 local_rhs(i) -=
815 rho_cp * nu_dcdd *
816 (scalar_product(grad_phi_T_i, dir_tensor * temperature_gradient)) *
817 JxW;
818 }
819
820 } // end loop on quadrature points
821}
822
825
826template <int dim>
827void
832
833template <int dim>
834void
836 const HeatTransferScratchData<dim> &scratch_data,
837 StabilizedMethodsCopyData &copy_data)
838{
839 // Laser parameters
840 const double concentration_factor = laser_parameters->concentration_factor;
841 const double laser_power = laser_parameters->laser_power;
842 const double absorptivity = laser_parameters->laser_absorptivity;
843 const double penetration_depth = laser_parameters->penetration_depth;
844 const double laser_start_time = laser_parameters->start_time;
845 const double laser_end_time = laser_parameters->end_time;
846 const double beam_radius = laser_parameters->beam_radius;
847 const bool beam_direction = laser_parameters->beam_direction;
848 const double current_time = this->simulation_control->get_current_time();
849
850 if (current_time >= laser_start_time && current_time <= laser_end_time)
851 {
852 // Get laser path
853 Function<dim> &laser_scan_path = *(laser_parameters->laser_scan_path);
854 laser_scan_path.set_time(current_time);
855
856 // For the laser heat source calculations, we need the radial distance, r,
857 // (in a dim-1 dimensional plane perpendicular to the laser beam
858 // direction) between the laser focal point and the quadrature points, as
859 // well as the axial distance, z, (in a laser emission direction) between
860 // the laser focal point and the quadrature points, separately. Hence, we
861 // get the laser location (laser_location) as a Point<dim>, in which the
862 // first and second components show the position of the laser focal point
863 // in a plane perpendicular to the emission direction, and the (dim-1)th
864 // component denotes the position of the laser focal point in the
865 // direction of emission. Then we use dim-1 auxiliary variables
866 // (Point<dim-1> laser_location_on_surface) to store the position of the
867 // laser focal point in the perpendicular plane to the emission direction,
868 // and double laser_location_in_depth to store the position of the laser
869 // focal point in the direction of emission.
870
871 // Get laser location
872 Point<dim> laser_location;
873 laser_location[0] = laser_scan_path.value(
874 laser_location, laser_parameters->perpendicular_plane_coordinate_one);
875 if constexpr (dim == 3)
876 {
877 laser_location[1] = laser_scan_path.value(
878 laser_location,
879 laser_parameters->perpendicular_plane_coordinate_two);
880 }
881
882 // Get laser location in depth (direction of emission).
883 double laser_location_in_depth = 0.0;
884 laser_location[dim - 1] =
885 laser_scan_path.value(laser_location,
886 laser_parameters->beam_orientation_coordinate);
887 laser_location_in_depth = laser_location[dim - 1];
888
889 // Get laser location on the operation surface
890 Point<dim - 1> laser_location_on_surface;
891 for (int d = 0; d < dim - 1; d++)
892 laser_location_on_surface[d] = laser_location[d];
893
894 const unsigned int n_q_points = scratch_data.n_q_points;
895 const unsigned int n_dofs = scratch_data.n_dofs;
896
897 // Copy data elements
898 auto &strong_residual = copy_data.strong_residual;
899 auto &local_rhs = copy_data.local_rhs;
900
901 // assembling right hand side
902 for (unsigned int q = 0; q < n_q_points; ++q)
903 {
904 // Get quadrature point location on surface to calculate its distance
905 // from the laser focal point in a perpendicular plane to the
906 // direction of emission
907 Point<dim - 1> quadrature_point_on_surface;
908 quadrature_point_on_surface[0] =
909 scratch_data.quadrature_points
910 [q][laser_parameters->perpendicular_plane_coordinate_one];
911 if constexpr (dim == 3)
912 {
913 quadrature_point_on_surface[1] =
914 scratch_data.quadrature_points
915 [q][laser_parameters->perpendicular_plane_coordinate_two];
916 }
917
918 // Get quadrature point depth to calculate its distance from the laser
919 // focal point in the direction of emission. Note that in
920 // two-dimensional simulations, this variable is always equal to zero
921 const double quadrature_point_depth =
922 scratch_data.quadrature_points[q][laser_parameters
923 ->beam_orientation_coordinate];
924
925 // if the laser beam is in negative direction and
926 // quadrature_point_depth is smaller than the laser_location_in_depth,
927 // or the laser beam is in positive direction and
928 // quadrature_point_depth is larger than laser_location_in_depth we
929 // need to apply the laser on the quadrature point, otherwise it is
930 // zero
931 double laser_quadrature_point_distance_in_depth = 0.0;
932 if ((beam_direction == 0 &&
933 quadrature_point_depth <= laser_location_in_depth) |
934 (beam_direction == 1 &&
935 quadrature_point_depth >= laser_location_in_depth))
936 laser_quadrature_point_distance_in_depth =
937 std::abs(quadrature_point_depth - laser_location_in_depth);
938
939 // Store JxW in local variable for faster access
940 const double JxW = scratch_data.fe_values_T.JxW(q);
941
942 // Calculate the strong residual for GLS stabilization
943 const double laser_heat_source =
944 (concentration_factor * absorptivity * laser_power /
945 (M_PI * beam_radius * beam_radius * penetration_depth)) *
946 exp(-1.0 * concentration_factor *
947 std::pow(laser_location_on_surface.distance(
948 quadrature_point_on_surface),
949 2.0) /
950 (beam_radius * beam_radius)) *
951 exp(-1.0 * laser_quadrature_point_distance_in_depth /
952 penetration_depth);
953 strong_residual[q] -= laser_heat_source;
954
955 for (unsigned int i = 0; i < n_dofs; ++i)
956 {
957 const auto phi_T_i = scratch_data.phi_T[q][i];
958
959 // rhs for : eta * alpha * P / (pi * R^2 * mu) * exp(-eta * r^2 /
960 // R^2) * exp(-|z| / mu) where eta, alpha, P, R, mu, r and z
961 // denote concentration factor, absorptivity, laser power, beam
962 // radius, penetration depth, radial distance from the laser focal
963 // point, and axial distance from the laser focal point,
964 // respectively.
965 local_rhs(i) += laser_heat_source * phi_T_i * JxW;
966 }
967 } // end loop on quadrature points
968 }
969}
970
973
974template <int dim>
975void
980
981template <int dim>
982void
984 const HeatTransferScratchData<dim> &scratch_data,
985 StabilizedMethodsCopyData &copy_data)
986{
987 // Laser parameters
988 const double concentration_factor = laser_parameters->concentration_factor;
989 const double laser_power = laser_parameters->laser_power;
990 const double absorptivity = laser_parameters->laser_absorptivity;
991 const double laser_start_time = laser_parameters->start_time;
992 const double laser_end_time = laser_parameters->end_time;
993 const double beam_radius = laser_parameters->beam_radius;
994 const double current_time = this->simulation_control->get_current_time();
995
996 if (current_time >= laser_start_time && current_time <= laser_end_time)
997 {
998 // Get laser path
999 Function<dim> &laser_scan_path = *(laser_parameters->laser_scan_path);
1000 laser_scan_path.set_time(current_time);
1001
1002 // For the laser heat source calculations, we need the radial distance, r,
1003 // (in a dim-1 dimensional plane perpendicular to the laser beam
1004 // direction) between the laser focal point and the quadrature points.
1005 // Here, the focal point is any given point on the laser's axis.
1006 // Hence, we get the laser location (laser_location) as a Point<dim>, in
1007 // which the first and second components show the position of the laser
1008 // focal point in a plane perpendicular to the emission direction.
1009 // Then we use dim-1 auxiliary variables (Point<dim-1>
1010 // laser_location_on_surface) to store the position of the laser focal
1011 // point in the perpendicular plane to the emission direction.
1012
1013 // Get laser location
1014 Point<dim> laser_location;
1015 for (int d = 0; d < dim; ++d)
1016 {
1017 laser_location[d] = laser_scan_path.value(laser_location, d);
1018 }
1019
1020 // Get laser location on the operation surface
1021 Point<dim - 1> laser_location_on_surface;
1022 for (int d = 0; d < dim - 1; d++)
1023 laser_location_on_surface[d] = laser_location[d];
1024
1025 const unsigned int n_q_points = scratch_data.n_q_points;
1026 const unsigned int n_dofs = scratch_data.n_dofs;
1027
1028 // Copy data elements
1029 auto &strong_residual = copy_data.strong_residual;
1030 auto &local_rhs = copy_data.local_rhs;
1031
1032 // assembling right hand side
1033 for (unsigned int q = 0; q < n_q_points; ++q)
1034 {
1035 // Store JxW in local variable for faster access
1036 const double JxW = scratch_data.fe_values_T.JxW(q);
1037
1038 const double filtered_phase_gradient_value_q_norm =
1039 scratch_data.filtered_phase_gradient_values[q].norm();
1040
1042 laser_location,
1043 laser_parameters->beam_axis,
1044 scratch_data.quadrature_points[q]);
1045
1046 // Calculate the strong residual for GLS stabilization
1047 const double incidence_angle_factor =
1048 (laser_parameters->enable_angle_of_incidence_dependence) ?
1049 scratch_data.phase_gradient_values[q] *
1050 laser_parameters->beam_axis /
1051 (scratch_data.phase_gradient_values[q].norm() *
1052 laser_parameters->beam_axis.norm() +
1053 1e-16) :
1054 1.0;
1055
1056 double laser_heat_source =
1057 incidence_angle_factor * absorptivity * laser_power *
1058 exp(-1.0 * concentration_factor * std::pow(r, 2.0) /
1059 (beam_radius * beam_radius));
1060
1061 if constexpr (dim == 2)
1062 {
1063 laser_heat_source *=
1064 2 * sqrt(concentration_factor) /
1065 (sqrt(std::pow(M_PI, 3)) * beam_radius * beam_radius);
1066 }
1067 if constexpr (dim == 3)
1068 {
1069 laser_heat_source *=
1070 concentration_factor / (M_PI * beam_radius * beam_radius);
1071 }
1072
1073 strong_residual[q] -=
1074 filtered_phase_gradient_value_q_norm * laser_heat_source;
1075
1076 for (unsigned int i = 0; i < n_dofs; ++i)
1077 {
1078 const auto phi_T_i = scratch_data.phi_T[q][i];
1079
1080 // rhs for: eta * alpha * P / (pi * R^2) * exp(-eta * r^2 /
1081 // R^2) * \grad_phi_norm where eta, alpha, P, R, and r denote the
1082 // concentration factor, absorptivity, laser power, beam radius,
1083 // radial distance from the laser focal point, and filtered phase
1084 // fraction gradient L2 norm, respectively.
1085 local_rhs(i) += filtered_phase_gradient_value_q_norm *
1086 laser_heat_source * phi_T_i * JxW;
1087 }
1088 } // end loop on quadrature points
1089 }
1090}
1091
1094
1095template <int dim>
1096void
1101
1102template <int dim>
1103void
1105 const HeatTransferScratchData<dim> &scratch_data,
1106 StabilizedMethodsCopyData &copy_data)
1107{
1108 // Laser parameters
1109 const double concentration_factor = laser_parameters->concentration_factor;
1110 const double laser_power = laser_parameters->laser_power;
1111 const double absorptivity = laser_parameters->laser_absorptivity;
1112 const double penetration_depth = laser_parameters->penetration_depth;
1113 const double laser_start_time = laser_parameters->start_time;
1114 const double laser_end_time = laser_parameters->end_time;
1115 const double beam_radius = laser_parameters->beam_radius;
1116 const bool beam_direction = laser_parameters->beam_direction;
1117 const double current_time = this->simulation_control->get_current_time();
1118
1119 if (current_time >= laser_start_time && current_time <= laser_end_time)
1120 {
1121 // Get laser path
1122 Function<dim> &laser_scan_path = *(laser_parameters->laser_scan_path);
1123 laser_scan_path.set_time(current_time);
1124
1125 // For the laser heat source calculations, we need the radial distance, r,
1126 // (in a dim-1 dimensional plane perpendicular to the laser beam
1127 // direction) between the laser focal point and the quadrature points, as
1128 // well as the axial distance, z, (in a laser emission direction) between
1129 // the laser focal point and the quadrature points, separately. Hence, we
1130 // get the laser location (laser_location) as a Point<dim>, in which the
1131 // first and second components show the position of the laser focal point
1132 // in a plane perpendicular to the emission direction, and the (dim-1)th
1133 // component denotes the position of the laser focal point in the
1134 // direction of emission. Then we use dim-1 auxiliary variables
1135 // (Point<dim-1> laser_location_on_surface) to store the position of the
1136 // laser focal point in the perpendicular plane to the emission direction,
1137 // and double laser_location_in_depth to store the position of the laser
1138 // focal point in the direction of emission.
1139
1140 // Get laser location
1141 Point<dim> laser_location;
1142 laser_location[0] = laser_scan_path.value(
1143 laser_location, laser_parameters->perpendicular_plane_coordinate_one);
1144 if constexpr (dim == 3)
1145 {
1146 laser_location[1] = laser_scan_path.value(
1147 laser_location,
1148 laser_parameters->perpendicular_plane_coordinate_two);
1149 }
1150
1151 // Get laser location in depth (direction of emission).
1152 double laser_location_in_depth = 0.0;
1153 laser_location[dim - 1] =
1154 laser_scan_path.value(laser_location,
1155 laser_parameters->beam_orientation_coordinate);
1156 laser_location_in_depth = laser_location[dim - 1];
1157
1158 // Get laser location on the operation surface
1159 Point<dim - 1> laser_location_on_surface;
1160 for (int d = 0; d < dim - 1; d++)
1161 laser_location_on_surface[d] = laser_location[d];
1162
1163 const unsigned int n_q_points = scratch_data.n_q_points;
1164 const unsigned int n_dofs = scratch_data.n_dofs;
1165
1166 // Copy data elements
1167 auto &strong_residual = copy_data.strong_residual;
1168 auto &local_rhs = copy_data.local_rhs;
1169
1170 // assembling right hand side
1171 for (unsigned int q = 0; q < n_q_points; ++q)
1172 {
1173 // Get quadrature point location on surface to calculate its distance
1174 // from the laser focal point in a perpendicular plane to the
1175 // direction of emission
1176 Point<dim - 1> quadrature_point_on_surface;
1177 quadrature_point_on_surface[0] =
1178 scratch_data.quadrature_points
1179 [q][laser_parameters->perpendicular_plane_coordinate_one];
1180 if constexpr (dim == 3)
1181 {
1182 quadrature_point_on_surface[1] =
1183 scratch_data.quadrature_points
1184 [q][laser_parameters->perpendicular_plane_coordinate_two];
1185 }
1186
1187 // Get quadrature point depth to calculate its distance from the laser
1188 // focal point in the direction of emission. Note that in
1189 // two-dimensional simulations, this variable is always equal to zero
1190 const double quadrature_point_depth =
1191 scratch_data.quadrature_points[q][laser_parameters
1192 ->beam_orientation_coordinate];
1193
1194 // if the laser beam is in negative direction and
1195 // quadrature_point_depth is smaller than the laser_location_in_depth,
1196 // or the laser beam is in positive direction and
1197 // quadrature_point_depth is larger than laser_location_in_depth we
1198 // need to apply the laser on the quadrature point, otherwise it is
1199 // zero
1200 double laser_quadrature_point_distance_in_depth = 0.0;
1201 if ((beam_direction == 0 &&
1202 quadrature_point_depth <= laser_location_in_depth) |
1203 (beam_direction == 1 &&
1204 quadrature_point_depth >= laser_location_in_depth))
1205 laser_quadrature_point_distance_in_depth =
1206 std::abs(quadrature_point_depth - laser_location_in_depth);
1207
1208 // Store JxW in local variable for faster access
1209 const double JxW = scratch_data.fe_values_T.JxW(q);
1210
1211 const double filtered_phase_value_q =
1212 scratch_data.filtered_phase_values[q];
1213
1214 // Calculate the strong residual for GLS stabilization
1215 const double laser_heat_source =
1216 (concentration_factor * absorptivity * laser_power /
1217 (M_PI * beam_radius * beam_radius * penetration_depth)) *
1218 exp(-1.0 * concentration_factor *
1219 std::pow(laser_location_on_surface.distance(
1220 quadrature_point_on_surface),
1221 2.0) /
1222 (beam_radius * beam_radius)) *
1223 exp(-1.0 * laser_quadrature_point_distance_in_depth /
1224 penetration_depth);
1225 strong_residual[q] -= filtered_phase_value_q * laser_heat_source;
1226
1227 for (unsigned int i = 0; i < n_dofs; ++i)
1228 {
1229 const auto phi_T_i = scratch_data.phi_T[q][i];
1230
1231 // rhs for : phase * eta * alpha * P / (pi * R^2 * mu) *
1232 // exp(-eta * r^2 / R^2) * exp(-|z| / mu) where phase, eta, alpha,
1233 // P, R, mu, r and z denote the phase (from the CLS) concentration
1234 // factor, absorptivity, laser power, beam radius, penetration
1235 // depth, radial distance from the laser focal point, and axial
1236 // distance from the laser focal point, respectively. The phase
1237 // is used here so that the laser source is only applied in the
1238 // metal (when phase is non-null).
1239
1240 local_rhs(i) +=
1241 filtered_phase_value_q * laser_heat_source * phi_T_i * JxW;
1242 }
1243 } // end loop on quadrature points
1244 }
1245}
1246
1249
1250template <int dim>
1251void
1256
1257template <int dim>
1258void
1260 const HeatTransferScratchData<dim> &scratch_data,
1261 StabilizedMethodsCopyData &copy_data)
1262{
1263 // Laser parameters
1264 const double laser_power = laser_parameters->laser_power;
1265 const double absorptivity = laser_parameters->laser_absorptivity;
1266 const double laser_start_time = laser_parameters->start_time;
1267 const double laser_end_time = laser_parameters->end_time;
1268 const double beam_radius = laser_parameters->beam_radius;
1269 const double current_time = this->simulation_control->get_current_time();
1270
1271 if (current_time >= laser_start_time && current_time <= laser_end_time)
1272 {
1273 // Get laser path
1274 Function<dim> &laser_scan_path = *(laser_parameters->laser_scan_path);
1275 laser_scan_path.set_time(current_time);
1276
1277 // For the laser heat source calculations, we need the radial distance, r,
1278 // (in a dim-1 dimensional plane perpendicular to the laser beam
1279 // direction) between the laser focal point and the quadrature points.
1280 // Here, the focal point is any given point on the laser's axis.
1281 // Hence, we get the laser location (laser_location) as a Point<dim>, in
1282 // which the first and second components show the position of the laser
1283 // focal point in a plane perpendicular to the emission direction.
1284 // Then we use dim-1 auxiliary variables (Point<dim-1>
1285 // laser_location_on_surface) to store the position of the laser focal
1286 // point in the perpendicular plane to the emission direction.
1287
1288 // Get laser location
1289 Point<dim> laser_location;
1290 laser_location[0] = laser_scan_path.value(
1291 laser_location, laser_parameters->perpendicular_plane_coordinate_one);
1292 if constexpr (dim == 3)
1293 {
1294 laser_location[1] = laser_scan_path.value(
1295 laser_location,
1296 laser_parameters->perpendicular_plane_coordinate_two);
1297 }
1298
1299 // Get laser location on the operation surface
1300 Point<dim - 1> laser_location_on_surface;
1301 for (int d = 0; d < dim - 1; d++)
1302 laser_location_on_surface[d] = laser_location[d];
1303
1304 const unsigned int n_q_points = scratch_data.n_q_points;
1305 const unsigned int n_dofs = scratch_data.n_dofs;
1306
1307 // Copy data elements
1308 auto &strong_residual = copy_data.strong_residual;
1309 auto &local_rhs = copy_data.local_rhs;
1310
1311 // assembling right-hand side
1312 for (unsigned int q = 0; q < n_q_points; ++q)
1313 {
1314 // Get quadrature point location on surface to calculate its distance
1315 // from the laser focal point in a perpendicular plane to the
1316 // direction of emission
1317 Point<dim - 1> quadrature_point_on_surface;
1318 quadrature_point_on_surface[0] =
1319 scratch_data.quadrature_points
1320 [q][laser_parameters->perpendicular_plane_coordinate_one];
1321 if constexpr (dim == 3)
1322 {
1323 quadrature_point_on_surface[1] =
1324 scratch_data.quadrature_points
1325 [q][laser_parameters->perpendicular_plane_coordinate_two];
1326 }
1327
1328 // Store JxW in local variable for faster access
1329 const double JxW = scratch_data.fe_values_T.JxW(q);
1330
1331 const double filtered_phase_gradient_value_q_norm =
1332 scratch_data.filtered_phase_gradient_values[q].norm();
1333
1334 // Calculate the strong residual for GLS stabilization
1335
1336 double laser_heat_source = 0.0;
1337
1338 const double incidence_angle_factor =
1339 (laser_parameters->enable_angle_of_incidence_dependence) ?
1340 scratch_data.phase_gradient_values[q] *
1341 laser_parameters->beam_axis /
1342 (scratch_data.phase_gradient_values[q].norm() *
1343 laser_parameters->beam_axis.norm() +
1344 1e-16) :
1345 1.0;
1346
1347 if (laser_location_on_surface.distance(quadrature_point_on_surface) <
1348 beam_radius)
1349 {
1350 laser_heat_source = incidence_angle_factor * absorptivity *
1351 laser_power /
1352 (M_PI * beam_radius * beam_radius);
1353 }
1354 strong_residual[q] -=
1355 filtered_phase_gradient_value_q_norm * laser_heat_source;
1356
1357 for (unsigned int i = 0; i < n_dofs; ++i)
1358 {
1359 const auto phi_T_i = scratch_data.phi_T[q][i];
1360
1361 local_rhs(i) += filtered_phase_gradient_value_q_norm *
1362 laser_heat_source * phi_T_i * JxW;
1363 }
1364 } // end loop on quadrature points
1365 }
1366}
1367
1370
1371template <int dim>
1372void
1374 const HeatTransferScratchData<dim> &scratch_data,
1375 StabilizedMethodsCopyData &copy_data)
1376{
1377 // Loop and quadrature information
1378 const unsigned int n_q_points = scratch_data.n_q_points;
1379 const unsigned int n_dofs = scratch_data.n_dofs;
1380
1381 // Copy data elements
1382 auto &local_matrix = copy_data.local_matrix;
1383
1384 const double Stefan_Boltzmann_constant =
1385 laser_parameters->radiation.Stefan_Boltzmann_constant;
1386
1387 const double emissivity = laser_parameters->radiation.emissivity;
1388
1389 // assembling local matrix and right hand side
1390 for (unsigned int q = 0; q < n_q_points; ++q)
1391 {
1392 const double temperature = scratch_data.present_temperature_values[q];
1393
1394 const Tensor<1, dim> filtered_phase_gradient_q =
1395 scratch_data.filtered_phase_gradient_values[q];
1396 // Store JxW in local variable for faster access
1397 const double JxW = scratch_data.fe_values_T.JxW(q);
1398
1399 for (unsigned int i = 0; i < n_dofs; ++i)
1400 {
1401 const auto phi_T_i = scratch_data.phi_T[q][i];
1402
1403 for (unsigned int j = 0; j < n_dofs; ++j)
1404 {
1405 const auto phi_T_j = scratch_data.phi_T[q][j];
1406
1407 // Matrix coefficients for the linearised radiation sink term at
1408 // the free surface (air/metal interface): |grad phi'| * 4 *
1409 // sigma * epsilon * T^3, where |grad phi'| is the filtered
1410 // phase gradient norm (which indicates an interface between the
1411 // metal and air if non-null), sigma is the Stefan Boltzmann
1412 // constant, epsilon is the emissivity of the free surface and T
1413 // is the current temperature.
1414 local_matrix(i, j) +=
1415 filtered_phase_gradient_q.norm() *
1416 (4.0 * Stefan_Boltzmann_constant * emissivity * temperature *
1418 phi_T_i * phi_T_j * JxW;
1419 }
1420 }
1421 } // end loop on quadrature points
1422}
1423
1424template <int dim>
1425void
1427 const HeatTransferScratchData<dim> &scratch_data,
1428 StabilizedMethodsCopyData &copy_data)
1429{
1430 // Loop and quadrature information
1431 const unsigned int n_q_points = scratch_data.n_q_points;
1432 const unsigned int n_dofs = scratch_data.n_dofs;
1433
1434 // Copy data elements
1435 auto &local_rhs = copy_data.local_rhs;
1436
1437 const double Stefan_Boltzmann_constant =
1438 laser_parameters->radiation.Stefan_Boltzmann_constant;
1439
1440 const double emissivity = laser_parameters->radiation.emissivity;
1441 const double T_inf = laser_parameters->radiation.Tinf;
1442
1443 // assembling local matrix and right hand side
1444 for (unsigned int q = 0; q < n_q_points; ++q)
1445 {
1446 const double temperature = scratch_data.present_temperature_values[q];
1447
1448 const Tensor<1, dim> filtered_phase_gradient_q =
1449 scratch_data.filtered_phase_gradient_values[q];
1450 // Store JxW in local variable for faster access
1451 const double JxW = scratch_data.fe_values_T.JxW(q);
1452
1453 for (unsigned int i = 0; i < n_dofs; ++i)
1454 {
1455 const auto phi_T_i = scratch_data.phi_T[q][i];
1456
1457 // Rhs for the linearised radiation sink term at the melt pool free
1458 // surface: |grad alpha|* sigma * epsilon * (T^3 - T_inf^3),
1459 // where |grad alpha| is the phase gradient norm (which indicates an
1460 // interface between the metal and air if non-null), sigma is the
1461 // Stefan Boltzmann constant, epsilon is the emissivity of the free
1462 // surface, T is the current temperature and T_inf is the reference
1463 // (environment) temperature.
1464 local_rhs(i) -=
1465 filtered_phase_gradient_q.norm() * Stefan_Boltzmann_constant *
1466 emissivity *
1468 T_inf * T_inf * T_inf * T_inf) *
1469 phi_T_i * JxW;
1470 }
1471
1472 } // end loop on quadrature points
1473}
1474
1477
1478template <int dim>
1479void
1481 const HeatTransferScratchData<dim> &scratch_data,
1482 StabilizedMethodsCopyData &copy_data)
1483{
1484 // Loop and quadrature informations
1485 const unsigned int n_q_points = scratch_data.n_q_points;
1486 const unsigned int n_dofs = scratch_data.n_dofs;
1487
1488 // Copy data elements
1489 auto &local_matrix = copy_data.local_matrix;
1490
1491 // assembling local matrix and right hand side
1492 for (unsigned int q = 0; q < n_q_points; ++q)
1493 {
1494 const double temperature = scratch_data.present_temperature_values[q];
1495
1496 std::map<field, double> field_value;
1497 field_value[field::temperature] = temperature;
1498
1499 const double evaporative_heat_flux_jacobian =
1500 this->evaporation_model->heat_flux_jacobian(field_value,
1502
1503 const Tensor<1, dim> filtered_phase_gradient_q =
1504 scratch_data.filtered_phase_gradient_values[q];
1505
1506 // Store JxW in local variable for faster access
1507 const double JxW = scratch_data.fe_values_T.JxW(q);
1508
1509 for (unsigned int i = 0; i < n_dofs; ++i)
1510 {
1511 const auto phi_T_i = scratch_data.phi_T[q][i];
1512
1513 for (unsigned int j = 0; j < n_dofs; ++j)
1514 {
1515 const auto phi_T_j = scratch_data.phi_T[q][j];
1516
1517 local_matrix(i, j) += filtered_phase_gradient_q.norm() *
1518 evaporative_heat_flux_jacobian * phi_T_i *
1519 phi_T_j * JxW;
1520 }
1521 }
1522 } // end loop on quadrature points
1523}
1524
1525template <int dim>
1526void
1528 const HeatTransferScratchData<dim> &scratch_data,
1529 StabilizedMethodsCopyData &copy_data)
1530{
1531 // Loop and quadrature informations
1532 const unsigned int n_q_points = scratch_data.n_q_points;
1533 const unsigned int n_dofs = scratch_data.n_dofs;
1534
1535 // Copy data elements
1536 auto &local_rhs = copy_data.local_rhs;
1537
1538 // assembling local matrix and right hand side
1539 for (unsigned int q = 0; q < n_q_points; ++q)
1540 {
1541 const double temperature = scratch_data.present_temperature_values[q];
1542
1543 std::map<field, double> field_value;
1544 field_value[field::temperature] = temperature;
1545
1546 const double evaporative_heat_flux =
1547 this->evaporation_model->heat_flux(field_value);
1548
1549 const Tensor<1, dim> filtered_phase_gradient_q =
1550 scratch_data.filtered_phase_gradient_values[q];
1551 // Store JxW in local variable for faster access
1552 const double JxW = scratch_data.fe_values_T.JxW(q);
1553
1554 for (unsigned int i = 0; i < n_dofs; ++i)
1555 {
1556 const auto phi_T_i = scratch_data.phi_T[q][i];
1557
1558 local_rhs(i) -= filtered_phase_gradient_q.norm() *
1559 evaporative_heat_flux * phi_T_i * JxW;
1560 }
1561 } // end loop on quadrature points
1562}
1563
1566
1567template <int dim>
1568void
1574
1575template <int dim>
1576void
1578 const HeatTransferScratchData<dim> &scratch_data,
1579 StabilizedMethodsCopyData &copy_data)
1580{
1581 // Loop and quadrature informations
1582 const unsigned int n_q_points = scratch_data.n_q_points;
1583 const unsigned int n_dofs = scratch_data.n_dofs;
1584
1585 // Copy data elements
1586 auto &local_rhs = copy_data.local_rhs;
1587
1588 // Right hand side
1589 for (unsigned int q = 0; q < n_q_points; ++q)
1590 {
1591 const double electric_conductivity =
1592 scratch_data.electric_conductivity[q];
1593 const double electric_permittivity_imag =
1594 scratch_data.electric_permittivity_imag[q];
1595 const double magnetic_permeability_imag =
1596 scratch_data.magnetic_permeability_imag[q];
1597
1598 // |E|^2 = |E_real|^2 + |E_imag|^2
1599 const double electric_field_squared_amplitude =
1600 scratch_data.electric_field_real_values[q].norm_square() +
1601 scratch_data.electric_field_imag_values[q].norm_square();
1602
1603 // |H|^2 = |H_real|^2 + |H_imag|^2
1604 const double magnetic_field_squared_amplitude =
1605 scratch_data.magnetic_field_real_values[q].norm_square() +
1606 scratch_data.magnetic_field_imag_values[q].norm_square();
1607
1608 // Joule heating: 0.5 * sigma * |E|^2, the factor omega*epsilon_0 is
1609 // included to recover the electric conductivity in its dimensional form,
1610 // i.e., sigma = omega * epsilon_0 * sigma_r.
1611 const double joule_heating = 0.5 * angular_frequency *
1612 vacuum_permittivity * electric_conductivity *
1613 electric_field_squared_amplitude;
1614
1615 // Dielectric loss heating: 0.5 * omega * epsilon_0 * epsilon_r'' * |E|^2
1616 const double dielectric_loss_heating =
1618 electric_permittivity_imag * electric_field_squared_amplitude;
1619
1620 // Magnetic loss heating: 0.5 * omega * mu_0 * mu_r'' * |H|^2
1621 const double magnetic_loss_heating =
1623 magnetic_permeability_imag * magnetic_field_squared_amplitude;
1624
1625 const double JxW = scratch_data.JxW[q];
1626
1627 for (unsigned int i = 0; i < n_dofs; ++i)
1628 {
1629 local_rhs(i) +=
1630 (joule_heating + dielectric_loss_heating + magnetic_loss_heating) *
1631 scratch_data.phi_T[q][i] * JxW;
1632 }
1633 } // end loop on quadrature points
1634}
1635
unsigned int number_of_previous_solutions(const Parameters::SimulationControl::TimeSteppingMethod method)
Get the number of previous time steps for a specific BDF scheme.
Definition bdf.h:97
Class that assembles the transient time arising from BDF time integration for the heat transfer solve...
const std::shared_ptr< SimulationControl > simulation_control
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_matrix Assembles the matrix
Class that assembles the evaporation sink for the heat transfer solver at the free surface (air/metal...
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_matrix Assembles the matrix
std::shared_ptr< EvaporationModel > evaporation_model
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
Class that assembles the core of the heat transfer equation. This class assembles the weak form of: ...
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_matrix Assembles the matrix
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
const std::shared_ptr< SimulationControl > simulation_control
Class that assembles the Discontinuity-Capturing Directional Dissipation stabilization term for the h...
const std::shared_ptr< SimulationControl > simulation_control
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
Assemble the matrix.
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
Class that assembles the radiation sink for the heat transfer solver at the free surface (air/metal i...
std::shared_ptr< Parameters::Laser< dim > > laser_parameters
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_matrix Assembles the matrix
Class that assembles the laser heating as a volumetric source for the heat transfer solver when CLS i...
std::shared_ptr< Parameters::Laser< dim > > laser_parameters
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
const std::shared_ptr< SimulationControl > simulation_control
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_matrix Assembles the matrix
Class that assembles the laser heating as a volumetric source for the heat transfer solver....
std::shared_ptr< Parameters::Laser< dim > > laser_parameters
const std::shared_ptr< SimulationControl > simulation_control
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_matrix Assembles the matrix
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
Class that assembles the laser heating as a surface flux for the heat transfer solver when CLS is ena...
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
const std::shared_ptr< SimulationControl > simulation_control
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_matrix Assembles the matrix
std::shared_ptr< Parameters::Laser< dim > > laser_parameters
Class that assembles the laser heating as a uniform surface flux for the heat transfer solver when CL...
const std::shared_ptr< SimulationControl > simulation_control
std::shared_ptr< Parameters::Laser< dim > > laser_parameters
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_matrix Assembles the matrix
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
Class that assembles the time average electromagnetic heating for the heat transfer solver when the t...
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_matrix Assembles the matrix
Class that assembles the Robin boundary condition for the heat transfer solver.
const BoundaryConditions::HeatTransferBoundaryConditions< dim > & boundary_conditions_ht
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_matrix Assembles the matrix
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
Class that assembles the viscous dissipation for the heat transfer solver, for the specific case of C...
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
Assemble the matrix.
const std::shared_ptr< SimulationControl > simulation_control
Class that assembles the viscous dissipation for the heat transfer solver.
virtual void assemble_rhs(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
assemble_rhs Assembles the rhs
virtual void assemble_matrix(const HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data) override
Assemble the matrix.
const std::shared_ptr< SimulationControl > simulation_control
Class that stores the information required by the assembly procedure for a heat transfer advection-di...
std::vector< double > filtered_phase_values
std::vector< Tensor< 1, dim > > electric_field_real_values
std::vector< Tensor< 1, dim > > temperature_gradients
std::vector< Tensor< 2, dim > > velocity_gradient_values
std::vector< unsigned int > boundary_face_id
std::vector< double > grad_specific_heat_temperature
std::vector< Tensor< 1, dim > > magnetic_field_real_values
std::vector< double > electric_conductivity
std::vector< double > present_temperature_values
std::vector< std::vector< double > > temperature_face_value
std::vector< double > dynamic_viscosity
std::vector< Tensor< 1, dim > > filtered_phase_gradient_values
std::vector< Tensor< 1, dim > > electric_field_imag_values
std::vector< double > present_temperature_laplacians
std::vector< Tensor< 1, dim > > phase_gradient_values
std::vector< double > electric_permittivity_imag
Table< 2, Tensor< 1, dim > > grad_phi_T
std::vector< double > thermal_conductivity
std::vector< Tensor< 1, dim > > velocity_values
std::vector< Tensor< 1, dim > > magnetic_field_imag_values
std::vector< std::vector< Tensor< 1, dim > > > previous_temperature_gradients
std::vector< double > magnetic_permeability_imag
std::vector< Point< dim > > quadrature_points
std::vector< std::vector< double > > previous_temperature_values
Class responsible for storing the information calculated using the assembly of stabilized scalar equa...
Definition copy_data.h:67
Vector< double > local_rhs
Definition copy_data.h:105
Vector< double > strong_residual
Definition copy_data.h:107
FullMatrix< double > local_matrix
Definition copy_data.h:104
std::vector< Vector< double > > strong_jacobian
Definition copy_data.h:108
DeclException1(EmissivityError, double,<< "Emissivity : "<< arg1<< " cannot be larger than 1.0 (black body) or smaller than 0.0")
@ velocity
Velocity vector field from fluid dynamics.
@ temperature
Temperature scalar field from heat transfer.
double find_point_line_distance(const Point< dim > &line_origin, const Tensor< 1, dim > &line_direction, const Point< dim > &point)
Calculate the minimum distance between a point and a line (defined using its orign and direction)....
bool is_steady(const Parameters::SimulationControl::TimeSteppingMethod method)
Determines if the time integration method is a steady-state method.