4#ifndef lethe_navier_stokes_base_h
5#define lethe_navier_stokes_base_h
28#include <deal.II/base/conditional_ostream.h>
29#include <deal.II/base/convergence_table.h>
30#include <deal.II/base/exceptions.h>
31#include <deal.II/base/function.h>
32#include <deal.II/base/quadrature_lib.h>
33#include <deal.II/base/table_handler.h>
34#include <deal.II/base/timer.h>
36#include <deal.II/dofs/dof_handler.h>
38#include <deal.II/fe/component_mask.h>
39#include <deal.II/fe/fe_system.h>
40#include <deal.II/fe/mapping_fe.h>
41#include <deal.II/fe/mapping_q_cache.h>
43#include <deal.II/grid/grid_out.h>
44#include <deal.II/grid/grid_tools.h>
46#include <deal.II/lac/affine_constraints.h>
53 FluidDynamicsBoundaryConditionMissing,
55 <<
"The boundary id: " << arg1
56 <<
" is defined in the triangulation, but not as a boundary condition for the fluid dynamics physics. Lethe does not assign a default boundary condition to boundary ids. Every boundary id defined within the triangulation must have a corresponding boundary condition defined in the input file.");
119template <
int dim,
typename VectorType,
typename DofsType>
169 virtual AffineConstraints<double> &
192 .rescale_residual_by_volume ?
222 this->simulation_parameters.post_processing.calculation_frequency ==
257 const bool restart =
false)
259 unsigned int ref_iter = 0;
355 bool restart =
false) = 0;
476 std::vector<SolutionTransfer<dim, VectorType>>
477 &previous_solutions_transfer);
500 .calculate_average_velocities ||
502 Parameters::FluidDynamicsInitialConditionType::
503 average_velocity_profile;
559 inline std::shared_ptr<Mapping<dim>>
645 const bool non_zero_constraints,
646 AffineConstraints<double> &constraints);
669 const typename DoFHandler<dim>::active_cell_iterator &cell,
670 const Point<dim> &plane_point,
671 const Tensor<1, dim> &plane_normal_vector)
673 for (
unsigned int v = 0; v < cell->n_vertices(); ++v)
675 Point<dim> cell_vertex = cell->vertex(v);
676 Tensor<1, dim> cell_vertex_to_plane_point_vector =
677 plane_point - cell_vertex;
678 double scalar_product_result =
679 scalar_product(cell_vertex_to_plane_point_vector,
680 plane_normal_vector);
681 if (scalar_product_result <= 0)
703 const typename DoFHandler<dim>::active_cell_iterator &cell,
704 const DoFHandler<dim> *dof_handler_ht,
706 std::vector<double> &local_temperature_values)
708 const typename DoFHandler<dim>::active_cell_iterator temperature_cell(
709 &(*(this->
triangulation)), cell->level(), cell->index(), dof_handler_ht);
713 local_temperature_values);
733 const typename DoFHandler<dim>::active_cell_iterator &cell,
734 const DoFHandler<dim> *dof_handler_cls,
736 std::vector<double> &local_filtered_phase_indicator_values)
738 const typename DoFHandler<dim>::active_cell_iterator cls_cell(
739 &(*(this->
triangulation)), cell->level(), cell->index(), dof_handler_cls);
743 filtered_phase_indicator_solution, local_filtered_phase_indicator_values);
760 const std::vector<types::global_dof_index> &local_dof_indices,
761 const std::vector<double> &local_temperature_values,
789 const DoFHandler<dim> *dof_handler_ht);
799 virtual std::vector<OutputStructTableHandler>
813 virtual std::vector<OutputStruct<dim, VectorType>>
874 std::vector<types::boundary_id> boundary_ids_in_triangulation =
876 for (
auto const &boundary_id_in_tria : boundary_ids_in_triangulation)
879 boundary_id_in_tria) !=
881 FluidDynamicsBoundaryConditionMissing(boundary_id_in_tria));
895 std::shared_ptr<FESystem<dim>>
fe;
967 std::shared_ptr<NavierStokesCouplingEvaluationSIPG<dim, double>>
974 std::vector<std::shared_ptr<NavierStokesAssemblerBase<dim>>>
assemblers;
990 std::shared_ptr<AverageVelocities<dim, VectorType, DofsType>>
1001 std::vector<std::map<types::boundary_id, Tensor<1, dim>>>
Dynamic flow controller that drives the average velocity of the flow towards a target value.
std::vector< StasisConstraintWithTemperature > stasis_constraint_structs
virtual void output_newton_update_norms() override
Output the L2 and Linfty norms of the correction vector.
void constrain_stasis_with_temperature(const DoFHandler< dim > *dof_handler_ht)
Constrain a fluid's subdomains according to the temperature field to null velocity and pressure field...
void box_refine_mesh(const bool restart)
Allow the initial refinement of all cells of the principal mesh that are partially contained in one o...
ConvergenceTable error_table
std::map< types::boundary_id, TableHandler > torques_tables
std::map< types::boundary_id, TableHandler > forces_tables
virtual void update_solutions_for_fluid_dynamics()
Required only for the matrix-free solver to update multiphysics solutions within iterate function.
PVDHandler pvdhandler_boundary
virtual void set_specified_fluid_dynamics_solution()
Specify the fluid dynamics solution instead of solving for it.
std::shared_ptr< MortarManagerBase< dim > > mortar_manager
std::shared_ptr< FESystem< dim > > fe
void connect_mortar_weight_signals()
Connect weight signals for load balancing of mortar cells. Cells touching mortar boundaries can be as...
Function< dim > * exact_solution
void verify_consistency_of_boundary_conditions()
Verify consistency of the input parameters for boundary conditions to ensure that for every boundary ...
void get_cell_temperature_values(const typename DoFHandler< dim >::active_cell_iterator &cell, const DoFHandler< dim > *dof_handler_ht, const GlobalVectorType &temperature_solution, std::vector< double > &local_temperature_values)
Get cell's local temperature values at quadrature points.
std::shared_ptr< Quadrature< dim > > cell_quadrature
double get_residual_rescale_metric() const override
Return the metric for residual rescaling. By default, should return 1. If the rescale_residual_by_vol...
AffineConstraints< double > nonzero_constraints
void write_output_results(const VectorType &solution)
Generate post-processing parallel VTU files from vector of solution_output_struct.
virtual void set_initial_condition(const Parameters::FluidDynamicsInitialConditionType initial_condition_type, const bool restart=false)
Set the initial condition.
const unsigned int pressure_fem_degree
void refine_mesh_adaptive()
Allow the refinement of the mesh based on an error estimator.
virtual void update_multi_stage_solution(double time_step)
MPI_Comm mpi_communicator
std::vector< std::map< types::boundary_id, Tensor< 1, dim > > > forces_on_boundaries
virtual std::vector< OutputStructTableHandler > gather_tables()
Returns a vector of references to TableHandler objects that needs to be serialized/ deserialized for ...
DofsType locally_owned_dofs
void define_zero_constraints()
Define the zero constraints used to solve the problem.
SDIRKVectors sdirk_vectors
Instance of SDIRK-related vectors.
const unsigned int n_mpi_processes
virtual void setup_dofs_fd()=0
Initialize the dofs for fluid dynamics.
unsigned int number_quadrature_points
virtual VectorType & get_local_evaluation_point() override
virtual void update_solutions_for_multiphysics()
Required only for the matrix-free solver to update solutions within iterate function.
void constrain_stasis_with_temperature_cls(const DoFHandler< dim > *dof_handler_cls, const DoFHandler< dim > *dof_handler_ht)
Constrain fluids' subdomains according to the temperature field to null velocity and pressure fields ...
void rescale_pressure_dofs_in_newton_update()
This function is used to rescale pressure DOFs in the newton correction.
std::shared_ptr< VectorType > present_solution
void write_output_torques()
Writes the torques per boundary condition to a text file output.
std::shared_ptr< Quadrature< dim - 1 > > face_quadrature
VectorType average_solution
void write_output_forces()
Writes the forces per boundary condition to a text file output.
void transfer_solution(SolutionTransfer< dim, VectorType > &solution_transfer, std::vector< SolutionTransfer< dim, VectorType > > &previous_solutions_transfer)
Transfer solution after mesh refinement.
virtual AffineConstraints< double > & get_nonzero_constraints() override
void make_solid_domain(const DoFHandler< dim > &dof_handler, const bool non_zero_constraints, AffineConstraints< double > &constraints)
Turn regions of the mesh where the material_id>0 into a solid block by injecting velocity and pressur...
virtual void refine_mesh()
Allow the refinement of the mesh according to one of the 2 methods proposed.
virtual void read_checkpoint()
Restart a previous simulation from a checkpoint file.
void define_non_zero_constraints()
Define the non-zero constraints used to solve the problem.
virtual VectorType & get_evaluation_point() override
Getter methods to get the private attributes for the physic currently solved.
virtual void enable_dynamic_zero_constraints_fd()
Enable the use of dynamic zero constraints by initializing required FEValues objects.
void postprocessing_torques(const VectorType &evaluation_point)
Post-processing function Outputs the torque acting on each boundary condition.
std::shared_ptr< Mapping< dim > > get_mapping()
Returns the mapping shared pointer. A MappingQCache is necessary for prescribed rotation in rotor-sta...
virtual void finish_time_step()
Finishes the time step of the fluid dynamics. Post-processing and time stepping.
TableHandler apparent_viscosity_table
void rotate_rotor_mapping(const bool is_first)
Rotate rotor mapping in mortar method.
std::shared_ptr< FEValues< dim > > fe_values_temperature
FEValues object used for temperature-dependent solid domain constraints.
void gather_output_results(const VectorType &solution, std::vector< OutputStruct< dim, VectorType > > &solution_output_structs)
Gather solution information to generate output results.
AffineConstraints< double > dynamic_zero_constraints
virtual void dynamic_flow_control()
If set to enable, dynamic_flow_control allows to control the flow by executing space-average velocity...
std::shared_ptr< NavierStokesCouplingEvaluationSIPG< dim, double > > mortar_coupling_evaluator
virtual VectorType & get_present_solution() override
virtual void update_multiphysics_time_average_solution()=0
Update the time average velocity field solution.
const unsigned int this_mpi_process
SimulationParameters< dim > simulation_parameters
TableHandler kinetic_energy_table
virtual VectorType & get_system_rhs() override
bool use_manifold_for_normal
bool check_existance_of_bc(BoundaryConditions::FluidDynamicsBoundaryType bc)
Check if a specifique boundary condition exist.
bool average_velocities_are_enabled() const
Indicate whether the time-averaged velocity object holds vectors that must be preserved....
virtual void set_initial_condition_fd(Parameters::FluidDynamicsInitialConditionType initial_condition_type, bool restart=false)=0
virtual void multi_stage_postresolution(unsigned int stage, Parameters::SimulationControl::TimeSteppingMethod method, double time_step)
Calculate from Update .
virtual void iterate()
Do a regular CFD iteration.
void finish_simulation_fd()
Finishes the simulation for fluid dynamics by calling the post-processing elements that are required.
void restore_average_velocities_after_checkpoint()
Restore the state of the time-averaged velocity object after its vectors have been deserialized.
virtual VectorType & get_newton_update() override
std::shared_ptr< CouplingOperator< dim, double > > mortar_coupling_operator
TableHandler flow_rate_table
virtual void postprocess_fd(bool first_iteration)
Post-process fluid dynamics after an iteration.
TimerOutput computing_timer
std::shared_ptr< std::vector< VectorType > > previous_solutions
VectorType evaluation_point
TableHandler pressure_power_table
std::shared_ptr< MappingQCache< dim > > mapping_cache
std::shared_ptr< Function< dim > > forcing_function
VectorType init_temporary_vector()
This function initializes correctly a temporary vector depending on the vector type.
std::shared_ptr< SimulationControl > simulation_control
void update_boundary_conditions()
Update non-zero constraints if the boundary is time dependent. Note: not implemented for the block fl...
VectorType local_evaluation_point
virtual std::vector< OutputStruct< dim, VectorType > > gather_output_hook()
Gather and return vector of output structs that are particular to some applications.
void finish_simulation()
Finish the simulation by calling all the post-processing elements that are required.
virtual void multi_stage_preresolution(unsigned int stage, Parameters::SimulationControl::TimeSteppingMethod method)
Update the sum_over_previous_stages variable to use it in the solver.
FlowControl< dim > flow_control
void refine_mesh_uniform()
Allow the uniform refinement of all the mesh.
TableHandler pressure_drop_table
std::vector< std::shared_ptr< NavierStokesAssemblerBase< dim > > > assemblers
std::shared_ptr< MultiphysicsInterface< dim > > multiphysics
virtual void set_solution_from_checkpoint(const std::string &checkpoint_file_prefix)
Read the solution from a checkpoint file and set it as the current solution.
std::shared_ptr< FEValues< dim > > fe_values_cls
NavierStokesBase(SimulationParameters< dim > &nsparam, const FluidDynamicsFormulation fluid_dynamics_formulation=FluidDynamicsFormulation::standard)
Construct the Navier-Stokes base and the multiphysics interface.
bool cell_in_constraining_domain(const typename DoFHandler< dim >::active_cell_iterator &cell, const Point< dim > &plane_point, const Tensor< 1, dim > &plane_normal_vector)
Checks and identifies if the cell is located in the constraining domain defined by a plane with its o...
AffineConstraints< double > zero_constraints
MeshController mesh_controller
virtual void percolate_time_vectors_fd()
finish_time_step Finishes the time step of the fluid dynamics Post-processing and time stepping
virtual void update_forcing_and_boundary_conditions()
Set the time of the forcing function and of the time-dependent boundary conditions to the current tim...
std::shared_ptr< AverageVelocities< dim, VectorType, DofsType > > average_velocities
virtual void setup_dofs()
Initialize the degree of freedom and the memory associated with them for fluid dynamics and enabled a...
TableHandler enstrophy_table
std::shared_ptr< Mapping< dim > > mapping
void identify_cell_and_constrain_velocity(const std::vector< types::global_dof_index > &local_dof_indices, const std::vector< double > &local_temperature_values, StasisConstraintWithTemperature &stasis_constraint_struct)
Identify if temperature DOFs of the cell are within the constraining range. If they are,...
TableHandler viscous_dissipation_table
virtual void update_mortar_configuration()
Update mortar configuration.
void postprocessing_forces(const VectorType &evaluation_point)
Post-processing function Outputs the forces acting on each boundary condition.
void set_nodal_values()
Set the nodal values of velocity and pressure.
DofsType locally_relevant_dofs
void get_cell_filtered_phase_indicator_values(const typename DoFHandler< dim >::active_cell_iterator &cell, const DoFHandler< dim > *dof_handler_cls, const GlobalVectorType &filtered_phase_indicator_solution, std::vector< double > &local_filtered_phase_indicator_values)
Get cell's local filtered phase indicator values at quadrature points.
virtual void write_checkpoint()
Write the checkpoint.
std::shared_ptr< DoFHandler< dim > > dof_handler
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
virtual ~NavierStokesBase()=default
void reinit_mortar_operators()
Initialize mortar coupling manager, operator, and evaluator.
virtual void postprocess(bool first_iteration)
Post-process simulation after an iteration.
const unsigned int velocity_fem_degree
The PVDHandler class manages the storage of the information required to write pvd file....
PhysicsSolver(const Parameters::NonLinearSolver non_linear_solver_parameters)
Constructor for the non-linear physics.
Identifiers for multiphysics modules and their solution fields.
FluidDynamicsFormulation
Formulation of the fluid dynamics equations solved by a Navier-Stokes solver.
@ standard
Standard Navier-Stokes equations.
@ fluid_dynamics
Fluid Dynamics (Velocity,Pressure).
FluidDynamicsBoundaryType
FluidDynamicsInitialConditionType
DeclException1(FluidDynamicsBoundaryConditionMissing, types::boundary_id,<< "The boundary id: "<< arg1<< " is defined in the triangulation, but not as a boundary condition for the fluid dynamics physics. Lethe does not assign a default boundary condition to boundary ids. Every boundary id defined within the triangulation must have a corresponding boundary condition defined in the input file.")
std::variant< OutputStructPostprocessor< dim, VectorType >, OutputStructSolution< dim, VectorType >, OutputStructCellVector > OutputStruct
Variant handler of the three output structs (OutputStructPostprocessor, OutputStructSolution and Outp...
Simulation control classes for managing time-stepping and iteration control in Lethe.
Structure that stores all SDIRK-related vectors used during the time integration process.
std::vector< VectorType > previous_k_j_solutions
Stores the previous k_j stage vectors (one per stage j < i).
VectorType sum_over_previous_stages
Stores the sum of a_ij * k_j for j < i.
VectorType locally_owned_for_calculation
VectorType sum_bi_ki
Stores the sum of b_i * k_i across all stages.
VectorType local_sum_over_previous_stages
VectorType local_sum_bi_ki
Struct containing fluid id, temperature and phase indicator range information, and flag containers fo...
StasisConstraintWithTemperature(const unsigned int fluid_id, const double min_solid_temperature, const double max_solid_temperature, const double filtered_phase_indicator_tolerance)
Default constructor of the struct.
std::unordered_set< types::global_dof_index > dofs_are_connected_to_fluid
Container of global DOF indices connected to at least one fluid cell.
std::unordered_set< types::global_dof_index > dofs_are_in_solid
Container of global DOF indices located in solid cells.
const double filtered_phase_indicator_tolerance
Tolerance applied on filtered phase indicator.
const unsigned int fluid_id
Identifier of the fluid that is constrained.
const double min_solid_temperature
Lower threshold values of the constraining field (temperature).
const double max_solid_temperature
Upper threshold values of the constraining field (temperature).
GlobalVectorType VectorType
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType