4#ifndef lethe_fluid_dynamics_matrix_free_h
5#define lethe_fluid_dynamics_matrix_free_h
13#include <deal.II/lac/precondition.h>
14#include <deal.II/lac/solver_gmres.h>
15#include <deal.II/lac/trilinos_precondition.h>
17#include <deal.II/multigrid/mg_coarse.h>
18#include <deal.II/multigrid/mg_constrained_dofs.h>
19#include <deal.II/multigrid/mg_matrix.h>
20#include <deal.II/multigrid/mg_smoother.h>
21#include <deal.II/multigrid/mg_transfer_global_coarsening.h>
22#include <deal.II/multigrid/mg_transfer_matrix_free.h>
23#include <deal.II/multigrid/multigrid.h>
27template <
typename VectorType>
30template <
typename VectorType,
typename VectorTypePrecondition>
35 template <
class VectorType,
class PreconditionerType>
39template <
int dim,
typename MGNumber>
52#ifndef LETHE_GMG_USE_FLOAT
58 using VectorType = LinearAlgebra::distributed::Vector<Number>;
62#if DEAL_II_VERSION_GTE(9, 8, 0)
70 PreconditionRelaxation<OperatorType, SmootherPreconditionerType>;
76 PreconditionMG<dim, MGVectorType, LSTransferType>;
78 PreconditionMG<dim, MGVectorType, GCTransferType>;
119 reinit(
const std::shared_ptr<Mapping<dim>> &mapping,
120 const std::shared_ptr<Quadrature<dim>> &cell_quadrature,
121 const std::shared_ptr<Function<dim>> &forcing_function,
122 const std::shared_ptr<SimulationControl> &simulation_control,
123 const std::shared_ptr<PhysicalPropertiesManager>
124 &physical_properties_manager,
125 const std::shared_ptr<FESystem<dim>> &fe);
163 const MGLevelObject<std::shared_ptr<OperatorType>> &
172 const MGLevelObject<std::shared_ptr<PreconditionBase<MGVectorType>>> &
202 std::vector<std::shared_ptr<const Triangulation<dim>>>
209 MGLevelObject<std::shared_ptr<MappingQCache<dim>>>
mappings;
212 MGLevelObject<MGTwoLevelTransfer<dim, MGVectorType>>
transfers;
222 MGLevelObject<MatrixFreeOperators::MGInterfaceOperator<OperatorType>>
224 MGLevelObject<MatrixFreeOperators::MGInterfaceOperator<OperatorType>>
228 mutable MGLevelObject<std::shared_ptr<PreconditionBase<MGVectorType>>>
247 std::shared_ptr<PreconditionAdapter<MGVectorType, TrilinosVectorType>>
260 std::shared_ptr<MGCoarseGridBase<MGVectorType>>
mg_coarse;
275 std::shared_ptr<PreconditionMG<dim, MGVectorType, GCTransferType>>
279 std::shared_ptr<PreconditionMG<dim, MGVectorType, LSTransferType>>
283 std::shared_ptr<Multigrid<MGVectorType>>
mg;
286 std::shared_ptr<PreconditionMG<dim, MGVectorType, LSTransferType>>
290 std::shared_ptr<PreconditionMG<dim, MGVectorType, GCTransferType>>
345#if DEAL_II_VERSION_GTE(9, 8, 0)
379 initialize(
const std::shared_ptr<SimulationControl> &simulation_control,
382 const VectorType &time_derivative_previous_solutions);
393 const VectorType &temperature_present_solution);
412 LinearAlgebra::distributed::Vector<double>,
415 using VectorType = LinearAlgebra::distributed::Vector<double>;
476 double time_step)
override;
511 bool restart =
false)
override;
604 const double relative_residual);
615 const double relative_residual);
626 const double relative_residual);
712 std::shared_ptr<std::vector<TrilinosWrappers::MPI::Vector>>
Dynamic flow controller that drives the average velocity of the flow towards a target value.
virtual void initialize_GMG()
Intialize the geometric multigrid preconditioner.
virtual void solve()
Solve the problem defined by simulation parameters by iterating through time or through the mesh refi...
void reinit_mortar_operators_mf()
Initialize mortar coupling manager, operator, and evaluator for the matrix-free solver.
TrilinosWrappers::MPI::Vector multiphysics_average_velocities
Trilinos vector storing the average velocities that are provided to other physics.
void solve_system_GMRES(const double absolute_residual, const double relative_residual)
GMRES solver with preconditioning.
void setup_ILU()
Setup the implicit LU preconditioner and call the solve function of the linear solver....
void print_mg_setup_times()
Prints the setup times for the geometric multigrid preconditioner.
std::shared_ptr< PhysicalPropertiesManager > physical_properties_manager
Pointer to the physical properties object.
std::shared_ptr< std::vector< TrilinosWrappers::MPI::Vector > > multiphysics_previous_solutions
Vector storing trilinos vectors containing the previous solutions that are provided to other physics.
virtual void update_solutions_for_fluid_dynamics() override
Provide present multiphysics solutions from the multiphysics interface to the fluid dynamics.
DoFHandler< dim > dof_handler_fe_q_iso_q1
Describes the layout of DoFs for FE_Q_iso_Q1 elements.
void update_forcing_and_boundary_conditions() override
Set the time of the forcing function and of the time-dependent boundary conditions to the current tim...
virtual void set_initial_condition_fd(Parameters::FluidDynamicsInitialConditionType initial_condition_type, bool restart=false) override
VectorType temperature_present_solution
Vector storing the present temperature solution from the heat transfer solver.
VectorType time_derivative_previous_solutions
Vector to store the time derivatives of the previous solutions at the end of each time step for time-...
void setup_preconditioner() override
Set up appropriate preconditioner.
virtual void update_solutions_for_multiphysics() override
Provide present and previous flow solutions to the multiphysics interface. These solutions can be acc...
virtual void update_multiphysics_time_average_solution() override
Update the average velocity field solution in the multiphyscics interface.
virtual void update_mortar_configuration() override
Update mortar configuration.
std::shared_ptr< TrilinosWrappers::MPI::Vector > multiphysics_present_solution
Trilinos vector storing the present solution that is provided to other physics.
virtual void assemble_system_rhs() override
Assemble the system right hand side associated with the solver.
std::shared_ptr< NavierStokesOperatorBase< dim, double > > system_operator
Matrix-free operator in used for all the matrix-vector multiplications calls (vmult).
void solve_system_direct(const double absolute_residual, const double relative_residual)
Direct solver using TrilinosWrappers::SolverDirect.
std::shared_ptr< MFNavierStokesPreconditionGMGBase< dim > > gmg_preconditioner
Geometric multigrid preconditioner.
void multi_stage_preresolution(unsigned int stage, Parameters::SimulationControl::TimeSteppingMethod method) override
Update the sum_over_previous_stages variable to use it in the solver.
void solve_system_BiCGStab(const double absolute_residual, const double relative_residual)
BiCGStab solver with preconditioning.
void calculate_time_derivative_previous_solutions()
Calculate and store time derivatives of previous solutions according to time-stepping scheme to use t...
virtual void create_GMG()
Create the geometric multigrid preconditioner.
FluidDynamicsMatrixFree(SimulationParameters< dim > &nsparam, const FluidDynamicsFormulation fluid_dynamics_formulation=FluidDynamicsFormulation::standard)
Constructor that sets the finite element degree and system operator according to simulation parameter...
void setup_GMG()
Setup the geometric multigrid preconditioner.
std::shared_ptr< TrilinosWrappers::PreconditionILU > ilu_preconditioner
Implicit LU preconditioner.
virtual void update_multi_stage_solution(double time_step) override
~FluidDynamicsMatrixFree()
Destructor.
virtual void setup_dofs_fd() override
Setup the degrees of freedom, system constraints, system operator and solution vectors.
virtual void assemble_system_matrix() override
Assemble the matrix associated with the solver. Only required for compilation and it is not used for ...
void solve_linear_system() override
Solve the linear system of equations using the method specified in the simulation parameters.
virtual void multi_stage_postresolution(unsigned int stage, Parameters::SimulationControl::TimeSteppingMethod method, double time_step) override
Calculate from Update .
LinearAlgebra::distributed::Vector< double > VectorType
void assemble_L2_projection()
Assemble a L2 projection matrix for the velocity and the pressure, which can be used to set the initi...
bool use_manifold_for_normal
MGLevelObject< std::shared_ptr< PreconditionBase< MGVectorType > > > mg_smoother_preconditioners
Preconditioners associated to smoothers.
std::shared_ptr< SolverControl > coarse_grid_solver_control_intermediate
Solver control for the coarse grid solver (intermediate level).
MGTransferGlobalCoarsening< dim, MGVectorType > GCTransferType
MGLevelObject< std::shared_ptr< OperatorType > > mg_operators
Level operators for the geometric multigrid.
PreconditionMG< dim, MGVectorType, GCTransferType > PreconditionerTypeGC
MGLevelObject< DoFHandler< dim > > temperature_dof_handlers
PreconditionRelaxation< OperatorType, SmootherPreconditionerType > SmootherType
std::shared_ptr< PreconditionMG< dim, MGVectorType, GCTransferType > > gc_multigrid_preconditioner
Global coarsening multigrid preconditioner object.
PreconditionChebyshev< OperatorType, MGVectorType, SmootherPreconditionerType > ChebyshevSmootherType
SimulationParameters< dim > simulation_parameters
Simulation parameters.
virtual ~MFNavierStokesPreconditionGMGBase()=default
Default destructor.
void setup_AMG()
Set up AMG object needed for coarse-grid solver or preconditioning.
TimerOutput mg_vmult_timer
Internal timer for vmult timings.
unsigned int maxlevel
Max level of the multigrid hierarchy.
std::shared_ptr< PreconditionAdapter< MGVectorType, TrilinosVectorType > > coarse_grid_precondition
Coarse grid solver (algebraic multigrid, ILU, direct solver).
void setup_ILU()
Set up ILU object needed for coarse-grid solver or preconditioning.
std::shared_ptr< Multigrid< MGVectorType > > mg
Multigrid method.
std::shared_ptr< mg::Matrix< MGVectorType > > mg_interface_matrix_in
Interface edge matrix needed only for local smoothing.
std::shared_ptr< SolverControl > direct_solver_control
Solver control for the direct solver.
MGTransferMatrixFreeWrapper< dim, MGNumber > LSTransferType
TimerOutput mg_setup_timer
Timer for specific geometric multigrid components.
LinearAlgebra::distributed::Vector< Number > VectorType
void initialize()
Initialize smoother, coarse grid solver and multigrid object needed for the geometric multigrid preco...
LinearAlgebra::distributed::Vector< double > TrilinosVectorType
std::shared_ptr< MGCoarseGridBase< MGVectorType > > mg_coarse_intermediate
Multigrid wrapper for the coarse grid solver (intermediate level).
std::shared_ptr< MGCoarseGridBase< MGVectorType > > mg_coarse
Multigrid wrapper for the coarse grid solver.
std::shared_ptr< SolverGMRES< MGVectorType > > coarse_grid_solver_intermediate
GMRES as coarse grid solver (intermediate level).
MGCoarseGridApplyOperator< MGVectorType, PreconditionAdapter< MGVectorType, TrilinosVectorType > > CoarseGridSolverApply
std::shared_ptr< SolverControl > coarse_grid_solver_control
Solver control for the coarse grid solver.
const DoFHandler< dim > & dof_handler
Describes the layout of DoFs and the type of FE.
std::shared_ptr< LSTransferType > mg_transfer_ls
Transfer operator for local smoothing.
PreconditionBase< MGVectorType > SmootherPreconditionerType
std::shared_ptr< mg::Matrix< MGVectorType > > mg_matrix
Multigrid level object storing all operators.
LinearAlgebra::distributed::Vector< MGNumber > MGVectorType
MFNavierStokesPreconditionGMGBase(const SimulationParameters< dim > &simulation_parameters, const DoFHandler< dim > &dof_handler, const DoFHandler< dim > &dof_handler_fe_q_iso_q1)
Construct a new precondition GMG object. Sets constraints, operators and transfer objects.
std::shared_ptr< PreconditionMG< dim, MGVectorType, GCTransferType > > gc_multigrid_preconditioner_intermediate
Global coarsening multigrid preconditioner object (intermediate level).
std::shared_ptr< GCTransferType > mg_transfer_gc_temperature
Transfer operator for global coarsening for the temperature.
unsigned int minlevel
Min level of the multigrid hierarchy.
void vmult(VectorType &dst, const VectorType &src) const
Calls the v cycle function of the multigrid object.
const MGLevelObject< std::shared_ptr< OperatorType > > & get_mg_operators() const
Getter function for all level operators.
void reinit(const std::shared_ptr< Mapping< dim > > &mapping, const std::shared_ptr< Quadrature< dim > > &cell_quadrature, const std::shared_ptr< Function< dim > > &forcing_function, const std::shared_ptr< SimulationControl > &simulation_control, const std::shared_ptr< PhysicalPropertiesManager > &physical_properties_manager, const std::shared_ptr< FESystem< dim > > &fe)
Initializes geometric multigrid preconditioner and pre-calculate terms that are constant.
std::vector< std::shared_ptr< const Triangulation< dim > > > coarse_grid_triangulations
Triangulations for the global coarsening case.
MGLevelObject< MGTwoLevelTransfer< dim, MGVectorType > > transfers_temperature
DoFHandler< dim > dof_handler_fe_q_iso_q1
Describes the layout of DoFs for FE_Q_iso_Q1 elements.
void print_relevant_info() const
Prints relevant multigrid information.
NavierStokesOperatorBase< dim, MGNumber > OperatorType
PreconditionMG< dim, MGVectorType, LSTransferType > PreconditionerTypeLS
std::vector< unsigned int > coarse_grid_iterations
Vector holding number of coarse grid iterations.
MGLevelObject< MatrixFreeOperators::MGInterfaceOperator< OperatorType > > ls_mg_operators
const MGLevelObject< std::shared_ptr< PreconditionBase< MGVectorType > > > & get_mg_smoother_preconditioners() const
Getter function for all level smoother preconditioners.
MGLevelObject< MGTwoLevelTransfer< dim, MGVectorType > > transfers
Transfers for each of the levels of the global coarsening algorithm.
MGLevelObject< MatrixFreeOperators::MGInterfaceOperator< OperatorType > > ls_mg_interface_in
std::shared_ptr< GCTransferType > mg_transfer_gc
Transfer operator for global coarsening.
std::shared_ptr< Multigrid< MGVectorType > > mg_intermediate
Multigrid method (intermediate level).
MGLevelObject< MGConstrainedDoFs > mg_constrained_dofs
ConditionalOStream pcout
Conditional Ostream.
std::shared_ptr< MGSmootherBase< MGVectorType > > mg_smoother
std::shared_ptr< PreconditionMG< dim, MGVectorType, LSTransferType > > ls_multigrid_preconditioner
Local smoothing multigrid preconditioner object.
MGLevelObject< std::shared_ptr< MappingQCache< dim > > > mappings
MappingQCache for each of the levels of the global coarsening algorithm.
std::shared_ptr< PreconditionMG< dim, MGVectorType, LSTransferType > > ls_multigrid_preconditioner_intermediate
Local smoothing multigrid preconditioner object (intermediate level).
unsigned int intlevel
Intermediate level of the multigrid hierarchy.
std::shared_ptr< SolverGMRES< TrilinosVectorType > > coarse_grid_solver
GMRES as coarse grid solver.
virtual void create_level_operator(const unsigned int level)=0
Creates the operator for a given level.
MGLevelObject< DoFHandler< dim > > dof_handlers
DoF handlers for each of the levels of the global coarsening algorithm.
void create_level_operator(const unsigned int level) override
Creates the operator for a given level.
typename MFNavierStokesPreconditionGMGBase< dim >::MGVectorType MGVectorType
typename MFNavierStokesPreconditionGMGBase< dim >::MGNumber MGNumber
MGTransferGlobalCoarsening< dim, MGVectorType > GCTransferType
MFNavierStokesPreconditionGMG(const SimulationParameters< dim > &simulation_parameters, const DoFHandler< dim > &dof_handler, const DoFHandler< dim > &dof_handler_fe_q_iso_q1)
typename MFNavierStokesPreconditionGMGBase< dim >::VectorType VectorType
void initialize_auxiliary_physics(const DoFHandler< dim > &temperature_dof_handler, const VectorType &temperature_present_solution)
Transfer the current temperature solution to the different multigrid levels and compute the thermal b...
NavierStokesBase(SimulationParameters< dim > &nsparam, const FluidDynamicsFormulation fluid_dynamics_formulation=FluidDynamicsFormulation::standard)
A class that serves as base for all the matrix-free Navier-Stokes operators.
A wrapper class around a preconditioner to be able to handle vector types that are not supported by t...
A base class of preconditioners used by the smoother.
Common exception declarations shared across multiple solvers in Lethe.
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.
FluidDynamicsInitialConditionType