Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
fluid_dynamics_vans_matrix_free.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2025-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_vans_matrix_free_h
5#define lethe_fluid_dynamics_vans_matrix_free_h
6
8
11
12
13/**
14 * @brief A geometric multigrid preconditioner implementation for
15 * incompressible VANS equations.
16 *
17 * @tparam dim An integer that denotes the dimension of the space in which
18 * the flow is solved
19 */
20template <int dim>
23{
24public:
25 /// Useful aliases to improve readability.
30#if DEAL_II_VERSION_GTE(9, 8, 0)
31 using GCTransferType = MGTransferMatrixFree<dim, MGNumber>;
32#else
33 using GCTransferType = MGTransferGlobalCoarsening<dim, MGVectorType>;
34#endif
35
36 /// Local-smoothing transfer used for the auxiliary (particle-projected)
37 /// fields. The auxiliary fields live on a single triangulation that has
38 /// multigrid level DoFs distributed, so a plain MGTransferMatrixFree is
39 /// sufficient -- they do not need to support hp-coarsening.
40 using LSTransferType = MGTransferMatrixFree<dim, MGNumber>;
41
42 /**
43 * @brief Constructor
44 * @param[in] param Complete set of parameters for the CFD-DEM or VANS
45 * simulations.
46 * @param[in] dof_handler DoFHandler used to solve the VANS equation.
47 * @param[in] dof_handler_fe_q_iso_q1 DoFHandler with degree=1 to be used in
48 * hp multigrid.
49 */
52 const DoFHandler<dim> &dof_handler,
53 const DoFHandler<dim> &dof_handler_fe_q_iso_q1);
54
55 /**
56 * @brief Creates the operator on a given level
57 * @param[in] level Level on which the operator is created..
58 */
59 void
60 create_level_operator(const unsigned int level) override;
61
62 /**
63 * @brief Initializes the preconditioner
64 * @param[in] simulation_control Simulation control object which is used to
65 * obtain information on the time step.
66 * @param[in] flow_control Flow controller which is used to provide volume
67 * forcing in the flow.
68 * @param[in] present_solution Current solution for the VANS equation.
69 * @param[in] time_derivative_previous_solutions Pre-calculated time
70 * derivative.
71 * @param[in] particle_projector Manage for the void fraction. This is used
72 * to obtain the void fraction on the levels of the grid.
73 *
74 * @tparam PropertiesIndex Index of the properties used within the
75 * ParticleHandler. Only the projected fields of the particle projector are
76 * used here, so this class itself does not depend on the properties index.
77 */
78 template <typename PropertiesIndex>
79 void
80 initialize(const std::shared_ptr<SimulationControl> &simulation_control,
81 FlowControl<dim> &flow_control,
82 const VectorType &present_solution,
83 const VectorType &time_derivative_previous_solutions,
84 const VectorType &time_derivative_void_fraction,
85 const ParticleProjector<dim, PropertiesIndex> &particle_projector);
86
87private:
88 /// Reference to the simulation parameters
90
91 /// Void Fraction DoF handlers for each of the levels of the global coarsening
92 /// algorithm
93 MGLevelObject<DoFHandler<dim>> void_fraction_dof_handlers;
94
95 /// Void fraction transfers for each of the levels of the global coarsening
96 /// algorithm
97 MGLevelObject<MGTwoLevelTransfer<dim, MGVectorType>> transfers_void_fraction;
98
99 /// Transfer operator for global coarsening for the void fraction
100 std::shared_ptr<GCTransferType> mg_transfer_gc_void_fraction;
101
102 /// Particle-fluid force DoF handlers for each of the levels of the global
103 /// coarsening algorithm
104 MGLevelObject<DoFHandler<dim>> pf_force_dof_handlers;
105
106 /// Particle-fluid force transfers for each of the levels of the global
107 /// coarsening algorithm
108 MGLevelObject<MGTwoLevelTransfer<dim, MGVectorType>> transfers_pf_force;
109
110 /// Transfer operator for global coarsening for the particle-fluid forces
111 std::shared_ptr<GCTransferType> mg_transfer_gc_pf_force;
112
113 /// Particle-fluid drag DoF handlers for each of the levels of the global
114 /// coarsening algorithm
115 MGLevelObject<DoFHandler<dim>> pf_drag_dof_handlers;
116
117 /// Particle-fluid drag transfers for each of the levels of the global
118 /// coarsening algorithm
119 MGLevelObject<MGTwoLevelTransfer<dim, MGVectorType>> transfers_pf_drag;
120
121 /// Transfer operator for global coarsening for the particle-fluid drag
122 std::shared_ptr<GCTransferType> mg_transfer_gc_pf_drag;
123
124 /// Particle velocity DoF handlers for each of the levels of the global
125 /// coarsening algorithm
126 MGLevelObject<DoFHandler<dim>> particle_velocity_dof_handlers;
127
128 /// Particle velocity for each of the levels of the global
129 /// coarsening algorithm
130 MGLevelObject<MGTwoLevelTransfer<dim, MGVectorType>>
132
133 /// Transfer operator for global coarsening for the particle velocity
134 std::shared_ptr<GCTransferType> mg_transfer_gc_particle_velocity;
135
136 /// Particle momentum transfer coefficient DoF handlers for each of the levels
137 /// of the global coarsening algorithm
138 MGLevelObject<DoFHandler<dim>> momentum_transfer_coefficient_dof_handlers;
139
140 /// Particle-fluid drag transfers for each of the levels of the global
141 /// coarsening algorithm
142 MGLevelObject<MGTwoLevelTransfer<dim, MGVectorType>>
144
145 /// Transfer operator for global coarsening for the particle-fluid drag
146 std::shared_ptr<GCTransferType> mg_transfer_gc_momentum_transfer_coefficient;
147
148 /// Local-smoothing transfer operators for every auxiliary field. These are
149 /// only built when the fluid_dynamics preconditioner is LSMG. The DoFHandler
150 /// inside the ParticleProjector is reused at every level (with multigrid
151 /// level DoFs distributed), so no per-level DoFHandler is stored.
152 std::shared_ptr<LSTransferType> mg_transfer_ls_void_fraction;
153 std::shared_ptr<LSTransferType> mg_transfer_ls_pf_force;
154 std::shared_ptr<LSTransferType> mg_transfer_ls_pf_drag;
155 std::shared_ptr<LSTransferType> mg_transfer_ls_particle_velocity;
156 std::shared_ptr<LSTransferType> mg_transfer_ls_momentum_transfer_coefficient;
157};
158
159/**
160 * @brief A solver for the Volume-Averaged incompressible Navier-Stokes equations
161 * implemented in a matrix-free fashion.
162 *
163 * A matrix-free stabilized solver for the Volume-Averaged incompressible
164 * Navier-Stokes (VANS) equations implemented in a matrix-free fashion with a
165 * sum-factorization approach. It uses a continuous Galerkin discretization and
166 * solves the fully-coupled discretized problem in a monolithic way using
167 * multigrid preconditioners. This class greatly inherits from the matrix-free
168 * implementation of the Navier-Stokes equations.
169 *
170 * @tparam dim An integer that denotes the dimension of the space in which
171 * the flow is solved.
172 * @tparam PropertiesIndex Index of the properties used within the
173 * ParticleHandler.
174 */
175template <int dim, typename PropertiesIndex>
177{
178 using VectorType = LinearAlgebra::distributed::Vector<double>;
179
180public:
181 /**
182 * @brief Constructor that sets the finite element degree and system operator
183 * according to simulation parameters. It initializes the CFD-DEM parameters,
184 * the particle mapping, the particle handler, and the void fraction manager.
185 * It also checks whether there are periodic boundaries.
186 *
187 * @param[in] param Relevant parameters for the solver.
188 */
190
191 /**
192 * @brief Solve the problem defined by simulation parameters by iterating
193 * through time or through the mesh refinements.
194 */
195 void
196 solve() override;
197
198protected:
199 /**
200 * @brief Read particles arising from a DEM simulation
201 */
202 virtual void
203 read_dem();
204
205 /**
206 * @brief Setup the degree of freedom of the flow solver and the degrees of freedom
207 * and constraints for the void fraction.
208 */
209 void
210 setup_dofs() override;
211
212 /**
213 * @brief Assembles the RHS of the VANS system of equation. This function
214 * also recalculates the particle-fluid interaction when the drag coupling
215 * is implicit.
216 */
217 void
218 assemble_system_rhs() override;
219
220 /**
221 * @brief Finish the time step and manage the end of the time step for the void
222 * fraction.
223 */
224 virtual void
226
227 /**
228 * @brief Add void fraction field to output files.
229 *
230 * @return Vector of OutputStructs that will be used to write the output results as VTU files.
231 */
232 std::vector<OutputStruct<dim, LinearAlgebra::distributed::Vector<double>>>
233 gather_output_hook() override;
234
235 /**
236 * @brief Create geometric multigrid preconditioner.
237 */
238 void
239 create_GMG() override;
240
241 /**
242 * Initializes (or re-initializes) geometric multigrid preconditioner
243 */
244 void
245 initialize_GMG() override;
246
247 /**
248 * @brief Evaluate the time derivative of the void fraction.
249 * This evaluates the time-derivative as a solution vector which can be passed
250 * to the matrix-free operator.
251 */
252 void
254
255 /// Simulation parameters for CFD-DEM simulations
257
258 /// Mapping used for the particles
259 MappingQGeneric<dim> particle_mapping;
260
261 /// Particle-handler used to store particles in CFD-DEM simulations
262 Particles::ParticleHandler<dim, dim> particle_handler;
263
264 /// Object that manages the void fraction calculation from functions
265 /// or from parameters.
267
268 /// Member variables which are used to manage boundary conditions
270 std::map<types::boundary_id, Tensor<1, dim>> cfd_periodic_offsets;
271 std::map<types::boundary_id, unsigned int> cfd_periodic_directions;
272
273 /// Vector to store the time derivative of the void fraction
275};
276#endif
Dynamic flow controller that drives the average velocity of the flow towards a target value.
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...
std::map< types::boundary_id, unsigned int > cfd_periodic_directions
LinearAlgebra::distributed::Vector< double > VectorType
virtual void read_dem()
Read particles arising from a DEM simulation.
void evaluate_time_derivative_void_fraction()
Evaluate the time derivative of the void fraction. This evaluates the time-derivative as a solution v...
void solve() override
Solve the problem defined by simulation parameters by iterating through time or through the mesh refi...
virtual void finish_time_step_fd()
Finish the time step and manage the end of the time step for the void fraction.
bool has_periodic_boundaries
Member variables which are used to manage boundary conditions.
void create_GMG() override
Create geometric multigrid preconditioner.
ParticleProjector< dim, PropertiesIndex > particle_projector
std::map< types::boundary_id, Tensor< 1, dim > > cfd_periodic_offsets
CFDDEMSimulationParameters< dim > cfd_dem_simulation_parameters
Simulation parameters for CFD-DEM simulations.
void setup_dofs() override
Setup the degree of freedom of the flow solver and the degrees of freedom and constraints for the voi...
FluidDynamicsVANSMatrixFree(CFDDEMSimulationParameters< dim > &param)
Constructor that sets the finite element degree and system operator according to simulation parameter...
Particles::ParticleHandler< dim, dim > particle_handler
Particle-handler used to store particles in CFD-DEM simulations.
VectorType time_derivative_void_fraction
Vector to store the time derivative of the void fraction.
void assemble_system_rhs() override
Assembles the RHS of the VANS system of equation. This function also recalculates the particle-fluid ...
std::vector< OutputStruct< dim, LinearAlgebra::distributed::Vector< double > > > gather_output_hook() override
Add void fraction field to output files.
MappingQGeneric< dim > particle_mapping
Mapping used for the particles.
void initialize()
Initialize smoother, coarse grid solver and multigrid object needed for the geometric multigrid preco...
const DoFHandler< dim > & dof_handler
Describes the layout of DoFs and the type of FE.
DoFHandler< dim > dof_handler_fe_q_iso_q1
Describes the layout of DoFs for FE_Q_iso_Q1 elements.
typename MFNavierStokesPreconditionGMGBase< dim >::MGVectorType MGVectorType
typename MFNavierStokesPreconditionGMGBase< dim >::MGNumber MGNumber
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
const CFDDEMSimulationParameters< dim > & cfd_dem_simulation_parameters
Reference to the simulation parameters.
typename MFNavierStokesPreconditionGMG< dim >::VectorType VectorType
Useful aliases to improve readability.
typename MFNavierStokesPreconditionGMG< dim >::MGVectorType MGVectorType
typename MFNavierStokesPreconditionGMG< dim >::MGNumber MGNumber
MGLevelObject< MGTwoLevelTransfer< dim, MGVectorType > > transfers_pf_force
MGTransferMatrixFree< dim, MGNumber > LSTransferType
std::shared_ptr< GCTransferType > mg_transfer_gc_momentum_transfer_coefficient
Transfer operator for global coarsening for the particle-fluid drag.
std::shared_ptr< GCTransferType > mg_transfer_gc_void_fraction
Transfer operator for global coarsening for the void fraction.
std::shared_ptr< LSTransferType > mg_transfer_ls_momentum_transfer_coefficient
std::shared_ptr< GCTransferType > mg_transfer_gc_pf_drag
Transfer operator for global coarsening for the particle-fluid drag.
MGLevelObject< DoFHandler< dim > > momentum_transfer_coefficient_dof_handlers
MGLevelObject< MGTwoLevelTransfer< dim, MGVectorType > > transfers_momentum_transfer_coefficient
void create_level_operator(const unsigned int level) override
Creates the operator on a given level.
MGLevelObject< MGTwoLevelTransfer< dim, MGVectorType > > transfers_particle_velocity
std::shared_ptr< LSTransferType > mg_transfer_ls_void_fraction
MGLevelObject< DoFHandler< dim > > pf_force_dof_handlers
std::shared_ptr< LSTransferType > mg_transfer_ls_particle_velocity
MGLevelObject< DoFHandler< dim > > void_fraction_dof_handlers
std::shared_ptr< GCTransferType > mg_transfer_gc_particle_velocity
Transfer operator for global coarsening for the particle velocity.
MFNavierStokesVANSPreconditionGMG(const CFDDEMSimulationParameters< dim > &param, const DoFHandler< dim > &dof_handler, const DoFHandler< dim > &dof_handler_fe_q_iso_q1)
Constructor.
MGTransferGlobalCoarsening< dim, MGVectorType > GCTransferType
std::shared_ptr< GCTransferType > mg_transfer_gc_pf_force
Transfer operator for global coarsening for the particle-fluid forces.
MGLevelObject< MGTwoLevelTransfer< dim, MGVectorType > > transfers_pf_drag
MGLevelObject< DoFHandler< dim > > particle_velocity_dof_handlers
std::shared_ptr< LSTransferType > mg_transfer_ls_pf_force
MGLevelObject< DoFHandler< dim > > pf_drag_dof_handlers
MGLevelObject< MGTwoLevelTransfer< dim, MGVectorType > > transfers_void_fraction
std::shared_ptr< LSTransferType > mg_transfer_ls_pf_drag
Particle information projection. This class manages the calculation of the projection of the particle...