Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
multiphysics_interface.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2021-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4/*
5 * This class provides an interface for multiphysics simulations by enabling
6 * the solution of multiple auxiliary physics on top of a computational
7 * fluid dynamics simulation. The auxiliary physics are stored in a map
8 * whose keys are the Parameters::PhysicsID int enum. The interface also
9 * knows whether the driving fluid dynamics solver solves the standard or
10 * the volume-averaged (VANS) Navier-Stokes equations, and refuses to
11 * instantiate an auxiliary physics that has no volume-averaged form yet.
12 */
13
14#ifndef lethe_multiphysics_interface_h
15#define lethe_multiphysics_interface_h
16
17#include <core/exceptions.h>
18#include <core/multiphysics.h>
21#include <core/solid_base.h>
22#include <core/vector.h>
23
26
27#include <deal.II/base/exceptions.h>
28
29#include <deal.II/distributed/tria_base.h>
30
31#include <deal.II/lac/trilinos_parallel_block_vector.h>
32#include <deal.II/lac/trilinos_vector.h>
33
34#include <algorithm>
35#include <map>
36#include <memory>
37#include <utility>
38
39using namespace dealii;
40
42 PhysicsIDNotAvailable,
43 int,
44 << " The physics with ID " << arg1
45 << " required by the multiphysics interface during the simulation is not available. Please check the input file to ensure that the physics is enabled or that the VANS formulation is used if the simulation requires the projected particle fields to be available. The projected particle temperature field is only available in thermal CFD-DEM simulations (solver type = dem_mp). ");
46
47template <int dim>
49{
50public:
51 /** @brief Construct the Multiphysics interface from the simulation parameters.
52 * Depending on which multiphysics element is enabled, the appropriate
53 * auxiliary physics is instantiated. Auxiliary physics that have no
54 * volume-averaged (VANS) form yet throw at construction time when
55 * @p p_fluid_dynamics_formulation is FluidDynamicsFormulation::VANS.
56 *
57 * @param[in] nsparam Simulation parameters.
58 * @param[in] p_triangulation Distributed triangulation shared by all
59 * physics.
60 * @param[in] p_simulation_control Simulation control shared by all
61 * physics.
62 * @param[in] p_pcout Parallel output stream.
63 * @param[in] p_fluid_dynamics_formulation The formulation of the fluid
64 * dynamics equations. Whether the solver solves the volume-averaged
65 * Navier-Stokes (VANS) equations or the standard Navier-Stokes equations.
66 */
68 const SimulationParameters<dim> &nsparam,
69 const std::shared_ptr<parallel::DistributedTriangulationBase<dim>>
70 &p_triangulation,
71 std::shared_ptr<SimulationControl> p_simulation_control,
72 ConditionalOStream &p_pcout,
73 const FluidDynamicsFormulation p_fluid_dynamics_formulation =
75
76 /**
77 * @brief Default destructor.
78 */
79 virtual ~MultiphysicsInterface() = default;
80
81 std::vector<PhysicsID>
83 {
84 return active_physics;
85 }
86
87 /**
88 * @brief Get the formulation of the fluid dynamics solver driving this interface.
89 * @return The formulation of the fluid dynamics solver.
90 */
96
97 /**
98 * @brief Make a field projected by the particle projector of the VANS
99 * solvers available in the interface. The VANS solvers call it in their
100 * constructor: always for the void fraction, and for the particle
101 * temperature in thermal CFD-DEM simulations (solver type = dem_mp).
102 *
103 * @param[in] physics_id The ID of the projected field to enable.
104 */
105 void
107 {
108 if (physics_id == PhysicsID::void_fraction)
109 {
111 }
112 else if (physics_id == PhysicsID::particle_temperature)
113 {
115 }
116 else
117 {
118 AssertThrow(
119 false,
120 ExcMessage(
121 "The physics ID provided is not associated with an existing projected particle field."));
122 }
123 }
124
125 /**
126 * @brief Write physic solved in the terminal
127 *
128 * @param physics_id number associated with auxiliary physics in multiphysics.h
129 */
130 void
131 announce_physics(const PhysicsID physics_id)
132 {
133 if (physics_id == PhysicsID::heat_transfer)
134 {
135 announce_string(pcout, "Heat Transfer");
136 }
137 else if (physics_id == PhysicsID::tracer)
138 {
139 announce_string(pcout, "Tracer");
140 }
141 else if (physics_id == PhysicsID::CLS)
142 {
143 announce_string(pcout, "CLS");
144 }
145 else if (physics_id == PhysicsID::cahn_hilliard)
146 {
147 announce_string(pcout, "Cahn-Hilliard");
148 }
149 else if (physics_id == PhysicsID::electromagnetics)
150 {
151 announce_string(pcout, "Electromagnetics");
152 }
153 else if (physics_id == PhysicsID::continuum_solid_dynamics)
154 {
155 announce_string(pcout, "Continuum Solid Dynamics");
156 }
157 else
158 {
159 AssertThrow(
160 false,
161 ExcMessage(
162 "You are trying to declare an unknown physics. You have reached this point in the software because of a software bug. Simulation will stop because of this error."));
163 }
164 }
165
166 /**
167 * @brief Call for the solution of the physics that should be solved
168 *
169 * @param fluid_dynamics_has_been_solved Boolean that states if the fluid dynamics has been
170 * already solved or not. See the map `solve_pre_fluid` to know which
171 * subphysics are solved before the fluid dynamics.
172 *
173 * @param time_stepping_method Time-Stepping method with which the assembly is called
174 */
175 void
176 solve(const bool fluid_dynamics_has_been_solved,
178 time_stepping_method)
179 {
180 // Loop through all the elements in the physics map. Consequently, iphys is
181 // an std::pair where iphys.first is the PhysicsID and iphys.second is the
182 // AuxiliaryPhysics pointer. This is how the map can be traversed
183 // sequentially.
184 for (auto &iphys : physics)
185 {
186 // Skip physics if not required from the coupling strategy
187 if (!iphys.second->should_solve_auxiliary_physics())
188 continue;
189
190 // If iphys.first should be solved BEFORE fluid dynamics
191 if (!fluid_dynamics_has_been_solved && solve_pre_fluid[iphys.first])
192 solve_physics(iphys.first, time_stepping_method);
193
194 // If iphys.first should be solved AFTER fluid dynamics OR if is not
195 // present in solve_pre_fluid map
196 else if (fluid_dynamics_has_been_solved &&
197 (!solve_pre_fluid[iphys.first] ||
198 solve_pre_fluid.count(iphys.first) == 0))
199 solve_physics(iphys.first, time_stepping_method);
200 }
201
202 for (auto &iphys : block_physics)
203 {
204 // Skip physics if not required from the coupling strategy
205 if (!iphys.second->should_solve_auxiliary_physics())
206 continue;
207
208 // If iphys.first should be solved BEFORE fluid dynamics
209 if (!fluid_dynamics_has_been_solved && solve_pre_fluid[iphys.first])
210 solve_block_physics(iphys.first, time_stepping_method);
211
212 // If iphys.first should be solved AFTER fluid dynamics OR if is not
213 // present in solve_pre_fluid map
214 else if (fluid_dynamics_has_been_solved &&
215 (!solve_pre_fluid[iphys.first] ||
216 solve_pre_fluid.count(iphys.first) == 0))
217 solve_block_physics(iphys.first, time_stepping_method);
218 }
219 }
220
221 /**
222 * @brief Call for the solution of a single physic
223 *
224 * @param time_stepping_method Time-Stepping method with which the assembly is called
225 */
226 void
227 solve_physics(const PhysicsID physics_id,
229 time_stepping_method)
230 {
231 // Announce physic solved (verbosity = physics_solving_strategy.verbosity)
232 if (verbosity.at(physics_id) != Parameters::Verbosity::quiet)
233 announce_physics(physics_id);
234
235 AssertThrow(std::ranges::find(active_physics, physics_id) !=
236 active_physics.end(),
237 ExcInternalError());
238
239 physics[physics_id]->time_stepping_method = time_stepping_method;
240 physics[physics_id]->solve_governing_system();
241 physics[physics_id]->modify_solution();
242 }
243
244 /**
245 * @brief Call for the solution of a single block physic
246 *
247 * @param time_stepping_method Time-Stepping method with which the assembly is called
248 */
249 void
252 time_stepping_method)
253 {
254 // Announce physic solved (verbosity = physics_solving_strategy.verbosity)
255 if (verbosity.at(physics_id) != Parameters::Verbosity::quiet)
256 announce_physics(physics_id);
257
258 AssertThrow(std::ranges::find(active_physics, physics_id) !=
259 active_physics.end(),
260 ExcInternalError());
261
262 block_physics[physics_id]->time_stepping_method = time_stepping_method;
263 block_physics[physics_id]->solve_governing_system();
264 block_physics[physics_id]->modify_solution();
265 }
266
267 /**
268 * @brief Gather and return vector of output structs that are particular to some applications.
269 *
270 * @return Vector of OutputStructs that will be used to write the output results as VTU files. This is a variant for GlobalVectorType.
271 */
272 std::vector<OutputStruct<dim, GlobalVectorType>>
274 {
275 std::vector<OutputStruct<dim, GlobalVectorType>> solution_output_structs;
276 for (auto &iphys : physics)
277 {
278 std::vector<OutputStruct<dim, GlobalVectorType>> output_structs =
279 iphys.second->gather_output_hook();
280 for (auto &output_struct : output_structs)
281 solution_output_structs.push_back(output_struct);
282 }
283
284 return solution_output_structs;
285 }
286
287 /**
288 * @brief Gather and return vector of output structs that are particular to some applications.
289 *
290 * @return Vector of OutputStructs that will be used to write the output results as VTU files. This is a variant for GlobalBlockVectorType.
291 */
292 std::vector<OutputStruct<dim, GlobalBlockVectorType>>
294 {
295 std::vector<OutputStruct<dim, GlobalBlockVectorType>>
296 solution_output_structs;
297 for (auto &iphys : block_physics)
298 {
299 std::vector<OutputStruct<dim, GlobalBlockVectorType>> output_structs =
300 iphys.second->gather_output_hook();
301 for (auto &output_struct : output_structs)
302 solution_output_structs.push_back(output_struct);
303 }
304
305 return solution_output_structs;
306 }
307
308 /**
309 * @brief Carry out the operations required to finish a simulation correctly for
310 * all auxiliary physics.
311 */
312 void
314 {
315 for (auto &iphys : physics)
316 {
317 iphys.second->finish_simulation();
318 }
319 for (auto &iphys : block_physics)
320 {
321 iphys.second->finish_simulation();
322 }
323 }
324
325 /**
326 * @brief Rearrange vector solution correctly for transient simulations for
327 * all auxiliary physics.
328 *
329 * @param fluid_dynamics_has_been_solved Boolean that states if the fluid dynamics has been
330 * already solved or not. See the map `solve_pre_fluid` to know which
331 * subphysics are solved before the fluid dynamics.
332 */
333 void
334 percolate_time_vectors(const bool fluid_dynamics_has_been_solved)
335 {
336 // Loop through all the elements in the physics map. Consequently, iphys is
337 // an std::pair where iphys.first is the PhysicsID and iphys.second is the
338 // AuxiliaryPhysics pointer. This is how the map can be traversed
339 // sequentially.
340 for (auto &iphys : physics)
341 {
342 // If iphys.first should be percolated BEFORE fluid dynamics is solved
343 if (!fluid_dynamics_has_been_solved && solve_pre_fluid[iphys.first])
344 iphys.second->percolate_time_vectors();
345
346 // If iphys.first should be percolated AFTER fluid dynamics is solved OR
347 // if is not present in solve_pre_fluid map
348 else if (fluid_dynamics_has_been_solved &&
349 (!solve_pre_fluid[iphys.first] ||
350 solve_pre_fluid.count(iphys.first) == 0))
351 iphys.second->percolate_time_vectors();
352 }
353 for (auto &iphys : block_physics)
354 {
355 // If iphys.first should be percolated BEFORE fluid dynamics is solved
356 if (!fluid_dynamics_has_been_solved && solve_pre_fluid[iphys.first])
357 iphys.second->percolate_time_vectors();
358
359 // If iphys.first should be percolated AFTER fluid dynamics is solved OR
360 // if is not present in solve_pre_fluid map
361 else if (fluid_dynamics_has_been_solved &&
362 (!solve_pre_fluid[iphys.first] ||
363 solve_pre_fluid.count(iphys.first) == 0))
364 iphys.second->percolate_time_vectors();
365 }
366 }
367
368 /**
369 * @param Update the boundary conditions of the auxiliary physics if they are time-dependent
370 */
371 void
373 {
374 for (auto &iphys : physics)
375 {
376 iphys.second->update_boundary_conditions();
377 }
378 for (auto &iphys : block_physics)
379 {
380 iphys.second->update_boundary_conditions();
381 }
382 }
383
384 /**
385 * @brief Prepares for the postprocessing of the current time step.
386 */
387 void
389 {
390 // Clear out the set used for identifying probes that contain the current
391 // time step.
392 this->probe_postprocessor.reset_current_time_set();
393 }
394
395 /**
396 * @brief Postprocess the auxiliary physics results. Post-processing this case implies
397 * the calculation of all derived quantities using the solution vector
398 * of the physics. It does not concern the output of the solution using
399 * the DataOutObject, which is accomplished through the
400 * attach_solution_to_output function
401 */
402 void
403 postprocess(bool first_iteration)
404 {
405 for (auto &iphys : physics)
406 {
407 iphys.second->postprocess(first_iteration);
408 }
409 for (auto &iphys : block_physics)
410 {
411 iphys.second->postprocess(first_iteration);
412 }
413
414 this->probe_postprocessor.write_probing_points_tables();
415 }
416
417 /**
418 * @brief Output the per iteration wallclock times.
419 */
420 void
422 {
423 for (auto &iphys : physics)
424 {
425 iphys.second->output_per_iteration_timer();
426 }
427 for (auto &iphys : block_physics)
428 {
429 iphys.second->output_per_iteration_timer();
430 }
431 }
432
433
434 /**
435 * @brief Prepare the auxiliary physics for mesh adaptation
436 */
437 void
439 {
440 for (auto &iphys : physics)
441 {
442 iphys.second->pre_mesh_adaptation();
443 }
444 for (auto &iphys : block_physics)
445 {
446 iphys.second->pre_mesh_adaptation();
447 }
448 }
449
450 /**
451 * @brief Interpolate solution onto new mesh
452 */
453 void
455 {
456 for (auto &iphys : physics)
457 {
458 iphys.second->post_mesh_adaptation();
459 }
460 for (auto &iphys : block_physics)
461 {
462 iphys.second->post_mesh_adaptation();
463 }
464 }
465
466
467
468 /**
469 * @brief Set-up the DofHandler and the degree of freedom associated with the physics.
470 */
471 void
473 {
474 for (auto &iphys : physics)
475 {
476 iphys.second->setup_dofs();
477 }
478 for (auto &iphys : block_physics)
479 {
480 iphys.second->setup_dofs();
481 }
482 };
483
484
485
486 /**
487 * @brief Sets-up the initial conditions associated with the physics. Generally, physics
488 * only support imposing nodal values, but some physics additionally
489 * support the use of L2 projection or steady-state solutions.
490 */
491 void
493 {
494 for (auto &iphys : physics)
495 {
496 iphys.second->set_initial_conditions();
497 }
498
499 for (auto &iphys : block_physics)
500 {
501 iphys.second->set_initial_conditions();
502 }
503 };
504
505 /**
506 * @brief Call for the solution of the linear system of an auxiliary physics.
507 *
508 */
509 void
511 {
512 AssertThrow((std::ranges::find(active_physics, physics_id) !=
513 active_physics.end()),
514 ExcInternalError());
515
516 physics[physics_id]->solve_linear_system();
517 };
518
519 /**
520 * @brief fluid_dynamics_is_block Verify if the fluid dynamics solution
521 * is stored as a block vector or not.
522 *
523 * @return boolean value indicating the fluid dynamics is stored as a block vector
524 */
525
526 bool
532
533
534 /**
535 * @brief Request a DOF handler for a given physics ID.
536 *
537 * @param physics_id The physics of the DOF handler being requested
538 *
539 * @return Reference to the DOF handler of the requested physics
540 */
541 const DoFHandler<dim> &
542 get_dof_handler(const PhysicsID physics_id)
543 {
544 // PhysicsID::void_fraction is not an auxiliary physics and is only accepted
545 // when the fluid dynamics formulation is VANS.
546 AssertThrow(is_field_available(physics_id),
547 PhysicsIDNotAvailable(physics_id));
548
549 return *physics_dof_handler[physics_id];
550 }
551
552 /**
553 * @brief Request a mapping for a given physics ID
554 *
555 * @param physics_id The physics of the mapping being requested
556 *
557 * @return Reference to the mapping of the requested physics
558 */
559 const Mapping<dim> &
560 get_mapping(const PhysicsID physics_id)
561 {
562 // PhysicsID::void_fraction is not an auxiliary physics and is only accepted
563 // when the fluid dynamics formulation is VANS.
564 AssertThrow(is_field_available(physics_id),
565 PhysicsIDNotAvailable(physics_id));
566
567 return *physics_mapping[physics_id];
568 }
569
570 /**
571 * @brief Request the reference to the present solution of a given physics
572 *
573 * @param physics_id The physics ID of the solution being requested
574 *
575 * @return Reference to the solution vector of the requested physics
576 */
577 const GlobalVectorType &
578 get_solution(const PhysicsID physics_id)
579 {
580 // PhysicsID::void_fraction is not an auxiliary physics and is only accepted
581 // when the fluid dynamics formulation is VANS.
582 AssertThrow(is_field_available(physics_id),
583 PhysicsIDNotAvailable(physics_id));
584 return *physics_solutions[physics_id];
585 }
586
587 /**
588 * @brief Request the reference to the present filtered solution of a given
589 * physics (used in CLS or CahnHilliard physics for STF calculation in the
590 * momentum balance)
591 *
592 * @param[in] physics_id ID of the physics for which the filtered solution is
593 * being requested
594 *
595 * @return Reference to the requested filtered solution vector.
596 */
597 const GlobalVectorType &
599 {
600 AssertThrow((std::ranges::find(active_physics, physics_id) !=
601 active_physics.end()),
602 ExcInternalError());
603 return *physics_filtered_solutions[physics_id];
604 }
605
606 /**
607 * @brief Request the reference to the present block solution of a given
608 * physics
609 *
610 * @param[in] physics_id The physics ID of the solution being requested
611 */
614 {
615 AssertThrow((std::ranges::find(active_physics, physics_id) !=
616 active_physics.end()),
617 ExcInternalError());
618 return *block_physics_solutions[physics_id];
619 }
620
621
622 /**
623 * @brief Request the reference to the time-average solution of a given physics
624 *
625 * @param[in] physics_id The physics ID of the solution being requested
626 */
627 const GlobalVectorType &
629 {
630 AssertThrow((std::ranges::find(active_physics, physics_id) !=
631 active_physics.end()),
632 ExcInternalError());
633 return *physics_time_average_solutions[physics_id];
634 }
635
636 /**
637 * @brief Request the reference to the present block average solution of a
638 * given physics
639 *
640 * @param[in] physics_id The physics ID of the solution being requested
641 */
644 {
645 AssertThrow((std::ranges::find(active_physics, physics_id) !=
646 active_physics.end()),
647 ExcInternalError());
648 return *block_physics_time_average_solutions[physics_id];
649 }
650
651 /**
652 * @brief Request the solid objects. Used an auxiliary physics
653 * needs to apply a boundary condition on a solid through
654 * Nitsche immersed boundary method.
655 *
656 * @param[in] number_solids The number of solids declared in the parameter
657 * file. The value is used to ensure that at least one solid has been
658 * declared.
659 *
660 * @note The method is called only in
661 * HeatTransfer<dim>::assemble_nitsche_heat_restriction,
662 * which is itself called only if number_solids > 0
663 */
664 const std::vector<std::shared_ptr<SolidBase<dim, dim>>> &
665 get_solids([[maybe_unused]] const int number_solids)
666 {
667 Assert(number_solids > 0, NoSolidWarning("the"));
668 AssertThrow(solids != nullptr,
669 dealii::ExcMessage("solids is not initialized"));
670 return *solids;
671 }
672
673 /**
674 * @brief Request the reference to the present solution vector of the
675 * projected phase indicator gradient (PIG)
676 */
677 const GlobalVectorType &
679
680 /**
681 * @brief Request the reference to the present solution of the curvature
682 */
683 const GlobalVectorType &
685
686 /**
687 * @brief Request the reference to the projected curvature DOF handler
688 */
689 const DoFHandler<dim> &
691
692 /**
693 * @brief Request the reference to the projected phase indicator gradient (PIG)
694 * DOF handler
695 */
696 const DoFHandler<dim> &
698
699 /**
700 * @brief Request shared pointer to immersed solid shape
701 */
702 std::shared_ptr<Shape<dim>>
704
705 /**
706 * @brief Share immersed solid shape
707 *
708 * @param[in] shape The reference to the shared pointer pointing to the
709 * immersed solid shape
710 */
711 void
712 set_immersed_solid_shape(const std::shared_ptr<Shape<dim>> &shape);
713
714 /**
715 * @brief Request the reference to the vector of previous solutions of a given
716 * physics.
717 *
718 * @param[in] physics_id The physics ID of the solution being requested
719 */
720 const std::vector<GlobalVectorType> &
722 {
723 // PhysicsID::void_fraction is not an auxiliary physics and is only accepted
724 // when the fluid dynamics formulation is VANS.
725 AssertThrow(is_field_available(physics_id),
726 PhysicsIDNotAvailable(physics_id));
727 return *physics_previous_solutions[physics_id];
728 }
729
730
731 /**
732 * @brief Request the reference to the vector of previous solutions of a given
733 * block physics
734 *
735 * @param[in] physics_id The physics ID of the solution being requested
736 */
737 const std::vector<GlobalBlockVectorType> &
739 {
740 AssertThrow((std::ranges::find(active_physics, physics_id) !=
741 active_physics.end()),
742 ExcInternalError());
743 return *block_physics_previous_solutions[physics_id];
744 }
745
746 /**
747 * @brief Sets the shared pointer to the DOFHandler of the physics in the
748 * multiphysics interface
749 *
750 * @param[in] physics_id The physics of the DOF handler being requested
751 *
752 * @param[in] dof_handler Shared pointer to the dof handler for which the
753 * reference is stored
754 */
755 void
756 set_dof_handler(const PhysicsID physics_id,
757 std::shared_ptr<DoFHandler<dim>> dof_handler)
758 {
759 AssertThrow(is_field_available(physics_id),
760 PhysicsIDNotAvailable(physics_id));
761 physics_dof_handler[physics_id] = std::move(dof_handler);
762 }
763
764 /**
765 * @brief Sets the shared pointer to the Mapping of the physics in the
766 * multiphysics interface
767 *
768 * @param[in] physics_id The physics of the mapping being requested
769 *
770 * @param[in] mapping Shared pointer to the mapping for which the
771 * reference is stored
772 */
773 void
774 set_mapping(const PhysicsID physics_id, std::shared_ptr<Mapping<dim>> mapping)
775 {
776 AssertThrow(is_field_available(physics_id),
777 PhysicsIDNotAvailable(physics_id));
778 physics_mapping[physics_id] = std::move(mapping);
779 }
780
781
782 /**
783 * @brief Sets the shared pointer to the vector of the SolidBase object. This
784 * allows the use of the solid base object in multiple physics at the same
785 * time.
786 *
787 * @param[in] solids_input Shared pointer to the vector of solidBase object
788 */
789 void
790 set_solid(std::shared_ptr<std::vector<std::shared_ptr<SolidBase<dim, dim>>>>
791 solids_input)
792 {
793 solids = std::move(solids_input);
794 }
795
796 /**
797 * @brief Sets the shared pointer to the solution of the physics in the
798 * multiphysics interface
799 *
800 * @param[in] physics_id The physics ID the present solution being set
801 *
802 * @param[in] solution_vector Shared pointer to the solution vector of the
803 * physics
804 */
805 void
806 set_solution(const PhysicsID physics_id,
807 std::shared_ptr<GlobalVectorType> solution_vector)
808 {
809 AssertThrow(is_field_available(physics_id),
810 PhysicsIDNotAvailable(physics_id));
811 physics_solutions[physics_id] = std::move(solution_vector);
812 }
813
814 /**
815 * @brief Sets the shared pointer to the filtered solution of the physics in
816 * the multiphysics interface (used in CLS or CahnHilliard physics for STF
817 * calculation in the momentum balance)
818 *
819 * @param[in] physics_id ID of the physics for which the filtered solution is
820 * being set
821 *
822 * @param[in] filtered_solution_vector Shared pointer to the filtered solution
823 * vector of the physics; this was implemented for CLS and CahnHilliard
824 * physics
825 */
826 void
828 const PhysicsID physics_id,
829 std::shared_ptr<GlobalVectorType> filtered_solution_vector)
830 {
831 AssertThrow((std::ranges::find(active_physics, physics_id) !=
832 active_physics.end()),
833 ExcInternalError());
834 physics_filtered_solutions[physics_id] =
835 std::move(filtered_solution_vector);
836 }
837
838
839 /**
840 * @brief Sets the shared pointer to the time-average solution of the physics in the multiphysics interface
841 *
842 * @param[in] physics_id The physics ID of the time averaged solution being
843 * set
844 *
845 * @param[in] solution_vector The shared pointer to the time averaged solution
846 * vector of the physics
847 */
848 void
850 std::shared_ptr<GlobalVectorType> solution_vector)
851 {
852 AssertThrow((std::ranges::find(active_physics, physics_id) !=
853 active_physics.end()),
854 ExcInternalError());
855 physics_time_average_solutions[physics_id] = std::move(solution_vector);
856 }
857
858 /**
859 * @brief Sets the reference to the solution of the physics in the multiphysics interface
860 *
861 * @param[in] physics_id The physics ID of the DOF handler being requested
862 *
863 * @param[in] solution_vector The shared pointer to the solution vector of the
864 * requested physics
865 */
866 void
868 std::shared_ptr<GlobalBlockVectorType> solution_vector)
869 {
870 AssertThrow((std::ranges::find(active_physics, physics_id) !=
871 active_physics.end()),
872 ExcInternalError());
873 block_physics_solutions[physics_id] = std::move(solution_vector);
874 }
875
876 /**
877 * @brief Sets the shared pointer to the time-average solution of the block
878 * physics in the multiphysics interface
879 *
880 * @param[in] physics_id The physics ID of the time averaged block vector
881 * solution being set
882 *
883 * @param[in] solution_vector The shared pointer to the block solution vector
884 * of the physics
885 */
886 void
888 const PhysicsID physics_id,
889 std::shared_ptr<GlobalBlockVectorType> solution_vector)
890 {
891 AssertThrow((std::ranges::find(active_physics, physics_id) !=
892 active_physics.end()),
893 ExcInternalError());
895 std::move(solution_vector);
896 }
897
898 /**
899 * @brief Sets the pointer to the vector of previous solutions of the physics in the multiphysics interface
900 *
901 * @param[in] physics_id The physics of the DOF handler
902 *
903 * @param[in] previous_solutions_vector The shared pointer to the vector of
904 * previous solutions
905 */
906 void
908 const PhysicsID physics_id,
909 std::shared_ptr<std::vector<GlobalVectorType>> previous_solutions_vector)
910 {
911 AssertThrow(is_field_available(physics_id),
912 PhysicsIDNotAvailable(physics_id));
913 physics_previous_solutions[physics_id] =
914 std::move(previous_solutions_vector);
915 }
916
917 /**
918 * @brief Sets the pointer to the vector of previous solutions of the block
919 * physics in the multiphysics interface
920 *
921 * @param[in] physics_id The physics of the DOF handler
922 *
923 * @param[in] previous_solutions_vector The shared pointer to the vector of
924 * previous block vector solutions
925 */
926 void
928 const PhysicsID physics_id,
929 std::shared_ptr<std::vector<GlobalBlockVectorType>>
930 previous_solutions_vector)
931 {
932 AssertThrow((std::ranges::find(active_physics, physics_id) !=
933 active_physics.end()),
934 ExcInternalError());
936 std::move(previous_solutions_vector);
937 }
938
939 /**
940 * @brief Compute error estimator for mesh refinement according to the auxiliary physic parameters
941 *
942 * @param[in] ivar The current element of the map
943 * simulation_parameters.mesh_adaptation.variables
944 *
945 * @param[in,out] estimated_error_per_cell The deal.II vector of
946 * estimated_error_per_cell
947 */
948 virtual void
950 const std::pair<const Variable, Parameters::MultipleAdaptationParameters>
951 &ivar,
952 dealii::Vector<float> &estimated_error_per_cell)
953 {
954 for (auto &iphys : physics)
955 {
956 iphys.second->compute_error_estimate(ivar, estimated_error_per_cell);
957 }
958 for (auto &iphys : block_physics)
959 {
960 iphys.second->compute_error_estimate(ivar, estimated_error_per_cell);
961 }
962 };
963
964 /**
965 * @brief Prepares auxiliary physics to write simulation checkpoint
966 */
967 virtual void
969 {
970 for (auto &iphys : physics)
971 {
972 iphys.second->write_checkpoint();
973 }
974 for (auto &iphys : block_physics)
975 {
976 iphys.second->write_checkpoint();
977 }
978 this->probe_postprocessor.write_checkpoint();
979 };
980
981 /**
982 * @brief Read solution from checkpoint from auxiliary physics
983 *
984 */
985 virtual void
987 {
988 for (auto &iphys : physics)
989 {
990 iphys.second->read_checkpoint();
991 }
992 for (auto &iphys : block_physics)
993 {
994 iphys.second->read_checkpoint();
995 }
996 this->probe_postprocessor.read_checkpoint();
997 };
998
999 /**
1000 * @brief Checks validity of the variable and if valid, calls the appropriate
1001 * PostprocessingProbes::postprocess_probes() function for the specified
1002 * variable.
1003 *
1004 * @tparam VectorType Type of vector of the solution vector.
1005 *
1006 * @param[in] mapping Mapping of the domain.
1007 * @param[in] dof_handler DoF handler associated to the solution field.
1008 * @param[in] present_solution Vector containing the scalar solution field.
1009 * For distributed meshes, ghost elements must be updated.
1010 * @param[in] variable Variable of interest.
1011 * @param[in] pcout Parallel console output stream.
1012 */
1013 template <typename VectorType>
1014 void
1015 postprocess_probes(const Mapping<dim> &mapping,
1016 const DoFHandler<dim> &dof_handler,
1017 const VectorType &present_solution,
1018 const Variable variable,
1019 const ConditionalOStream &pcout)
1020 {
1021 if (probe_postprocessor.implemented_scalar_variables.contains(variable))
1022 {
1023 std::vector<double> evaluated_scalar_values;
1024 probe_postprocessor.postprocess_probes(mapping,
1025 dof_handler,
1026 present_solution,
1027 variable,
1028 pcout,
1029 evaluated_scalar_values);
1030 }
1031 else if (probe_postprocessor.implemented_vector_variables.contains(
1032 variable))
1033 {
1034 std::vector<Tensor<1, dim, double>> evaluated_vector_values;
1035 probe_postprocessor.postprocess_probes(mapping,
1036 dof_handler,
1037 present_solution,
1038 variable,
1039 pcout,
1040 evaluated_vector_values);
1041 }
1042 else
1043 AssertThrow(
1044 false,
1045 ExcMessage(
1046 "The probe functionality has only been implemented and tested "
1047 "for the variables: velocity, pressure, phase, and temperature."));
1048 }
1049
1050private:
1052 std::map<PhysicsID, Parameters::Verbosity> verbosity;
1053 ConditionalOStream pcout;
1055
1056 // Always true if the VANS solver is used
1058
1059 // True if the VANS solver projects the particle temperature and provides it
1060 // to the interface
1062
1063 // Data structure to store all physics which were enabled
1064 std::vector<PhysicsID> active_physics;
1065
1066
1067 // Map that states if the physics are solved before the fluid dynamics
1068 std::map<PhysicsID, bool> solve_pre_fluid{{fluid_dynamics, false},
1069 {CLS, true},
1070 {heat_transfer, false},
1071 {tracer, false},
1072 {cahn_hilliard, true},
1073 {electromagnetics, true},
1074 {continuum_solid_dynamics, false}};
1075
1076 // Auxiliary physics are stored within a map of shared pointer to ensure
1077 // proper memory management.
1078 std::map<PhysicsID, std::shared_ptr<AuxiliaryPhysics<dim, GlobalVectorType>>>
1080
1081 std::map<PhysicsID,
1082 std::shared_ptr<AuxiliaryPhysics<dim, GlobalBlockVectorType>>>
1084
1085 /// Map of physics and shared pointers to their respective DoFHandler
1086 std::map<PhysicsID, std::shared_ptr<DoFHandler<dim>>> physics_dof_handler;
1087
1088 /// Map of physics and shared pointers to their respective Mapping
1089 std::map<PhysicsID, std::shared_ptr<Mapping<dim>>> physics_mapping;
1090
1091 /// Shared pointer to the vector containing shared pointers to solid objects
1092 std::shared_ptr<std::vector<std::shared_ptr<SolidBase<dim, dim>>>> solids;
1093
1094 /// Map of physics and shared pointers to their respective solutions.
1095 std::map<PhysicsID, std::shared_ptr<GlobalVectorType>> physics_solutions;
1096
1097 /**
1098 * Map of physics and shared pointers to their respective solutions.
1099 * Same as MultiphysicsInterface::physics_solutions, but used with
1100 * BlockVector.
1101 */
1102 std::map<PhysicsID, std::shared_ptr<GlobalBlockVectorType>>
1104
1105 /**
1106 * Map of physics and shared pointers to their respective filtered
1107 * solutions. These solutions are used with both CLS and Cahn-Hilliard
1108 * multiphase flow approaches for surface tension force calculation in the
1109 * momentum equation.
1110 */
1111 std::map<PhysicsID, std::shared_ptr<GlobalVectorType>>
1113
1114 /**
1115 * Map of physics and shared pointers to their respective filtered
1116 * solutions. Same as MultiphysicsInterface::physics_filtered_solutions, but
1117 * used with BlockVector.
1118 */
1119 std::map<PhysicsID, std::shared_ptr<GlobalVectorType>>
1121
1122 /**
1123 * Map of physics and shared pointers to their respective vector of previous
1124 * solutions.
1125 */
1126 std::map<PhysicsID, std::shared_ptr<std::vector<GlobalVectorType>>>
1128
1129 /**
1130 * Map of physics and shared pointers to their respective vector of previous
1131 * solutions.
1132 * Same as MultiphysicsInterface::physics_previous_solutions, but used with
1133 * BlockVector.
1134 */
1135 std::map<PhysicsID, std::shared_ptr<std::vector<GlobalBlockVectorType>>>
1137
1138 /**
1139 * Map of physics and shared pointers to their respective time-averaged
1140 * solutions.
1141 */
1142 std::map<PhysicsID, std::shared_ptr<GlobalVectorType>>
1144
1145 /**
1146 * Map of physics and shared pointers to their respective time-averaged
1147 * solutions.
1148 * Same as MultiphysicsInterface::physics_time_average_solutions, but used
1149 * with BlockVector.
1150 */
1151 std::map<PhysicsID, std::shared_ptr<GlobalBlockVectorType>>
1153
1154 /// Shared pointer to immersed solid shapes to be used by auxiliary physics
1155 std::shared_ptr<Shape<dim>> immersed_solid_shape;
1156
1157 /**
1158 * Map of physics and shared pointers to their respective previous (n-1)
1159 * solutions.
1160 */
1161 std::map<PhysicsID, std::shared_ptr<GlobalVectorType>> physics_solutions_m1;
1162 std::map<PhysicsID, std::shared_ptr<GlobalBlockVectorType>>
1164
1165 /**
1166 * @brief Checks the required dependencies between multiphase models and handles
1167 * the corresponding assertions.
1168 *
1169 * @param[in] nsparam Simulation parameters.
1170 */
1171 void
1173 const SimulationParameters<dim> &nsparam);
1174
1175 /**
1176 * @brief Return true if the fields of @p physics_id are registered in the interface: either the physics is active, or it is a field projected under the VANS formulation and enabled with enable_projected_particle_fields().
1177 *
1178 * @param[in] physics_id The ID of the physics to check.
1179 * @return true if the fields of @p physics_id are registered in the interface, false otherwise.
1180 */
1181 bool
1182 is_field_available(const PhysicsID physics_id) const;
1183
1184 /// Probe postprocessing object
1186};
1187
1188
1189#endif
bool fluid_dynamics_is_block() const
fluid_dynamics_is_block Verify if the fluid dynamics solution is stored as a block vector or not.
void percolate_time_vectors(const bool fluid_dynamics_has_been_solved)
Rearrange vector solution correctly for transient simulations for all auxiliary physics.
virtual void read_checkpoint()
Read solution from checkpoint from auxiliary physics.
void solve_linear_system(const PhysicsID physics_id)
Call for the solution of the linear system of an auxiliary physics.
void set_mapping(const PhysicsID physics_id, std::shared_ptr< Mapping< dim > > mapping)
Sets the shared pointer to the Mapping of the physics in the multiphysics interface.
std::map< PhysicsID, std::shared_ptr< AuxiliaryPhysics< dim, GlobalVectorType > > > physics
std::map< PhysicsID, std::shared_ptr< GlobalBlockVectorType > > block_physics_time_average_solutions
const GlobalBlockVectorType & get_block_time_average_solution(const PhysicsID physics_id)
Request the reference to the present block average solution of a given physics.
void set_solid(std::shared_ptr< std::vector< std::shared_ptr< SolidBase< dim, dim > > > > solids_input)
Sets the shared pointer to the vector of the SolidBase object. This allows the use of the solid base ...
const GlobalVectorType & get_solution(const PhysicsID physics_id)
Request the reference to the present solution of a given physics.
void solve_physics(const PhysicsID physics_id, const Parameters::SimulationControl::TimeSteppingMethod time_stepping_method)
Call for the solution of a single physic.
std::vector< PhysicsID > active_physics
std::vector< OutputStruct< dim, GlobalBlockVectorType > > gather_output_hook_global_block_vector()
Gather and return vector of output structs that are particular to some applications.
FluidDynamicsFormulation get_fluid_dynamics_formulation() const
Get the formulation of the fluid dynamics solver driving this interface.
const GlobalVectorType & get_filtered_solution(const PhysicsID physics_id)
Request the reference to the present filtered solution of a given physics (used in CLS or CahnHilliar...
std::vector< OutputStruct< dim, GlobalVectorType > > gather_output_hook_global_vector()
Gather and return vector of output structs that are particular to some applications.
void set_time_average_solution(const PhysicsID physics_id, std::shared_ptr< GlobalVectorType > solution_vector)
Sets the shared pointer to the time-average solution of the physics in the multiphysics interface.
std::shared_ptr< std::vector< std::shared_ptr< SolidBase< dim, dim > > > > solids
Shared pointer to the vector containing shared pointers to solid objects.
const std::vector< GlobalBlockVectorType > & get_block_previous_solutions(const PhysicsID physics_id)
Request the reference to the vector of previous solutions of a given block physics.
const std::vector< GlobalVectorType > & get_previous_solutions(const PhysicsID physics_id)
Request the reference to the vector of previous solutions of a given physics.
const GlobalVectorType & get_time_average_solution(const PhysicsID physics_id)
Request the reference to the time-average solution of a given physics.
void solve_block_physics(const PhysicsID physics_id, const Parameters::SimulationControl::TimeSteppingMethod time_stepping_method)
Call for the solution of a single block physic.
const GlobalVectorType & get_projected_phase_indicator_gradient_solution()
Request the reference to the present solution vector of the projected phase indicator gradient (PIG).
void prepare_for_mesh_adaptation()
Prepare the auxiliary physics for mesh adaptation.
const FluidDynamicsFormulation fluid_dynamics_formulation
bool is_field_available(const PhysicsID physics_id) const
Return true if the fields of physics_id are registered in the interface: either the physics is active...
std::map< PhysicsID, std::shared_ptr< Mapping< dim > > > physics_mapping
Map of physics and shared pointers to their respective Mapping.
std::map< PhysicsID, std::shared_ptr< GlobalBlockVectorType > > block_physics_solutions_m1
void set_block_time_average_solution(const PhysicsID physics_id, std::shared_ptr< GlobalBlockVectorType > solution_vector)
Sets the shared pointer to the time-average solution of the block physics in the multiphysics interfa...
void solve(const bool fluid_dynamics_has_been_solved, const Parameters::SimulationControl::TimeSteppingMethod time_stepping_method)
Call for the solution of the physics that should be solved.
const DoFHandler< dim > & get_curvature_dof_handler()
Request the reference to the projected curvature DOF handler.
void set_block_solution(const PhysicsID physics_id, std::shared_ptr< GlobalBlockVectorType > solution_vector)
Sets the reference to the solution of the physics in the multiphysics interface.
std::map< PhysicsID, std::shared_ptr< DoFHandler< dim > > > physics_dof_handler
Map of physics and shared pointers to their respective DoFHandler.
virtual ~MultiphysicsInterface()=default
Default destructor.
virtual void compute_error_estimate(const std::pair< const Variable, Parameters::MultipleAdaptationParameters > &ivar, dealii::Vector< float > &estimated_error_per_cell)
Compute error estimator for mesh refinement according to the auxiliary physic parameters.
void set_filtered_solution(const PhysicsID physics_id, std::shared_ptr< GlobalVectorType > filtered_solution_vector)
Sets the shared pointer to the filtered solution of the physics in the multiphysics interface (used i...
void set_immersed_solid_shape(const std::shared_ptr< Shape< dim > > &shape)
Share immersed solid shape.
std::map< PhysicsID, std::shared_ptr< GlobalVectorType > > physics_time_average_solutions
void setup_dofs()
Set-up the DofHandler and the degree of freedom associated with the physics.
PostprocessingProbes< dim > probe_postprocessor
Probe postprocessing object.
std::map< PhysicsID, std::shared_ptr< GlobalVectorType > > physics_solutions_m1
void output_per_iteration_timer()
Output the per iteration wallclock times.
void set_block_previous_solutions(const PhysicsID physics_id, std::shared_ptr< std::vector< GlobalBlockVectorType > > previous_solutions_vector)
Sets the pointer to the vector of previous solutions of the block physics in the multiphysics interfa...
const GlobalVectorType & get_curvature_solution()
Request the reference to the present solution of the curvature.
std::map< PhysicsID, std::shared_ptr< AuxiliaryPhysics< dim, GlobalBlockVectorType > > > block_physics
void set_initial_conditions()
Sets-up the initial conditions associated with the physics. Generally, physics only support imposing ...
const DoFHandler< dim > & get_dof_handler(const PhysicsID physics_id)
Request a DOF handler for a given physics ID.
std::shared_ptr< Shape< dim > > get_immersed_solid_shape()
Request shared pointer to immersed solid shape.
void enable_projected_particle_fields(PhysicsID physics_id)
Make a field projected by the particle projector of the VANS solvers available in the interface....
void announce_physics(const PhysicsID physics_id)
Write physic solved in the terminal.
void post_mesh_adaptation()
Interpolate solution onto new mesh.
void postprocess(bool first_iteration)
Postprocess the auxiliary physics results. Post-processing this case implies the calculation of all d...
std::map< PhysicsID, std::shared_ptr< std::vector< GlobalVectorType > > > physics_previous_solutions
std::map< PhysicsID, bool > solve_pre_fluid
void postprocess_probes(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const VectorType &present_solution, const Variable variable, const ConditionalOStream &pcout)
Checks validity of the variable and if valid, calls the appropriate PostprocessingProbes::postprocess...
MultiphysicsInterface(const SimulationParameters< dim > &nsparam, const std::shared_ptr< parallel::DistributedTriangulationBase< dim > > &p_triangulation, std::shared_ptr< SimulationControl > p_simulation_control, ConditionalOStream &p_pcout, const FluidDynamicsFormulation p_fluid_dynamics_formulation=FluidDynamicsFormulation::standard)
Construct the Multiphysics interface from the simulation parameters. Depending on which multiphysics ...
void set_previous_solutions(const PhysicsID physics_id, std::shared_ptr< std::vector< GlobalVectorType > > previous_solutions_vector)
Sets the pointer to the vector of previous solutions of the physics in the multiphysics interface.
std::map< PhysicsID, std::shared_ptr< GlobalVectorType > > physics_solutions
Map of physics and shared pointers to their respective solutions.
void inspect_multiphysics_models_dependencies(const SimulationParameters< dim > &nsparam)
Checks the required dependencies between multiphase models and handles the corresponding assertions.
void finish_simulation()
Carry out the operations required to finish a simulation correctly for all auxiliary physics.
void prepare_for_postprocessing()
Prepares for the postprocessing of the current time step.
void set_dof_handler(const PhysicsID physics_id, std::shared_ptr< DoFHandler< dim > > dof_handler)
Sets the shared pointer to the DOFHandler of the physics in the multiphysics interface.
const GlobalBlockVectorType & get_block_solution(const PhysicsID physics_id)
Request the reference to the present block solution of a given physics.
std::vector< PhysicsID > get_active_physics()
const DoFHandler< dim > & get_projected_phase_indicator_gradient_dof_handler()
Request the reference to the projected phase indicator gradient (PIG) DOF handler.
std::map< PhysicsID, std::shared_ptr< std::vector< GlobalBlockVectorType > > > block_physics_previous_solutions
void set_solution(const PhysicsID physics_id, std::shared_ptr< GlobalVectorType > solution_vector)
Sets the shared pointer to the solution of the physics in the multiphysics interface.
std::map< PhysicsID, std::shared_ptr< GlobalVectorType > > physics_filtered_solutions
std::shared_ptr< Shape< dim > > immersed_solid_shape
Shared pointer to immersed solid shapes to be used by auxiliary physics.
std::map< PhysicsID, std::shared_ptr< GlobalVectorType > > block_physics_filtered_solutions
const std::vector< std::shared_ptr< SolidBase< dim, dim > > > & get_solids(const int number_solids)
Request the solid objects. Used an auxiliary physics needs to apply a boundary condition on a solid t...
virtual void write_checkpoint()
Prepares auxiliary physics to write simulation checkpoint.
std::map< PhysicsID, std::shared_ptr< GlobalBlockVectorType > > block_physics_solutions
std::map< PhysicsID, Parameters::Verbosity > verbosity
const Mapping< dim > & get_mapping(const PhysicsID physics_id)
Request a mapping for a given physics ID.
const Parameters::Multiphysics< dim > multiphysics_parameters
A base class used to represent geometrical entities. Its main uses are to return signed distance and ...
Definition shape.h:53
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
Common exception declarations shared across multiple solvers in Lethe.
Identifiers for multiphysics modules and their solution fields.
Variable
Solution fields of the different physics that are used as an indicator for multiple purposes (e....
FluidDynamicsFormulation
Formulation of the fluid dynamics equations solved by a Navier-Stokes solver.
@ standard
Standard Navier-Stokes equations.
PhysicsID
Unique identifiers for each physics module in Lethe.
@ fluid_dynamics
Fluid Dynamics (Velocity,Pressure).
@ tracer
Passive scalar tracer (Tracer).
@ continuum_solid_dynamics
Euler-Euler solid phase (solid velocity, solid volume fraction).
@ electromagnetics
Time-harmonic electromagnetics (Electric field, Magnetic field).
@ CLS
@ particle_temperature
@ void_fraction
@ heat_transfer
Heat transfer (Temperature).
@ cahn_hilliard
Cahn-Hilliard (Phase indicator, Potential).
DeclException1(PhysicsIDNotAvailable, int,<< " The physics with ID "<< arg1<< " required by the multiphysics interface during the simulation is not available. Please check the input file to ensure that the physics is enabled or that the VANS formulation is used if the simulation requires the projected particle fields to be available. The projected particle temperature field is only available in thermal CFD-DEM simulations (solver type = dem_mp). ")
Simulation control classes for managing time-stepping and iteration control in Lethe.
Multiphysics - the parameters for multiphysics simulations and handles sub-physics parameters.
GlobalVectorType VectorType
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17
dealii::TrilinosWrappers::MPI::BlockVector GlobalBlockVectorType
Definition vector.h:18