14#ifndef lethe_multiphysics_interface_h
15#define lethe_multiphysics_interface_h
27#include <deal.II/base/exceptions.h>
29#include <deal.II/distributed/tria_base.h>
31#include <deal.II/lac/trilinos_parallel_block_vector.h>
32#include <deal.II/lac/trilinos_vector.h>
42 PhysicsIDNotAvailable,
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). ");
69 const std::shared_ptr<parallel::DistributedTriangulationBase<dim>>
71 std::shared_ptr<SimulationControl> p_simulation_control,
72 ConditionalOStream &p_pcout,
81 std::vector<PhysicsID>
121 "The physics ID provided is not associated with an existing projected particle field."));
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."));
176 solve(
const bool fluid_dynamics_has_been_solved,
178 time_stepping_method)
187 if (!iphys.second->should_solve_auxiliary_physics())
196 else if (fluid_dynamics_has_been_solved &&
205 if (!iphys.second->should_solve_auxiliary_physics())
214 else if (fluid_dynamics_has_been_solved &&
229 time_stepping_method)
239 physics[physics_id]->time_stepping_method = time_stepping_method;
240 physics[physics_id]->solve_governing_system();
241 physics[physics_id]->modify_solution();
252 time_stepping_method)
262 block_physics[physics_id]->time_stepping_method = time_stepping_method;
272 std::vector<OutputStruct<dim, GlobalVectorType>>
275 std::vector<OutputStruct<dim, GlobalVectorType>> solution_output_structs;
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);
284 return solution_output_structs;
292 std::vector<OutputStruct<dim, GlobalBlockVectorType>>
295 std::vector<OutputStruct<dim, GlobalBlockVectorType>>
296 solution_output_structs;
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);
305 return solution_output_structs;
317 iphys.second->finish_simulation();
321 iphys.second->finish_simulation();
344 iphys.second->percolate_time_vectors();
348 else if (fluid_dynamics_has_been_solved &&
351 iphys.second->percolate_time_vectors();
357 iphys.second->percolate_time_vectors();
361 else if (fluid_dynamics_has_been_solved &&
364 iphys.second->percolate_time_vectors();
376 iphys.second->update_boundary_conditions();
380 iphys.second->update_boundary_conditions();
407 iphys.second->postprocess(first_iteration);
411 iphys.second->postprocess(first_iteration);
425 iphys.second->output_per_iteration_timer();
429 iphys.second->output_per_iteration_timer();
442 iphys.second->pre_mesh_adaptation();
446 iphys.second->pre_mesh_adaptation();
458 iphys.second->post_mesh_adaptation();
462 iphys.second->post_mesh_adaptation();
476 iphys.second->setup_dofs();
480 iphys.second->setup_dofs();
496 iphys.second->set_initial_conditions();
501 iphys.second->set_initial_conditions();
516 physics[physics_id]->solve_linear_system();
541 const DoFHandler<dim> &
547 PhysicsIDNotAvailable(physics_id));
565 PhysicsIDNotAvailable(physics_id));
583 PhysicsIDNotAvailable(physics_id));
664 const std::vector<std::shared_ptr<SolidBase<dim, dim>>> &
667 Assert(number_solids > 0, NoSolidWarning(
"the"));
668 AssertThrow(
solids !=
nullptr,
669 dealii::ExcMessage(
"solids is not initialized"));
689 const DoFHandler<dim> &
696 const DoFHandler<dim> &
702 std::shared_ptr<Shape<dim>>
720 const std::vector<GlobalVectorType> &
726 PhysicsIDNotAvailable(physics_id));
737 const std::vector<GlobalBlockVectorType> &
757 std::shared_ptr<DoFHandler<dim>> dof_handler)
760 PhysicsIDNotAvailable(physics_id));
777 PhysicsIDNotAvailable(physics_id));
793 solids = std::move(solids_input);
807 std::shared_ptr<GlobalVectorType> solution_vector)
810 PhysicsIDNotAvailable(physics_id));
829 std::shared_ptr<GlobalVectorType> filtered_solution_vector)
835 std::move(filtered_solution_vector);
850 std::shared_ptr<GlobalVectorType> solution_vector)
868 std::shared_ptr<GlobalBlockVectorType> solution_vector)
889 std::shared_ptr<GlobalBlockVectorType> solution_vector)
895 std::move(solution_vector);
909 std::shared_ptr<std::vector<GlobalVectorType>> previous_solutions_vector)
912 PhysicsIDNotAvailable(physics_id));
914 std::move(previous_solutions_vector);
929 std::shared_ptr<std::vector<GlobalBlockVectorType>>
930 previous_solutions_vector)
936 std::move(previous_solutions_vector);
950 const std::pair<const Variable, Parameters::MultipleAdaptationParameters>
952 dealii::Vector<float> &estimated_error_per_cell)
956 iphys.second->compute_error_estimate(ivar, estimated_error_per_cell);
960 iphys.second->compute_error_estimate(ivar, estimated_error_per_cell);
972 iphys.second->write_checkpoint();
976 iphys.second->write_checkpoint();
990 iphys.second->read_checkpoint();
994 iphys.second->read_checkpoint();
1013 template <
typename VectorType>
1016 const DoFHandler<dim> &dof_handler,
1019 const ConditionalOStream &
pcout)
1023 std::vector<double> evaluated_scalar_values;
1029 evaluated_scalar_values);
1034 std::vector<Tensor<1, dim, double>> evaluated_vector_values;
1040 evaluated_vector_values);
1046 "The probe functionality has only been implemented and tested "
1047 "for the variables: velocity, pressure, phase, and temperature."));
1078 std::map<PhysicsID, std::shared_ptr<AuxiliaryPhysics<dim, GlobalVectorType>>>
1082 std::shared_ptr<AuxiliaryPhysics<dim, GlobalBlockVectorType>>>
1092 std::shared_ptr<std::vector<std::shared_ptr<SolidBase<dim, dim>>>>
solids;
1102 std::map<PhysicsID, std::shared_ptr<GlobalBlockVectorType>>
1111 std::map<PhysicsID, std::shared_ptr<GlobalVectorType>>
1119 std::map<PhysicsID, std::shared_ptr<GlobalVectorType>>
1126 std::map<PhysicsID, std::shared_ptr<std::vector<GlobalVectorType>>>
1135 std::map<PhysicsID, std::shared_ptr<std::vector<GlobalBlockVectorType>>>
1142 std::map<PhysicsID, std::shared_ptr<GlobalVectorType>>
1151 std::map<PhysicsID, std::shared_ptr<GlobalBlockVectorType>>
1162 std::map<PhysicsID, std::shared_ptr<GlobalBlockVectorType>>
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
bool particle_void_fraction_field_enabled
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.
void update_boundary_conditions()
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
bool particle_temperature_field_enabled
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 ...
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...
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).
@ 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
dealii::TrilinosWrappers::MPI::BlockVector GlobalBlockVectorType