Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
particle_projector.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2021-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_void_fraction_h
5#define lethe_void_fraction_h
6
10#include <core/vector.h>
11
15
16#include <deal.II/base/index_set.h>
17#include <deal.II/base/utilities.h>
18
19#include <deal.II/distributed/tria_base.h>
20
21#include <deal.II/dofs/dof_handler.h>
22
23#include <deal.II/fe/fe_q.h>
24#include <deal.II/fe/fe_simplex_p.h>
25#include <deal.II/fe/fe_system.h>
26#include <deal.II/fe/mapping_fe.h>
27
28#include <deal.II/lac/affine_constraints.h>
29#include <deal.II/lac/trilinos_precondition.h>
30#include <deal.II/lac/trilinos_sparse_matrix.h>
31
32#include <deal.II/numerics/data_out.h>
33#include <deal.II/numerics/vector_tools.h>
34
35#include <deal.II/particles/particle_handler.h>
36
37#include <utility>
38
39using namespace dealii;
40
42 NotSupportedMeshAdaptationMethod,
43 "Mesh adaptation is only supported with the steady time-stepping method "
44 "in the VANS and CFD-DEM solvers at the moment because the void fraction "
45 "field is not yet updated during mesh adaptation.");
46
47/** \
48 * @brief Calculate the area of intersection between a circular (2D) particle and a circle. \
49 * \
50 * @param[in] r_particle Radius of the particle \
51 * @param[in] r_circle Radius of the circle \
52 * @param[in] neighbor_distance Distance between the particle and the circle \
53 */ \
54#
55inline double
56particle_circle_intersection_2d(const double r_particle,
57 const double r_circle,
58 const double neighbor_distance)
59{
60 return pow(r_particle, 2) * Utilities::fixed_power<-1, double>(
61 cos((pow(neighbor_distance, 2) +
62 pow(r_particle, 2) - pow(r_circle, 2)) /
63 (2 * neighbor_distance * r_particle))) +
64 Utilities::fixed_power<2, double>(r_circle) *
65 Utilities::fixed_power<-1, double>(
66 cos((pow(neighbor_distance, 2) - pow(r_particle, 2) +
67 pow(r_circle, 2)) /
68 (2 * neighbor_distance * r_circle))) -
69 0.5 * sqrt((-neighbor_distance + r_particle + r_circle) *
70 (neighbor_distance + r_particle - r_circle) *
71 (neighbor_distance - r_particle + r_circle) *
72 (neighbor_distance + r_particle + r_circle));
73}
74
75/**
76 * @brief Calculate the volume of intersection between a spherical (3D) particle and a sphere.
77 *
78 * @param[in] r_particle Radius of the particle
79 * @param[in] r_sphere Radius of the sphere
80 * @param[in] neighbor_distance Distance between the particle and the sphere
81 */
82
83inline double
84particle_sphere_intersection_3d(const double r_particle,
85 const double r_sphere,
86 const double neighbor_distance)
87{
88 return M_PI *
89 Utilities::fixed_power<2, double>(r_sphere + r_particle -
90 neighbor_distance) *
91 (Utilities::fixed_power<2, double>(neighbor_distance) +
92 (2 * neighbor_distance * r_particle) -
93 (3 * Utilities::fixed_power<2, double>(r_particle)) +
94 (2 * neighbor_distance * r_sphere) + (6 * r_sphere * r_particle) -
95 (3 * Utilities::fixed_power<2, double>(r_sphere))) /
96 (12 * neighbor_distance);
97}
98
99/**
100 * @brief Evaluate a Gaussian filter kernel between a particle and a point.
101 *
102 * The kernel is normalised so that its integral over R^dim equals the
103 * particle volume V_p. With this normalisation the same downstream
104 * normalisation procedure used by the spherical QCM filter (dividing by
105 * the accumulated volumetric_contribution to recover the particle volume)
106 * applies unchanged.
107 *
108 * The Gaussian has non-compact support: contributions outside the QCM
109 * neighbor-cell stencil are silently dropped. The accumulated normalisation
110 * absorbs the missing mass, but the projected shape will be biased if sigma
111 * is comparable to the stencil reach. Choose sigma accordingly.
112 *
113 * @tparam dim Number of spatial dimensions.
114 *
115 * @param[in] r_particle Radius of the particle.
116 * @param[in] sigma Standard deviation of the Gaussian (the QCM filter length).
117 * @param[in] distance Distance between the particle center and the evaluation
118 * point.
119 */
120template <int dim>
121inline double
122gaussian_filter_kernel(const double r_particle,
123 const double sigma,
124 const double distance)
125{
126 const double v_particle =
127 (dim == 3) ?
128 (4.0 / 3.0) * M_PI * Utilities::fixed_power<3, double>(r_particle) :
129 M_PI * Utilities::fixed_power<2, double>(r_particle);
130 const double inv_norm = 1.0 / std::pow(2.0 * M_PI * sigma * sigma, 0.5 * dim);
131 return v_particle * inv_norm *
132 std::exp(-0.5 * distance * distance / (sigma * sigma));
133}
134
135/**
136 * @brief ParticleFieldQCM calculator.
137 * This class stores the required information for the calculation of a
138 * field or a particle-fluid interaction onto a mesh. This class does not solve
139 * any equation, but compartmentalize the necessary information for the
140 * projection of the particle field or interaction onto a mesh. Multiple
141 * instances of this function can be called to establish new projections.In the
142 * case of a particle-fluid interaction, there is no particle field to project
143 * and, consequently, the property_start_index parameter is given an invalid
144 * default value (-1).
145 *
146 * @tparam dim An integer that denotes the number of spatial dimensions.
147 * @tparam n_components The number of components in the field. This number should be either 1 (a scalar) or dim (a Tensor<1,dim>)
148 * @tparam property_start_index An integer that indicates at which particle property the field starts.
149 * If the propery_start_index is negative, then there is no property start and
150 * this project is not used to project a particle field.
151 */
152template <int dim, int n_components, int property_start_index = -1>
154{
155public:
156 /**
157 * @brief Constructor
158 *
159 * @param triangulation The triangulation on which the particles reside
160 * @param fe_degree The finite element degree used to interpolate the field
161 * @param simplex A flag to indicate if the simulations are being done with simplex elements.
162 * @param neumann_boundaries A flag to indicate what to do with cells that do not contain particles.
163 * If the neumann_boundaries is set to true, then cells without particles do
164 * not have a mass matrix assembled. This corresponds to setting a neumann
165 * boundary at the cells which do not contain particles.
166 * @param conservative_projection A flag to indicate if the projection
167 * of the field must be conservative. When a projection is conservative,
168 * the integral of the field over the triangulation will be strictly
169 * equal to the field summed over all particles. This is useful when
170 * projecting a quantity such as the force acting on the particles. When
171 * conservative is put to false, the projection is meant to be a smooth
172 * representation of the particle information and does not conserve it.
173 */
174 ParticleFieldQCM(parallel::DistributedTriangulationBase<dim> *triangulation,
175 const unsigned int fe_degree,
176 const bool simplex,
177 const bool neumann_boundaries,
178 const bool conservative_projection)
179 : dof_handler(std::make_shared<DoFHandler<dim>>(*triangulation))
183 {
184 if (simplex)
185 {
186 const FE_SimplexP<dim> fe_temp(fe_degree);
187 fe = std::make_shared<FESystem<dim>>(fe_temp, n_components);
188 }
189 else
190 {
191 const FE_Q<dim> temp_fe(fe_degree);
192 fe = std::make_shared<FESystem<dim>>(temp_fe, n_components);
193 }
194 }
195
196 /// DoFHandler that manages the particle field. It is stored as a shared
197 /// pointer so that it can be provided to the multiphysics interface.
198 std::shared_ptr<DoFHandler<dim>> dof_handler;
199
200 /// deal.II vector for the particle field solution.
201 LinearAlgebra::distributed::Vector<double> particle_field_solution;
202
203 /// Finite element for the particle field
204 std::shared_ptr<FESystem<dim>> fe;
205
206 /// Index set for the locally owned degree of freedoms
208
209 /// Index set for the locally relevant degree of freedoms
211
212 /// System matrix used to assemble the smoothed L2 projection of the void
213 /// fraction
214 TrilinosWrappers::SparseMatrix system_matrix;
215
216 /// Right-hand side used to assemble the smoothed L2 projection of the void
217 /// fraction
218 LinearAlgebra::distributed::Vector<double> system_rhs;
219
220 /// Constraints used for the boundary conditions of the particle field
221 AffineConstraints<double> particle_field_constraints;
222
223 /// Preconditioner used when solving the L2 projection. This preconditioner
224 /// is stored within the class since there are situations where the matrix
225 /// is kept for multiple iterations. Consequently, there is no point in
226 /// reassembling the preconditioner for these iterations.
227 std::shared_ptr<TrilinosWrappers::PreconditionILU> ilu_preconditioner;
228
229 /// Boolean that indicates if Neumann boundary conditions are used during the
230 /// projection In this case, instead of assuming a value of zero if there are
231 /// no particles, the mass matrix is cancelled in region without particles
232 /// which results in a no flux zone.
234
235 /// Boolean that indicates if the projection is conservative. If the
236 /// projection is conservative, the integral over the domain of the field will
237 /// recover the sum of the field over all particles.
239
240 /// When a projection does not have neumann_boundaries, the matrix for the
241 /// system is constant in time. Consequently, there is no point in assembling
242 /// the matrix and initializing the preconditioner. This flag monitors if the
243 /// matrix has already been assembled. It is reset every time setup_dofs() is
244 /// called for the projector.
246
247 /// When set to true, setup_dofs() will additionally call distribute_mg_dofs()
248 /// on the underlying DoFHandler. This is required by local-smoothing
249 /// multigrid (LSMG) so that the field can be interpolated to every
250 /// triangulation level.
252
253 /**
254 * @brief Setup the degrees of freedom. This function allocates the necessary memory.
255 */
256 void
257 setup_dofs();
258};
259
260/**
261 * @brief Particle information projection.
262 * This class manages the calculation of the projection of the particle
263 * fields onto a triangulation. Its main use is the calculation of the
264 * void fraction which is used as an auxiliary field for the solvers that solve
265 * the Volume-Averaged Navier-Stokes equations. The present architecture
266 * of the class support all of the different void fraction calculation methods
267 * within a single class instead of building a class hierarchy. This is
268 * because there are only a few void fraction calculation strategies.
269 *
270 * Using QCM, this class is also capable of projecting arbitrary fields
271 * belonging to the particle back onto the mesh by instantiating
272 * @ParticleFieldQCM class.
273 *
274 * @tparam dim An integer that denotes the number of spatial dimensions.
275 * @tparam PropertiesIndex Index of the properties used within the
276 * ParticleHandler.
277 */
278template <int dim, typename PropertiesIndex>
280{
281public:
282 /**
283 * @brief Constructor for the void fraction calculator.
284 *
285 * @param triangulation The triangulation on which the simulation is being done.
286 * @param input_parameters The parameters for the void fraction calculation.
287 * @param linear_solver_parameters The parameters for the linear solver. This is used to solve the L2 projection of the void fraction
288 * @param particle_handler The particle handler used to manage the particles in the simulation. This object must be provided even if the particles are not used to establish the void fraction.
289 * @param fe_degree The finite element degree used to interpolate the void fraction.
290 * @param simplex A flag to indicate if the simulations are being done with simplex elements.
291 * @param pcout The ConditionalOStream used to print the information.
292 */
294 parallel::DistributedTriangulationBase<dim> *triangulation,
295 std::shared_ptr<Parameters::VoidFractionParameters<dim>> input_parameters,
297 Particles::ParticleHandler<dim> *particle_handler,
298 const unsigned int fe_degree,
299 const bool simplex,
300 const ConditionalOStream &pcout)
302 , dof_handler(std::make_shared<DoFHandler<dim>>(*triangulation))
304 , void_fraction_parameters(std::move(input_parameters))
308 , particle_velocity(triangulation, fe_degree, simplex, true, false)
309 , particle_temperature(triangulation, fe_degree, simplex, true, false)
311 fe_degree,
312 simplex,
313 false,
314 true)
315 , fluid_drag_on_particles(triangulation, fe_degree, simplex, false, true)
317 fe_degree,
318 simplex,
319 false,
320 true)
321 {
322 if (simplex)
323 {
324 fe = std::make_shared<FE_SimplexP<dim>>(fe_degree);
325 mapping = std::make_shared<MappingFE<dim>>(*fe);
326 quadrature = std::make_shared<QGaussSimplex<dim>>(fe->degree + 1);
327 }
328 else
329 {
330 // Usual case, for quad/hex meshes
331 fe = std::make_shared<FE_Q<dim>>(fe_degree);
332 mapping = std::make_shared<MappingQ<dim>>(fe->degree);
333 if (this->void_fraction_parameters->quadrature_rule ==
335 {
336 if (this->void_fraction_parameters->n_quadrature_points == 0)
337 quadrature = std::make_shared<QGauss<dim>>(fe->degree + 1);
338 else
339 quadrature = std::make_shared<QGauss<dim>>(
340 this->void_fraction_parameters->n_quadrature_points);
341 }
342 else if (this->void_fraction_parameters->quadrature_rule ==
344 {
345 if (this->void_fraction_parameters->n_quadrature_points == 0)
346 quadrature = std::make_shared<QGaussLobatto<dim>>(fe->degree + 2);
347 else if (this->void_fraction_parameters->n_quadrature_points >= 3)
348 quadrature = std::make_shared<QGaussLobatto<dim>>(
349 this->void_fraction_parameters->n_quadrature_points);
350 else
351 throw(std::runtime_error(
352 "For void fraction using Gauss-Lobatto ('gauss_lobatto') quadrature rule, the minimum number of quadrature points is 3"));
353 }
354 else
355 {
356 AssertThrow(
357 false,
358 ExcMessage(
359 "An invalid quadrature rule was provided to the ParticleProject class."));
360 }
361 }
362
363 // Initialize the void fraction previous solution vector
364 previous_void_fraction = std::make_shared<std::vector<GlobalVectorType>>();
365
366 // Initialize the void fraction current solution vector
367 void_fraction_locally_relevant = std::make_shared<GlobalVectorType>();
368
369 // Initialize the particle temperature vector provided to the multiphysics
370 // interface
372 std::make_shared<GlobalVectorType>();
373
374 AssertThrow(
375 !void_fraction_parameters->project_particle_velocity ||
376 void_fraction_parameters->l2_smoothing_length > 0,
377 ExcMessage(
378 "The projection of the particle velocity field requires that the l2 smoothing length be > 0. Otherwise, the Poisson equation used in the Neumann boundary is invalid."));
379
380 AssertThrow(
381 void_fraction_parameters->project_particle_velocity == false ||
382 (void_fraction_parameters->project_particle_velocity &&
384 ExcMessage(
385 "The projection of the particle velocity currently requires that the QCM method be used for the calculation of the void fraction."));
386
387 AssertThrow(
389 void_fraction_parameters->l2_smoothing_length > 0,
390 ExcMessage(
391 "The particle temperature is always projected in thermal CFD-DEM simulations (solver type = dem_mp), which requires that the l2 smoothing length be > 0. Otherwise, the Poisson equation used in the Neumann boundary is invalid."));
392 }
393
394 /**
395 * @brief Setup the degrees of freedom.
396 *
397 */
398 void
399 setup_dofs() override;
400
401 /**
402 * @brief Request that all DoFHandlers managed by this projector also
403 * distribute multigrid level DoFs the next time setup_dofs() is called.
404 * This is required by the local-smoothing multigrid (LSMG) preconditioner
405 * of the VANS matrix-free solver, which needs the auxiliary fields on
406 * every triangulation level. Must be called before setup_dofs().
407 *
408 * @param[in] enabled If true, distribute_mg_dofs() will be called on the
409 * void-fraction DoFHandler and on every ParticleFieldQCM DoFHandler.
410 */
411 void
412 enable_multigrid_level_dofs(const bool enabled = true)
413 {
415 particle_velocity.multigrid_level_dofs_required = enabled;
416 fluid_force_on_particles_two_way_coupling.multigrid_level_dofs_required =
417 enabled;
418 fluid_drag_on_particles.multigrid_level_dofs_required = enabled;
419 momentum_transfer_coefficient.multigrid_level_dofs_required = enabled;
420 }
421
422 /**
423 * @brief Establish the constraints of the void fraction systems.
424 *
425 * @param[in] boundary_conditions The boundary conditions of fluid dynamics.
426 * This is used to establish periodic boundary conditions for the void
427 * fraction.
428 *
429 */
430 void
433 &boundary_conditions);
434
435 /**
436 * @brief Calculate the void fraction.
437 *
438 * @param[in] time Current time for which the void fraction is to be
439 * calculated.
440 *
441 */
442 void
443 calculate_void_fraction(const double time);
444
445 /**
446 * @brief Project the particle temperature onto the fluid mesh with the QCM,
447 * then copy it into particle_temperature_locally_relevant, the vector
448 * provided to the multiphysics interface.
449 */
450 void
452
453 /**
454 * @brief Calculate all the necessary information for the particle-fluid coupling.
455 * This means calculating the projection of the particle-fluid interaction
456 * forces as well as the solid velocity onto the CFD mesh.
457 *
458 */
459 template <typename VectorType>
460 void
462 const Parameters::CFDDEM &cfd_dem_parameters,
463 DoFHandler<dim> &fluid_dof_handler,
464 const VectorType &present_velocity_pressure_solution,
465 const std::vector<VectorType> &previous_velocity_pressure_solution,
466 const Tensor<1, 3> &gravity,
467 NavierStokesScratchData<dim> scratch_data);
468
469 /**
470 * @brief Assemble and solve the system.
471 */
472 void
473 solve() override
474 {}
475
476 /**
477 * @brief Percolate the time vector for the void fraction. This operation is called at the end of a time step. It percolates both the deal.II and the Trilinos vectors.
478 *
479 * TODO - Refactor the ParticleProjector class to use deal.II vectors for
480 * everything instead of a blend of Trilinos and deal.II vector.
481 *
482 */
483 void
485 {
486 for (unsigned int i = previous_void_fraction->size() - 1; i > 0; --i)
487 {
488 (*this->previous_void_fraction)[i] =
489 (*this->previous_void_fraction)[i - 1];
492 }
495 }
496
497 /**
498 * @brief Initialize the void fraction at the beginning of a simulation.
499 *
500 * @param[in] time The current time. This is used for time-dependent
501 * functions.
502 */
503 void
504 initialize_void_fraction(const double time)
505 {
507 for (auto &previous_solution : *this->previous_void_fraction)
508 previous_solution = *this->void_fraction_locally_relevant;
509
510 for (auto &previous_solution : this->void_fraction_previous_solution)
511 previous_solution = void_fraction_solution;
512 }
513
514 /**
515 * @brief Calculates the projection of a particle field onto the mesh.
516 *
517 * @tparam property_start_index An integer for the particle_property that will be projected
518 *
519 * @tparam n_components The number of components of the field. This should be either 1 (scalar) or dim (a Tensor<1,dim>).
520 *
521 * @param field_qcm The container for the field that will be projected.
522 *
523 */
524
525 template <int property_start_index, int n_components>
526 void
529
530
531 /**
532 * @brief Zeros out and update the ghost values of the auxiliary fields.
533 * This is necessary when the void fraction calculation mode does not rely on
534 * particles.
535 */
536 void
538 {
539 fluid_force_on_particles_two_way_coupling.particle_field_solution = 0.;
540 fluid_force_on_particles_two_way_coupling.particle_field_solution
541 .update_ghost_values();
542 momentum_transfer_coefficient.particle_field_solution = 0.;
543 momentum_transfer_coefficient.particle_field_solution.update_ghost_values();
544 particle_velocity.particle_field_solution = 0.;
545 particle_velocity.particle_field_solution.update_ghost_values();
546 fluid_drag_on_particles.particle_field_solution = 0.;
547 fluid_drag_on_particles.particle_field_solution.update_ghost_values();
548 }
549
550 /**
551 * @brief Write the location of the QCM quadrature points and the radius of
552 * the filter centered at each of them for visualization.
553 *
554 * @param[in] folder Output folder.
555 * @param[in] prefix Prefix for the output files.
556 * @param[in] group_files Number of files the output is grouped into.
557 */
558 void
559 write_qcm_quadrature_points(const std::string &folder,
560 const std::string &prefix,
561 const unsigned int group_files);
562
563 /// DoFHandler that manages the void fraction, it is a shared pointer because
564 /// it is used by the multiphysics interface
565 std::shared_ptr<DoFHandler<dim>> dof_handler;
566
567 /// Mapping for the void fraction
568 std::shared_ptr<Mapping<dim>> mapping;
569
570 /// Quadrature for the void fraction
571 std::shared_ptr<Quadrature<dim>> quadrature;
572
573 /// The solutions are made public instead of using getters
574 /// Solution of the void fraction at previous time steps, it is a shared
575 /// pointer because it is used by the multiphysics interface
576 std::shared_ptr<std::vector<GlobalVectorType>> previous_void_fraction;
577
578 /// Fully distributed (including locally relevant) solution, it is a shared
579 /// pointer because it is used by the multiphysics interface
580 std::shared_ptr<GlobalVectorType> void_fraction_locally_relevant;
581
582 /// Locally owned solution of the void fraction
584
585 /// deal.II vector for the void fraction
586 LinearAlgebra::distributed::Vector<double> void_fraction_solution;
587
588 /// deal.II vector the previous void fraction
589 std::vector<LinearAlgebra::distributed::Vector<double>>
591
592 /// Finite element for the void fraction
593 std::shared_ptr<FiniteElement<dim>> fe;
594
595 /// Index set for the locally owned degree of freedoms
597
598 /// Index set for the locally relevant degree of freedoms
600
601 /// Constraints used for the boundary conditions of the void fraction.
602 /// Currently, this is only used to establish periodic void fractions. This
603 /// object has to be made public because the boundary conditions are set
604 /// outside of the object for now.
605 AffineConstraints<double> void_fraction_constraints;
606
607private:
608 /**
609 * @brief Calculate the characteristic radius of a sphere with a given volume (area in 2D):
610 * R = (2*dim*V/pi)^(1/dim) / 2
611 *
612 * @param volume value for which the equivalent radius of a sphere is calculated.
613 *
614 * @return Radius of a sphere with equivalent volume
615 */
616 static double
618 {
619 return 0.5 * pow(2.0 * static_cast<double>(dim) * volume / M_PI,
620 1.0 / static_cast<double>(dim));
621 }
622
623 /**
624 * @brief Calculate the characteristic length of the QCM filter from a cell measure.
625 *
626 * The returned length is the averaging-sphere radius when the spherical
627 * filter is used, and the standard deviation sigma when the gaussian filter
628 * is used. The cell-measure-to-length mapping itself does not depend on the
629 * filter type.
630 *
631 * @param cell_measure The measure of the cell in which QCM is calculated.
632 *
633 * @return The QCM filter characteristic length used in the calculations.
634 */
635 inline double
637 {
638 if (void_fraction_parameters->qcm_sphere_equal_cell_volume == true)
639 {
640 // Get the radius by the volume of sphere which is
641 // equal to the volume of cell
642 return radius_sphere_equivalent_volume(cell_measure);
643 }
644 else
645 {
646 // The radius is obtained from the volume of sphere based
647 // on R_s = h_omega
648 return std::cbrt(cell_measure);
649 }
650 }
651
652 /**
653 * @brief Calculate the intersection measure (volume in 3D and area in 2D) between a particle and an hypersphere.
654 * This is used when calculating the intersection volume between the averaging
655 * sphere and a particle in QCM. The calculation inherently assumes that the
656 * radius of the averaging sphere is larger than that of the particle.
657 *
658 * @param r_particle The radius of the particle
659 * @param r_sphere The radius of the averaging sphere
660 * @param distance_between_spheres The distance between the centers of the spheres
661 *
662 * @return The intersection volume (in 3D) or area (in 2d)
663 */
664
665 static double
667 double r_sphere,
668 double distance_between_spheres)
669 {
670 // Particle completely in the reference sphere
671 if (distance_between_spheres <= (r_sphere - r_particle))
672 {
673 if constexpr (dim == 2)
674 return M_PI * Utilities::fixed_power<2>(r_particle);
675 if constexpr (dim == 3)
676 return 4. / 3. * M_PI * Utilities::fixed_power<3>(r_particle);
677 }
678
679 // Particle partially in the reference sphere
680 if ((distance_between_spheres > (r_sphere - r_particle)) &&
681 (distance_between_spheres < (r_sphere + r_particle)))
682 {
683 if constexpr (dim == 2)
684 return particle_circle_intersection_2d(r_particle,
685 r_sphere,
686 distance_between_spheres);
687
688 else if constexpr (dim == 3)
689 return particle_sphere_intersection_3d(r_particle,
690 r_sphere,
691 distance_between_spheres);
692 }
693
694 // Particle completely outside the reference
695 // sphere. The intersection volume is zero.
696 return 0;
697 }
698
699 /**
700 * @brief Evaluate the QCM filter kernel selected at compile time.
701 *
702 * Dispatches between the spherical indicator kernel
703 * (calculate_intersection_measure) and the Gaussian kernel
704 * (gaussian_filter_kernel) without runtime branching in the inner loop.
705 *
706 * @tparam filter_type The QCM filter type to evaluate.
707 *
708 * @param[in] r_particle Radius of the particle.
709 * @param[in] filter_length Characteristic length of the filter (averaging
710 * sphere radius for spherical, standard deviation sigma for gaussian).
711 * @param[in] distance Distance between the particle center and the evaluation
712 * point.
713 */
714 template <Parameters::QCMFilterType filter_type>
715 static inline double
716 evaluate_filter(const double r_particle,
717 const double filter_length,
718 const double distance)
719 {
720 if constexpr (filter_type == Parameters::QCMFilterType::spherical)
721 return calculate_intersection_measure(r_particle,
722 filter_length,
723 distance);
724 else if constexpr (filter_type == Parameters::QCMFilterType::gaussian)
725 return gaussian_filter_kernel<dim>(r_particle, filter_length, distance);
726 else
727 {
728 // Defensive: a new QCMFilterType was added but not handled here.
729 AssertThrow(
730 false,
731 ExcMessage(
732 "Unhandled QCMFilterType in ParticleProjector::evaluate_filter."));
733 return 0.0;
734 }
735 }
736
737 /**
738 * @brief Calculate the void fraction using a function. This is a straightforward usage of VectorTools.
739 *
740 * @param[in] time Current time for which the void fraction is to be
741 * calculated.
742 *
743 */
744 void
745 calculate_void_fraction_function(const double time);
746
747 /**
748 * @brief Calculate the void fraction using the particle centered method.
749 *
750 */
751 void
753
754 /**
755 * @brief Calculate the void fraction using the satellite point method.
756 *
757 */
758 void
760
761 /**
762 * @brief Calculate the void fraction using the Quadrature-Centered Method (QCM).
763 *
764 * Thin dispatcher that selects the filter kernel at runtime and forwards
765 * to the templated implementation calculate_void_fraction_qcm_impl.
766 */
767 void
769
770 /**
771 * @brief Templated implementation of the Quadrature-Centered Method (QCM).
772 *
773 * @tparam filter_type The QCM filter type used to weigh particle
774 * contributions. Selected at runtime by the public dispatcher.
775 */
776 template <Parameters::QCMFilterType filter_type>
777 void
779
780 /**
781 * @brief Templated implementation of calculate_field_projection.
782 *
783 * @tparam filter_type The QCM filter type used to weigh particle
784 * contributions. Selected at runtime by the public dispatcher.
785 */
786 template <Parameters::QCMFilterType filter_type,
787 int n_components,
788 int property_start_index>
789 void
792
793 /**
794 * @brief Solve the linear system resulting from the assemblies.
795 *
796 */
797 virtual void
799
800 /**
801 * @brief Calculate and return the periodic offset distance vector of the domain which is needed
802 * for the periodic boundary conditions using the QCM or SPM for void fraction
803 * with the GLS VANS/CFD-DEM solver. The distance is based on one of the
804 * periodic boundaries. This periodic boundary is then used as the reference
805 * for all particle locations shifted by this offset vector.
806 *
807 * @param[in] boundary_id The ID of one of the periodic boundaries
808 *
809 * @return The periodic offset vector.
810 */
811 inline Tensor<1, dim>
812 get_periodic_offset_distance(unsigned int boundary_id) const
813 {
814 Tensor<1, dim> offset;
815
816 // Iterating over the active cells in the triangulation
817 for (const auto &cell : (*this->triangulation).active_cell_iterators())
818 {
819 if (cell->is_locally_owned() || cell->is_ghost())
820 {
821 if (cell->at_boundary())
822 {
823 // Iterating over cell faces
824 for (unsigned int face_id = 0; face_id < cell->n_faces();
825 ++face_id)
826 {
827 unsigned int face_boundary_id =
828 cell->face(face_id)->boundary_id();
829
830 // Check if face is on the boundary, if so, get
831 // the periodic offset distance for one pair of periodic
832 // faces only since periodic boundaries are aligned with the
833 // direction and only axis are currently allowed
834 if (face_boundary_id == boundary_id)
835 {
836 Point<dim> face_center = cell->face(face_id)->center();
837 auto periodic_cell = cell->periodic_neighbor(face_id);
838 unsigned int periodic_face_id =
839 cell->periodic_neighbor_face_no(face_id);
840 Point<dim> periodic_face_center =
841 periodic_cell->face(periodic_face_id)->center();
842
843 offset = periodic_face_center - face_center;
844
845 return offset;
846 }
847 }
848 }
849 }
850 }
851
852 // A zero tensor is returned in case no cells are found on the periodic
853 // boundaries on this processor. This processor won't handle particle in
854 // cells at periodic boundaries, so it won't affect any computation.
855 return offset;
856 }
857
858 /// Triangulation
859 parallel::DistributedTriangulationBase<dim> *triangulation;
860
861 /// Parameters for the calculation of the void fraction
862 /// Right now this is used for the VANS matrix-free solver
863 /// to directly calculate the void fraction from the function itself.
864 /// The function will be removed back to private in a future PR.
865 std::shared_ptr<Parameters::VoidFractionParameters<dim>>
867
868 /// Linear solvers for the calculation of the void fraction
870
871 /// Particle handler used when the void fraction depends on particles
872 Particles::ParticleHandler<dim> *particle_handler;
873
874
875 /// Preconditioner used for the solution of the smoothed L2 projection of the
876 /// void fraction
877 std::shared_ptr<TrilinosWrappers::PreconditionILU> ilu_preconditioner;
878
879 /// System matrix used to assemble the smoothed L2 projection of the void
880 /// fraction
881 TrilinosWrappers::SparseMatrix system_matrix_void_fraction;
882
883 /// Right-hand side used to assemble the smoothed L2 projection of the void
884 /// fraction
886
887 /// Vertices to cell map, this is used in the QCM and the satellite point
888 /// method to access the neighboring cells of a cell.
889 std::map<unsigned int,
890 std::set<typename DoFHandler<dim>::active_cell_iterator>>
892
893 /// Boolean to indicate if the mesh has periodic boundaries
895
896 /// Map of offsets for periodic boundary conditions
897 std::map<types::boundary_id, Tensor<1, dim>> cfd_periodic_offsets;
898
899 /// Map of directions associated with periodic boundary conditions
900 std::map<types::boundary_id, unsigned int> cfd_periodic_directions;
901
902 /// Vertices to periodic cell map, this is used in the QCM and the satellite
903 /// point method to access the neighboring cells of a cell.
904 std::map<unsigned int,
905 std::set<typename DoFHandler<dim>::active_cell_iterator>>
907
908 /// Smoothing length factor for the void fraction calculation
909 const double l2_smoothing_factor =
910 Utilities::fixed_power<2>(void_fraction_parameters->l2_smoothing_length);
911
912 /// Boolean indicator used to check if the particles have at least been
913 /// projected once. This is mainly used for assertions and sanity checking
914 /// purposes
916
917 /// When set, setup_dofs() will additionally call distribute_mg_dofs() on the
918 /// void-fraction DoFHandler. This is required by local-smoothing multigrid
919 /// (LSMG) of the VANS matrix-free solver. The flag is propagated to every
920 /// ParticleFieldQCM by enable_multigrid_level_dofs().
922
923public:
924 /// Projector used to save the particle velocity field onto the mesh
925 /// This field is not volumetric, meaning that the integral over the
926 /// entire domain of this field will not yield the sum of the particle
927 /// velocity over all the particles.
929
930 /// Projector used to save the particle temperature field onto the mesh
931 /// This field is not volumetric, meaning that the integral over the
932 /// entire domain of this field will not yield the sum of the particle
933 /// temperature over all the particles. The particle temperature is only
934 /// projected if the particle properties have thermal properties (for dem_mp
935 /// simulations). Otherwise, its index is set to -1 and the field is not
936 /// projected.
939
940 /// Copy of the projected particle temperature, including the locally
941 /// relevant ghost values, in the vector type of the multiphysics interface.
942 /// It is a shared pointer because it is used by the multiphysics interface.
943 std::shared_ptr<GlobalVectorType> particle_temperature_locally_relevant;
944
945 /// Projector used to save the forces used in the two-way coupling scheme,
946 /// without drag. This field is volumetric. The integral of this field over
947 /// the entire domain will result in the sum of the force (without drag) over
948 /// all of the particles.
951
952 /// Projector used to store the drag force. The drag is stored as a separate
953 /// field since we may want to make implicit calculations of it. This field
954 /// is volumetric. The integral of this field over the entire domain will
955 /// result in the sum of the drag force over all the particles.
957
958 /// Projector used to save the momentum transfer coefficient (beta). This
959 /// field is volumetric. The integral of this field over the entire domain
960 /// will result in the sum of the momentum transfer coefficient over all
961 /// particles.
964};
965#endif
This class manages the boundary conditions forhe fluid dynamics solver It introduces the boundary fun...
Class that stores the information required by the assembly procedure for a Navier-Stokes equation....
Parameters controlling the void fraction computation in CFD-DEM simulations.
ParticleFieldQCM calculator. This class stores the required information for the calculation of a fiel...
const bool neumann_boundaries
IndexSet locally_owned_dofs
Index set for the locally owned degree of freedoms.
std::shared_ptr< FESystem< dim > > fe
Finite element for the particle field.
IndexSet locally_relevant_dofs
Index set for the locally relevant degree of freedoms.
const bool conservative_projection
TrilinosWrappers::SparseMatrix system_matrix
void setup_dofs()
Setup the degrees of freedom. This function allocates the necessary memory.
std::shared_ptr< DoFHandler< dim > > dof_handler
std::shared_ptr< TrilinosWrappers::PreconditionILU > ilu_preconditioner
LinearAlgebra::distributed::Vector< double > system_rhs
ParticleFieldQCM(parallel::DistributedTriangulationBase< dim > *triangulation, const unsigned int fe_degree, const bool simplex, const bool neumann_boundaries, const bool conservative_projection)
Constructor.
LinearAlgebra::distributed::Vector< double > particle_field_solution
deal.II vector for the particle field solution.
AffineConstraints< double > particle_field_constraints
Constraints used for the boundary conditions of the particle field.
std::map< unsigned int, std::set< typename DoFHandler< dim >::active_cell_iterator > > vertices_to_cell
IndexSet locally_owned_dofs
Index set for the locally owned degree of freedoms.
const Parameters::LinearSolver linear_solver_parameters
Linear solvers for the calculation of the void fraction.
double calculate_filter_length_from_cell_measure(const double cell_measure)
Calculate the characteristic length of the QCM filter from a cell measure.
GlobalVectorType void_fraction_locally_owned
Locally owned solution of the void fraction.
std::shared_ptr< GlobalVectorType > void_fraction_locally_relevant
void calculate_field_projection(ParticleFieldQCM< dim, property_start_index, n_components > &field_qcm)
Calculates the projection of a particle field onto the mesh.
std::shared_ptr< FiniteElement< dim > > fe
Finite element for the void fraction.
std::map< types::boundary_id, unsigned int > cfd_periodic_directions
Map of directions associated with periodic boundary conditions.
std::shared_ptr< DoFHandler< dim > > dof_handler
void calculate_void_fraction(const double time)
Calculate the void fraction.
void calculate_field_projection_impl(ParticleFieldQCM< dim, n_components, property_start_index > &field_qcm)
Templated implementation of calculate_field_projection.
static double evaluate_filter(const double r_particle, const double filter_length, const double distance)
Evaluate the QCM filter kernel selected at compile time.
std::map< unsigned int, std::set< typename DoFHandler< dim >::active_cell_iterator > > vertices_to_periodic_cell
std::shared_ptr< Quadrature< dim > > quadrature
Quadrature for the void fraction.
void calculate_void_fraction_quadrature_centered_method()
Calculate the void fraction using the Quadrature-Centered Method (QCM).
void setup_constraints(const BoundaryConditions::FluidDynamicsBoundaryConditions< dim > &boundary_conditions)
Establish the constraints of the void fraction systems.
void calculate_void_fraction_particle_centered_method()
Calculate the void fraction using the particle centered method.
std::shared_ptr< Parameters::VoidFractionParameters< dim > > void_fraction_parameters
TrilinosWrappers::SparseMatrix system_matrix_void_fraction
std::vector< LinearAlgebra::distributed::Vector< double > > void_fraction_previous_solution
deal.II vector the previous void fraction
void write_qcm_quadrature_points(const std::string &folder, const std::string &prefix, const unsigned int group_files)
Write the location of the QCM quadrature points and the radius of the filter centered at each of them...
static double radius_sphere_equivalent_volume(const double volume)
Calculate the characteristic radius of a sphere with a given volume (area in 2D): R = (2*dim*V/pi)^(1...
virtual void solve_linear_system_and_update_solution() override
Solve the linear system resulting from the assemblies.
Tensor< 1, dim > get_periodic_offset_distance(unsigned int boundary_id) const
Calculate and return the periodic offset distance vector of the domain which is needed for the period...
std::map< types::boundary_id, Tensor< 1, dim > > cfd_periodic_offsets
Map of offsets for periodic boundary conditions.
GlobalVectorType system_rhs_void_fraction
ParticleFieldQCM< dim, 3, PropertiesIndex::fem_force_two_way_coupling_x > fluid_force_on_particles_two_way_coupling
void calculate_void_fraction_function(const double time)
Calculate the void fraction using a function. This is a straightforward usage of VectorTools.
void zero_out_and_ghost_auxiliary_fields()
Zeros out and update the ghost values of the auxiliary fields. This is necessary when the void fracti...
const double l2_smoothing_factor
Smoothing length factor for the void fraction calculation.
parallel::DistributedTriangulationBase< dim > * triangulation
Triangulation.
std::shared_ptr< Mapping< dim > > mapping
Mapping for the void fraction.
void initialize_void_fraction(const double time)
Initialize the void fraction at the beginning of a simulation.
ParticleFieldQCM< dim, 1, PropertiesIndex::momentum_transfer_coefficient > momentum_transfer_coefficient
std::shared_ptr< std::vector< GlobalVectorType > > previous_void_fraction
IndexSet locally_relevant_dofs
Index set for the locally relevant degree of freedoms.
static double calculate_intersection_measure(double r_particle, double r_sphere, double distance_between_spheres)
Calculate the intersection measure (volume in 3D and area in 2D) between a particle and an hyperspher...
LinearAlgebra::distributed::Vector< double > void_fraction_solution
deal.II vector for the void fraction
std::shared_ptr< TrilinosWrappers::PreconditionILU > ilu_preconditioner
void calculate_void_fraction_satellite_point_method()
Calculate the void fraction using the satellite point method.
AffineConstraints< double > void_fraction_constraints
bool has_periodic_boundaries
Boolean to indicate if the mesh has periodic boundaries.
void calculate_void_fraction_qcm_impl()
Templated implementation of the Quadrature-Centered Method (QCM).
Particles::ParticleHandler< dim > * particle_handler
Particle handler used when the void fraction depends on particles.
void enable_multigrid_level_dofs(const bool enabled=true)
Request that all DoFHandlers managed by this projector also distribute multigrid level DoFs the next ...
void calculate_particle_temperature_projection()
Project the particle temperature onto the fluid mesh with the QCM, then copy it into particle_tempera...
void percolate_void_fraction()
Percolate the time vector for the void fraction. This operation is called at the end of a time step....
ParticleFieldQCM< dim, 1, DEM::temperature_property_index< PropertiesIndex > > particle_temperature
ParticleProjector(parallel::DistributedTriangulationBase< dim > *triangulation, std::shared_ptr< Parameters::VoidFractionParameters< dim > > input_parameters, const Parameters::LinearSolver &linear_solver_parameters, Particles::ParticleHandler< dim > *particle_handler, const unsigned int fe_degree, const bool simplex, const ConditionalOStream &pcout)
Constructor for the void fraction calculator.
void calculate_particle_fluid_forces_projection(const Parameters::CFDDEM &cfd_dem_parameters, DoFHandler< dim > &fluid_dof_handler, const VectorType &present_velocity_pressure_solution, const std::vector< VectorType > &previous_velocity_pressure_solution, const Tensor< 1, 3 > &gravity, NavierStokesScratchData< dim > scratch_data)
Calculate all the necessary information for the particle-fluid coupling. This means calculating the p...
ParticleFieldQCM< dim, 3, PropertiesIndex::v_x > particle_velocity
void setup_dofs() override
Setup the degrees of freedom.
void solve() override
Assemble and solve the system.
std::shared_ptr< GlobalVectorType > particle_temperature_locally_relevant
ParticleFieldQCM< dim, 3, PropertiesIndex::fem_drag_x > fluid_drag_on_particles
PhysicsLinearSubequationsSolver(const ConditionalOStream &pcout)
Constructor for physics subequations that require the use of a linear solver within the span of the p...
DEM particle property definitions and output name management.
constexpr bool has_thermal_properties
Whether a properties index set carries thermal properties.
@ gauss
Gauss quadrature rule (default).
@ gauss_lobatto
Gauss-Lobatto quadrature rule.
@ qcm
Quadrature centered method.
QCMFilterType
Filter kernel used by the Quadrature-Centered Method (QCM) to weigh particle contributions onto the m...
@ gaussian
Gaussian filter parametrised by a standard deviation sigma.
@ spherical
Spherical indicator (heaviside) filter (default, original QCM).
Parameter structures for CFD-DEM coupled simulations.
double particle_circle_intersection_2d(const double r_particle, const double r_circle, const double neighbor_distance)
Calculate the area of intersection between a circular (2D) particle and a circle. \ .
DeclExceptionMsg(NotSupportedMeshAdaptationMethod, "Mesh adaptation is only supported with the steady time-stepping method " "in the VANS and CFD-DEM solvers at the moment because the void fraction " "field is not yet updated during mesh adaptation.")
double particle_sphere_intersection_3d(const double r_particle, const double r_sphere, const double neighbor_distance)
Calculate the volume of intersection between a spherical (3D) particle and a sphere.
double gaussian_filter_kernel(const double r_particle, const double sigma, const double distance)
Evaluate a Gaussian filter kernel between a particle and a point.
Parameters for the CFD-DEM coupled solver.
LinearSolver - Parameters that control the solution of the linear system of equations that arise from...
GlobalVectorType VectorType
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17