Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
multiphysics_interface.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
6#include <solvers/cls.h>
11#include <solvers/tracer.h>
12
13#include <deal.II/base/exceptions.h>
14
15#include <string>
16
17#define _unused(x) ((void)(x))
18
20 ThermalBuoyancyWithoutFluidDynamicsError,
21 bool,
22 << std::boolalpha << "Thermal buoyancy force is activated (" << arg1
23 << "), while fluid dynamics is not activated (false)." << std::endl
24 << "Thermal buoyancy force cannot be activated without activating fluid dynamics.");
25
27 ThermalBuoyancyWithoutHeatTransferError,
28 bool,
29 << std::boolalpha << "Thermal buoyancy force is activated (" << arg1
30 << "), while heat transfer is not activated (false)." << std::endl
31 << "Thermal buoyancy force cannot be activated without activating heat transfer.");
32
34 MicrowaveHeatingWithoutElectromagneticsError,
35 bool,
36 << std::boolalpha << "Microwave heating is activated (" << arg1
37 << "), while electromagnetics is not activated (false)." << std::endl
38 << "Microwave heating cannot be activated without activating electromagnetics.");
39
41 MarangoniWithoutFluidDynamicsError,
42 bool,
43 << std::boolalpha << "Marangoni effect is activated (" << arg1
44 << "), while fluid dynamics is not activated (false)." << std::endl
45 << "Marangoni effect cannot be activated without activating fluid dynamics.");
46
48 MarangoniWithoutHeatTransferError,
49 bool,
50 << std::boolalpha << "Marangoni effect is activated (" << arg1
51 << "), while heat transfer is not activated (false)." << std::endl
52 << "Marangoni effect cannot be activated without activating heat transfer.");
53
55 MarangoniWithoutSurfaceTensionForceError,
56 bool,
57 << std::boolalpha << "Marangoni effect is activated (" << arg1
58 << "), while surface tension force is not activated (false)." << std::endl
59 << "Marangoni effect cannot be activated without activating surface tension force.");
60
62 SurfaceTensionForceWithoutCLSError,
63 bool,
64 << std::boolalpha << "Surface tension force is activated (" << arg1
65 << "), while CLS is not activated (false)." << std::endl
66 << "Surface tension force cannot be activated without activating CLS.");
67
69 MarangoniWithoutCLSError,
70 bool,
71 << std::boolalpha << "Marangoni effect is activated (" << arg1
72 << "), while CLS is not activated (false)." << std::endl
73 << "Marangoni effect cannot be activated without activating CLS.");
74
76 InterfaceSharpeningWithoutCLSError,
77 bool,
78 << std::boolalpha << "Interface sharpening is activated (" << arg1
79 << "), while CLS is not activated (false)." << std::endl
80 << "Interface sharpening cannot be activated without activating CLS.");
81
82DeclExceptionMsg(CahnHilliardWithHeatTransferError,
83 "Cahn-Hilliard and heat transfer are both activated. "
84 "This combination is not currently supported.");
85
86DeclExceptionMsg(CahnHilliardWithThermalBuoyancyForceError,
87 "Cahn-Hilliard and thermal buoyancy force are both activated. "
88 "This combination is not currently supported.");
89
91 PhysicsVANSFormNotImplementedError,
92 std::string,
93 << "The \"" << arg1
94 << "\" auxiliary physics is enabled together with the VANS "
95 "(volume-averaged Navier-Stokes) fluid dynamics solver, but a "
96 "volume-averaged form of this physics is not yet implemented "
97 "in Lethe. Disable this physics in the multiphysics subsection, "
98 "or use a solver of the standard Navier-Stokes equations "
99 "(e.g. lethe-fluid).");
100
101template <int dim>
103 const SimulationParameters<dim> &nsparam,
104 const std::shared_ptr<parallel::DistributedTriangulationBase<dim>>
105 &p_triangulation,
106 std::shared_ptr<SimulationControl> p_simulation_control,
107 ConditionalOStream &p_pcout,
108 const FluidDynamicsFormulation p_fluid_dynamics_formulation)
109 : multiphysics_parameters(nsparam.multiphysics)
110 , pcout(p_pcout)
111 , fluid_dynamics_formulation(p_fluid_dynamics_formulation)
112 , probe_postprocessor(p_simulation_control,
113 nsparam.post_processing.probing_points,
114 nsparam.post_processing.output_frequency,
115 nsparam.post_processing.verbosity)
116{
118
119 // Fluid dynamics is always considered active
120 // since its DofHandler is required at all time by
121 // the other physics. Consequently, disabling it only
122 // prevents solving it, but not allocating it.
123 {
125 }
126 if (multiphysics_parameters.heat_transfer)
127 {
128 AssertThrow(fluid_dynamics_formulation ==
130 PhysicsVANSFormNotImplementedError("Heat transfer"));
134 nsparam.linear_solver.at(PhysicsID::heat_transfer).verbosity !=
139 physics[PhysicsID::heat_transfer] = std::make_shared<HeatTransfer<dim>>(
140 this, nsparam, p_triangulation, p_simulation_control);
141 }
142 if (multiphysics_parameters.tracer)
143 {
144 AssertThrow(fluid_dynamics_formulation ==
146 PhysicsVANSFormNotImplementedError("Tracer"));
150 nsparam.linear_solver.at(PhysicsID::tracer).verbosity !=
155 physics[PhysicsID::tracer] = std::make_shared<Tracer<dim>>(
156 this, nsparam, p_triangulation, p_simulation_control);
157 }
159 {
160 AssertThrow(fluid_dynamics_formulation ==
162 PhysicsVANSFormNotImplementedError("CLS"));
166 nsparam.linear_solver.at(PhysicsID::CLS).verbosity !=
171 physics[PhysicsID::CLS] = std::make_shared<ConservativeLevelSet<dim>>(
172 this, nsparam, p_triangulation, p_simulation_control);
173 }
174
175 if (multiphysics_parameters.cahn_hilliard)
176 {
177 AssertThrow(fluid_dynamics_formulation ==
179 PhysicsVANSFormNotImplementedError("Cahn-Hilliard"));
183 nsparam.linear_solver.at(PhysicsID::cahn_hilliard).verbosity !=
188 physics[PhysicsID::cahn_hilliard] = std::make_shared<CahnHilliard<dim>>(
189 this, nsparam, p_triangulation, p_simulation_control);
190 }
191
192 if (multiphysics_parameters.electromagnetics)
193 {
194 // The volume-averaged form of the time-harmonic Maxwell equations is the
195 // same as the standard form, but uses the volume-averaged material
196 // properties.
202
205 std::make_shared<TimeHarmonicMaxwell<dim>>(this,
206 nsparam,
207 p_triangulation,
208 p_simulation_control);
209 }
210
211
212 if (multiphysics_parameters.continuum_solid_dynamics)
213 {
214 // The solid phase exists in the volume-averaged formulation
216 ContinuumSolidDynamicsWithoutVANSError());
222 .verbosity != Parameters::Verbosity::quiet) ?
227 std::make_shared<ContinuumSolidDynamics<dim>>(this,
228 nsparam,
229 p_triangulation,
230 p_simulation_control);
231 }
232
234 {
235 // The moments of the particle size distributions are computed by
236 // QMOMKit
237#ifndef LETHE_WITH_QMOMKIT
238 AssertThrow(false, QMOMWithoutQMOMKitError());
239#endif
240 AssertThrow(false,
241 ExcMessage("The \"qmom\" physics is enabled in the "
242 "multiphysics subsection, but its solver is not "
243 "implemented yet. Only its parameters are "
244 "available. Set \"qmom\" to false."));
245 }
246}
247
248template <int dim>
249const GlobalVectorType &
251{
252 // Throw error if CLS is not enabled
253 AssertThrow((std::ranges::find(active_physics, PhysicsID::CLS) !=
254 active_physics.end()),
255 ExcInternalError());
256 // Throw error if surface tension force is not enabled
257 AssertThrow(
258 (multiphysics_parameters.cls_parameters.surface_tension_force.enable),
259 ExcInternalError());
260
261 return dynamic_cast<ConservativeLevelSet<dim> &>(*physics[PhysicsID::CLS])
263}
264
265template <int dim>
266const GlobalVectorType &
268{
269 // Throw error if CLS is not enabled
270 AssertThrow((std::ranges::find(active_physics, PhysicsID::CLS) !=
271 active_physics.end()),
272 ExcInternalError());
273 // Throw error if surface tension force is not enabled
274 AssertThrow(
275 (multiphysics_parameters.cls_parameters.surface_tension_force.enable),
276 ExcInternalError());
277
278 return dynamic_cast<ConservativeLevelSet<dim> &>(*physics[PhysicsID::CLS])
280}
281
282template <int dim>
283const DoFHandler<dim> &
285{
286 // Throw error if CLS is not enabled
287 AssertThrow((std::ranges::find(active_physics, PhysicsID::CLS) !=
288 active_physics.end()),
289 ExcInternalError());
290 // Throw error if surface tension force is not enabled
291 AssertThrow(
292 (multiphysics_parameters.cls_parameters.surface_tension_force.enable),
293 ExcInternalError());
294
295 return dynamic_cast<ConservativeLevelSet<dim> &>(*physics[PhysicsID::CLS])
297}
298
299template <int dim>
300const DoFHandler<dim> &
302{
303 // Throw error if CLS is not enabled
304 AssertThrow((std::ranges::find(active_physics, PhysicsID::CLS) !=
305 active_physics.end()),
306 ExcInternalError());
307 // Throw error if surface tension force is not enabled
308 AssertThrow(
309 (multiphysics_parameters.cls_parameters.surface_tension_force.enable),
310 ExcInternalError());
311
312 return dynamic_cast<ConservativeLevelSet<dim> &>(*physics[PhysicsID::CLS])
314}
315
316template <int dim>
317std::shared_ptr<Shape<dim>>
319{
320 // This shared pointer is also used to check if an immersed boundary solid
321 // method is being used, depending on whether the pointer is assigned.
323}
324
325template <int dim>
326void
328 const std::shared_ptr<Shape<dim>> &shape)
329{
330 immersed_solid_shape = shape;
331}
332
333template <int dim>
334void
336 const SimulationParameters<dim> &nsparam)
337{
338 bool thermal_buoyancy_force_enabled =
339 nsparam.multiphysics.thermal_buoyancy_force;
340 bool heat_transfer_enabled = nsparam.multiphysics.heat_transfer;
341 bool microwave_heating_enabled = nsparam.multiphysics.microwave_heating;
342 bool marangoni_effect_enabled =
343 nsparam.multiphysics.cls_parameters.surface_tension_force
344 .enable_marangoni_effect;
345 bool surface_tension_force_enabled =
346 nsparam.multiphysics.cls_parameters.surface_tension_force.enable;
347 bool fluid_dynamics_enabled = nsparam.multiphysics.fluid_dynamics;
348 bool interface_sharpening_enabled =
349 nsparam.multiphysics.cls_parameters.reinitialization_method.sharpening
350 .enable;
351 bool CLS_enabled = nsparam.multiphysics.CLS;
352 bool cahn_hilliard_enabled = nsparam.multiphysics.cahn_hilliard;
353 bool electromagnetics_enabled = nsparam.multiphysics.electromagnetics;
354
355 // To avoid getting unused parameter warning
356 _unused(thermal_buoyancy_force_enabled && heat_transfer_enabled &&
357 marangoni_effect_enabled && surface_tension_force_enabled &&
358 fluid_dynamics_enabled && interface_sharpening_enabled &&
359 CLS_enabled && cahn_hilliard_enabled && electromagnetics_enabled);
360
361 // Dependence of thermal buoyancy force on fluid dynamics
362 AssertThrow(!(thermal_buoyancy_force_enabled == true &&
363 fluid_dynamics_enabled == false),
364 ThermalBuoyancyWithoutFluidDynamicsError(
365 thermal_buoyancy_force_enabled));
366
367 // Dependence of thermal buoyancy force on heat transfer
368 AssertThrow(
369 !(thermal_buoyancy_force_enabled == true && heat_transfer_enabled == false),
370 ThermalBuoyancyWithoutHeatTransferError(thermal_buoyancy_force_enabled));
371
372 // Dependence of Marangoni effect on fluid dynamics
373 AssertThrow(!(marangoni_effect_enabled == true &&
374 fluid_dynamics_enabled == false),
375 MarangoniWithoutFluidDynamicsError(marangoni_effect_enabled));
376
377 // Dependence of Marangoni effect on heat transfer
378 AssertThrow(!(marangoni_effect_enabled == true &&
379 heat_transfer_enabled == false),
380 MarangoniWithoutHeatTransferError(marangoni_effect_enabled));
381
382 // Dependence of Marangoni effect on surface tension force
383 AssertThrow(!(marangoni_effect_enabled == true &&
384 surface_tension_force_enabled == false),
385 MarangoniWithoutSurfaceTensionForceError(
386 marangoni_effect_enabled));
387
388 // Dependence of surface tension force on CLS
389 AssertThrow(!(surface_tension_force_enabled == true && CLS_enabled == false),
390 SurfaceTensionForceWithoutCLSError(
391 surface_tension_force_enabled));
392
393 // Dependence of Marangoni effect on CLS
394 AssertThrow(!(marangoni_effect_enabled == true && CLS_enabled == false),
395 MarangoniWithoutCLSError(marangoni_effect_enabled));
396
397 // Dependence of interface sharpening on CLS
398 AssertThrow(!(interface_sharpening_enabled == true && CLS_enabled == false),
399 InterfaceSharpeningWithoutCLSError(interface_sharpening_enabled));
400
401 // Cahn-Hilliard does not support heat transfer
402 AssertThrow(!(cahn_hilliard_enabled == true && heat_transfer_enabled == true),
403 CahnHilliardWithHeatTransferError());
404
405 // Cahn-Hilliard does not support thermal buoyancy force
406 AssertThrow(!(cahn_hilliard_enabled == true &&
407 thermal_buoyancy_force_enabled == true),
408 CahnHilliardWithThermalBuoyancyForceError());
409
410 // Dependence of Microwave heating in heat transfer on electromagnetics
411 AssertThrow(
412 !(microwave_heating_enabled == true &&
413 (electromagnetics_enabled == false || heat_transfer_enabled == false)),
414 MicrowaveHeatingWithoutElectromagneticsError(microwave_heating_enabled));
415}
416
417template <int dim>
418bool
420{
421 // Check if the physics_id is in active_physics
422 if (std::ranges::find(active_physics, physics_id) != active_physics.end())
423 return true;
424
425 // Special case for the fields projected by the particle projector of the
426 // VANS solvers. They are not active physics, but are available as fields in
427 // the multiphysics interface when the fluid dynamics formulation is VANS and
428 // the VANS solver enabled them with enable_projected_particle_fields().
430 {
431 if (physics_id == PhysicsID::void_fraction)
433 if (physics_id == PhysicsID::particle_temperature)
435 }
436
437 return false;
438}
439
440template void
442 const Mapping<2> &mapping,
443 const DoFHandler<2> &dof_handler,
444 const GlobalVectorType &present_solution,
445 const Variable variable,
446 const ConditionalOStream &pcout);
447template void
449 const Mapping<3> &mapping,
450 const DoFHandler<3> &dof_handler,
451 const GlobalVectorType &present_solution,
452 const Variable variable,
453 const ConditionalOStream &pcout);
454template void
456 const Mapping<2> &mapping,
457 const DoFHandler<2> &dof_handler,
458 const GlobalBlockVectorType &present_solution,
459 const Variable variable,
460 const ConditionalOStream &pcout);
461template void
463 const Mapping<3> &mapping,
464 const DoFHandler<3> &dof_handler,
465 const GlobalBlockVectorType &present_solution,
466 const Variable variable,
467 const ConditionalOStream &pcout);
468
469#ifndef LETHE_USE_LDV
470template void
472 const Mapping<2> &mapping,
473 const DoFHandler<2> &dof_handler,
474 const LinearAlgebra::distributed::Vector<double> &present_solution,
475 const Variable variable,
476 const ConditionalOStream &pcout);
477template void
479 const Mapping<3> &mapping,
480 const DoFHandler<3> &dof_handler,
481 const LinearAlgebra::distributed::Vector<double> &present_solution,
482 const Variable variable,
483 const ConditionalOStream &pcout);
484#endif
485
486template class MultiphysicsInterface<2>;
487template class MultiphysicsInterface<3>;
std::map< PhysicsID, std::shared_ptr< AuxiliaryPhysics< dim, GlobalVectorType > > > physics
std::vector< PhysicsID > active_physics
const GlobalVectorType & get_projected_phase_indicator_gradient_solution()
Request the reference to the present solution vector of the projected phase indicator gradient (PIG).
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...
const DoFHandler< dim > & get_curvature_dof_handler()
Request the reference to the projected curvature DOF handler.
void set_immersed_solid_shape(const std::shared_ptr< Shape< dim > > &shape)
Share immersed solid shape.
PostprocessingProbes< dim > probe_postprocessor
Probe postprocessing object.
const GlobalVectorType & get_curvature_solution()
Request the reference to the present solution of the curvature.
std::shared_ptr< Shape< dim > > get_immersed_solid_shape()
Request shared pointer to immersed solid shape.
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 inspect_multiphysics_models_dependencies(const SimulationParameters< dim > &nsparam)
Checks the required dependencies between multiphase models and handles the corresponding assertions.
const DoFHandler< dim > & get_projected_phase_indicator_gradient_dof_handler()
Request the reference to the projected phase indicator gradient (PIG) DOF handler.
std::shared_ptr< Shape< dim > > immersed_solid_shape
Shared pointer to immersed solid shapes to be used by auxiliary physics.
std::map< PhysicsID, Parameters::Verbosity > verbosity
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
Parameters::Multiphysics< dim > multiphysics
std::map< PhysicsID, Parameters::LinearSolver > linear_solver
std::map< PhysicsID, Parameters::NonLinearSolver > physics_solving_strategy
Auxiliary physics for the solid phase of the Euler-Euler (two-fluid) model.
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.
@ VANS
Volume-averaged Navier-Stokes (VANS) equations.
@ 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).
#define _unused(x)
DeclExceptionMsg(CahnHilliardWithHeatTransferError, "Cahn-Hilliard and heat transfer are both activated. " "This combination is not currently supported.")
DeclException1(ThermalBuoyancyWithoutFluidDynamicsError, bool,<< std::boolalpha<< "Thermal buoyancy force is activated ("<< arg1<< "), while fluid dynamics is not activated (false)."<< std::endl<< "Thermal buoyancy force cannot be activated without activating fluid dynamics.")
Vector-valued function of the fields of the quadrature method of moments (QMOM) physics: the scalars ...
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17
dealii::TrilinosWrappers::MPI::BlockVector GlobalBlockVectorType
Definition vector.h:18