Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
fluid_dynamics_matrix_based.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2019-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_fluid_dynamics_matrix_based_h
5#define lethe_fluid_dynamics_matrix_based_h
6
7#include <core/exceptions.h>
8#include <core/multiphysics.h>
9#include <core/vector.h>
10
11#include <solvers/copy_data.h>
14
15#include <deal.II/lac/sparse_matrix.h>
16#include <deal.II/lac/trilinos_precondition.h>
17#include <deal.II/lac/trilinos_solver.h>
18#include <deal.II/lac/trilinos_sparse_matrix.h>
19#include <deal.II/lac/trilinos_vector.h>
20
21using namespace dealii;
22
23/**
24 * @brief A solver class for the Navier-Stokes equation using GLS stabilization
25 *
26 * @tparam dim An integer that denotes the dimension of the space in which
27 * the flow is solved
28 *
29 * @ingroup solvers
30 */
31
32template <int dim>
34 : public NavierStokesBase<dim, GlobalVectorType, IndexSet>
35{
36public:
37 /**
38 * @brief Construct the matrix-based Navier-Stokes solver.
39 * @param[in] nsparam Relevant parameters for the solver.
40 * @param[in] fluid_dynamics_formulation The formulation of the fluid dynamics
41 * equations. Whether the solver solves the volume-averaged Navier-Stokes
42 * (VANS) equations or the standard Navier-Stokes equations.
43 */
46 const FluidDynamicsFormulation fluid_dynamics_formulation =
49
50 /**
51 * @brief solve Solves the Navier-Stokes problem
52 *
53 * This functions solves the problem defined by the Navier-Stokes parameter
54 * by iterating through time or through the mesh refinements.
55 */
56 virtual void
57 solve();
58
59protected:
60 /**
61 * @brief setup_dofs_fd Setup the degree of freedom, system matrix and solution vectors
62 * Navier-Stokes problem
63 */
64 virtual void
65 setup_dofs_fd() override;
66
67 /**
68 * @brief Update the sum_over_previous_stages variable to use it in the solver.
69 *
70 * @param stage An unsigned integer which gives the index of the current stage
71 * @param method SDIRK method for now (BDF methods are single stage)
72 */
73 void
75 unsigned int stage,
77
78 /**
79 * @brief Calculate \f$ k_i \f$ from \f$ u*_i : k_i = \frac{u*_i - u_n}{time_step*a_ii} - \sum{j=1}^{i-1} a_ij * k_j \f$
80 * Update \f$ \sum_{i=1}^{N_{stages}} b_i * k_i \f$
81 *
82 * @param stage An unsigned integer which gives the index of the current stage
83 * @param method SDIRK methods for now (BDF methods are single stage)
84 */
85 virtual void
87 unsigned int stage,
89 double time_step) override;
90
91 /**
92 * @brief \f$ u_{n+1} = u_n + time_step * \sum_{i=1}^{N_{stages}} b_i * k_i \f$
93 *
94 * @param time_step The current time step to build the solution at the next time step
95 */
96 virtual void
97 update_multi_stage_solution(double time_step) override;
98
99 /**
100 * @brief Sets the initial condition for the solver
101 *
102 * If the simulation is restarted from a checkpoint, the initial solution
103 * setting is bypassed and the checkpoint is instead read.
104 *
105 * @param initial_condition_type The type of initial condition to be set
106 *
107 * @param restart A boolean that indicates if the simulation is being restarted.
108 * if set to true, the initial conditions are never set, but are instead
109 * overridden by the read_checkpoint functionality.
110 *
111 **/
112 virtual void
115 bool restart = false) override;
116
117protected:
118 /**
119 * @brief Assembles the matrix associated with the solver
120 */
121 virtual void
122 assemble_system_matrix() override;
123
124 /**
125 * @brief Assemble the rhs associated with the solver
126 */
127 virtual void
128 assemble_system_rhs() override;
129
130 /**
131 * @brief Updates the average velocity field solution in the multiphyscics interface
132 */
133 virtual void
135
136 /**
137 * @brief Set-up the appropriate preconditioner
138 */
139 void
140 setup_preconditioner() override;
141
142 /**
143 * @brief Define the zero constraints used to solved the problem that change
144 * with other physics' solutions.
145 *
146 * It differs from FluidDynamicsMatrixBased::define_zero_constraints as it
147 * changes in time depending on the physics' solutions. Currently, it is only
148 * used to constraint solid with the temperature's evolution.
149 */
150 void
152
153 /**
154 * @brief Fix a constant pressure on the minimum dof index. This can be enabled
155 * in the simulation control parameters.
156 */
157 void
159
160 /**
161 * @brief Update mortar configuration.
162 *
163 * When the rotor domain is rotated, the mortar cells need to be reinitialized
164 * according to the new rotor-stator interface configuration.
165 */
166 virtual void
168
169 /**
170 * @brief Assemble the local matrix for a given cell.
171 *
172 * This function is used by the WorkStream class to assemble
173 * the system matrix. It is a thread safe function.
174 *
175 * @param cell The cell for which the local matrix is assembled.
176 *
177 * @param scratch_data The scratch data which is used to store
178 * the calculated finite element information at the gauss point.
179 * See the documentation for NavierStokesScratchData for more
180 * information
181 *
182 * @param copy_data The copy data which is used to store
183 * the results of the assembly over a cell
184 */
185 virtual void
187 const typename DoFHandler<dim>::active_cell_iterator &cell,
188 NavierStokesScratchData<dim> &scratch_data,
190
191 /**
192 * @brief Assemble the local rhs for a given cell
193 *
194 * @param cell The cell for which the local matrix is assembled.
195 *
196 * @param scratch_data The scratch data which is used to store
197 * the calculated finite element information at the gauss point.
198 * See the documentation for NavierStokesScratchData for more
199 * information
200 *
201 * @param copy_data The copy data which is used to store
202 * the results of the assembly over a cell
203 */
204 virtual void
206 const typename DoFHandler<dim>::active_cell_iterator &cell,
207 NavierStokesScratchData<dim> &scratch_data,
209
210 /**
211 * @brief sets up the vector of assembler functions
212 */
213 virtual void
215
216
217 /**
218 * @brief Copy local cell information to global matrix
219 */
220
221 virtual void
223 const StabilizedMethodsTensorCopyData<dim> &copy_data);
224
225 /**
226 * @brief Copy local cell rhs information to global rhs
227 */
228
229 virtual void
231 const StabilizedMethodsTensorCopyData<dim> &copy_data);
232
233 /**
234 * @brief Call for the assembly of the linear system of equation
235 *
236 * @param initial_step Indicates if this is the first solution of the linear system.
237 * If this is the case, the non_zero version of the constraints are used for
238 * the Dirichlet boundary conditions
239 */
240 void
241 solve_linear_system() override;
242
243private:
244 /**
245 * @brief Assembles an L2_projection matrix for the velocity and the pressure.
246 * This L2 projection matrix can be used to set the initial condition for
247 * the Navier-Stokes problem
248 */
249 void
251
252
253 /**
254 * @brief Solver for the L2 Projection linear system at the initial time step to apply this initial condition. It always uses the GMRES solver with ILU(N) by default.
255 *
256 * @param[in] absolute_residual Absolute residual for the solver stopping
257 * criterion.
258 * @param[in] relative_residual Relative residual for the solver stopping
259 * criterion.
260 */
261
262 void
263 solve_L2_system(const double absolute_residual,
264 const double relative_residual);
265
266
267 /**
268 * @brief GMRES solver with ILU(N) preconditioning or AMG preconditioning
269 * @param[in] absolute_residual Absolute residual for the solver stopping
270 * criterion.
271 * @param[in] relative_residual Relative residual for the solver stopping
272 * criterion.
273 */
274 void
275 solve_system_GMRES(const double absolute_residual,
276 const double relative_residual);
277
278 /**
279 * @brief BiCGStab solver with ILU(N) preconditioning
280 * @param[in] absolute_residual Absolute residual for the solver stopping
281 * criterion.
282 * @param[in] relative_residual Relative residual for the solver stopping
283 * criterion.
284 */
285 void
286 solve_system_BiCGStab(const double absolute_residual,
287 const double relative_residual);
288 /**
289 * @brief Direct solver using TrilinosWrappers::SolverDirect
290 * The use of this solver should be avoided for 3D problems
291 */
292 void
293 solve_system_direct(const double absolute_residual,
294 const double relative_residual);
295
296 /**
297 * @brief Set-up AMG preconditioner
298 */
299 void
300 setup_AMG();
301
302 /**
303 * @brief Set-up ILU preconditioner
304 */
305 void
306 setup_ILU();
307
308
309 /**
310 * Members
311 */
312protected:
313 TrilinosWrappers::SparseMatrix system_matrix;
314
315private:
316 SparsityPattern sparsity_pattern;
317 std::shared_ptr<TrilinosWrappers::PreconditionILU> ilu_preconditioner;
318 std::shared_ptr<TrilinosWrappers::PreconditionAMG> amg_preconditioner;
321};
322
323
324#endif
void define_dynamic_zero_constraints()
Define the zero constraints used to solved the problem that change with other physics' solutions.
virtual void solve()
solve Solves the Navier-Stokes problem
TrilinosWrappers::SparseMatrix system_matrix
void assemble_L2_projection()
Assembles an L2_projection matrix for the velocity and the pressure. This L2 projection matrix can be...
virtual void copy_local_rhs_to_global_rhs(const StabilizedMethodsTensorCopyData< dim > &copy_data)
Copy local cell rhs information to global rhs.
virtual void update_multiphysics_time_average_solution() override
Updates the average velocity field solution in the multiphyscics interface.
std::shared_ptr< TrilinosWrappers::PreconditionAMG > amg_preconditioner
void solve_linear_system() override
Call for the assembly of the linear system of equation.
void setup_AMG()
Set-up AMG preconditioner.
virtual void setup_assemblers()
sets up the vector of assembler functions
void define_pressure_constraints()
Fix a constant pressure on the minimum dof index. This can be enabled in the simulation control param...
virtual void set_initial_condition_fd(Parameters::FluidDynamicsInitialConditionType initial_condition_type, bool restart=false) override
Sets the initial condition for the solver.
std::shared_ptr< TrilinosWrappers::PreconditionILU > ilu_preconditioner
virtual void multi_stage_postresolution(unsigned int stage, Parameters::SimulationControl::TimeSteppingMethod method, double time_step) override
Calculate from Update .
virtual void assemble_local_system_rhs(const typename DoFHandler< dim >::active_cell_iterator &cell, NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data)
Assemble the local rhs for a given cell.
virtual void update_mortar_configuration() override
Update mortar configuration.
void solve_system_BiCGStab(const double absolute_residual, const double relative_residual)
BiCGStab solver with ILU(N) preconditioning.
void solve_system_direct(const double absolute_residual, const double relative_residual)
Direct solver using TrilinosWrappers::SolverDirect The use of this solver should be avoided for 3D pr...
virtual void assemble_system_matrix() override
Assembles the matrix associated with the solver.
void setup_preconditioner() override
Set-up the appropriate 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 setup_ILU()
Set-up ILU preconditioner.
virtual void setup_dofs_fd() override
setup_dofs_fd Setup the degree of freedom, system matrix and solution vectors Navier-Stokes problem
void solve_L2_system(const double absolute_residual, const double relative_residual)
Solver for the L2 Projection linear system at the initial time step to apply this initial condition....
void solve_system_GMRES(const double absolute_residual, const double relative_residual)
GMRES solver with ILU(N) preconditioning or AMG preconditioning.
virtual void copy_local_matrix_to_global_matrix(const StabilizedMethodsTensorCopyData< dim > &copy_data)
Copy local cell information to global matrix.
virtual void update_multi_stage_solution(double time_step) override
virtual void assemble_system_rhs() override
Assemble the rhs associated with the solver.
virtual void assemble_local_system_matrix(const typename DoFHandler< dim >::active_cell_iterator &cell, NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data)
Assemble the local matrix for a given cell.
FluidDynamicsMatrixBased(SimulationParameters< dim > &nsparam, const FluidDynamicsFormulation fluid_dynamics_formulation=FluidDynamicsFormulation::standard)
Construct the matrix-based Navier-Stokes solver.
NavierStokesBase(SimulationParameters< dim > &nsparam, const FluidDynamicsFormulation fluid_dynamics_formulation=FluidDynamicsFormulation::standard)
Class that stores the information required by the assembly procedure for a Navier-Stokes equation....
Class responsible for storing the information calculated using the assembly of stabilized Tensor<1,...
Definition copy_data.h:166
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.