Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
heat_transfer.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
5#include <core/bdf.h>
7
9
10#include <deal.II/base/exceptions.h>
11#include <deal.II/base/work_stream.h>
12
13#include <deal.II/dofs/dof_renumbering.h>
14#include <deal.II/dofs/dof_tools.h>
15
16#include <deal.II/lac/affine_constraints.h>
17#include <deal.II/lac/dynamic_sparsity_pattern.h>
18#include <deal.II/lac/solver_control.h>
19#include <deal.II/lac/sparsity_tools.h>
20#include <deal.II/lac/trilinos_precondition.h>
21#include <deal.II/lac/trilinos_solver.h>
22
23#include <deal.II/numerics/error_estimator.h>
24#include <deal.II/numerics/vector_tools.h>
25
27 MeltVolumeRequiresPhaseChange,
28 "Calculation of the melt volume requires that a fluid has at least a 'phase_change' physical property model");
29
30template <int dim>
31void
40
41
42template <int dim>
43void
50
51template <int dim>
52void
54{
55 Assert(
56 !this->simulation_parameters.physical_properties_manager.is_non_newtonian(),
57 RequiresConstantViscosity("assemble_nitsche_heat_restriction"));
58
59 auto &solids = this->multiphysics->get_solids(
60 this->simulation_parameters.nitsche->number_solids);
61
62 // Loops over solids
63 for (unsigned int i_solid = 0; i_solid < solids.size(); ++i_solid)
64 {
65 // Initialize the solid and its particles
66 std::shared_ptr<Particles::ParticleHandler<dim>> &solid_ph =
67 solids[i_solid]->get_solid_particle_handler();
68
69 if (this->simulation_parameters.nitsche->nitsche_solids[i_solid]
70 ->enable_heat_bc)
71 {
72 const unsigned int dofs_per_cell = this->fe->dofs_per_cell;
73
74 std::vector<types::global_dof_index> heat_dof_indices(dofs_per_cell);
75 FullMatrix<double> local_matrix(dofs_per_cell, dofs_per_cell);
76 dealii::Vector<double> local_rhs(dofs_per_cell);
77
78 Function<dim> *solid_temperature =
79 solids[i_solid]->get_solid_temperature();
80
81 // Penalization terms
82 const double beta =
83 this->simulation_parameters.nitsche->nitsche_solids[i_solid]
84 ->beta_heat;
85
86 // Loop over all local particles
87 auto particle = solid_ph->begin();
88 while (particle != solid_ph->end())
89 {
90 local_matrix = 0;
91 local_rhs = 0;
92
93 const auto &cell = particle->get_surrounding_cell();
94
95 // double h_cell = 0;
96 // if (dim == 2)
97 // h_cell =
98 // std::sqrt(4. * cell->measure() / M_PI) /
99 // this->simulation_parameters.fem_parameters.velocity_degree;
100 // else if (dim == 3)
101 // h_cell =
102 // pow(6 * cell->measure() / M_PI, 1. / 3.) /
103 // this->simulation_parameters.fem_parameters.velocity_degree;
104 // Penalty parameter is disabled for heat transfer from since we
105 // don't necessarily want to strictly impose a Dirichlet BC
106 const double penalty_parameter =
107 1.; /// std::pow(h_cell * h_cell, double(dim) / double(dim));
108 const auto &dh_cell =
109 typename DoFHandler<dim>::cell_iterator(*cell,
110 &(*this->dof_handler));
111 dh_cell->get_dof_indices(heat_dof_indices);
112
113 const auto pic = solid_ph->particles_in_cell(cell);
114 Assert(pic.begin() == particle, ExcInternalError());
115 for (const auto &p : pic)
116 {
117 const ArrayView<const double> properties = p.get_properties();
118
119 double fluid_temperature = 0;
120 const auto &ref_q = p.get_reference_location();
121 const auto &real_q = p.get_location();
122 const auto &JxW = properties[0];
123
124 for (unsigned int k = 0; k < dofs_per_cell; ++k)
125 {
126 // Get the fluid temperature at non-quadrature point
127 // (particle in fluid)
129 fluid_temperature +=
130 evaluation_point[heat_dof_indices[k]] *
131 this->fe->shape_value(k, ref_q);
132 }
133 // Assemble the matrix or the rhs
134 for (unsigned int i = 0; i < dofs_per_cell; ++i)
135 {
136 if (assemble_matrix)
137 {
138 for (unsigned int j = 0; j < dofs_per_cell; ++j)
139 {
140 local_matrix(i, j) +=
141 penalty_parameter * beta *
142 this->fe->shape_value(i, ref_q) *
143 this->fe->shape_value(j, ref_q) * JxW;
144 }
145 }
146 else
147 {
148 // Regular residual
149 local_rhs(i) += penalty_parameter * beta *
150 (solid_temperature->value(real_q, 0) -
151 fluid_temperature) *
152 this->fe->shape_value(i, ref_q) * JxW;
153 }
154 }
155 }
156 const AffineConstraints<double> &constraints_used =
157 this->zero_constraints;
158 auto &system_rhs = this->system_rhs;
159 constraints_used.distribute_local_to_global(local_matrix,
160 local_rhs,
161 heat_dof_indices,
162 this->system_matrix,
163 system_rhs);
164 particle = pic.end();
165 }
166 this->system_matrix.compress(VectorOperation::add);
167 this->system_rhs.compress(VectorOperation::add);
168 }
169 }
170}
171
172template <int dim>
173void
175{
176 auto &solids = this->multiphysics->get_solids(
177 this->simulation_parameters.nitsche->number_solids);
178 std::vector<double> heat_flux_on_nitsche_ib_vector(solids.size(), 0);
179
180 // Loops over solids
181 for (unsigned int i_solid = 0; i_solid < solids.size(); ++i_solid)
182 {
183 // Initialize the solid and its particles
184 std::shared_ptr<Particles::ParticleHandler<dim>> &solid_ph =
185 solids[i_solid]->get_solid_particle_handler();
186 double heat_flux_on_nitsche_bc = 0;
187
188 if (this->simulation_parameters.nitsche->nitsche_solids[i_solid]
189 ->enable_heat_bc)
190 {
191 const unsigned int dofs_per_cell = this->fe->dofs_per_cell;
192
193 std::vector<types::global_dof_index> heat_dof_indices(dofs_per_cell);
194 FullMatrix<double> local_matrix(dofs_per_cell, dofs_per_cell);
195 dealii::Vector<double> local_rhs(dofs_per_cell);
196
197 Function<dim> *solid_temperature =
198 solids[i_solid]->get_solid_temperature();
199
200 // Penalization terms
201 const double beta =
202 this->simulation_parameters.nitsche->nitsche_solids[i_solid]
203 ->beta_heat;
204
205 // Loop over all local particles
206 auto particle = solid_ph->begin();
207 while (particle != solid_ph->end())
208 {
209 local_matrix = 0;
210 local_rhs = 0;
211
212 const auto &cell = particle->get_surrounding_cell();
213
214 const auto &dh_cell =
215 typename DoFHandler<dim>::cell_iterator(*cell,
216 &(*this->dof_handler));
217 dh_cell->get_dof_indices(heat_dof_indices);
218
219 const auto pic = solid_ph->particles_in_cell(cell);
220 Assert(pic.begin() == particle, ExcInternalError());
221 for (const auto &p : pic)
222 {
223 const ArrayView<const double> properties = p.get_properties();
224
225 double fluid_temperature = 0;
226 const auto &ref_q = p.get_reference_location();
227 const auto &real_q = p.get_location();
228 const auto &JxW = properties[0];
229
230 for (unsigned int k = 0; k < dofs_per_cell; ++k)
231 {
232 // Get the fluid temperature at non-quadrature point
233 // (particle in fluid)
234 fluid_temperature +=
235 (*this->present_solution)[heat_dof_indices[k]] *
236 this->fe->shape_value(k, ref_q);
237 }
238 // Calculate heat flux on the Nitsche IB
239 heat_flux_on_nitsche_bc +=
240 beta *
241 (solid_temperature->value(real_q, 0) - fluid_temperature) *
242 JxW;
243 }
244 particle = pic.end();
245 }
246 }
247 heat_flux_on_nitsche_ib_vector[i_solid] =
248 Utilities::MPI::sum(heat_flux_on_nitsche_bc,
249 triangulation->get_mpi_communicator());
250 }
251
252 // Console output
253 if (simulation_parameters.post_processing.verbosity ==
255 {
256 this->pcout << "Heat flux at the nitsche immersed boundary : "
257 << std::endl;
258 for (unsigned int i_solid = 0; i_solid < solids.size(); ++i_solid)
259 {
260 this->pcout << "\t Nitsche boundary " << i_solid << " : "
261 << heat_flux_on_nitsche_ib_vector[i_solid] << std::endl;
262 }
263 }
264
265 // Filling table
266 for (unsigned int i_solid = 0; i_solid < solids.size(); ++i_solid)
267 {
268 this->heat_flux_table.add_value("flux_nitsche_solid_" +
269 Utilities::int_to_string(i_solid, 1),
270 heat_flux_on_nitsche_ib_vector[i_solid]);
271 }
272}
273
274template <int dim>
275void
277{
278 AssertThrow(time_stepping_is_sdirk(
279 this->simulation_control->get_assembly_method()) == false,
280 ExcMessage(
281 "The SDIRK scheme is not yet supported for this physics"));
282
283 this->assemblers.clear();
284
285 // Laser heat source
286 if (this->simulation_parameters.laser_parameters->activate_laser)
287 {
288 if (this->simulation_parameters.multiphysics.CLS)
289 {
290 // Call for the specific assembler of the laser source term
291 // Laser source is applied at the interface (surface flux)
292 if (this->simulation_parameters.laser_parameters->laser_type ==
294 dim>::LaserType::gaussian_heat_flux_cls_interface)
295 {
296 this->assemblers.emplace_back(
297 std::make_shared<
299 this->simulation_control,
300 this->simulation_parameters.laser_parameters));
301 }
302 else if (this->simulation_parameters.laser_parameters->laser_type ==
304 dim>::LaserType::uniform_heat_flux_cls_interface)
305 {
306 this->assemblers.emplace_back(
307 std::make_shared<
309 this->simulation_control,
310 this->simulation_parameters.laser_parameters));
311 }
312 else // Laser is applied in fluid 1 as a volumetric source
313 {
314 this->assemblers.emplace_back(
315 std::make_shared<
317 this->simulation_control,
318 this->simulation_parameters.laser_parameters));
319 }
320
321 // Assembler of the radiation sink term applied only at the air/metal
322 // interface. The radiation term in that case is treated as a source
323 // term instead of a boundary term.
324 if (this->simulation_parameters.laser_parameters->radiation
325 .enable_radiation)
326 {
327 this->assemblers.emplace_back(
328 std::make_shared<
330 this->simulation_control,
331 this->simulation_parameters.laser_parameters));
332 }
333 }
334 else
335 {
336 this->assemblers.emplace_back(
338 this->simulation_control,
339 this->simulation_parameters.laser_parameters));
340 }
341 }
342
343 // Evaporation cooling
344 if (this->simulation_parameters.multiphysics.CLS)
345 {
346 if (this->simulation_parameters.evaporation.enable_evaporation_cooling)
347 {
348 this->assemblers.emplace_back(
350 this->simulation_control,
351 this->simulation_parameters.evaporation));
352 }
353 }
354
355 // Robin boundary condition
356 if (this->simulation_parameters.boundary_conditions_ht
357 .has_convection_radiation_bc)
358 {
359 this->assemblers.emplace_back(
360 std::make_shared<HeatTransferAssemblerRobinBC<dim>>(
361 this->simulation_control,
362 simulation_parameters.boundary_conditions_ht));
363 }
364
365 // Microwave heating
366 if (this->simulation_parameters.multiphysics.microwave_heating)
367 {
368 // Check if the time-harmonic Maxwell physics solution scaling type is
369 // not <none>, since the solution needs to not be dimensionless for the
370 // heat transfer physics to be able to use it.
371 AssertThrow(
372 this->simulation_parameters.multiphysics
373 .time_harmonic_maxwell_parameters.electromagnetic_scaling_type !=
375 ExcMessage("Time-harmonic Maxwell solution scaling is none, but heat "
376 "transfer physics requires a non-dimensionless solution."));
377
378 this->assemblers.emplace_back(
379 std::make_shared<
381 this->simulation_control,
382 this->simulation_parameters.multiphysics
383 .time_harmonic_maxwell_parameters,
384 this->simulation_parameters.dimensionality));
385 }
386
387
388 if (this->simulation_parameters.multiphysics.viscous_dissipation)
389 {
390 if (this->simulation_parameters.multiphysics.CLS)
391 {
392 // Call for the specific assembler
393 this->assemblers.emplace_back(
395 this->simulation_control,
396 this->simulation_parameters.multiphysics.cls_parameters
397 .viscous_dissipative_fluid));
398 }
399 else
400 {
401 this->assemblers.emplace_back(
403 this->simulation_control));
404 }
405 }
406
407 if (this->simulation_parameters.stabilization
408 .heat_transfer_dcdd_stabilization)
409 {
410 this->assemblers.emplace_back(
412 this->simulation_control));
413 }
414
415 // Time-stepping schemes
416 if (time_stepping_is_bdf(this->simulation_control->get_assembly_method()))
417 {
418 this->assemblers.emplace_back(
419 std::make_shared<HeatTransferAssemblerBDF<dim>>(
420 this->simulation_control));
421 }
422
423 // Core assembler
424 this->assemblers.emplace_back(
425 std::make_shared<HeatTransferAssemblerCore<dim>>(this->simulation_control));
426}
427
428template <int dim>
429void
431{
432 TimerOutput::Scope t(this->computing_timer, "Assemble matrix");
433
434 this->system_matrix = 0;
436
437 const DoFHandler<dim> &dof_handler_fluid =
438 multiphysics->get_dof_handler(PhysicsID::fluid_dynamics);
439
440 const double delta_T_ref = calculate_delta_T_ref(1.);
441
442 auto scratch_data = HeatTransferScratchData<dim>(
443 this->simulation_parameters.physical_properties_manager,
444 *this->fe,
445 *this->cell_quadrature,
446 *this->temperature_mapping,
447 dof_handler_fluid.get_fe(),
448 *this->face_quadrature,
449 delta_T_ref);
450
451 if (this->simulation_parameters.multiphysics.CLS)
452 {
453 const DoFHandler<dim> &dof_handler_cls =
454 this->multiphysics->get_dof_handler(PhysicsID::CLS);
455 scratch_data.enable_cls(
456 dof_handler_cls.get_fe(),
457 *this->cell_quadrature,
458 *this->temperature_mapping,
459 this->simulation_parameters.multiphysics.cls_parameters.phase_filter);
460 }
461
462 if (this->simulation_parameters.multiphysics.electromagnetics)
463 {
464 const DoFHandler<dim> &dof_handler_thm =
465 this->multiphysics->get_dof_handler(PhysicsID::electromagnetics);
466 scratch_data.enable_time_harmonic_maxwell(dof_handler_thm.get_fe(),
467 *this->cell_quadrature,
468 *this->temperature_mapping);
469 }
470
471 WorkStream::run(this->dof_handler->begin_active(),
472 this->dof_handler->end(),
473 *this,
476 scratch_data,
477 StabilizedMethodsCopyData(this->fe->n_dofs_per_cell(),
478 this->cell_quadrature->size()));
479
480 system_matrix.compress(VectorOperation::add);
481
482 if (this->simulation_parameters.nitsche->number_solids > 0)
484}
485
486template <int dim>
487void
489 const typename DoFHandler<dim>::active_cell_iterator &cell,
490 HeatTransferScratchData<dim> &scratch_data,
491 StabilizedMethodsCopyData &copy_data)
492{
493 copy_data.cell_is_local = cell->is_locally_owned();
494 if (!cell->is_locally_owned())
495 return;
496
497 auto source_term = simulation_parameters.source_term.heat_transfer_source;
498 source_term->set_time(simulation_control->get_current_time());
499
500 scratch_data.reinit(cell,
501 this->evaluation_point,
502 *this->previous_solutions,
503 &(*source_term));
504
505 const DoFHandler<dim> &dof_handler_fluid =
506 multiphysics->get_dof_handler(PhysicsID::fluid_dynamics);
507
508 typename DoFHandler<dim>::active_cell_iterator fd_cell(&(*triangulation),
509 cell->level(),
510 cell->index(),
511 &dof_handler_fluid);
512
513 if (multiphysics->fluid_dynamics_is_block())
514 {
515 // Check if the post processed variable needs to be calculated with the
516 // average velocity profile or the fluid solution.
517 if (this->simulation_parameters.initial_condition->type ==
519 average_velocity_profile &&
520 !this->simulation_parameters.multiphysics.fluid_dynamics &&
521 simulation_control->get_current_time() >
522 this->simulation_parameters.post_processing
523 .initial_time_for_average_velocities)
524 {
525 scratch_data.reinit_fluid_dynamics(
526 fd_cell,
527 multiphysics->get_block_time_average_solution(
529 this->simulation_parameters.ale);
530 }
531 else
532 {
533 if (!this->simulation_parameters.ale.enabled())
534 scratch_data.reinit_fluid_dynamics(fd_cell,
535 multiphysics->get_block_solution(
537 this->simulation_parameters.ale);
538 }
539 }
540 else
541 {
542 // Check if the post processed variable needs to be calculated with the
543 // average velocity profile or the fluid solution.
544 if (this->simulation_parameters.initial_condition->type ==
546 average_velocity_profile &&
547 !this->simulation_parameters.multiphysics.fluid_dynamics &&
548 simulation_control->get_current_time() >
549 this->simulation_parameters.post_processing
550 .initial_time_for_average_velocities)
551 {
552 scratch_data.reinit_fluid_dynamics(
553 fd_cell,
554 multiphysics->get_time_average_solution(PhysicsID::fluid_dynamics),
555 this->simulation_parameters.ale);
556 }
557 else
558 {
559 scratch_data.reinit_fluid_dynamics(fd_cell,
560 multiphysics->get_solution(
562 this->simulation_parameters.ale);
563 }
564 }
565
566 if (this->simulation_parameters.multiphysics.CLS)
567 {
568 const DoFHandler<dim> &dof_handler_cls =
569 this->multiphysics->get_dof_handler(PhysicsID::CLS);
570 typename DoFHandler<dim>::active_cell_iterator phase_cell(
571 &(*(this->triangulation)),
572 cell->level(),
573 cell->index(),
574 &dof_handler_cls);
575
576 scratch_data.reinit_cls(phase_cell,
577 this->multiphysics->get_solution(PhysicsID::CLS),
578 this->multiphysics->get_filtered_solution(
580 }
581
582 if (this->simulation_parameters.multiphysics.electromagnetics)
583 {
584 const DoFHandler<dim> &dof_handler_thm =
585 this->multiphysics->get_dof_handler(PhysicsID::electromagnetics);
586 typename DoFHandler<dim>::active_cell_iterator thm_cell(
587 &(*(this->triangulation)),
588 cell->level(),
589 cell->index(),
590 &dof_handler_thm);
591
592 scratch_data.reinit_time_harmonic_maxwell(
593 thm_cell,
594 this->multiphysics->get_solution(PhysicsID::electromagnetics));
595 }
596
597 scratch_data.calculate_physical_properties();
598
599 copy_data.reset();
600
601 for (auto &assembler : this->assemblers)
602 {
603 assembler->assemble_matrix(scratch_data, copy_data);
604 }
605
606
607 cell->get_dof_indices(copy_data.local_dof_indices);
608}
609
610template <int dim>
611void
613 const StabilizedMethodsCopyData &copy_data)
614{
615 if (!copy_data.cell_is_local)
616 return;
617
618 const AffineConstraints<double> &constraints_used = this->zero_constraints;
619 constraints_used.distribute_local_to_global(copy_data.local_matrix,
620 copy_data.local_dof_indices,
622}
623
624
625template <int dim>
626void
628{
629 TimerOutput::Scope t(this->computing_timer, "Assemble RHS");
630
631 this->system_rhs = 0;
633
634 const DoFHandler<dim> &dof_handler_fluid =
635 multiphysics->get_dof_handler(PhysicsID::fluid_dynamics);
636
637 const double delta_T_ref = calculate_delta_T_ref(1.);
638
639 auto scratch_data = HeatTransferScratchData<dim>(
640 this->simulation_parameters.physical_properties_manager,
641 *this->fe,
642 *this->cell_quadrature,
643 *this->temperature_mapping,
644 dof_handler_fluid.get_fe(),
645 *this->face_quadrature,
646 delta_T_ref);
647
648 if (this->simulation_parameters.multiphysics.CLS)
649 {
650 const DoFHandler<dim> &dof_handler_cls =
651 this->multiphysics->get_dof_handler(PhysicsID::CLS);
652 scratch_data.enable_cls(
653 dof_handler_cls.get_fe(),
654 *this->cell_quadrature,
655 *this->temperature_mapping,
656 this->simulation_parameters.multiphysics.cls_parameters.phase_filter);
657 }
658
659 if (this->simulation_parameters.multiphysics.electromagnetics)
660 {
661 const DoFHandler<dim> &dof_handler_thm =
662 this->multiphysics->get_dof_handler(PhysicsID::electromagnetics);
663 scratch_data.enable_time_harmonic_maxwell(dof_handler_thm.get_fe(),
664 *this->cell_quadrature,
665 *this->temperature_mapping);
666 }
667
668 WorkStream::run(this->dof_handler->begin_active(),
669 this->dof_handler->end(),
670 *this,
673 scratch_data,
674 StabilizedMethodsCopyData(this->fe->n_dofs_per_cell(),
675 this->cell_quadrature->size()));
676
677 this->system_rhs.compress(VectorOperation::add);
678
679 if (this->simulation_parameters.nitsche->number_solids > 0)
681}
682
683template <int dim>
684void
686 const typename DoFHandler<dim>::active_cell_iterator &cell,
687 HeatTransferScratchData<dim> &scratch_data,
688 StabilizedMethodsCopyData &copy_data)
689{
690 copy_data.cell_is_local = cell->is_locally_owned();
691 if (!cell->is_locally_owned())
692 return;
693
694 auto source_term = simulation_parameters.source_term.heat_transfer_source;
695 source_term->set_time(simulation_control->get_current_time());
696
697 scratch_data.reinit(cell,
698 this->evaluation_point,
699 *this->previous_solutions,
700 &(*source_term));
701
702 const DoFHandler<dim> &dof_handler_fluid =
703 multiphysics->get_dof_handler(PhysicsID::fluid_dynamics);
704
705 typename DoFHandler<dim>::active_cell_iterator fd_cell(&(*triangulation),
706 cell->level(),
707 cell->index(),
708 &dof_handler_fluid);
709
710 if (multiphysics->fluid_dynamics_is_block())
711 {
712 // Check if the post processed variable needs to be calculated with the
713 // average velocity profile or the fluid solution.
714 if (this->simulation_parameters.initial_condition->type ==
716 average_velocity_profile &&
717 !this->simulation_parameters.multiphysics.fluid_dynamics &&
718 simulation_control->get_current_time() >
719 this->simulation_parameters.post_processing
720 .initial_time_for_average_velocities)
721 {
722 scratch_data.reinit_fluid_dynamics(
723 fd_cell,
724 multiphysics->get_block_time_average_solution(
726 this->simulation_parameters.ale);
727 }
728 else
729 {
730 scratch_data.reinit_fluid_dynamics(fd_cell,
731 multiphysics->get_block_solution(
733 this->simulation_parameters.ale);
734 }
735 scratch_data.reinit_velocity_gradient(
736 multiphysics->get_block_solution(PhysicsID::fluid_dynamics));
737 }
738 else
739 {
740 // Check if the post processed variable needs to be calculated with the
741 // average velocity profile or the fluid solution.
742 if (this->simulation_parameters.initial_condition->type ==
744 average_velocity_profile &&
745 !this->simulation_parameters.multiphysics.fluid_dynamics &&
746 simulation_control->get_current_time() >
747 this->simulation_parameters.post_processing
748 .initial_time_for_average_velocities)
749 {
750 scratch_data.reinit_fluid_dynamics(
751 fd_cell,
752 multiphysics->get_time_average_solution(PhysicsID::fluid_dynamics),
753 this->simulation_parameters.ale);
754 }
755 else
756 {
757 scratch_data.reinit_fluid_dynamics(fd_cell,
758 multiphysics->get_solution(
760 this->simulation_parameters.ale);
761 }
762
763 scratch_data.reinit_velocity_gradient(
765 }
766
767 if (this->simulation_parameters.multiphysics.CLS)
768 {
769 const DoFHandler<dim> &dof_handler_cls =
770 this->multiphysics->get_dof_handler(PhysicsID::CLS);
771 typename DoFHandler<dim>::active_cell_iterator phase_cell(
772 &(*(this->triangulation)),
773 cell->level(),
774 cell->index(),
775 &dof_handler_cls);
776
777 scratch_data.reinit_cls(phase_cell,
778 this->multiphysics->get_solution(PhysicsID::CLS),
779 this->multiphysics->get_filtered_solution(
781 }
782
783 if (this->simulation_parameters.multiphysics.electromagnetics)
784 {
785 const DoFHandler<dim> &dof_handler_thm =
786 this->multiphysics->get_dof_handler(PhysicsID::electromagnetics);
787 typename DoFHandler<dim>::active_cell_iterator thm_cell(
788 &(*(this->triangulation)),
789 cell->level(),
790 cell->index(),
791 &dof_handler_thm);
792
793 scratch_data.reinit_time_harmonic_maxwell(
794 thm_cell,
795 this->multiphysics->get_solution(PhysicsID::electromagnetics));
796 }
797
798 scratch_data.calculate_physical_properties();
799
800 copy_data.reset();
801
802 for (auto &assembler : this->assemblers)
803 {
804 assembler->assemble_rhs(scratch_data, copy_data);
805 }
806
807 cell->get_dof_indices(copy_data.local_dof_indices);
808}
809
810template <int dim>
811void
813 const StabilizedMethodsCopyData &copy_data)
814{
815 if (!copy_data.cell_is_local)
816 return;
817
818 const AffineConstraints<double> &constraints_used = this->zero_constraints;
819 constraints_used.distribute_local_to_global(copy_data.local_rhs,
820 copy_data.local_dof_indices,
821 system_rhs);
822}
823
824template <int dim>
825std::vector<OutputStruct<dim, GlobalVectorType>>
827
828{
829 std::vector<OutputStruct<dim, GlobalVectorType>> solution_output_structs;
830 solution_output_structs.emplace_back(
832 *this->dof_handler,
833 *this->present_solution,
834 std::vector<std::string>{"temperature"},
835 std::vector<DataComponentInterpretation::DataComponentInterpretation>{
836 DataComponentInterpretation::component_is_scalar});
837
838 // Get number of fluids and solids
839 const unsigned int n_fluids =
840 this->simulation_parameters.physical_properties_manager
841 .get_number_of_fluids();
842 const unsigned int n_solids =
843 this->simulation_parameters.physical_properties_manager
844 .get_number_of_solids();
845 unsigned int mesh_m_id = 0;
846
847 // Check if there are solids
848 const bool solid_phase_present = (n_solids > 0);
849
850 // Postprocess heat fluxes
852 heat_flux_postprocessors.reserve(n_fluids + n_solids);
853 // Heat fluxes in fluids
854 for (unsigned int f_id = 0; f_id < n_fluids; ++f_id)
855 {
856 heat_flux_postprocessors.emplace_back(
858 "f",
859 f_id,
860 mesh_m_id,
861 solid_phase_present));
862 solution_output_structs.emplace_back(
864 *this->dof_handler,
865 *this->present_solution,
866 std::make_shared<HeatFluxPostprocessor<dim>>(
868 }
869 // Heat fluxes in solids
870 for (unsigned int m_id = n_fluids; m_id < n_fluids + n_solids; ++m_id)
871 {
872 mesh_m_id += 1;
873 heat_flux_postprocessors.emplace_back(
875 "s",
876 m_id - n_fluids,
877 mesh_m_id,
878 solid_phase_present));
879 solution_output_structs.emplace_back(
881 *this->dof_handler,
882 *this->present_solution,
883 std::make_shared<HeatFluxPostprocessor<dim>>(
885 }
886
887 // Ouput the time average temperature and time average heat flux
888 if (simulation_parameters.post_processing.calculate_average_temp_and_hf)
889 {
891 this->average_temperature->get_average_scalar();
892 solution_output_structs.emplace_back(
894 *this->dof_handler,
896 std::vector<std::string>{"average_temperature"},
897 std::vector<DataComponentInterpretation::DataComponentInterpretation>{
898 DataComponentInterpretation::component_is_scalar});
899
900 // Output the time average heat flux
902 average_heat_flux_postprocessors.reserve(n_fluids + n_solids);
903
904 // Heat fluxes in fluids
905 for (unsigned int f_id = 0; f_id < n_fluids; ++f_id)
906 {
909 "average_f",
910 f_id,
911 mesh_m_id,
912 solid_phase_present));
913 solution_output_structs.emplace_back(
914 std::in_place_type<
916 *this->dof_handler,
918 std::make_shared<HeatFluxPostprocessor<dim>>(
920 }
921 // Heat fluxes in solids
922 for (unsigned int m_id = n_fluids; m_id < n_fluids + n_solids; ++m_id)
923 {
924 mesh_m_id += 1;
927 "average_s",
928 m_id - n_fluids,
929 mesh_m_id,
930 solid_phase_present));
931 solution_output_structs.emplace_back(
932 std::in_place_type<
934 *this->dof_handler,
936 std::make_shared<HeatFluxPostprocessor<dim>>(
938 }
939 }
940 return solution_output_structs;
941}
942
943template <int dim>
944double
946{
947 double solution_maximum, solution_minimum;
948#ifndef LETHE_USE_LDV
949 if (is_steady(simulation_parameters.simulation_control.method))
950 {
951 solution_maximum = this->present_solution->max();
952 solution_minimum = this->present_solution->min();
953 }
954 else
955 {
956 solution_maximum = (*this->previous_solutions)[0].max();
957 solution_minimum = (*this->previous_solutions)[0].min();
958 }
959#endif
960
961 // Calculate delta_T_ref.
962 double delta_T_ref =
963 std::max(solution_maximum - solution_minimum, minimum_delta_T_ref);
964
965 // Set minimum value as 1 to prevent overshooting of diffusivity
966 return delta_T_ref;
967}
968
969template <int dim>
970double
972{
973 auto mpi_communicator = triangulation->get_mpi_communicator();
974
975 FEValues<dim> fe_values(*this->temperature_mapping,
976 *fe,
977 *this->cell_quadrature,
978 update_values | update_gradients |
979 update_quadrature_points | update_JxW_values);
980
981 const unsigned int n_q_points = this->cell_quadrature->size();
982
983 std::vector<double> q_exact_solution(n_q_points);
984 std::vector<double> q_scalar_values(n_q_points);
985
986 auto &exact_solution = simulation_parameters.analytical_solution->temperature;
987 exact_solution.set_time(simulation_control->get_current_time());
988
989 double l2error = 0.;
990
991 for (const auto &cell : dof_handler->active_cell_iterators())
992 {
993 if (cell->is_locally_owned())
994 {
995 fe_values.reinit(cell);
996 fe_values.get_function_values(*present_solution, q_scalar_values);
997
998 // Get the exact solution at all gauss points
999 exact_solution.value_list(fe_values.get_quadrature_points(),
1000 q_exact_solution);
1001
1002 for (unsigned int q = 0; q < n_q_points; q++)
1003 {
1004 double sim = q_scalar_values[q];
1005 double exact = q_exact_solution[q];
1006 l2error += (sim - exact) * (sim - exact) * fe_values.JxW(q);
1007 }
1008 }
1009 }
1010 l2error = Utilities::MPI::sum(l2error, mpi_communicator);
1011 return l2error;
1012}
1013
1014template <int dim>
1015void
1017{
1018 auto mpi_communicator = triangulation->get_mpi_communicator();
1019 unsigned int this_mpi_process(
1020 Utilities::MPI::this_mpi_process(mpi_communicator));
1021
1022 if (this_mpi_process == 0 &&
1023 simulation_parameters.analytical_solution->verbosity !=
1025 {
1026 error_table.omit_column_from_convergence_rate_evaluation("cells");
1027
1028
1029 if (simulation_parameters.simulation_control.method ==
1031 {
1032 error_table.evaluate_all_convergence_rates(
1033 ConvergenceTable::reduction_rate_log2);
1034 }
1035 error_table.set_scientific("error_temperature", true);
1036 error_table.set_precision("error_temperature",
1037 simulation_control->get_log_precision());
1038 error_table.write_text(std::cout);
1039 }
1040
1042 {
1043 announce_string(this->pcout, "Heat Transfer");
1044 this->pcout << std::defaultfloat;
1045 this->computing_timer.print_summary();
1046 this->pcout << std::scientific;
1047 }
1048}
1049
1050template <int dim>
1051void
1053{
1054 for (unsigned int i = previous_solutions->size() - 1; i > 0; --i)
1055 {
1056 (*previous_solutions)[i] = (*previous_solutions)[i - 1];
1057 }
1058 (*previous_solutions)[0] = *this->present_solution;
1059}
1060
1061template <int dim>
1062void
1064{
1065 if (simulation_parameters.analytical_solution->calculate_error() == true &&
1066 !first_iteration)
1067 {
1068 double temperature_error = calculate_L2_error();
1069
1070 error_table.add_value("cells",
1071 this->triangulation->n_global_active_cells());
1072 error_table.add_value("error_temperature", temperature_error);
1073 error_table.set_scientific("error_temperature", true);
1074
1075 if (Utilities::MPI::this_mpi_process(
1076 this->triangulation->get_mpi_communicator()) == 0)
1077 {
1078 std::string filename =
1079 simulation_parameters.simulation_control.output_folder +
1080 simulation_parameters.analytical_solution->get_filename() +
1081 "_heat_transfer.dat";
1082 std::ofstream output(filename.c_str());
1083 error_table.write_text(output);
1084 }
1085
1086 if (simulation_parameters.analytical_solution->verbosity ==
1088 {
1089 this->pcout << "L2 error temperature : " << temperature_error
1090 << std::endl;
1091 }
1092 }
1093
1094 if (simulation_parameters.post_processing.calculate_average_temp_and_hf)
1095 {
1096 this->average_temperature->calculate_average_scalar(
1097 *this->present_solution,
1098 this->simulation_parameters.post_processing,
1099 simulation_control->get_current_time(),
1100 simulation_control->get_time_step());
1101 }
1102
1103 // Set-up domain name for output files
1104 Parameters::FluidIndicator monitored_fluid =
1105 this->simulation_parameters.post_processing.postprocessed_fluid;
1106 // default: monophase simulations
1107 std::string domain_name("fluid");
1108 bool gather_cls(false);
1109
1110 if (this->simulation_parameters.physical_properties_manager
1111 .get_number_of_fluids() == 2)
1112 {
1113 // Multiphase flow
1114 gather_cls = true;
1115 switch (monitored_fluid)
1116 {
1117 default:
1118 {
1119 domain_name = "fluid";
1120 break;
1121 }
1123 {
1124 domain_name = "fluid_0";
1125 break;
1126 }
1128 {
1129 domain_name = "fluid_1";
1130 break;
1131 }
1132 }
1133 }
1134
1135 // Temperature statistics
1136 if (simulation_parameters.post_processing.calculate_temperature_statistics)
1137 {
1139 monitored_fluid,
1140 domain_name,
1141 false);
1142 // Postprocess the temperature statistics again to calculate the spatial
1143 // average of the time-averaged temperature. Flag time_average is set to
1144 // true.
1145 if (simulation_parameters.post_processing.calculate_average_temp_and_hf)
1146 {
1148 monitored_fluid,
1149 domain_name,
1150 true);
1151 }
1152
1153 if (simulation_control->get_iteration_number() %
1154 this->simulation_parameters.post_processing.output_frequency ==
1155 0)
1156 this->write_temperature_statistics(domain_name);
1157 }
1158
1159 // Heat flux calculation
1160 if (simulation_parameters.post_processing.calculate_heat_flux)
1161 {
1162 // Parse fluid present solution
1163 if (multiphysics->fluid_dynamics_is_block())
1164 {
1165 postprocess_heat_flux_on_bc(gather_cls,
1166 multiphysics->get_block_solution(
1168
1170 monitored_fluid,
1171 domain_name,
1172 multiphysics->get_block_solution(
1174 }
1175 else
1176 {
1178 gather_cls, multiphysics->get_solution(PhysicsID::fluid_dynamics));
1179
1181 monitored_fluid,
1182 domain_name,
1183 multiphysics->get_solution(
1185 }
1186
1187 if (this->simulation_parameters.nitsche->number_solids > 0)
1189
1190 if (simulation_control->get_iteration_number() %
1191 this->simulation_parameters.post_processing.output_frequency ==
1192 0)
1193 this->write_heat_flux(domain_name);
1194 }
1195
1196 // Algebraic melt volume
1197 if (simulation_parameters.post_processing.calculate_algebraic_melt_volume)
1198 {
1199 TimerOutput::Scope t(this->computing_timer,
1200 "Calculate algebraic melt volume");
1201 AssertThrow(
1202 simulation_parameters.physical_properties_manager.has_phase_change(),
1203 MeltVolumeRequiresPhaseChange());
1205
1206 if (simulation_control->get_iteration_number() %
1207 this->simulation_parameters.post_processing.output_frequency ==
1208 0)
1210 }
1211
1212 // Geometric melt volume
1213 if (simulation_parameters.post_processing.calculate_geometric_melt_volume)
1214 {
1215 TimerOutput::Scope t(this->computing_timer,
1216 "Calculate geometric melt volume");
1218 if (simulation_control->get_iteration_number() %
1219 this->simulation_parameters.post_processing.output_frequency ==
1220 0)
1222 }
1223
1224 // Temperature isocontour bounding boxes
1225 if (this->simulation_parameters.post_processing.isocontour_bounding_boxes
1226 .ids_and_isocontours_per_variable.contains(Variable::temperature))
1227 {
1228 TimerOutput::Scope t(
1229 this->computing_timer,
1230 "Compute bounding values of temperature isocontours");
1233 this->simulation_parameters.post_processing.isocontour_bounding_boxes
1234 .ids_and_isocontours_per_variable,
1235 *this->dof_handler,
1236 *this->present_solution,
1237 this->simulation_control->get_current_time(),
1238 this->simulation_parameters.post_processing.verbosity,
1239 this->pcout,
1240 this->temperature_isocontour_bounding_values_tables);
1241
1242 if (simulation_control->get_iteration_number() %
1243 this->simulation_parameters.post_processing.output_frequency ==
1244 0)
1246 this->dof_handler->get_mpi_communicator(),
1247 this->simulation_parameters.simulation_control.output_folder,
1249 this->simulation_parameters.post_processing.isocontour_bounding_boxes
1250 .ids_and_isocontours_per_variable,
1251 this->temperature_isocontour_bounding_values_tables);
1252 }
1253
1254 // Postprocess probes
1255 if (this->simulation_parameters.post_processing.probing_points
1256 .probing_points_per_variable.contains(Variable::temperature))
1257 this->multiphysics->postprocess_probes(*temperature_mapping,
1258 *dof_handler,
1261 this->pcout);
1262}
1263
1264template <int dim>
1265void
1267{
1268 announce_string(this->pcout, "Heat Transfer");
1269 this->pcout << std::defaultfloat;
1270 this->computing_timer.print_summary();
1271 this->pcout << std::scientific;
1272 this->computing_timer.reset();
1273}
1274
1275template <int dim>
1276void
1278{
1279 solution_transfer->prepare_for_coarsening_and_refinement(*present_solution);
1280
1281 for (unsigned int i = 0; i < previous_solutions->size(); ++i)
1282 {
1283 previous_solutions_transfer[i].prepare_for_coarsening_and_refinement(
1284 (*previous_solutions)[i]);
1285 }
1286
1287 if (simulation_parameters.post_processing.calculate_average_temp_and_hf)
1288 this->average_temperature->prepare_for_mesh_adaptation();
1289}
1290
1291template <int dim>
1292void
1294{
1295 auto mpi_communicator = triangulation->get_mpi_communicator();
1296
1297
1298 // Set up the vectors for the transfer
1299 GlobalVectorType tmp(locally_owned_dofs, mpi_communicator);
1300
1301 // Interpolate the solution at time and previous time
1302 solution_transfer->interpolate(tmp);
1303
1304 // Distribute constraints
1305 nonzero_constraints.distribute(tmp);
1306
1307 // Fix on the new mesh
1308 *present_solution = tmp;
1309
1310 // Transfer previous solutions
1311 for (unsigned int i = 0; i < previous_solutions->size(); ++i)
1312 {
1313 GlobalVectorType tmp_previous_solution(locally_owned_dofs,
1314 mpi_communicator);
1315 previous_solutions_transfer[i].interpolate(tmp_previous_solution);
1316 nonzero_constraints.distribute(tmp_previous_solution);
1317 (*previous_solutions)[i] = tmp_previous_solution;
1318 }
1319
1320 if (simulation_parameters.post_processing.calculate_average_temp_and_hf)
1321 this->average_temperature->post_mesh_adaptation();
1322}
1323
1324template <int dim>
1325void
1327 const std::pair<const Variable, Parameters::MultipleAdaptationParameters>
1328 &ivar,
1329 dealii::Vector<float> &estimated_error_per_cell)
1330{
1331 if (ivar.first == Variable::temperature)
1332 {
1333 AssertThrow(
1334 ivar.second.error_estimator ==
1336 ExcMessage(
1337 "Only the Kelly error estimator is currently implemented for the "
1338 "<temperature> field."));
1339
1340
1341 ComponentMask temperature_mask =
1342 fe->component_mask(FEValuesExtractors::Scalar(0));
1343 compute_kelly(estimated_error_per_cell, temperature_mask);
1344 }
1345}
1346
1347
1348template <int dim>
1349void
1351 dealii::Vector<float> &estimated_error_per_cell,
1352 const ComponentMask &component_mask)
1353{
1354 KellyErrorEstimator<dim>::estimate(
1355 *this->temperature_mapping,
1356 *this->dof_handler,
1357 *this->face_quadrature,
1358 typename std::map<types::boundary_id, const Function<dim, double> *>(),
1359 *this->present_solution,
1360 estimated_error_per_cell,
1361 component_mask);
1362}
1363
1364template <int dim>
1365std::vector<OutputStructTableHandler>
1367{
1368 std::vector<OutputStructTableHandler> table_output_structs;
1369
1370 std::string prefix =
1371 this->simulation_parameters.simulation_control.output_folder;
1372 std::string suffix = ".checkpoint";
1373
1374 if (this->simulation_parameters.analytical_solution->calculate_error())
1375 table_output_structs.emplace_back(
1376 this->error_table,
1377 prefix + this->simulation_parameters.analytical_solution->get_filename() +
1378 "_HT" + suffix);
1379
1380 if (this->simulation_parameters.post_processing.calculate_heat_flux)
1381 table_output_structs.emplace_back(
1382 this->heat_flux_table,
1383 prefix +
1384 this->simulation_parameters.post_processing.heat_flux_output_name +
1385 suffix);
1386
1387 if (this->simulation_parameters.post_processing
1388 .calculate_temperature_statistics)
1389 table_output_structs.emplace_back(
1390 this->statistics_table,
1391 prefix +
1392 this->simulation_parameters.post_processing.temperature_output_name +
1393 suffix);
1394
1395 if (this->simulation_parameters.post_processing
1396 .calculate_algebraic_melt_volume)
1397 table_output_structs.emplace_back(
1399 prefix +
1400 this->simulation_parameters.post_processing
1401 .algebraic_melt_volume_output_name +
1402 suffix);
1403
1404 if (this->simulation_parameters.post_processing
1405 .calculate_geometric_melt_volume)
1406 table_output_structs.emplace_back(
1408 prefix +
1409 this->simulation_parameters.post_processing
1410 .geometric_melt_volume_output_name +
1411 suffix);
1412
1413 if (this->simulation_parameters.post_processing.isocontour_bounding_boxes
1414 .ids_and_isocontours_per_variable.contains(Variable::temperature))
1415 {
1416 // Get iterator range that corresponds to the variable "temperature"
1417 auto [begin, end] =
1418 this->simulation_parameters.post_processing.isocontour_bounding_boxes
1419 .ids_and_isocontours_per_variable.equal_range(Variable::temperature);
1420
1421 // Initialize iterator for the table(s)
1422 unsigned int i = 0;
1423
1424 for (auto it = begin; it != end; ++it, ++i)
1425 {
1426 // Get isocontour output name
1427 const std::string &isocontour_output_name =
1428 it->second.second.output_name;
1429
1430 table_output_structs.emplace_back(
1432 prefix + isocontour_output_name + suffix);
1433 }
1434 }
1435
1436 return table_output_structs;
1437}
1438
1439template <int dim>
1440void
1442{
1443 auto mpi_communicator = this->triangulation->get_mpi_communicator();
1444 std::vector<const GlobalVectorType *> sol_set_transfer;
1445
1447 std::make_shared<SolutionTransfer<dim, GlobalVectorType>>(*dof_handler);
1448
1449 sol_set_transfer.emplace_back(&(*present_solution));
1450 for (const auto &previous_solution : *previous_solutions)
1451 {
1452 sol_set_transfer.emplace_back(&previous_solution);
1453 }
1454
1455 std::string checkpoint_file_prefix =
1456 this->simulation_parameters.simulation_control.output_folder +
1457 this->simulation_parameters.restart_parameters.filename;
1458
1459 if (simulation_parameters.post_processing.calculate_average_temp_and_hf)
1460 {
1461 std::vector<const GlobalVectorType *> avg_scalar_set_transfer =
1462 this->average_temperature->save(checkpoint_file_prefix);
1463
1464 sol_set_transfer.insert(sol_set_transfer.end(),
1465 avg_scalar_set_transfer.begin(),
1466 avg_scalar_set_transfer.end());
1467 }
1468
1469 solution_transfer->prepare_for_serialization(sol_set_transfer);
1470
1471 // Serialize all post-processing tables that are currently used with the Heat
1472 // Transfer solver
1473 const std::vector<OutputStructTableHandler> &table_output_structs =
1474 this->gather_tables();
1475 serialize_tables_vector(table_output_structs, mpi_communicator);
1476}
1477
1478template <int dim>
1479void
1481{
1482 auto mpi_communicator = triangulation->get_mpi_communicator();
1483 this->pcout << "Reading heat transfer checkpoint" << std::endl;
1484
1485 std::vector<GlobalVectorType *> input_vectors(1 + previous_solutions->size());
1486 GlobalVectorType distributed_system(locally_owned_dofs, mpi_communicator);
1487 input_vectors[0] = &distributed_system;
1488
1489
1490 std::vector<GlobalVectorType> distributed_previous_solutions;
1491 distributed_previous_solutions.reserve(previous_solutions->size());
1492 for (unsigned int i = 0; i < previous_solutions->size(); ++i)
1493 {
1494 distributed_previous_solutions.emplace_back(
1495 GlobalVectorType(locally_owned_dofs, mpi_communicator));
1496 input_vectors[i + 1] = &distributed_previous_solutions[i];
1497 }
1498
1499 SolutionTransfer<dim, GlobalVectorType> system_trans_vectors(
1500 *this->dof_handler);
1501
1502 std::string checkpoint_file_prefix =
1503 this->simulation_parameters.simulation_control.output_folder +
1504 this->simulation_parameters.restart_parameters.filename;
1505
1506 if (simulation_parameters.post_processing.calculate_average_temp_and_hf)
1507 {
1508 std::vector<GlobalVectorType *> sum_vectors =
1509 this->average_temperature->read(checkpoint_file_prefix);
1510
1511 input_vectors.insert(input_vectors.end(),
1512 sum_vectors.begin(),
1513 sum_vectors.end());
1514 }
1515
1516 solution_transfer->deserialize(input_vectors);
1517
1518 if (simulation_parameters.post_processing.calculate_average_temp_and_hf)
1519 {
1520 // Reset the time-averaged temperature and heat flux if the initial time
1521 // for averaging has not been reached
1522 if ((this->simulation_parameters.post_processing
1523 .initial_time_for_average_temp_and_hf +
1524 1e-6 * simulation_control->get_time_step()) >
1525 this->simulation_control->get_current_time())
1526 {
1527 this->pcout
1528 << "Warning: The checkpointed time-averaged temperature and heat flux have been reinitialized because the initial averaging time has not yet been reached."
1529 << std::endl;
1530 this->average_temperature->zero_average_after_restart();
1531 }
1532 this->average_temperature->sanitize_after_restart();
1533 }
1534
1535 *present_solution = distributed_system;
1536 for (unsigned int i = 0; i < previous_solutions->size(); ++i)
1537 {
1538 (*previous_solutions)[i] = distributed_previous_solutions[i];
1539 }
1540
1541 // Deserialize all post-processing tables that are currently used with the
1542 // Heat Transfer solver
1543 std::vector<OutputStructTableHandler> table_output_structs =
1544 this->gather_tables();
1545 deserialize_tables_vector(table_output_structs, mpi_communicator);
1546}
1547
1548
1549template <int dim>
1550void
1552{
1554
1555 // Proceed with setting up the DoFs
1556 dof_handler->distribute_dofs(*fe);
1557 DoFRenumbering::Cuthill_McKee(*this->dof_handler);
1558
1559 auto mpi_communicator = triangulation->get_mpi_communicator();
1560
1561
1562 locally_owned_dofs = dof_handler->locally_owned_dofs();
1563 locally_relevant_dofs = DoFTools::extract_locally_relevant_dofs(*dof_handler);
1564
1567 mpi_communicator);
1568
1569 // Previous solutions for transient schemes
1570 for (auto &solution : *this->previous_solutions)
1571 {
1572 solution.reinit(locally_owned_dofs,
1574 mpi_communicator);
1575 }
1576
1577 system_rhs.reinit(locally_owned_dofs, mpi_communicator);
1578
1579 newton_update.reinit(locally_owned_dofs, mpi_communicator);
1580
1581 local_evaluation_point.reinit(this->locally_owned_dofs, mpi_communicator);
1582
1583 {
1584 nonzero_constraints.clear();
1586 this->locally_relevant_dofs);
1587 DoFTools::make_hanging_node_constraints(*this->dof_handler,
1589
1590 for (auto const &[id, type] :
1591 this->simulation_parameters.boundary_conditions_ht.type)
1592 {
1593 // Dirichlet condition : imposed temperature at i_bc
1595 {
1596 VectorTools::interpolate_boundary_values(
1597 *this->dof_handler,
1598 id,
1599 *this->simulation_parameters.boundary_conditions_ht
1600 .dirichlet_value.at(id),
1602 }
1604 {
1605 const auto &periodic_boundary =
1606 this->simulation_parameters.boundary_conditions_ht
1607 .periodic_boundaries.at(id);
1608 DoFTools::make_periodicity_constraints(
1609 *this->dof_handler,
1610 id,
1611 periodic_boundary.neighbor_id,
1612 periodic_boundary.direction,
1614 }
1615 }
1616
1617 // Initialize the vectors used in the time average temperature calculation
1618 if (this->simulation_parameters.post_processing
1619 .calculate_average_temp_and_hf)
1620 {
1621 this->average_temperature->initialize_vectors(
1622 this->locally_owned_dofs,
1624 mpi_communicator);
1625 }
1626 }
1627 nonzero_constraints.close();
1628
1629 // Boundary conditions for Newton correction
1630 {
1631 zero_constraints.clear();
1633 this->locally_relevant_dofs);
1634 DoFTools::make_hanging_node_constraints(*this->dof_handler,
1636
1637 for (auto const &[id, type] :
1638 this->simulation_parameters.boundary_conditions_ht.type)
1639 {
1641 {
1642 VectorTools::interpolate_boundary_values(
1643 *this->dof_handler,
1644 id,
1645 Functions::ZeroFunction<dim>(),
1647 }
1649 {
1650 const auto &periodic_boundary =
1651 this->simulation_parameters.boundary_conditions_ht
1652 .periodic_boundaries.at(id);
1653 DoFTools::make_periodicity_constraints(
1654 *this->dof_handler,
1655 id,
1656 periodic_boundary.neighbor_id,
1657 periodic_boundary.direction,
1659 }
1660 }
1661 }
1662 zero_constraints.close();
1663
1664 // Sparse matrices initialization
1665 DynamicSparsityPattern dsp(locally_relevant_dofs);
1666 DoFTools::make_sparsity_pattern(*this->dof_handler,
1667 dsp,
1669 /*keep_constrained_dofs = */ true);
1670
1671 SparsityTools::distribute_sparsity_pattern(dsp,
1673 mpi_communicator,
1677 dsp,
1678 mpi_communicator);
1679
1680 this->pcout << " Number of thermal degrees of freedom: "
1681 << dof_handler->n_dofs() << std::endl;
1682
1683 // Provide the heat transfer dof_handler and present solution pointers to the
1684 // multiphysics interface
1685 multiphysics->set_dof_handler(PhysicsID::heat_transfer, this->dof_handler);
1687 this->temperature_mapping);
1689 multiphysics->set_previous_solutions(PhysicsID::heat_transfer,
1690 this->previous_solutions);
1691}
1692
1693template <int dim>
1694void
1696{
1697 if (!this->simulation_parameters.boundary_conditions_ht.time_dependent)
1698 return;
1699
1700 double time = this->simulation_control->get_current_time();
1701 // We begin by setting the new time for all expressions, although the change
1702 // for the convection-radiation-flux boundary conditions won't be applied in
1703 // this function
1704 for (auto const &[id, type] :
1705 this->simulation_parameters.boundary_conditions_ht.type)
1706 {
1707 this->simulation_parameters.boundary_conditions_ht.dirichlet_value.at(id)
1708 ->set_time(time);
1709 this->simulation_parameters.boundary_conditions_ht.h.at(id)->set_time(
1710 time);
1711 this->simulation_parameters.boundary_conditions_ht.Tinf.at(id)->set_time(
1712 time);
1713 this->simulation_parameters.boundary_conditions_ht.emissivity.at(id)
1714 ->set_time(time);
1715 this->simulation_parameters.boundary_conditions_ht.heat_flux_bc.at(id)
1716 ->set_time(time);
1717 }
1718
1719 nonzero_constraints.clear();
1721 this->locally_relevant_dofs);
1722 DoFTools::make_hanging_node_constraints(*this->dof_handler,
1724
1725 for (auto const &[id, type] :
1726 this->simulation_parameters.boundary_conditions_ht.type)
1727 {
1728 // Dirichlet condition : imposed temperature at i_bc
1730 {
1731 VectorTools::interpolate_boundary_values(
1732 *this->dof_handler,
1733 id,
1734 *this->simulation_parameters.boundary_conditions_ht.dirichlet_value
1735 .at(id),
1737 }
1739 {
1740 const auto &periodic_boundary =
1741 this->simulation_parameters.boundary_conditions_ht
1742 .periodic_boundaries.at(id);
1743 DoFTools::make_periodicity_constraints(*this->dof_handler,
1744 id,
1745 periodic_boundary.neighbor_id,
1746 periodic_boundary.direction,
1748 }
1749 }
1750 nonzero_constraints.close();
1751}
1752
1753template <int dim>
1754void
1756{
1757 VectorTools::interpolate(*this->temperature_mapping,
1758 *dof_handler,
1759 simulation_parameters.initial_condition->temperature,
1764}
1765
1766template <int dim>
1767void
1769{
1770 TimerOutput::Scope t(this->computing_timer, "Setup ILU");
1771
1772 const unsigned int ilu_fill =
1774 .ilu_precond_fill;
1775 const double ilu_atol =
1777 .ilu_precond_atol;
1778 const double ilu_rtol =
1780 .ilu_precond_rtol;
1781 TrilinosWrappers::PreconditionILU::AdditionalData preconditionerOptions(
1782 ilu_fill, ilu_atol, ilu_rtol, 0);
1783
1784 ilu_preconditioner = std::make_shared<TrilinosWrappers::PreconditionILU>();
1785
1786 ilu_preconditioner->initialize(system_matrix, preconditionerOptions);
1787}
1788
1789template <int dim>
1790void
1792{
1793 TimerOutput::Scope t(this->computing_timer, "Setup AMG");
1794
1795 // Constant modes for the temperature scalar field
1796 std::vector<std::vector<bool>> constant_modes;
1797
1798 ComponentMask components(1, true);
1799 constant_modes =
1800 DoFTools::extract_constant_modes(*this->dof_handler, components);
1801
1802 // The heat transfer operator is non-symmetric since heat transfer is always
1803 // solved assuming that there can be advection
1804 const bool elliptic = false;
1805 bool higher_order_elements = false;
1806 if (fe->degree > 1)
1807 higher_order_elements = true;
1808 const unsigned int n_cycles =
1810 .amg_n_cycles;
1811 const bool w_cycle =
1813 .amg_w_cycles;
1814 const double aggregation_threshold =
1816 .amg_aggregation_threshold;
1817 const unsigned int smoother_sweeps =
1819 .amg_smoother_sweeps;
1820 const unsigned int smoother_overlap =
1822 .amg_smoother_overlap;
1823 const bool output_details = false;
1824 const char *smoother_type = "ILU";
1825 const char *coarse_type = "ILU";
1826 TrilinosWrappers::PreconditionAMG::AdditionalData preconditionerOptions(
1827 elliptic,
1828 higher_order_elements,
1829 n_cycles,
1830 w_cycle,
1831 aggregation_threshold,
1832 constant_modes,
1833 smoother_sweeps,
1834 smoother_overlap,
1835 output_details,
1836 smoother_type,
1837 coarse_type);
1838
1839 Teuchos::ParameterList parameter_ml;
1840 std::unique_ptr<Epetra_MultiVector> distributed_constant_modes;
1841 preconditionerOptions.set_parameters(parameter_ml,
1842 distributed_constant_modes,
1844 const double ilu_fill =
1846 .amg_precond_ilu_fill;
1847 const double ilu_atol =
1849 .amg_precond_ilu_atol;
1850 const double ilu_rtol =
1852 .amg_precond_ilu_rtol;
1853 parameter_ml.set("smoother: ifpack level-of-fill", ilu_fill);
1854 parameter_ml.set("smoother: ifpack absolute threshold", ilu_atol);
1855 parameter_ml.set("smoother: ifpack relative threshold", ilu_rtol);
1856
1857 parameter_ml.set("coarse: ifpack level-of-fill", ilu_fill);
1858 parameter_ml.set("coarse: ifpack absolute threshold", ilu_atol);
1859 parameter_ml.set("coarse: ifpack relative threshold", ilu_rtol);
1860
1861 amg_preconditioner = std::make_shared<TrilinosWrappers::PreconditionAMG>();
1862 amg_preconditioner->initialize(system_matrix, parameter_ml);
1863}
1864
1865template <int dim>
1866void
1868{
1869 TimerOutput::Scope t(this->computing_timer, "Solve linear system");
1870
1871 auto mpi_communicator = triangulation->get_mpi_communicator();
1872
1873 const AffineConstraints<double> &constraints_used = this->zero_constraints;
1874
1875 const double absolute_residual =
1877 .minimum_residual;
1878 const double relative_residual =
1880 .relative_residual;
1881
1882 const double rescale_metric = this->get_residual_rescale_metric();
1883 const double current_residual = system_rhs.l2_norm() / rescale_metric;
1884 const double linear_solver_tolerance =
1885 std::max(relative_residual * current_residual, absolute_residual);
1886 if (this->simulation_parameters.linear_solver.at(PhysicsID::heat_transfer)
1887 .verbosity != Parameters::Verbosity::quiet)
1888 {
1889 this->pcout << " -Tolerance of iterative solver is : "
1890 << linear_solver_tolerance << std::endl;
1891 }
1892 const double non_rescaled_linear_solver_tolerance =
1893 linear_solver_tolerance * rescale_metric;
1894
1895 GlobalVectorType completely_distributed_solution(locally_owned_dofs,
1896 mpi_communicator);
1897
1898 SolverControl solver_control(simulation_parameters.linear_solver
1900 .max_iterations,
1901 non_rescaled_linear_solver_tolerance,
1902 true,
1903 true);
1904
1905 TrilinosWrappers::SolverGMRES::AdditionalData solver_parameters(
1906 false,
1908 .max_krylov_vectors);
1909
1910
1911 TrilinosWrappers::SolverGMRES solver(solver_control, solver_parameters);
1912
1913 const auto preconditioner_type =
1915 .preconditioner;
1916
1917 if (preconditioner_type == Parameters::LinearSolver::PreconditionerType::ilu)
1918 {
1919 setup_ilu();
1920 solver.solve(system_matrix,
1921 completely_distributed_solution,
1922 system_rhs,
1924 }
1925 else if (preconditioner_type ==
1927 {
1928 setup_amg();
1929 solver.solve(system_matrix,
1930 completely_distributed_solution,
1931 system_rhs,
1933 }
1934 else
1935 AssertThrow(
1936 false,
1937 ExcMessage(
1938 "This linear solver does not support this preconditioner. Only <ilu> and <amg> preconditioners are supported."));
1939
1941 .verbosity != Parameters::Verbosity::quiet)
1942 {
1943 this->pcout << " -Iterative solver took : " << solver_control.last_step()
1944 << " steps to reach a residual norm of "
1945 << solver_control.last_value() / rescale_metric << std::endl;
1946 }
1947
1948 constraints_used.distribute(completely_distributed_solution);
1949 newton_update = completely_distributed_solution;
1950}
1951
1952template <int dim>
1953void
1955 const bool gather_cls,
1956 const Parameters::FluidIndicator monitored_fluid,
1957 const std::string &domain_name,
1958 const bool time_average)
1959{
1960 const unsigned int n_q_points = this->cell_quadrature->size();
1961 const MPI_Comm mpi_communicator = this->dof_handler->get_mpi_communicator();
1962
1963 // Initialize heat transfer information
1964 std::vector<double> local_temperature_values(n_q_points);
1965 FEValues<dim> fe_values_ht(*this->temperature_mapping,
1966 *this->fe,
1967 *this->cell_quadrature,
1968 update_values | update_JxW_values);
1969
1970 // Initialize CLS information
1971 std::shared_ptr<const DoFHandler<dim>> dof_handler_cls;
1972 std::shared_ptr<FEValues<dim>> fe_values_cls;
1973 std::vector<double> filtered_phase_values(n_q_points);
1974
1975 if (gather_cls)
1976 {
1977 dof_handler_cls = std::shared_ptr<const DoFHandler<dim>>(
1978 &this->multiphysics->get_dof_handler(PhysicsID::CLS),
1979 [](const DoFHandler<dim> *) {});
1980 ;
1981 fe_values_cls =
1982 std::make_shared<FEValues<dim>>(*this->temperature_mapping,
1983 dof_handler_cls->get_fe(),
1984 *this->cell_quadrature,
1985 update_values);
1986 }
1987
1988 // Other initializations
1989 double phase_coefficient(0.);
1990 double volume_integral(0.);
1991 double temperature_integral(0.);
1992 double minimum_temperature(std::numeric_limits<double>::max());
1993 double maximum_temperature(std::numeric_limits<double>::lowest());
1994 // boolean used to state if the quadrature point is in the
1995 // postprocessed_fluid, i.e. its temperature should be considered
1996 // in the minimum and maximum temperature calculation
1997 bool point_is_in_postprocessed_fluid(false);
1998
1999 // Calculate min, max and average
2000 for (const auto &cell : this->dof_handler->active_cell_iterators())
2001 {
2002 if (cell->is_locally_owned())
2003 {
2004 // Gather heat transfer information
2005 fe_values_ht.reinit(cell);
2006
2007 if (!time_average)
2008 {
2009 fe_values_ht.get_function_values(*this->present_solution,
2010 local_temperature_values);
2011 }
2012 else
2013 {
2014 // calculate the average using the time-averaged temperature
2015 fe_values_ht.get_function_values(
2016 this->average_temperature->get_average_scalar(),
2017 local_temperature_values);
2018 }
2019
2020 if (gather_cls)
2021 {
2022 // Get CLS active cell iterator
2023 typename DoFHandler<dim>::active_cell_iterator cell_cls(
2024 &(*(this->triangulation)),
2025 cell->level(),
2026 cell->index(),
2027 &(*dof_handler_cls));
2028
2029 // Gather CLS information
2030 fe_values_cls->reinit(cell_cls);
2031 fe_values_cls->get_function_values(
2032 this->multiphysics->get_filtered_solution(PhysicsID::CLS),
2033 filtered_phase_values);
2034 }
2035
2036 for (unsigned int q = 0; q < n_q_points; q++)
2037 {
2038 std::tie(phase_coefficient, point_is_in_postprocessed_fluid) =
2039 set_phase_coefficient(gather_cls,
2040 monitored_fluid,
2041 filtered_phase_values[q]);
2042
2043 if (point_is_in_postprocessed_fluid)
2044 {
2045 maximum_temperature =
2046 std::max(local_temperature_values[q], maximum_temperature);
2047 minimum_temperature =
2048 std::min(local_temperature_values[q], minimum_temperature);
2049 }
2050
2051 volume_integral += fe_values_ht.JxW(q) * phase_coefficient;
2052 temperature_integral += local_temperature_values[q] *
2053 phase_coefficient * fe_values_ht.JxW(q);
2054 } // end loop on quadrature points
2055 }
2056 } // end loop on cell
2057
2058 minimum_temperature =
2059 Utilities::MPI::min(minimum_temperature, mpi_communicator);
2060 maximum_temperature =
2061 Utilities::MPI::max(maximum_temperature, mpi_communicator);
2062
2063 volume_integral = Utilities::MPI::sum(volume_integral, mpi_communicator);
2064 temperature_integral =
2065 Utilities::MPI::sum(temperature_integral, mpi_communicator);
2066 double temperature_average = temperature_integral / volume_integral;
2067
2068 // Calculate standard deviation
2069 double temperature_variance_integral = 0;
2070 for (const auto &cell : this->dof_handler->active_cell_iterators())
2071 {
2072 if (cell->is_locally_owned())
2073 {
2074 fe_values_ht.reinit(cell);
2075
2076 if (!time_average)
2077 {
2078 fe_values_ht.get_function_values(*this->present_solution,
2079 local_temperature_values);
2080 }
2081 else
2082 {
2083 // calculate the average using the time-averaged temperature
2084 fe_values_ht.get_function_values(
2085 this->average_temperature->get_average_scalar(),
2086 local_temperature_values);
2087 }
2088
2089 if (gather_cls)
2090 {
2091 // Get CLS active cell iterator
2092 typename DoFHandler<dim>::active_cell_iterator cell_cls(
2093 &(*(this->triangulation)),
2094 cell->level(),
2095 cell->index(),
2096 &(*dof_handler_cls));
2097
2098 // Gather CLS information
2099 fe_values_cls->reinit(cell_cls);
2100 fe_values_cls->get_function_values(
2101 this->multiphysics->get_filtered_solution(PhysicsID::CLS),
2102 filtered_phase_values);
2103 }
2104
2105 for (unsigned int q = 0; q < n_q_points; q++)
2106 {
2107 phase_coefficient =
2108 set_phase_coefficient(gather_cls,
2109 monitored_fluid,
2110 filtered_phase_values[q])
2111 .first;
2112
2113 temperature_variance_integral +=
2114 (local_temperature_values[q] - temperature_average) *
2115 (local_temperature_values[q] - temperature_average) *
2116 phase_coefficient * fe_values_ht.JxW(q);
2117 } // end loop on quadrature points
2118 }
2119 } // end loop on cell
2120
2121 temperature_variance_integral =
2122 Utilities::MPI::sum(temperature_variance_integral, mpi_communicator);
2123 double temperature_variance = temperature_variance_integral / volume_integral;
2124 double temperature_std_deviation = std::sqrt(temperature_variance);
2125
2126 // Console output
2127 if (simulation_parameters.post_processing.verbosity ==
2129 {
2130 std::string temperature_label =
2131 time_average ? "Time-averaged temperature statistics on " :
2132 "Temperature statistics on ";
2133 this->pcout << temperature_label << domain_name << ": " << std::endl;
2134 this->pcout << "\t Min: " << minimum_temperature << std::endl;
2135 this->pcout << "\t Max: " << maximum_temperature << std::endl;
2136 this->pcout << "\t Average: " << temperature_average << std::endl;
2137 this->pcout << "\t Std-Dev: " << temperature_std_deviation << std::endl;
2138 }
2139
2140 // Fill table
2141 if (!time_average)
2142 {
2143 this->statistics_table.add_value(
2144 "time", this->simulation_control->get_current_time());
2145 this->statistics_table.add_value("min", minimum_temperature);
2146 this->statistics_table.add_value("max", maximum_temperature);
2147 this->statistics_table.add_value("average", temperature_average);
2148 this->statistics_table.add_value("std-dev", temperature_std_deviation);
2149 }
2150 else
2151 {
2152 this->statistics_table.add_value("min_time_average", minimum_temperature);
2153 this->statistics_table.add_value("max_time_average", maximum_temperature);
2154 this->statistics_table.add_value("time_average_average",
2155 temperature_average);
2156 this->statistics_table.add_value("std-dev_time_average",
2157 temperature_std_deviation);
2158 }
2159}
2160
2161template <int dim>
2162void
2164{
2165 auto mpi_communicator = triangulation->get_mpi_communicator();
2166
2167 if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
2168 {
2169 std::string filename =
2170 simulation_parameters.simulation_control.output_folder +
2171 simulation_parameters.post_processing.temperature_output_name + "_" +
2172 domain_name + ".dat";
2173 std::ofstream output(filename.c_str());
2174
2175 this->statistics_table.write_text(output);
2176 }
2177}
2178
2179template <int dim>
2180void
2182{
2183 const unsigned int n_q_points = this->cell_quadrature->size();
2184 const MPI_Comm mpi_communicator = this->dof_handler->get_mpi_communicator();
2185
2186 // Local variable to check if it is a CLS simulation
2187 const bool gather_cls = this->simulation_parameters.multiphysics.CLS;
2188
2189 AssertThrow(!(!gather_cls && this->simulation_parameters.post_processing
2190 .monitored_fluid_with_phase_change ==
2192 ExcMessage(
2193 "For single-fluid flows only 'fluid_0' can be monitored."));
2194
2195 // Initialize heat transfer information
2196 std::vector<double> local_temperature_values(n_q_points);
2197 FEValues<dim> fe_values_ht(*this->temperature_mapping,
2198 *this->fe,
2199 *this->cell_quadrature,
2200 update_values | update_JxW_values);
2201
2202 // Initialize CLS information
2203 std::shared_ptr<const DoFHandler<dim>> dof_handler_cls;
2204 std::shared_ptr<FEValues<dim>> fe_values_cls;
2205 std::vector<double> filtered_phase_values(n_q_points);
2206
2207 // Get the raw physical properties parameters to calculate the liquid fraction
2208 // in-situ
2209 const auto &physical_properties_parameters =
2210 this->simulation_parameters.physical_properties_manager
2211 .get_physical_properties_parameters();
2212
2213 if (gather_cls)
2214 {
2215 dof_handler_cls = std::shared_ptr<const DoFHandler<dim>>(
2216 &this->multiphysics->get_dof_handler(PhysicsID::CLS),
2217 [](const DoFHandler<dim> *) {});
2218 fe_values_cls =
2219 std::make_shared<FEValues<dim>>(*this->temperature_mapping,
2220 dof_handler_cls->get_fe(),
2221 *this->cell_quadrature,
2222 update_values);
2223 }
2224
2225 // Variables for the integration
2226 double liquid_volume_integral(0.);
2227
2228 // Calculate min, max and average
2229 for (const auto &cell : this->dof_handler->active_cell_iterators())
2230 {
2231 if (cell->is_locally_owned())
2232 {
2233 // Gather heat transfer information
2234 fe_values_ht.reinit(cell);
2235 fe_values_ht.get_function_values(*this->present_solution,
2236 local_temperature_values);
2237
2238 if (gather_cls)
2239 {
2240 // Get CLS active cell iterator
2241 typename DoFHandler<dim>::active_cell_iterator cell_cls(
2242 &(*(this->triangulation)),
2243 cell->level(),
2244 cell->index(),
2245 &(*dof_handler_cls));
2246
2247 // Gather CLS information
2248 fe_values_cls->reinit(cell_cls);
2249 fe_values_cls->get_function_values(
2250 this->multiphysics->get_filtered_solution(PhysicsID::CLS),
2251 filtered_phase_values);
2252 }
2253
2254 for (unsigned int q = 0; q < n_q_points; q++)
2255 {
2256 // If CLS is enabled, gather the liquid fraction if the fluid has
2257 // a phase indicator
2258 if (!gather_cls)
2259 {
2260 liquid_volume_integral +=
2261 calculate_liquid_fraction(local_temperature_values[q],
2262 physical_properties_parameters
2263 .fluids[0]
2264 .phase_change_parameters) *
2265 fe_values_ht.JxW(q);
2266 }
2267 else
2268 {
2269 // Case of fluid 0 being a phase change
2270 if (this->simulation_parameters.post_processing
2271 .monitored_fluid_with_phase_change ==
2273 {
2274 liquid_volume_integral +=
2275 (1. - filtered_phase_values[q]) *
2276 calculate_liquid_fraction(local_temperature_values[q],
2277 physical_properties_parameters
2278 .fluids[0]
2279 .phase_change_parameters) *
2280 fe_values_ht.JxW(q);
2281 }
2282
2283 // Case of fluid 1 being a phase change
2284 if (this->simulation_parameters.post_processing
2285 .monitored_fluid_with_phase_change ==
2287 {
2288 liquid_volume_integral +=
2289 (filtered_phase_values[q]) *
2290 calculate_liquid_fraction(local_temperature_values[q],
2291 physical_properties_parameters
2292 .fluids[1]
2293 .phase_change_parameters) *
2294 fe_values_ht.JxW(q);
2295 }
2296 }
2297 } // end loop on quadrature points
2298 }
2299 } // end loop on cell
2300
2301 liquid_volume_integral =
2302 Utilities::MPI::sum(liquid_volume_integral, mpi_communicator);
2303
2304 // Initialize table column names
2305 std::string melt_volume_column_name, melt_volume_console_string;
2306 if constexpr (dim == 2)
2307 {
2308 melt_volume_column_name = "melt_surface_alge";
2309 melt_volume_console_string = "melt surface alge";
2310 }
2311 else if constexpr (dim == 3)
2312 {
2313 melt_volume_column_name = "melt_volume_alge";
2314 melt_volume_console_string = "melt volume alge";
2315 }
2316
2317 // Console output
2318 if (simulation_parameters.post_processing.verbosity ==
2320 {
2321 this->pcout << melt_volume_console_string << ": "
2322 << liquid_volume_integral << std::endl;
2323 }
2324
2325 // Fill table
2326 this->melt_volume_alge_table.add_value(
2327 "time", this->simulation_control->get_current_time());
2328 this->melt_volume_alge_table.set_scientific("time", true);
2329 this->melt_volume_alge_table.add_value(melt_volume_column_name,
2330 liquid_volume_integral);
2331 this->melt_volume_alge_table.set_precision(melt_volume_column_name, 8);
2332 this->melt_volume_alge_table.set_scientific(melt_volume_column_name, true);
2333}
2334
2335template <int dim>
2336void
2338{
2339 auto mpi_communicator = triangulation->get_mpi_communicator();
2340
2341 if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
2342 {
2343 std::string filename =
2344 simulation_parameters.simulation_control.output_folder +
2345 simulation_parameters.post_processing
2346 .algebraic_melt_volume_output_name +
2347 ".dat";
2348 std::ofstream output(filename.c_str());
2349
2350 this->melt_volume_alge_table.write_text(output);
2351 }
2352}
2353
2354template <int dim>
2355void
2357{
2358 const MPI_Comm mpi_communicator = this->dof_handler->get_mpi_communicator();
2359
2360 // Local variable to check if it is a CLS simulation
2361 const bool gather_cls = this->simulation_parameters.multiphysics.CLS;
2362
2363 AssertThrow(!(!gather_cls && this->simulation_parameters.post_processing
2364 .monitored_fluid_with_phase_change ==
2366 ExcMessage(
2367 "For single-fluid flows only 'fluid_0' can be monitored."));
2368
2369 // Initializes variables for the melt volume and surface
2370 double melt_volume;
2371 double melt_surface;
2372
2373 // Initialize melt indicator vectors
2374 GlobalVectorType melt_indicator_vector_owned_copy(
2375 this->dof_handler->locally_owned_dofs(), mpi_communicator);
2376 GlobalVectorType melt_indicator_vector_relevant_copy(
2377 this->dof_handler->locally_owned_dofs(),
2378 DoFTools::extract_locally_relevant_dofs(*this->dof_handler),
2379 mpi_communicator);
2380
2381 // For single fluid flows
2382 const double melting_temperature =
2383 this->simulation_parameters.post_processing.melting_temperature;
2384
2385 // Initialize CLS related objects
2386 std::shared_ptr<const DoFHandler<dim>> dof_handler_cls;
2387 std::shared_ptr<NonMatching::FEValues<dim>> non_matching_fe_values_cls;
2388 std::shared_ptr<GlobalVectorType> phase_indicator_vector_owned_copy;
2389 const double phase_indicator_interface_value = 0.5;
2390
2391 if (gather_cls)
2392 {
2393 // Get liquidus temperature and generate signed phase indicator level set
2394 // for intersection operation
2395 dof_handler_cls = std::shared_ptr<const DoFHandler<dim>>(
2396 &this->multiphysics->get_dof_handler(PhysicsID::CLS),
2397 [](const DoFHandler<dim> *) {});
2398
2399 // Local copy to shift phase indicator solution to make the region of
2400 // interest 'inside' (negative values)
2401 phase_indicator_vector_owned_copy = std::make_shared<GlobalVectorType>();
2402 phase_indicator_vector_owned_copy->reinit(
2403 this->dof_handler->locally_owned_dofs(), mpi_communicator);
2404 FETools::interpolate(
2405 *dof_handler_cls,
2406 this->multiphysics->get_solution(PhysicsID::CLS),
2407 *this->dof_handler,
2408 *phase_indicator_vector_owned_copy); // Ensure DoF correspondence for
2409 // intersection vector later
2410 phase_indicator_vector_owned_copy->add(-phase_indicator_interface_value);
2411 if (this->simulation_parameters.post_processing
2412 .monitored_fluid_with_phase_change ==
2414 phase_indicator_vector_owned_copy->operator*=(-1);
2415
2416 // Get the intersection region between the monitored fluid and the
2417 // melting temperature isocurve
2418 for (const auto dof_id : this->dof_handler->locally_owned_dofs())
2419 {
2420 melt_indicator_vector_owned_copy[dof_id] =
2421 std::max<double>((-1.0 * ((*this->present_solution)[dof_id] -
2422 melting_temperature)),
2423 (*phase_indicator_vector_owned_copy)[dof_id]);
2424 }
2425 melt_indicator_vector_relevant_copy = melt_indicator_vector_owned_copy;
2426 }
2427 else // Single-fluid flow
2428 {
2429 // Transpose temperature to get volume of the region where the temperature
2430 // is over the melting temperature
2431 melt_indicator_vector_owned_copy = *this->present_solution;
2432 melt_indicator_vector_owned_copy.add(-melting_temperature);
2433 melt_indicator_vector_owned_copy.operator*=(
2434 -1); // Make the liquid region 'inside' (negative values) for the
2435 // NonMatching MeshClassifier.
2436 melt_indicator_vector_relevant_copy = melt_indicator_vector_owned_copy;
2437 }
2438
2439 // Compute volume and surface integral
2440 std::tie(melt_volume, melt_surface) =
2442 *this->dof_handler, *this->fe, melt_indicator_vector_relevant_copy);
2443
2444 // Initialize table column names
2445 std::string melt_volume_column_name, melt_volume_console_string;
2446 std::string melt_contour_column_name, melt_contour_console_string;
2447 if constexpr (dim == 2)
2448 {
2449 melt_volume_column_name = "melt_surface_geo";
2450 melt_contour_column_name = "melt_contour_length_geo";
2451 melt_volume_console_string = "melt surface geo";
2452 melt_contour_console_string = "melt contour length geo";
2453 }
2454 else if constexpr (dim == 3)
2455 {
2456 melt_volume_column_name = "melt_volume_geo";
2457 melt_contour_column_name = "melt_contour_surface_geo";
2458 melt_volume_console_string = "melt volume geo";
2459 melt_contour_console_string = "melt contour surface geo";
2460 }
2461
2462 // Console output
2463 if (simulation_parameters.post_processing.verbosity ==
2465 {
2466 this->pcout << melt_volume_console_string << ": " << melt_volume
2467 << std::endl;
2468 this->pcout << melt_contour_console_string << ": " << melt_surface
2469 << std::endl;
2470 }
2471
2472 // Fill table
2473 this->melt_volume_geo_table.add_value(
2474 "time", this->simulation_control->get_current_time());
2475 this->melt_volume_geo_table.set_scientific("time", true);
2476 this->melt_volume_geo_table.add_value(melt_volume_column_name, melt_volume);
2477 this->melt_volume_geo_table.set_precision(melt_volume_column_name, 8);
2478 this->melt_volume_geo_table.set_scientific(melt_volume_column_name, true);
2479 this->melt_volume_geo_table.add_value(melt_contour_column_name, melt_surface);
2480 this->melt_volume_geo_table.set_precision(melt_contour_column_name, 8);
2481 this->melt_volume_geo_table.set_scientific(melt_contour_column_name, true);
2482}
2483
2484template <int dim>
2485void
2487{
2488 auto mpi_communicator = triangulation->get_mpi_communicator();
2489
2490 if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
2491 {
2492 std::string filename =
2493 simulation_parameters.simulation_control.output_folder +
2494 simulation_parameters.post_processing
2495 .geometric_melt_volume_output_name +
2496 ".dat";
2497 std::ofstream output(filename.c_str());
2498
2499 this->melt_volume_geo_table.write_text(output);
2500 }
2501}
2502
2503template <int dim>
2504template <typename VectorType>
2505void
2507 const bool gather_cls,
2508 const VectorType &current_solution_fd)
2509{
2510 const unsigned int n_q_points_face = this->face_quadrature->size();
2511 const MPI_Comm mpi_communicator = this->dof_handler->get_mpi_communicator();
2512
2513 // Initialize heat transfer information
2514 std::vector<double> local_temperature_values(n_q_points_face);
2515 std::vector<Tensor<1, dim>> temperature_gradient(n_q_points_face);
2516 FEFaceValues<dim> fe_face_values_ht(*this->temperature_mapping,
2517 this->dof_handler->get_fe(),
2518 *this->face_quadrature,
2519 update_values | update_gradients |
2520 update_JxW_values |
2521 update_normal_vectors);
2522
2523 // Initialize fluid dynamics information
2524 const DoFHandler<dim> &dof_handler_fd =
2525 multiphysics->get_dof_handler(PhysicsID::fluid_dynamics);
2526 const FEValuesExtractors::Vector velocities(0);
2527 std::vector<Tensor<1, dim>> local_velocity_values(n_q_points_face);
2528 FEFaceValues<dim> fe_face_values_fd(*this->temperature_mapping,
2529 dof_handler_fd.get_fe(),
2530 *this->face_quadrature,
2531 update_values);
2532
2533 // Initialize CLS information
2534 std::shared_ptr<const DoFHandler<dim>> dof_handler_cls;
2535 std::shared_ptr<FEFaceValues<dim>> fe_face_values_cls;
2536 std::vector<double> filtered_phase_values(n_q_points_face);
2537
2538 if (gather_cls)
2539 {
2540 dof_handler_cls = std::shared_ptr<const DoFHandler<dim>>(
2541 &this->multiphysics->get_dof_handler(PhysicsID::CLS),
2542 [](const DoFHandler<dim> *) {});
2543 fe_face_values_cls =
2544 std::make_shared<FEFaceValues<dim>>(*this->temperature_mapping,
2545 dof_handler_cls->get_fe(),
2546 *this->face_quadrature,
2547 update_values);
2548 }
2549
2550 // Initialize fluid properties
2551 auto &properties_manager =
2552 this->simulation_parameters.physical_properties_manager;
2553 std::map<field, double> field_values;
2554 std::map<field, std::vector<double>> fields;
2555
2556 // monophase flow
2557 double density(0.);
2558 double specific_heat(0.);
2559 double thermal_conductivity(0.);
2560
2561 // multiphase flow
2562 std::vector<double> density_0(n_q_points_face);
2563 std::vector<double> specific_heat_0(n_q_points_face);
2564 std::vector<double> thermal_conductivity_0(n_q_points_face);
2565 std::vector<double> density_1(n_q_points_face);
2566 std::vector<double> specific_heat_1(n_q_points_face);
2567 std::vector<double> thermal_conductivity_1(n_q_points_face);
2568
2569 switch (properties_manager.get_number_of_fluids())
2570 {
2571 default:
2572 {
2573 // Get values for monophase flow
2574 const auto density_model = properties_manager.get_density();
2575 const auto specific_heat_model =
2576 properties_manager.get_specific_heat();
2577 const auto conductivity_model =
2578 properties_manager.get_thermal_conductivity();
2579
2580 density = density_model->value(field_values);
2581 specific_heat = specific_heat_model->value(field_values);
2582 thermal_conductivity = conductivity_model->value(field_values);
2583
2584 break;
2585 }
2586 case 2:
2587 {
2588 // Get prm values for multiphase flow - will be blended in the
2589 // integration loop
2590 const auto density_models = properties_manager.get_density_vector();
2591 const auto specific_heat_models =
2592 properties_manager.get_specific_heat_vector();
2593 const auto thermal_conductivity_models =
2594 properties_manager.get_thermal_conductivity_vector();
2595
2596 density_models[0]->vector_value(fields, density_0);
2597 specific_heat_models[0]->vector_value(fields, specific_heat_0);
2598 thermal_conductivity_models[0]->vector_value(fields,
2599 thermal_conductivity_0);
2600
2601 density_models[1]->vector_value(fields, density_1);
2602 specific_heat_models[1]->vector_value(fields, specific_heat_1);
2603 thermal_conductivity_models[1]->vector_value(fields,
2604 thermal_conductivity_1);
2605
2606 break;
2607 }
2608 } // end switch on number of fluids
2609
2610 std::map<types::boundary_id, double> heat_flux;
2611 std::map<types::boundary_id, double> convective_flux;
2612
2613 // Get vector of heat transfer boundary conditions
2614 for (const auto &cell : this->dof_handler->active_cell_iterators())
2615 {
2616 if (cell->is_locally_owned() && cell->at_boundary())
2617 {
2618 for (const auto face : cell->face_indices())
2619 {
2620 if (cell->face(face)->at_boundary())
2621 {
2622 types::boundary_id boundary_index =
2623 cell->face(face)->boundary_id();
2624
2625 // Gather h coefficient and T_inf
2626 const double h_coefficient =
2627 this->simulation_parameters.boundary_conditions_ht.h
2628 .at(boundary_index)
2629 ->value(Point<dim>());
2630 const double T_inf =
2631 this->simulation_parameters.boundary_conditions_ht.Tinf
2632 .at(boundary_index)
2633 ->value(Point<dim>());
2634
2635
2636 // Gather heat transfer information
2637 fe_face_values_ht.reinit(cell, face);
2638 fe_face_values_ht.get_function_values(
2639 *this->present_solution, local_temperature_values);
2640 fe_face_values_ht.get_function_gradients(
2641 *this->present_solution, temperature_gradient);
2642
2643 // Get fluid dynamics active cell iterator
2644 typename DoFHandler<dim>::active_cell_iterator cell_fd(
2645 &(*(this->triangulation)),
2646 cell->level(),
2647 cell->index(),
2648 &dof_handler_fd);
2649
2650 // Gather fluid dynamics information
2651 fe_face_values_fd.reinit(cell_fd, face);
2652 fe_face_values_fd[velocities].get_function_values(
2653 current_solution_fd, local_velocity_values);
2654
2655 if (gather_cls)
2656 {
2657 // Get CLS active cell iterator
2658 typename DoFHandler<dim>::active_cell_iterator cell_cls(
2659 &(*(this->triangulation)),
2660 cell->level(),
2661 cell->index(),
2662 &(*dof_handler_cls));
2663
2664 // Gather CLS information
2665 fe_face_values_cls->reinit(cell_cls, face);
2666 fe_face_values_cls->get_function_values(
2667 this->multiphysics->get_filtered_solution(
2669 filtered_phase_values);
2670 }
2671
2672 // Loop on the quadrature points
2673 for (unsigned int q = 0; q < n_q_points_face; q++)
2674 {
2675 if (properties_manager.get_number_of_fluids() == 2)
2676 {
2677 // Blend the physical properties using the CLS
2678 // field
2679 thermal_conductivity =
2680 calculate_point_property(filtered_phase_values[q],
2681 thermal_conductivity_0[q],
2682 thermal_conductivity_1[q]);
2683
2684 density =
2685 calculate_point_property(filtered_phase_values[q],
2686 density_0[q],
2687 density_1[q]);
2688
2689 specific_heat =
2690 calculate_point_property(filtered_phase_values[q],
2691 specific_heat_0[q],
2692 specific_heat_1[q]);
2693 }
2694
2695 Tensor<1, dim> normal_vector_ht =
2696 -fe_face_values_ht.normal_vector(q);
2697
2698 heat_flux[boundary_index] +=
2699 (-thermal_conductivity * temperature_gradient[q] *
2700 normal_vector_ht +
2701 local_temperature_values[q] * density * specific_heat *
2702 local_velocity_values[q] * normal_vector_ht) *
2703 fe_face_values_ht.JxW(q);
2704
2705 convective_flux[boundary_index] +=
2706 h_coefficient * (local_temperature_values[q] - T_inf) *
2707 fe_face_values_ht.JxW(q);
2708
2709 } // end loop on quadrature points
2710 } // end loop on faces
2711 } // end face is a boundary face
2712 } // end condition cell at boundary
2713 } // end loop on cells
2714
2715
2716 // Sum across all cores
2717 for (auto const &[id, type] :
2718 this->simulation_parameters.boundary_conditions_ht.type)
2719 {
2720 heat_flux[id] = Utilities::MPI::sum(heat_flux[id], mpi_communicator);
2721
2722 convective_flux[id] =
2723 Utilities::MPI::sum(convective_flux[id], mpi_communicator);
2724 }
2725
2726 // Console output
2727 if (simulation_parameters.post_processing.verbosity ==
2729 {
2730 this->pcout
2731 << "Total heat flux at the heat transfer boundary conditions : "
2732 << std::endl;
2733 for (auto const &[id, type] :
2734 this->simulation_parameters.boundary_conditions_ht.type)
2735 this->pcout << "\t boundary " << id << " : " << heat_flux.at(id)
2736 << std::endl;
2737
2738
2739 this->pcout
2740 << "Convective heat flux at the heat transfer boundary conditions : "
2741 << std::endl;
2742 for (auto const &[id, type] :
2743 this->simulation_parameters.boundary_conditions_ht.type)
2744 this->pcout << "\t boundary " << id << " : " << convective_flux.at(id)
2745 << std::endl;
2746 }
2747
2748 // Filling table
2749 this->heat_flux_table.add_value("time",
2750 this->simulation_control->get_current_time());
2751 for (auto const &[id, type] :
2752 this->simulation_parameters.boundary_conditions_ht.type)
2753 {
2754 this->heat_flux_table.add_value("total_flux_bc_" +
2755 Utilities::int_to_string(id, 1),
2756 heat_flux.at(id));
2757 this->heat_flux_table.add_value("convective_flux_bc_" +
2758 Utilities::int_to_string(id, 1),
2759 convective_flux.at(id));
2760 }
2761}
2762
2763template void
2765 const bool gather_cls,
2766 const GlobalVectorType &current_solution_fd);
2767
2768template void
2770 const bool gather_cls,
2771 const GlobalVectorType &current_solution_fd);
2772
2773template void
2775 const bool gather_cls,
2776 const GlobalBlockVectorType &current_solution_fd);
2777
2778template void
2780 const bool gather_cls,
2781 const GlobalBlockVectorType &current_solution_fd);
2782
2783template <int dim>
2784template <typename VectorType>
2785void
2787 const bool gather_cls,
2788 const Parameters::FluidIndicator monitored_fluid,
2789 const std::string &domain_name,
2790 const VectorType &current_solution_fd)
2791{
2792 const unsigned int n_q_points = this->cell_quadrature->size();
2793 const MPI_Comm mpi_communicator = this->dof_handler->get_mpi_communicator();
2794
2795 // Initialize heat transfer information
2796 std::vector<double> local_temperature_values(n_q_points);
2797 std::vector<Tensor<1, dim>> temperature_gradient(n_q_points);
2798 FEValues<dim> fe_values_ht(*this->temperature_mapping,
2799 this->dof_handler->get_fe(),
2800 *this->cell_quadrature,
2801 update_values | update_JxW_values);
2802
2803 // Initialize fluid dynamics information
2804 const DoFHandler<dim> &dof_handler_fd =
2805 multiphysics->get_dof_handler(PhysicsID::fluid_dynamics);
2806 const FEValuesExtractors::Vector velocities(0);
2807 std::vector<Tensor<1, dim>> local_velocity_values(n_q_points);
2808 FEValues<dim> fe_values_fd(*this->temperature_mapping,
2809 dof_handler_fd.get_fe(),
2810 *this->cell_quadrature,
2811 update_values);
2812
2813 // Initialize CLS information
2814 std::shared_ptr<const DoFHandler<dim>> dof_handler_cls;
2815 std::shared_ptr<FEValues<dim>> fe_values_cls;
2816 std::vector<double> filtered_phase_values(n_q_points);
2817
2818 if (gather_cls)
2819 {
2820 dof_handler_cls = std::shared_ptr<const DoFHandler<dim>>(
2821 &this->multiphysics->get_dof_handler(PhysicsID::CLS),
2822 [](const DoFHandler<dim> *) {});
2823 fe_values_cls =
2824 std::make_shared<FEValues<dim>>(*this->temperature_mapping,
2825 dof_handler_cls->get_fe(),
2826 *this->cell_quadrature,
2827 update_values);
2828 }
2829
2830 // Initialize fluid properties
2831 auto &properties_manager =
2832 this->simulation_parameters.physical_properties_manager;
2833 std::map<field, double> field_values;
2834 std::map<field, std::vector<double>> fields;
2835
2836 // monophase flow
2837 double density(0.);
2838 double specific_heat(0.);
2839
2840 // multiphase flow
2841 std::vector<double> density_0(n_q_points);
2842 std::vector<double> specific_heat_0(n_q_points);
2843 std::vector<double> density_1(n_q_points);
2844 std::vector<double> specific_heat_1(n_q_points);
2845
2846 switch (properties_manager.get_number_of_fluids())
2847 {
2848 default:
2849 {
2850 // Get values for monophase flow
2851 const auto density_model = properties_manager.get_density();
2852 const auto specific_heat_model =
2853 properties_manager.get_specific_heat();
2854
2855 density = density_model->value(field_values);
2856 specific_heat = specific_heat_model->value(field_values);
2857
2858 break;
2859 }
2860 case 2:
2861 {
2862 // Get prm values for multiphase flow - will be blended in the
2863 // integration loop
2864 const auto density_models = properties_manager.get_density_vector();
2865 const auto specific_heat_models =
2866 properties_manager.get_specific_heat_vector();
2867
2868 density_models[0]->vector_value(fields, density_0);
2869 specific_heat_models[0]->vector_value(fields, specific_heat_0);
2870
2871 density_models[1]->vector_value(fields, density_1);
2872 specific_heat_models[1]->vector_value(fields, specific_heat_1);
2873
2874 break;
2875 }
2876 } // end switch on number of fluids
2877
2878 // Other initializations
2879 double phase_coefficient(0.);
2880 double heat_in_domain(0.);
2881
2882 // Integrate on all domain
2883 for (const auto &cell : this->dof_handler->active_cell_iterators())
2884 {
2885 if (cell->is_locally_owned())
2886 {
2887 // Gather heat transfer information
2888 fe_values_ht.reinit(cell);
2889 fe_values_ht.get_function_values(*this->present_solution,
2890 local_temperature_values);
2891
2892 // Get fluid dynamics active cell iterator
2893 typename DoFHandler<dim>::active_cell_iterator cell_fd(
2894 &(*(this->triangulation)),
2895 cell->level(),
2896 cell->index(),
2897 &dof_handler_fd);
2898
2899 // Gather fluid dynamics information
2900 fe_values_fd.reinit(cell_fd);
2901 fe_values_fd[velocities].get_function_values(current_solution_fd,
2902 local_velocity_values);
2903
2904 if (gather_cls)
2905 {
2906 // Get CLS active cell iterator
2907 typename DoFHandler<dim>::active_cell_iterator cell_cls(
2908 &(*(this->triangulation)),
2909 cell->level(),
2910 cell->index(),
2911 &(*dof_handler_cls));
2912
2913 // Gather CLS information
2914 fe_values_cls->reinit(cell_cls);
2915 fe_values_cls->get_function_values(
2916 this->multiphysics->get_filtered_solution(PhysicsID::CLS),
2917 filtered_phase_values);
2918 }
2919
2920 // Loop on the quadrature points
2921 for (unsigned int q = 0; q < n_q_points; q++)
2922 {
2923 phase_coefficient =
2924 set_phase_coefficient(gather_cls,
2925 monitored_fluid,
2926 filtered_phase_values[q])
2927 .first;
2928
2929 if (properties_manager.get_number_of_fluids() == 2)
2930 {
2931 // Blend the physical properties using the CLS
2932 // field
2933 density = calculate_point_property(filtered_phase_values[q],
2934 density_0[q],
2935 density_1[q]);
2936
2937 specific_heat =
2938 calculate_point_property(filtered_phase_values[q],
2939 specific_heat_0[q],
2940 specific_heat_1[q]);
2941 }
2942
2943 heat_in_domain +=
2944 (density * specific_heat * local_temperature_values[q]) *
2945 phase_coefficient * fe_values_ht.JxW(q);
2946
2947 } // end loop on quadrature points
2948 }
2949 } // end loop on cells
2950
2951 heat_in_domain = Utilities::MPI::sum(heat_in_domain, mpi_communicator);
2952
2953 // Console output
2954 if (simulation_parameters.post_processing.verbosity ==
2956 {
2957 this->pcout << "Thermal energy in " << domain_name << " : "
2958 << heat_in_domain << std::endl;
2959 }
2960
2961 // Filling table
2962 this->heat_flux_table.add_value("thermal_energy_" + domain_name,
2963 heat_in_domain);
2964}
2965
2966template void
2968 const bool gather_cls,
2969 const Parameters::FluidIndicator monitored_fluid,
2970 const std::string &domain_name,
2971 const GlobalVectorType &current_solution_fd);
2972
2973template void
2975 const bool gather_cls,
2976 const Parameters::FluidIndicator monitored_fluid,
2977 const std::string &domain_name,
2978 const GlobalVectorType &current_solution_fd);
2979
2980template void
2982 const bool gather_cls,
2983 const Parameters::FluidIndicator monitored_fluid,
2984 const std::string &domain_name,
2985 const GlobalBlockVectorType &current_solution_fd);
2986
2987template void
2989 const bool gather_cls,
2990 const Parameters::FluidIndicator monitored_fluid,
2991 const std::string &domain_name,
2992 const GlobalBlockVectorType &current_solution_fd);
2993
2994template <int dim>
2995void
2996HeatTransfer<dim>::write_heat_flux(const std::string &domain_name)
2997{
2998 auto mpi_communicator = triangulation->get_mpi_communicator();
2999
3000 if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
3001 {
3002 std::string filename =
3003 simulation_parameters.simulation_control.output_folder +
3004 simulation_parameters.post_processing.heat_flux_output_name + "_" +
3005 domain_name + ".dat";
3006 std::ofstream output(filename.c_str());
3007
3008 this->heat_flux_table.write_text(output);
3009 }
3010}
3011
3012template <int dim>
3013std::pair<double, bool>
3015 const bool gather_cls,
3016 const Parameters::FluidIndicator monitored_fluid,
3017 const double phase_value_q)
3018{
3019 double phase_coefficient(0.);
3020 bool point_is_in_postprocessed_fluid(false);
3021
3022 switch (monitored_fluid)
3023 {
3024 default:
3025 {
3026 // Parameters::FluidIndicator::both
3027 phase_coefficient = 1.;
3028 point_is_in_postprocessed_fluid = true;
3029 break;
3030 }
3032 {
3033 if (gather_cls)
3034 {
3035 phase_coefficient = 1. - phase_value_q;
3036 if (phase_value_q < 0.5)
3037 point_is_in_postprocessed_fluid = true;
3038 }
3039 else
3040 {
3041 // In the case of monophase simulations, "fluid_0" is
3042 // equivalent to "both" (all domain) calculation
3043 phase_coefficient = 1.;
3044 point_is_in_postprocessed_fluid = true;
3045 }
3046 break;
3047 }
3049 {
3050 if (gather_cls)
3051 {
3052 phase_coefficient = phase_value_q;
3053 if (phase_value_q > 0.5)
3054 point_is_in_postprocessed_fluid = true;
3055 }
3056 else
3057 {
3058 // Defensive only here, this has been checked already
3059 // in simulation_parameters.h
3060 throw std::logic_error(
3061 "Inconsistency in .prm!\n when CLS = false"
3062 "\n use (default value): set postprocessed fluid = both"
3063 "\n or: set postprocessed fluid = fluid_0");
3064 }
3065 break;
3066 }
3067 } // end switch on monitored fluid
3068
3069 return std::make_pair(phase_coefficient, point_is_in_postprocessed_fluid);
3070}
3071
3072template class HeatTransfer<2>;
3073template class HeatTransfer<3>;
Compute the local heat flux vector field within a domain.
Class that assembles the transient time arising from BDF time integration for the heat transfer solve...
Class that assembles the evaporation sink for the heat transfer solver at the free surface (air/metal...
Class that assembles the core of the heat transfer equation. This class assembles the weak form of: ...
Class that assembles the Discontinuity-Capturing Directional Dissipation stabilization term for the h...
Class that assembles the radiation sink for the heat transfer solver at the free surface (air/metal i...
Class that assembles the laser heating as a volumetric source for the heat transfer solver when CLS i...
Class that assembles the laser heating as a volumetric source for the heat transfer solver....
Class that assembles the laser heating as a surface flux for the heat transfer solver when CLS is ena...
Class that assembles the laser heating as a uniform surface flux for the heat transfer solver when CL...
Class that assembles the time average electromagnetic heating for the heat transfer solver when the t...
Class that assembles the Robin boundary condition for the heat transfer solver.
Class that assembles the viscous dissipation for the heat transfer solver, for the specific case of C...
Class that assembles the viscous dissipation for the heat transfer solver.
Class that stores the information required by the assembly procedure for a heat transfer advection-di...
void reinit_cls(const typename DoFHandler< dim >::active_cell_iterator &cell, const VectorType &current_solution, const VectorType &current_filtered_solution)
Reinitialize the content of the scratch for CLS.
void reinit_fluid_dynamics(const typename DoFHandler< dim >::active_cell_iterator &cell, const VectorType &current_solution, const Parameters::ALE< dim > &ale)
Reinitialize cell's velocity and pressure values with values calculated in the Fluid Dynamics (FD) ph...
void calculate_physical_properties()
Calculates the physical properties. This method calculates the physical properties that may be requir...
void reinit_velocity_gradient(const VectorType &current_solution)
Reinitialize the velocity gradient, calculated by the Fluid Dynamics.
void reinit_time_harmonic_maxwell(const typename DoFHandler< dim >::active_cell_iterator &cell, const VectorType &current_solution)
Reinitialize the content of the scratch for the time-harmonic Maxwell problem.
void reinit(const typename DoFHandler< dim >::active_cell_iterator &cell, const VectorType &current_solution, const std::vector< GlobalVectorType > &previous_solutions, Function< dim > *source_function)
Reinitializes the content of the scratch.
Implementation of heat transfer as an auxiliary physics. The heat equation is weakly coupled to the v...
void write_geometric_melt_volume()
Write the geometric melt volume to an output file.
void percolate_time_vectors() override
Rearrange vector solution correctly for transient simulations.
void write_algebraic_melt_volume()
Post-processing. Write the algebraic melt volume to an output file.
TimerOutput computing_timer
Store information related to the computing time such as CPU times or wall time.
void assemble_nitsche_heat_restriction(const bool assemble_matrix)
Call for the assembly of the matrix and the right-hand side of the Nitsche restriction for the heat t...
GlobalVectorType local_evaluation_point
The local evaluation point. Ghosts cells are not considered in this evaluation.
void postprocess_geometric_melt_volume_and_surface()
Compute the geometric melt volume (3D) or surface (2D) and the contour surface area (3D) or length (2...
void solve_linear_system() override
Call for the solution of the linear system of equation using ILU or GMRES.
IndexSet locally_owned_dofs
Store a subset of the DoF indices that are stored on a particular processor on a distributed architec...
std::shared_ptr< SimulationControl > simulation_control
Responsible for the control of steady-state and transient simulations. Contains all the information r...
GlobalVectorType average_temperature_to_output
Locally owned average temperature calculated using the AverageScalar object.
double calculate_L2_error()
Calculate the L2 error of the solution.
TableHandler melt_volume_geo_table
Evolution of the melt volume in the simulated domain.
TableHandler heat_flux_table
Contain heat flux information used for post-processing:
std::shared_ptr< AverageScalar< dim > > average_temperature
Compute the average temperature in time.
std::shared_ptr< TrilinosWrappers::PreconditionAMG > amg_preconditioner
AMG preconditioner used by the iterative linear solver.
void postprocess_algebraic_melt_volume()
Compute the algebraic (phase indicator and liquid fraction weighted) melt volume (3D) or surface (2D)...
MultiphysicsInterface< dim > * multiphysics
void postprocess_temperature_statistics(const bool gather_cls, const Parameters::FluidIndicator monitored_fluid, const std::string &domain_name, const bool time_average)
Post-processing. Calculate temperature statistics on the domain : Max, min, average and standard-devi...
void setup_ilu()
Set up the ILU preconditioner stored in ilu_preconditioner.
std::vector< HeatFluxPostprocessor< dim > > heat_flux_postprocessors
Compute local heat flux quantities from temperature field and material properties.
TrilinosWrappers::SparseMatrix system_matrix
The system matrix.
void output_per_iteration_timer() override
Output the per iteration wallclock times.
virtual void copy_local_matrix_to_global_matrix(const StabilizedMethodsCopyData &copy_data)
Copy local cell information to global matrix.
virtual void assemble_local_system_rhs(const typename DoFHandler< dim >::active_cell_iterator &cell, HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data)
Assemble the local rhs for a given cell.
AffineConstraints< double > zero_constraints
void compute_kelly(dealii::Vector< float > &estimated_error_per_cell, const ComponentMask &component_mask)
Compute the Kelly error estimator on the temperature variable for mesh refinement....
void write_checkpoint() override
Prepare Heat Transfer to write checkpoint.
virtual void setup_assemblers()
Set up the vector of assembler functions.
const SimulationParameters< dim > & simulation_parameters
Contain the simulation parameter file information.
void post_mesh_adaptation() override
Interpolate the auxiliary physics variables to the new mesh.
std::vector< std::shared_ptr< ThermalConductivityModel > > thermal_conductivity_models
Abstract class that allows to calculate the thermal conductivity on each quadrature point using the t...
std::shared_ptr< Quadrature< dim - 1 > > face_quadrature
Approximate an integral by evaluating the integrand at specific points and summing the point values w...
virtual void assemble_local_system_matrix(const typename DoFHandler< dim >::active_cell_iterator &cell, HeatTransferScratchData< dim > &scratch_data, StabilizedMethodsCopyData &copy_data)
Assemble the local matrix for a given cell.
std::shared_ptr< SolutionTransfer< dim, GlobalVectorType > > solution_transfer
SolutionTransfer<dim, GlobalVectorType>> is used to implement the transfer of a discrete FE function ...
std::shared_ptr< Quadrature< dim > > cell_quadrature
Approximate an integral by evaluating the integrand at specific points and summing the point values w...
void write_heat_flux(const std::string &domain_name)
Post-processing. Write the heat transfer values to an output file.
std::vector< SolutionTransfer< dim, GlobalVectorType > > previous_solutions_transfer
previous_solutions_transfer occupies the same role as solution_transfer but for solutions at previous...
std::vector< OutputStruct< dim, GlobalVectorType > > gather_output_hook() override
Gather and return vector of output structs that are particular to some applications.
std::pair< double, bool > set_phase_coefficient(const bool gather_cls, const Parameters::FluidIndicator monitored_fluid, const double phase_value_q)
Set a phase_coefficient that is used in the postprocessing, to account for multiphase flow.
void write_temperature_statistics(const std::string &domain_name)
Post-processing. Write the temperature statistics to an output file.
GlobalVectorType evaluation_point
The point at which the evaluation is performed.
void setup_amg()
Set up the AMG preconditioner stored in amg_preconditioner.
std::shared_ptr< Mapping< dim > > temperature_mapping
Transformation which maps point in the reference cell to points in the actual grid cell.
void assemble_rhs()
Call for the assembly of the right-hand side.
void read_checkpoint() override
Allow Heat Transfer to set up solution vector from checkpoint file.
GlobalVectorType newton_update
The direction used to perform the newton iteration in . Where is the size of the step.
void finish_simulation() override
Carry out the operations required to finish a simulation correctly.
std::vector< TableHandler > temperature_isocontour_bounding_values_tables
Vector of tables containing evolution of temperature isocontour bounding values.
void pre_mesh_adaptation() override
Prepare the auxiliary physics variables for a mesh refinement/coarsening.
void postprocess_thermal_energy_in_fluid(const bool gather_cls, const Parameters::FluidIndicator monitored_fluid, const std::string &domain_name, const VectorType &current_solution_fd)
std::vector< std::shared_ptr< HeatTransferAssemblerBase< dim > > > assemblers
Assemblers for the matrix and the right hand side (RHS).
void compute_error_estimate(const std::pair< const Variable, Parameters::MultipleAdaptationParameters > &ivar, dealii::Vector< float > &estimated_error_per_cell) override
Compute the error estimator for mesh refinement.
double calculate_delta_T_ref(double minimum_delta_T_ref=1.)
Calculate delta_T_ref for the DCDD shock capture mechanism. delta_T_ref = T_max - T_min.
std::vector< OutputStructTableHandler > gather_tables() override
Returns a vector of references to TableHandler objects that needs to be serialized/deserialized for t...
double get_residual_rescale_metric() const override
Return the metric for residual rescaling. By default, should return 1. If the rescale_residual_by_vol...
void update_boundary_conditions() override
Update non zero constraints if the boundary is time-dependent.
std::shared_ptr< DoFHandler< dim > > dof_handler
Given a triangulation and a description of a finite element, this class enumerates degrees of freedom...
ConvergenceTable error_table
Store some convergence data, such as residuals of the cg-method, or some evaluated L2-errors of discr...
void postprocess(bool first_iteration) override
Postprocess the auxiliary physics results. Post-processing this case implies the calculation of all d...
IndexSet locally_relevant_dofs
Store a subset of the DoF indices that contains both the locally_owned_dofs and the DoF indices on gh...
void assemble_system_matrix() override
Assemble the matrix associated with the solver.
std::vector< HeatFluxPostprocessor< dim > > average_heat_flux_postprocessors
Compute local average heat flux quantities from temperature field and material properties.
std::shared_ptr< GlobalVectorType > present_solution
A vector containing all the values of the solution.
std::shared_ptr< FiniteElement< dim > > fe
The base class for finite element.
void assemble_system_rhs() override
Assemble the rhs associated with the solver.
void setup_dofs() override
Set up the DofHandler and the degrees of freedom associated with the physics.
std::shared_ptr< std::vector< GlobalVectorType > > previous_solutions
Previous solution vector.
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
Collection of cells that cover the domain on which one wants to solve a partial differential equation...
void verify_consistency_of_boundary_conditions()
Verify consistency of the input parameters for boundary conditions to ensure that for every boundary ...
void postprocess_heat_flux_on_bc(const bool gather_cls, const VectorType &current_solution_fd)
std::shared_ptr< TrilinosWrappers::PreconditionILU > ilu_preconditioner
ILU preconditioner used by the iterative linear solver.
TableHandler statistics_table
Temperature statistics table used for post-processing. It contains the minimum , maximum,...
AffineConstraints< double > nonzero_constraints
Store the nonzero constraints that arise from several sources such as boundary conditions and hanging...
virtual void copy_local_rhs_to_global_rhs(const StabilizedMethodsCopyData &copy_data)
Copy local cell rhs information to global rhs.
void assemble_matrix_and_rhs()
Call for the assembly of the matrix and the right-hand side.
GlobalVectorType system_rhs
The right hand side vector.
void postprocess_heat_flux_on_nitsche_ib()
void set_initial_conditions() override
Set up the initial conditions associated with the physics. heat_transfer allows a temperature functio...
TableHandler melt_volume_alge_table
Liquid fraction in the domain.
Laser parameters - Defines the parameters for the laser heat source.
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
FullMatrix< double > local_matrix
Definition copy_data.h:104
void reset()
Resets the cell_matrix, cell_rhs, strong_residual and strong_jacobian to zero.
Definition copy_data.h:92
std::vector< types::global_dof_index > local_dof_indices
Definition copy_data.h:106
void serialize_tables_vector(const std::vector< OutputStructTableHandler > &table_output_structs, const MPI_Comm mpi_communicator)
Serializes all the TableHandler objects in table_output_structs.
Definition utilities.h:602
void announce_string(const ConditionalOStream &pcout, const std::string &expression, const char delimiter='-')
Prints a string and then adds a line above and below made with dashes containing as many dashes as th...
Definition utilities.h:500
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 deserialize_tables_vector(std::vector< OutputStructTableHandler > &table_output_structs, const MPI_Comm mpi_communicator)
Deserializes all the TableHandler objects in table_output_structs.
Definition utilities.h:624
DeclExceptionMsg(MeltVolumeRequiresPhaseChange, "Calculation of the melt volume requires that a fluid has at least a 'phase_change' physical property model")
@ temperature
Temperature scalar field from heat transfer.
@ fluid_dynamics
Fluid Dynamics (Velocity,Pressure).
@ electromagnetics
Time-harmonic electromagnetics (Electric field, Magnetic field).
@ CLS
@ heat_transfer
Heat transfer (Temperature).
void postprocess_isocontour_bounding_values(const Variable &variable, const std::multimap< Variable, std::pair< unsigned int, typename Parameters::PostProcessing< dim >::IsocontourBoundingBoxes::Isocontour > > &ids_and_isocontours_per_variable, const DoFHandler< dim > &dof_handler, const VectorType &solution_vector, const double current_time, const Parameters::Verbosity &verbosity, const ConditionalOStream &pcout, std::vector< TableHandler > &isocontour_bounding_values_tables)
Identifies the bounding values of requested isocontours using InterfaceTools::compute_isocontour_boun...
void write_isocontour_bounding_values_tables(const MPI_Comm &mpi_communicator, const std::string &output_folder, const Variable &variable, const std::multimap< Variable, std::pair< unsigned int, typename Parameters::PostProcessing< dim >::IsocontourBoundingBoxes::Isocontour > > &ids_and_isocontours_per_variable, const std::vector< TableHandler > &isocontour_bounding_values_tables)
Writes the bounding values tables of the specified isocontours in their respective output files.
std::pair< double, double > integrate_volume_and_surface(const DoFHandler< dim > &dof_handler, const FiniteElement< dim > &fe, const VectorType &level_set_vector_relevant_copy)
Integrate the surface area of a given level of a level set field and the volume enclosed by it....
FluidIndicator
Class to account for different fluid indicators. This is used for multiphase simulations in PostProce...
Definition parameters.h:75
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 ...
std::pair< double, double > calculate_L2_error(const DoFHandler< dim > &dof_handler, const VectorType &evaluation_point, const Function< dim > *exact_solution, const Quadrature< dim > &quadrature_formula, const Mapping< dim > &mapping)
Calculates the L2 norm of the error on velocity and pressure.
Struct containing information about the solution output. It is used to pass the information required ...
Struct containing information about the solution output. It is used to pass all the information requi...
@ ilu
Incomplete LU Factorization.
GlobalVectorType VectorType
bool is_steady(const Parameters::SimulationControl::TimeSteppingMethod method)
Determines if the time integration method is a steady-state method.
bool time_stepping_is_bdf(const Parameters::SimulationControl::TimeSteppingMethod method)
Determines if the time integration method is within the bdf family.
bool time_stepping_is_sdirk(const Parameters::SimulationControl::TimeSteppingMethod method)
Determines if the time integration method is within the sdirk family.
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17
dealii::TrilinosWrappers::MPI::BlockVector GlobalBlockVectorType
Definition vector.h:18