Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
particle_projector.cc
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
5#include <core/pvd_handler.h>
7#include <core/vector.h>
8
12
13#include <deal.II/base/timer.h>
14
15#include <deal.II/dofs/dof_tools.h>
16
17#include <deal.II/fe/fe_values.h>
18
19#include <deal.II/grid/grid_generator.h>
20#include <deal.II/grid/grid_tools.h>
21
22#include <deal.II/lac/solver_cg.h>
23#include <deal.II/lac/sparsity_tools.h>
24#include <deal.II/lac/trilinos_solver.h>
25
26#include <deal.II/numerics/vector_tools.h>
27
28#include <type_traits>
29
30using namespace dealii;
31
32template <int dim, int n_components, int component_start>
33void
35{
36 // Get a constant copy of the communicator since it is used extensively to
37 // establish the void fraction vectors
38 const MPI_Comm mpi_communicator = dof_handler->get_mpi_communicator();
39
40 dof_handler->distribute_dofs(*fe);
42 dof_handler->distribute_mg_dofs();
43 locally_owned_dofs = dof_handler->locally_owned_dofs();
44
45 locally_relevant_dofs = DoFTools::extract_locally_relevant_dofs(*dof_handler);
46
47 // deal.II vector that will also hold the solution
48 this->particle_field_solution.reinit(dof_handler->locally_owned_dofs(),
49 DoFTools::extract_locally_active_dofs(
51 mpi_communicator);
52
53 // Force the vector to zero after the reinit.
55
58 DoFTools::make_hanging_node_constraints(*dof_handler,
60
62
63 // The particle field matrix sparsity pattern is always a block diagonal
64 // matrix meaning that the components of the particle fields are never coupled
65 // with one another. We can enforce this directly inside the sparsity pattern.
66 // This makes it significantly cheaper to solve the linear systems associated
67 // with the projection.
68 Table<2, DoFTools::Coupling> coupling_table(n_components, n_components);
69 for (int i = 0; i < n_components; ++i)
70 for (int j = 0; j < n_components; ++j)
71 {
72 if (i != j)
73 coupling_table[i][j] = DoFTools::Coupling::none;
74 else
75 coupling_table[i][j] = DoFTools::Coupling::always;
76 }
77
78 DynamicSparsityPattern dsp(locally_relevant_dofs);
79 DoFTools::make_sparsity_pattern(
80 *dof_handler, coupling_table, dsp, particle_field_constraints, false);
81
82 SparsityTools::distribute_sparsity_pattern(dsp,
84 mpi_communicator,
86
89 dsp,
90 mpi_communicator);
91
92
95 mpi_communicator);
96
97 // Since we have reset the entire matrix, it now requires assembly;
99}
100
101template <int dim, typename PropertiesIndex>
102void
104{
105 // First we setup the dofs related to the void fraction
106
107 // Get a constant copy of the communicator since it is used extensively to
108 // establish the void fraction vectors
109 const MPI_Comm mpi_communicator = dof_handler->get_mpi_communicator();
110
111 dof_handler->distribute_dofs(*fe);
113 dof_handler->distribute_mg_dofs();
114 locally_owned_dofs = dof_handler->locally_owned_dofs();
115
116 locally_relevant_dofs = DoFTools::extract_locally_relevant_dofs(*dof_handler);
117
120 DoFTools::make_hanging_node_constraints(*dof_handler,
122
124
127 mpi_communicator);
128
130
131 // Initialize vector of previous solutions for the void fraction
132 for (auto &solution : *this->previous_void_fraction)
133 {
134 solution.reinit(this->locally_owned_dofs,
136 this->triangulation->get_mpi_communicator());
137 }
138
140 locally_owned_dofs, this->triangulation->get_mpi_communicator());
141
142 // deal.II vector that will also hold the solution
143 this->void_fraction_solution.reinit(
144 dof_handler->locally_owned_dofs(),
145 DoFTools::extract_locally_active_dofs(*dof_handler),
146 this->triangulation->get_mpi_communicator());
147
150 // Initialize vector of previous solutions for the void fraction
151 for (auto &solution : this->void_fraction_previous_solution)
152 {
153 solution.reinit(dof_handler->locally_owned_dofs(),
154 DoFTools::extract_locally_active_dofs(*dof_handler),
155 this->triangulation->get_mpi_communicator());
156 }
157
158 DynamicSparsityPattern dsp(locally_relevant_dofs);
159 DoFTools::make_sparsity_pattern(*dof_handler,
160 dsp,
162 false);
163
164 SparsityTools::distribute_sparsity_pattern(
165 dsp,
167 this->triangulation->get_mpi_communicator(),
169
173 dsp,
174 this->triangulation->get_mpi_communicator());
175
176
178 this->triangulation->get_mpi_communicator());
179
180
181 // Vertices to cell mapping
183
184 // TODO BB both these fields are always set-up even if they are not used. This
185 // is ok since this will just take a little bit of extra memory. If this
186 // becomes an issue, we can enable/disable their allocation with an additional
187 // bool parameter inside the CFD-DEM parameters.
189 fluid_drag_on_particles.setup_dofs();
190 particle_velocity.setup_dofs();
192
193 // Only allocate the particle temperature field in thermal CFD-DEM
194 // simulations (solver type = dem_mp)
196 {
197 particle_temperature.setup_dofs();
198
199 // The particle temperature is provided to the multiphysics interface,
200 // so we need to ensure the solution vector is reinitialized with the
201 // correct locally relevant dofs.
203 particle_temperature.locally_owned_dofs,
204 particle_temperature.locally_relevant_dofs,
205 mpi_communicator);
206 }
207}
208
209
210template <int dim, typename PropertiesIndex>
211void
214 &boundary_conditions)
215{
217 // Define constraints for periodic boundary conditions
219 void_fraction_constraints.reinit(dof_handler->locally_owned_dofs(),
221 DoFTools::make_hanging_node_constraints(*dof_handler,
223
224
225 for (auto const &[id, type] : boundary_conditions.type)
226 {
228 {
229 const auto &periodic_boundary =
230 boundary_conditions.periodic_boundaries.at(id);
231 cfd_periodic_directions[id] = periodic_boundary.direction;
232 DoFTools::make_periodicity_constraints(
233 *this->dof_handler,
234 id,
235 periodic_boundary.neighbor_id,
236 periodic_boundary.direction,
237 this->void_fraction_constraints);
238
240
241 // Get periodic offset if void fraction method is qcm or spm
242 if (this->void_fraction_parameters->mode ==
244 this->void_fraction_parameters->mode ==
246 {
248 }
249 }
250 }
252
253 AssertThrow(
254 has_periodic_boundaries == false ||
255 (void_fraction_parameters->project_particle_velocity == false &&
257 ExcMessage(
258 "The projection of the particle velocity, and the projection of the particle temperature done in thermal CFD-DEM simulations (solver type = dem_mp), are currently not supported for periodic boundary conditions"));
259
260
261 // Reinit system matrix
262 DynamicSparsityPattern dsp(locally_relevant_dofs);
263 DoFTools::make_sparsity_pattern(*dof_handler,
264 dsp,
265 void_fraction_constraints,
266 false);
267
268 SparsityTools::distribute_sparsity_pattern(
269 dsp,
271 this->triangulation->get_mpi_communicator(),
273
274 system_matrix_void_fraction.reinit(
277 dsp,
278 this->triangulation->get_mpi_communicator());
279
280 if (has_periodic_boundaries)
282 *this->dof_handler, this->vertices_to_periodic_cell);
283}
284
285
286template <int dim, typename PropertiesIndex>
287void
289 const double time)
290{
291 announce_string(this->pcout, "Void Fraction");
292
294 {
296 // If its a function, no need to solve a linear system of equations so
297 // return.
298 return;
299 }
300 // The void fraction is established using a particle handler.
301 // A right-hand side and a linear system of equation are assembled and then
302 // solved. The resulting solution yields the nodal values of the void
303 // fraction.
305 {
307 }
309 {
312 }
314 {
316 }
317
319
320 if (void_fraction_parameters->project_particle_velocity)
321 {
323 }
324}
325
326template <int dim, typename PropertiesIndex>
327void
330{
331 // Only the particles of thermal CFD-DEM simulations (solver type = dem_mp)
332 // carry a temperature
334 {
336
337// Transfer the particle temperature solution to the multiphysics interface
338// vector. This is needed since the multiphysics interface uses a different
339// vector type than the one used in the particle projector depending on the
340// build configuration.
341#ifndef LETHE_USE_LDV
342 GlobalVectorType temporary_solution_vector(
343 particle_temperature.locally_owned_dofs,
344 particle_temperature.dof_handler->get_mpi_communicator());
345
347 temporary_solution_vector,
348 particle_temperature.particle_field_solution);
349
350 *particle_temperature_locally_relevant = temporary_solution_vector;
351#else
352 particle_temperature_locally_relevant->copy_locally_owned_data_from(
353 particle_temperature.particle_field_solution);
354 particle_temperature_locally_relevant->update_ghost_values();
355#endif
356 }
357}
358
359
360template <int dim, typename PropertiesIndex>
361void
363 const double time)
364{
365 // The current time of the function is set for time-dependant functions
366 void_fraction_parameters->void_fraction.set_time(time);
367
368 // The function is directly interpolate at the nodes.
369 // This is not an L2 projection, but a direct evaluation.
370 // This may lead to some issues on coarses meshes if a high-order
371 // interpolation (>FE_Q(1)) is used.
372 VectorTools::interpolate(*mapping,
373 *this->dof_handler,
374 void_fraction_parameters->void_fraction,
376
377 // Propagate ghost values
379
380#ifndef LETHE_USE_LDV
381 // Perform copy between two vector types to ensure there is a deal.II vector
384 void_fraction_solution.update_ghost_values();
385#else
387#endif
388}
389
390template <int dim, typename PropertiesIndex>
391void
394{
395 FEValues<dim> fe_values_void_fraction(*mapping,
396 *fe,
397 *quadrature,
398 update_values | update_JxW_values |
399 update_gradients);
400
401 const unsigned int dofs_per_cell = fe->dofs_per_cell;
402 const unsigned int n_q_points = quadrature->size();
403 FullMatrix<double> local_matrix_void_fraction(dofs_per_cell, dofs_per_cell);
404 Vector<double> local_rhs_void_fraction(dofs_per_cell);
405 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
406 std::vector<double> phi_vf(dofs_per_cell);
407 std::vector<Tensor<1, dim>> grad_phi_vf(dofs_per_cell);
408
411
412 for (const auto &cell : this->dof_handler->active_cell_iterators())
413 {
414 if (cell->is_locally_owned())
415 {
416 fe_values_void_fraction.reinit(cell);
417
418 local_matrix_void_fraction = 0;
419 local_rhs_void_fraction = 0;
420
421 double solid_volume_in_cell = 0;
422
423 // Loop over particles in cell
424 // Begin and end iterator for particles in cell
425 const auto pic = particle_handler->particles_in_cell(cell);
426 for (auto &particle : pic)
427 {
428 auto particle_properties = particle.get_properties();
429 if constexpr (dim == 2)
430 {
431 solid_volume_in_cell +=
432 M_PI * 0.25 *
433 Utilities::fixed_power<2>(
434 particle_properties[PropertiesIndex::dp]);
435 }
436 if constexpr (dim == 3)
437 {
438 solid_volume_in_cell +=
439 M_PI * 1. / 6. *
440 Utilities::fixed_power<3>(
441 particle_properties[PropertiesIndex::dp]);
442 }
443 }
444 double cell_volume = cell->measure();
445
446 // Calculate cell void fraction
447 double cell_void_fraction =
448 (cell_volume - solid_volume_in_cell) / cell_volume;
449
450 for (unsigned int q = 0; q < n_q_points; ++q)
451 {
452 const double JxW = fe_values_void_fraction.JxW(q);
453
454 for (unsigned int k = 0; k < dofs_per_cell; ++k)
455 {
456 phi_vf[k] = fe_values_void_fraction.shape_value(k, q);
457 grad_phi_vf[k] = fe_values_void_fraction.shape_grad(k, q);
458 }
459 for (unsigned int i = 0; i < dofs_per_cell; ++i)
460 {
461 // Assemble L2 projection
462 // Matrix assembly
463 for (unsigned int j = 0; j < dofs_per_cell; ++j)
464 {
465 local_matrix_void_fraction(i, j) +=
466 (phi_vf[j] * phi_vf[i] + this->l2_smoothing_factor *
467 grad_phi_vf[j] *
468 grad_phi_vf[i]) *
469 JxW;
470 }
471 local_rhs_void_fraction(i) +=
472 phi_vf[i] * cell_void_fraction * JxW;
473 }
474 }
475 cell->get_dof_indices(local_dof_indices);
476 void_fraction_constraints.distribute_local_to_global(
477 local_matrix_void_fraction,
478 local_rhs_void_fraction,
479 local_dof_indices,
482 }
483 }
484 system_matrix_void_fraction.compress(VectorOperation::add);
485 system_rhs_void_fraction.compress(VectorOperation::add);
486}
487
488template <int dim, typename PropertiesIndex>
489void
492{
493 FEValues<dim> fe_values_void_fraction(*mapping,
494 *fe,
495 *quadrature,
496 update_values | update_JxW_values |
497 update_gradients);
498
499 const unsigned int dofs_per_cell = fe->dofs_per_cell;
500 const unsigned int n_q_points = quadrature->size();
501 FullMatrix<double> local_matrix_void_fraction(dofs_per_cell, dofs_per_cell);
502 Vector<double> local_rhs_void_fraction(dofs_per_cell);
503 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
504 std::vector<double> phi_vf(dofs_per_cell);
505 std::vector<Tensor<1, dim>> grad_phi_vf(dofs_per_cell);
506
509
510 // Creation of reference sphere and components required for mapping into
511 // individual particles. This calculation is done once and cached
512 // since it requires creating a triangulation and quadrature points which
513 // would prohibitively expensive to do for each individual particle.
514 //-------------------------------------------------------------------------
515 QGauss<dim> quadrature_particle(1);
516 Triangulation<dim> particle_triangulation;
517 Point<dim> center;
518
519 // Reference particle with radius 1
520 GridGenerator::hyper_ball(particle_triangulation, center, 1);
521 particle_triangulation.refine_global(
522 void_fraction_parameters->particle_refinement_factor);
523
524 DoFHandler<dim> dof_handler_particle(particle_triangulation);
525
526 FEValues<dim> fe_values_particle(*mapping,
527 *fe,
528 quadrature_particle,
529 update_JxW_values |
530 update_quadrature_points);
531
532 dof_handler_particle.distribute_dofs(*fe);
533
534 std::vector<Point<dim>> reference_quadrature_location(
535 quadrature_particle.size() *
536 particle_triangulation.n_global_active_cells());
537
538 std::vector<double> reference_quadrature_weights(
539 quadrature_particle.size() *
540 particle_triangulation.n_global_active_cells());
541
542 std::vector<Point<dim>> quadrature_particle_location(
543 quadrature_particle.size() *
544 particle_triangulation.n_global_active_cells());
545
546 std::vector<double> quadrature_particle_weights(
547 quadrature_particle.size() *
548 particle_triangulation.n_global_active_cells());
549
550 unsigned int n = 0;
551 for (const auto &particle_cell : dof_handler_particle.active_cell_iterators())
552 {
553 fe_values_particle.reinit(particle_cell);
554 for (unsigned int q = 0; q < quadrature_particle.size(); ++q)
555 {
556 reference_quadrature_weights[n] =
557 (M_PI * Utilities::fixed_power<dim>(2.0) / (2.0 * dim)) /
558 reference_quadrature_weights.size();
559 reference_quadrature_location[n] =
560 fe_values_particle.quadrature_point(q);
561 n++;
562 }
563 }
564 //-------------------------------------------------------------------------
565 // At this stage, everything related to the reference particle has been
566 // correctly pre-calculated and stored. Now we assemble the system using
567 // the satellite point method to calculate the void fraction adequately.
568
569 for (const auto &cell : this->dof_handler->active_cell_iterators())
570 {
571 if (cell->is_locally_owned())
572 {
573 fe_values_void_fraction.reinit(cell);
574
575 local_matrix_void_fraction = 0;
576 local_rhs_void_fraction = 0;
577
578 double solid_volume_in_cell = 0;
579
580 // Active neighbors include the current cell as well
581 auto active_neighbors =
583
584 for (unsigned int m = 0; m < active_neighbors.size(); m++)
585 {
586 // Loop over particles in cell
587 // Begin and end iterator for particles in cell
588 const auto pic =
589 particle_handler->particles_in_cell(active_neighbors[m]);
590 for (auto &particle : pic)
591 {
592 auto particle_properties = particle.get_properties();
593 auto particle_location = particle.get_location();
594
595 // Translation factor used to translate the reference sphere
596 // location and size to those of the particles. Usually, we
597 // take it as the radius of every individual particle. This
598 // makes our method valid for different particle
599 // distribution.
600 double translational_factor =
601 particle_properties[PropertiesIndex::dp] * 0.5;
602
603 // Resize and translate the reference sphere
604 // to the particle size and position according the volume
605 // ratio between sphere and particle.
606 for (unsigned int l = 0;
607 l < reference_quadrature_location.size();
608 ++l)
609 {
610 // For example, in 3D V_particle/V_sphere =
611 // r_particle³/r_sphere³ and since r_sphere is always 1,
612 // then V_particle/V_sphere = r_particle³. Therefore,
613 // V_particle = r_particle³ * V_sphere.
614 quadrature_particle_weights[l] =
615 Utilities::fixed_power<dim>(translational_factor) *
616 reference_quadrature_weights[l];
617
618 // Here, we translate the position of the reference
619 // sphere into the position of the particle, but for
620 // this we have to shrink or expand the size of the
621 // reference sphere to be equal to the size of the
622 // particle as the location of the quadrature points is
623 // affected by the size by multiplying with the
624 // particle's radius. We then translate by taking the
625 // translational vector between the reference sphere
626 // center and the particle's center. This translates
627 // directly into the translational vector being the
628 // particle's position as the reference sphere is always
629 // located at (0,0) in 2D or (0,0,0) in 3D.
630 quadrature_particle_location[l] =
631 (translational_factor *
632 reference_quadrature_location[l]) +
633 particle_location;
634
635 if (cell->point_inside(quadrature_particle_location[l]))
636 solid_volume_in_cell += quadrature_particle_weights[l];
637 }
638 }
639 }
640
641 // Same steps for the periodic neighbors with particle location
642 // correction
643 auto active_periodic_neighbors =
646
647 for (unsigned int m = 0; m < active_periodic_neighbors.size(); m++)
648 {
649 const auto pic = particle_handler->particles_in_cell(
650 active_periodic_neighbors[m]);
651 for (auto &particle : pic)
652 {
653 auto particle_properties = particle.get_properties();
654
655 unsigned int neighbor_dir = 0;
656 Tensor<1, dim> neighbor_offset = Tensor<1, dim>();
657 for (const auto &[bid, d] : cfd_periodic_directions)
658 {
659 if (std::abs(active_periodic_neighbors[m]->center()[d] -
660 cell->center()[d]) > cell->diameter())
661 {
662 neighbor_dir = d;
663 neighbor_offset = cfd_periodic_offsets.at(bid);
664 break;
665 }
666 }
667
668 const Point<dim> particle_location =
669 (active_periodic_neighbors[m]->center()[neighbor_dir] >
670 cell->center()[neighbor_dir]) ?
671 particle.get_location() - neighbor_offset :
672 particle.get_location() + neighbor_offset;
673
674 double translational_factor =
675 particle_properties[PropertiesIndex::dp] * 0.5;
676
677 for (unsigned int l = 0;
678 l < reference_quadrature_location.size();
679 ++l)
680 {
681 quadrature_particle_weights[l] =
682 Utilities::fixed_power<dim>(translational_factor) *
683 reference_quadrature_weights[l];
684
685 quadrature_particle_location[l] =
686 (translational_factor *
687 reference_quadrature_location[l]) +
688 particle_location;
689
690 if (cell->point_inside(quadrature_particle_location[l]))
691 solid_volume_in_cell += quadrature_particle_weights[l];
692 }
693 }
694 }
695
696 double cell_volume = cell->measure();
697
698 // Calculate cell void fraction
699 double cell_void_fraction =
700 (cell_volume - solid_volume_in_cell) / cell_volume;
701
702 for (unsigned int q = 0; q < n_q_points; ++q)
703 {
704 for (unsigned int k = 0; k < dofs_per_cell; ++k)
705 {
706 phi_vf[k] = fe_values_void_fraction.shape_value(k, q);
707 grad_phi_vf[k] = fe_values_void_fraction.shape_grad(k, q);
708 }
709 for (unsigned int i = 0; i < dofs_per_cell; ++i)
710 {
711 // Matrix assembly
712 for (unsigned int j = 0; j < dofs_per_cell; ++j)
713 {
714 local_matrix_void_fraction(i, j) +=
715 (phi_vf[j] * phi_vf[i]) *
716 fe_values_void_fraction.JxW(q) +
717 (this->l2_smoothing_factor * grad_phi_vf[j] *
718 grad_phi_vf[i] * fe_values_void_fraction.JxW(q));
719 }
720 local_rhs_void_fraction(i) += phi_vf[i] * cell_void_fraction *
721 fe_values_void_fraction.JxW(q);
722 }
723 }
724 cell->get_dof_indices(local_dof_indices);
725 void_fraction_constraints.distribute_local_to_global(
726 local_matrix_void_fraction,
727 local_rhs_void_fraction,
728 local_dof_indices,
731 }
732 }
733
734 system_matrix_void_fraction.compress(VectorOperation::add);
735 system_rhs_void_fraction.compress(VectorOperation::add);
736}
737
738template <int dim, typename PropertiesIndex>
739void
742{
743 switch (void_fraction_parameters->qcm_filter_type)
744 {
748 break;
751 break;
752 default:
753 AssertThrow(false,
754 ExcMessage("Unhandled QCMFilterType in QCM dispatcher."));
755 }
756}
757
758template <int dim, typename PropertiesIndex>
759template <Parameters::QCMFilterType filter_type>
760void
762{
763 FEValues<dim> fe_values_void_fraction(*mapping,
764 *fe,
765 *quadrature,
766 update_values |
767 update_quadrature_points |
768 update_JxW_values | update_gradients);
769
770 const unsigned int dofs_per_cell = this->fe->dofs_per_cell;
771 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
772 const unsigned int n_q_points = quadrature->size();
773 FullMatrix<double> local_matrix_void_fraction(dofs_per_cell, dofs_per_cell);
774 Vector<double> local_rhs_void_fraction(dofs_per_cell);
775 std::vector<double> phi_vf(dofs_per_cell);
776 std::vector<Tensor<1, dim>> grad_phi_vf(dofs_per_cell);
777
778 // QCM filter characteristic length. For the spherical filter this is the
779 // averaging-sphere radius; for the gaussian filter it is the standard
780 // deviation sigma. The same parameter (qcm_smoothing_length) supplies it in
781 // both cases.
782 double filter_length = 0.0;
783 double particles_volume_in_kernel;
784 double quadrature_void_fraction;
785 double qcm_smoothing_length = void_fraction_parameters->qcm_smoothing_length;
786
787 // If the filter length is user-defined via qcm_smoothing_length, it is
788 // calculated from it once; otherwise, it must be recomputed from each cell
789 // measure while looping over the cells.
790 bool calculate_filter_length_from_cell = true;
791 if (qcm_smoothing_length > 1e-16)
792 {
793 filter_length = 0.5 * qcm_smoothing_length;
794 calculate_filter_length_from_cell = false;
795 }
796
799
800 // Clear all contributions of particles from the previous time step
801 for (const auto &cell : dof_handler->active_cell_iterators())
802 {
803 if (cell->is_locally_owned())
804 {
805 const auto pic = particle_handler->particles_in_cell(cell);
806
807 for (auto &particle : pic)
808 {
809 auto particle_properties = particle.get_properties();
810
811 particle_properties[PropertiesIndex::volumetric_contribution] = 0;
812 }
813 }
814 }
815
816 // Determine the new volumetric contributions of the particles necessary
817 // for void fraction calculation
818 for (const auto &cell : dof_handler->active_cell_iterators())
819 {
820 if (cell->is_locally_owned())
821 {
822 fe_values_void_fraction.reinit(cell);
823
824 // Active neighbors include the current cell as well
825 auto active_neighbors =
827
828 auto active_periodic_neighbors =
831
832 // Array of real locations for the quadrature points
833 std::vector<std::vector<Point<dim>>>
834 neighbor_quadrature_point_location(
835 active_neighbors.size(), std::vector<Point<dim>>(n_q_points));
836
837 for (unsigned int m = 0; m < active_neighbors.size(); m++)
838 {
839 fe_values_void_fraction.reinit(active_neighbors[m]);
840
841 neighbor_quadrature_point_location[m] =
842 fe_values_void_fraction.get_quadrature_points();
843 }
844
845 // Array of real locations for the periodic neighbor quadrature
846 // points
847 std::vector<std::vector<Point<dim>>>
848 periodic_neighbor_quadrature_point_location(
849 active_periodic_neighbors.size(),
850 std::vector<Point<dim>>(n_q_points));
851
852 for (unsigned int m = 0; m < active_periodic_neighbors.size(); m++)
853 {
854 fe_values_void_fraction.reinit(active_periodic_neighbors[m]);
855
856 periodic_neighbor_quadrature_point_location[m] =
857 fe_values_void_fraction.get_quadrature_points();
858 }
859
860 // Loop over the particles in the current cell
861 const auto pic = particle_handler->particles_in_cell(cell);
862 for (auto &particle : pic)
863 {
864 auto particle_properties = particle.get_properties();
865 const double r_particle =
866 0.5 * particle_properties[PropertiesIndex::dp];
867
868 // Loop over neighboring cells to determine if the current
869 // particle intersects the filter kernels centered at their
870 // quadrature points.
871 //***********************************************************************
872 for (unsigned int m = 0; m < active_neighbors.size(); m++)
873 {
874 // Define the length of the reference kernel to be used as
875 // the averaging volume for the QCM. If the reference kernel
876 // length was given by the user the value is already
877 // defined since it is not dependent on any measure of the
878 // active cell
879 if (calculate_filter_length_from_cell)
880 {
882 active_neighbors[m]->measure());
883 }
884
885 // Loop over quadrature points
886 for (unsigned int k = 0; k < n_q_points; ++k)
887 {
888 // Distance between particle and quadrature point
889 double neighbor_distance =
890 particle.get_location().distance(
891 neighbor_quadrature_point_location[m][k]);
892
893 // Add the filter kernel contribution to the particle's
894 // volumetric contribution.
895 particle_properties
896 [PropertiesIndex::volumetric_contribution] +=
898 filter_length,
899 neighbor_distance);
900 }
901 }
902
903 // Loop over periodic neighboring cells to determine if the
904 // current particle intersects the filter kernels centered
905 // at their quadrature points.
906 //***********************************************************************
907 for (unsigned int m = 0; m < active_periodic_neighbors.size();
908 m++)
909 {
910 if (calculate_filter_length_from_cell)
911 {
913 active_periodic_neighbors[m]->measure());
914 }
915
916 // Loop over quadrature points
917 for (unsigned int k = 0; k < n_q_points; ++k)
918 {
919 // Adjust the location of the particle in the cell to
920 // account for the periodicity. If the position of the
921 // periodic cell is greater than the position of the
922 // current cell, the particle location needs a positive
923 // correction, and vice versa
924 unsigned int neighbor_dir = 0;
925 Tensor<1, dim> neighbor_offset = Tensor<1, dim>();
926 for (const auto &[bid, d] : cfd_periodic_directions)
927 {
928 if (std::abs(
929 active_periodic_neighbors[m]->center()[d] -
930 cell->center()[d]) > cell->diameter())
931 {
932 neighbor_dir = d;
933 neighbor_offset = cfd_periodic_offsets.at(bid);
934 break;
935 }
936 }
937
938 const Point<dim> particle_location =
939 (active_periodic_neighbors[m]->center()[neighbor_dir] >
940 cell->center()[neighbor_dir]) ?
941 particle.get_location() + neighbor_offset :
942 particle.get_location() - neighbor_offset;
943
944
945 // Distance between particle and quadrature point
946 double periodic_neighbor_distance =
947 particle_location.distance(
948 periodic_neighbor_quadrature_point_location[m][k]);
949
950 // Add the filter kernel contribution to the particle's
951 // volumetric contribution.
952 particle_properties
953 [PropertiesIndex::volumetric_contribution] +=
955 r_particle,
956 filter_length,
957 periodic_neighbor_distance);
958 }
959 }
960 }
961 }
962 }
963
964 particle_handler->update_ghost_particles();
965
966 // After the particles' contributions have been determined, calculate and
967 // normalize the void fraction
968 for (const auto &cell : dof_handler->active_cell_iterators())
969 {
970 if (cell->is_locally_owned())
971 {
972 fe_values_void_fraction.reinit(cell);
973
974 local_matrix_void_fraction = 0;
975 local_rhs_void_fraction = 0;
976
977 double sum_quadrature_weights = 0;
978
979 for (unsigned int q = 0; q < n_q_points; ++q)
980 {
981 sum_quadrature_weights += fe_values_void_fraction.JxW(q);
982 }
983
984 Assert(
985 sum_quadrature_weights > 0,
986 ExcMessage(
987 "The sum of the quadrature weight should be strictly positive."));
988
989 // Define the QCM filter characteristic length for this cell.
990 if (calculate_filter_length_from_cell)
991 {
992 filter_length =
994 }
995
996 // Array of real locations for the quadrature points
997 std::vector<Point<dim>> quadrature_point_location;
998
999 quadrature_point_location =
1000 fe_values_void_fraction.get_quadrature_points();
1001
1002 // Active neighbors include the current cell as well
1003 auto active_neighbors =
1005
1006 // Periodic neighbors of the current cell
1007 auto active_periodic_neighbors =
1010
1011 for (unsigned int q = 0; q < n_q_points; ++q)
1012 {
1013 particles_volume_in_kernel = 0;
1014 quadrature_void_fraction = 0;
1015
1016 for (unsigned int m = 0; m < active_neighbors.size(); m++)
1017 {
1018 // Loop over particles in neighboring cell
1019 // Begin and end iterator for particles in neighboring cell
1020 const auto pic =
1021 particle_handler->particles_in_cell(active_neighbors[m]);
1022 for (auto &particle : pic)
1023 {
1024 auto particle_properties = particle.get_properties();
1025 const double r_particle =
1026 particle_properties[PropertiesIndex::dp] * 0.5;
1027
1028 // Calculate the ratio between the particle volume and the
1029 // total volume it contributes to all kernels
1030 const double particle_volume_ratio =
1031 (M_PI * Utilities::fixed_power<dim>(r_particle * 2.0) /
1032 (2 * dim)) /
1033 particle_properties
1034 [PropertiesIndex::volumetric_contribution];
1035
1036 // Distance between particle and quadrature point
1037 // centers
1038 const double distance = particle.get_location().distance(
1039 quadrature_point_location[q]);
1040
1041 // Calculate the normalized particle contribution
1042 particles_volume_in_kernel +=
1043 particle_volume_ratio *
1045 filter_length,
1046 distance);
1047 }
1048 }
1049
1050 // Execute same operations for periodic neighbors, if the
1051 // simulation has no periodic boundaries, the container is
1052 // empty. Also, those operations cannot be done in the previous
1053 // loop because the particles on the periodic side need a
1054 // correction with an offset for the distance with the
1055 // quadrature point
1056 for (unsigned int m = 0; m < active_periodic_neighbors.size();
1057 m++)
1058 {
1059 // Loop over particles in periodic neighbor cell
1060 const auto pic = particle_handler->particles_in_cell(
1061 active_periodic_neighbors[m]);
1062 for (auto &particle : pic)
1063 {
1064 auto particle_properties = particle.get_properties();
1065 const double r_particle =
1066 particle_properties[PropertiesIndex::dp] * 0.5;
1067
1068 // Adjust the location of the particle in the cell to
1069 // account for the periodicity. If the position of the
1070 // periodic cell is greater than the position of the
1071 // current cell, the particle location needs a negative
1072 // correction, and vice versa. Since the particle is in
1073 // the periodic cell, this correction is the inverse of
1074 // the correction for the volumetric contribution
1075 unsigned int neighbor_dir = 0;
1076 Tensor<1, dim> neighbor_offset = Tensor<1, dim>();
1077 for (const auto &[bid, d] : cfd_periodic_directions)
1078 {
1079 if (std::abs(
1080 active_periodic_neighbors[m]->center()[d] -
1081 cell->center()[d]) > cell->diameter())
1082 {
1083 neighbor_dir = d;
1084 neighbor_offset = cfd_periodic_offsets.at(bid);
1085 break;
1086 }
1087 }
1088
1089 const Point<dim> particle_location =
1090 (active_periodic_neighbors[m]->center()[neighbor_dir] >
1091 cell->center()[neighbor_dir]) ?
1092 particle.get_location() - neighbor_offset :
1093 particle.get_location() + neighbor_offset;
1094
1095
1096 // Distance between particle and quadrature point
1097 // centers
1098 const double distance = particle_location.distance(
1099 quadrature_point_location[q]);
1100
1101 // Calculate the ratio between the particle volume and the
1102 // total volume it contributes to all kernels
1103 const double particle_volume_ratio =
1104 (M_PI * Utilities::fixed_power<dim>(r_particle * 2.0) /
1105 (2 * dim)) /
1106 particle_properties
1107 [PropertiesIndex::volumetric_contribution];
1108
1109 // Calculate the normalized particle contribution
1110 particles_volume_in_kernel +=
1111 particle_volume_ratio *
1113 filter_length,
1114 distance);
1115 }
1116 if (particles_volume_in_kernel > 1.001)
1117 {
1118 std::cout << "WARNING: particles_volume_in_kernel = "
1119 << particles_volume_in_kernel << " at cell "
1120 << cell->center() << std::endl;
1121 }
1122 }
1123
1124 // We use the volume of the cell as it is equal to the volume
1125 // of the sphere
1126 quadrature_void_fraction =
1127 ((fe_values_void_fraction.JxW(q) * cell->measure() /
1128 sum_quadrature_weights) -
1129 particles_volume_in_kernel) /
1130 (fe_values_void_fraction.JxW(q) * cell->measure() /
1131 sum_quadrature_weights);
1132
1133 for (unsigned int k = 0; k < dofs_per_cell; ++k)
1134 {
1135 phi_vf[k] = fe_values_void_fraction.shape_value(k, q);
1136 grad_phi_vf[k] = fe_values_void_fraction.shape_grad(k, q);
1137 }
1138
1139 for (unsigned int i = 0; i < dofs_per_cell; ++i)
1140 {
1141 // Assemble L2 projection
1142 // Matrix assembly
1143 for (unsigned int j = 0; j < dofs_per_cell; ++j)
1144 {
1145 local_matrix_void_fraction(i, j) +=
1146 ((phi_vf[j] * phi_vf[i]) +
1147 (this->l2_smoothing_factor * grad_phi_vf[j] *
1148 grad_phi_vf[i])) *
1149 fe_values_void_fraction.JxW(q);
1150 }
1151
1152 local_rhs_void_fraction(i) += phi_vf[i] *
1153 quadrature_void_fraction *
1154 fe_values_void_fraction.JxW(q);
1155 }
1156 }
1157
1158 cell->get_dof_indices(local_dof_indices);
1159 void_fraction_constraints.distribute_local_to_global(
1160 local_matrix_void_fraction,
1161 local_rhs_void_fraction,
1162 local_dof_indices,
1165 }
1166 }
1167
1168 system_matrix_void_fraction.compress(VectorOperation::add);
1169 system_rhs_void_fraction.compress(VectorOperation::add);
1170}
1171
1172// first: the template of the class
1173template <int dim, typename PropertiesIndex>
1174// second: the template of the method
1175template <int n_components, int property_start_index>
1176void
1179{
1180 switch (void_fraction_parameters->qcm_filter_type)
1181 {
1184 field_qcm);
1185 break;
1188 field_qcm);
1189 break;
1190 default:
1191 AssertThrow(
1192 false,
1193 ExcMessage(
1194 "Unhandled QCMFilterType in calculate_field_projection dispatcher."));
1195 }
1196}
1197
1198// first: the template of the class
1199template <int dim, typename PropertiesIndex>
1200// second: the template of the method
1201template <Parameters::QCMFilterType filter_type,
1202 int n_components,
1203 int property_start_index>
1204void
1207{
1208 AssertThrow(n_components == 1 || n_components == dim,
1209 ExcMessage(
1210 "QCM projection of a field only supports 1 or dim components"));
1211
1212 AssertThrow(
1213 has_periodic_boundaries == false,
1214 ExcMessage(
1215 "The QCM projection of a particle field is not currently supported "
1216 "with periodic boundary conditions. The periodic constraints are not "
1217 "applied to the particle field constraints."));
1218
1219 FEValues<dim> fe_values_field(*mapping,
1220 *field_qcm.fe,
1221 *quadrature,
1222 update_values | update_quadrature_points |
1223 update_JxW_values | update_gradients);
1224
1225 // Field extractor if dim components are used
1226 FEValuesExtractors::Vector vector_extractor;
1227 vector_extractor.first_vector_component = 0;
1228
1229 const unsigned int dofs_per_cell = field_qcm.fe->dofs_per_cell;
1230 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
1231 const unsigned int n_q_points = quadrature->size();
1232 FullMatrix<double> local_matrix(dofs_per_cell, dofs_per_cell);
1233 Vector<double> local_rhs(dofs_per_cell);
1234
1235
1236 // Declare the vectors for the shape function differently depending on the
1237 // number of components. We currently assume either 1 or dim components.
1238 std::conditional_t<n_components == 1,
1239 std::vector<double>,
1240 std::vector<Tensor<1, dim>>>
1241 phi_vf(dofs_per_cell);
1242 std::conditional_t<n_components == 1,
1243 std::vector<Tensor<1, dim>>,
1244 std::vector<Tensor<2, dim>>>
1245 grad_phi_vf(dofs_per_cell);
1246
1247 // QCM filter characteristic length (averaging-sphere radius for spherical,
1248 // sigma for gaussian).
1249 double filter_length = 0.0;
1250 double total_volume_of_particles_in_sphere;
1251 std::conditional_t<n_components == 1, double, Tensor<1, dim>>
1252 particle_field_in_sphere;
1253 double qcm_smoothing_length = void_fraction_parameters->qcm_smoothing_length;
1254
1255 bool calculate_filter_length_from_cell = true;
1256 if (qcm_smoothing_length > 1e-16)
1257 {
1258 filter_length = 0.5 * qcm_smoothing_length;
1259 calculate_filter_length_from_cell = false;
1260 }
1261
1262 // Set the system rhs to zero, but also zero out the ghost values so that
1263 // we can also write to the ghost values.
1264 field_qcm.system_rhs = 0;
1265
1266 // The matrix is reset to zero only if it requires assembly.
1267 if (field_qcm.matrix_requires_assembly)
1268 field_qcm.system_matrix = 0;
1269
1270 for (const auto &cell : field_qcm.dof_handler->active_cell_iterators())
1271 {
1272 if (cell->is_locally_owned())
1273 {
1274 fe_values_field.reinit(cell);
1275
1276 local_matrix = 0;
1277 local_rhs = 0;
1278
1279 // Array of real locations for the quadrature points
1280 std::vector<Point<dim>> quadrature_point_location;
1281
1282 quadrature_point_location = fe_values_field.get_quadrature_points();
1283
1284 // Active neighbors include the current cell as well
1285 auto active_neighbors =
1287
1288 // Periodic neighbors of the current cell
1289 auto active_periodic_neighbors =
1292
1293 // Define the QCM filter characteristic length for this cell.
1294 if (calculate_filter_length_from_cell)
1295 {
1296 filter_length =
1298 }
1299
1300 for (unsigned int q = 0; q < n_q_points; ++q)
1301 {
1302 total_volume_of_particles_in_sphere = 0;
1303 particle_field_in_sphere = 0;
1304
1305 for (unsigned int m = 0; m < active_neighbors.size(); m++)
1306 {
1307 // Loop over particles in neighbor cell
1308 // Begin and end iterator for particles in neighbor cell
1309 const auto pic =
1310 particle_handler->particles_in_cell(active_neighbors[m]);
1311 for (auto &particle : pic)
1312 {
1313 double distance = 0;
1314 auto particle_properties = particle.get_properties();
1315 const double r_particle =
1316 particle_properties[PropertiesIndex::dp] * 0.5;
1317
1318 // Distance between particle and quadrature point
1319 // centers
1320 distance = particle.get_location().distance(
1321 quadrature_point_location[q]);
1322
1323 const double particle_volume_in_sphere =
1325 filter_length,
1326 distance);
1327
1328 total_volume_of_particles_in_sphere +=
1329 particle_volume_in_sphere;
1330
1331 // If the projection is to be conservative, then the
1332 // volumetric distribution is equal to the volume of the
1333 // sphere divided by the volumetric contribution of the
1334 // particle. Otherwise, the contribution is just the
1335 // volume of the sphere which will be later divided by the
1336 // total volume of particles in the QCM sphere.
1337
1338 const double volumetric_contribution =
1339 field_qcm.conservative_projection ?
1340 particle_volume_in_sphere /
1341 (particle_properties
1342 [PropertiesIndex::volumetric_contribution]) :
1343 particle_volume_in_sphere;
1344
1345 if constexpr (n_components == 1)
1346 particle_field_in_sphere +=
1347 volumetric_contribution *
1348 particle_properties[property_start_index];
1349 else
1350 {
1351 for (int d = 0; d < n_components; ++d)
1352 {
1353 particle_field_in_sphere[d] +=
1354 volumetric_contribution *
1355 particle_properties[property_start_index + d];
1356 }
1357 }
1358 }
1359 }
1360
1361 // Execute same operations for periodic neighbors, if the
1362 // simulation has no periodic boundaries, the container is
1363 // empty. Also, those operations cannot be done in the previous
1364 // loop because the particles on the periodic side need a
1365 // correction with an offset for the distance with the
1366 // quadrature point
1367 for (unsigned int m = 0; m < active_periodic_neighbors.size();
1368 m++)
1369 {
1370 // Loop over particles in periodic neighbor cell
1371 const auto pic = particle_handler->particles_in_cell(
1372 active_periodic_neighbors[m]);
1373 for (auto &particle : pic)
1374 {
1375 double distance = 0;
1376 auto particle_properties = particle.get_properties();
1377 const double r_particle =
1378 particle_properties[PropertiesIndex::dp] * 0.5;
1379
1380 // Adjust the location of the particle in the cell to
1381 // account for the periodicity. If the position of the
1382 // periodic cell if greater than the position of the
1383 // current cell, the particle location needs a negative
1384 // correction, and vice versa. Since the particle is in
1385 // the periodic cell, this correction is the inverse of
1386 // the correction for the volumetric contribution
1387 unsigned int neighbor_dir = 0;
1388 Tensor<1, dim> neighbor_offset = Tensor<1, dim>();
1389 for (const auto &[bid, d] : cfd_periodic_directions)
1390 {
1391 if (std::abs(
1392 active_periodic_neighbors[m]->center()[d] -
1393 cell->center()[d]) > cell->diameter())
1394 {
1395 neighbor_dir = d;
1396 neighbor_offset = cfd_periodic_offsets.at(bid);
1397 break;
1398 }
1399 }
1400
1401 const Point<dim> particle_location =
1402 (active_periodic_neighbors[m]->center()[neighbor_dir] >
1403 cell->center()[neighbor_dir]) ?
1404 particle.get_location() - neighbor_offset :
1405 particle.get_location() + neighbor_offset;
1406
1407
1408 // Distance between particle and quadrature point
1409 // centers
1410 distance = particle_location.distance(
1411 quadrature_point_location[q]);
1412
1413 const double particle_volume_in_sphere =
1415 filter_length,
1416 distance);
1417
1418 total_volume_of_particles_in_sphere +=
1419 particle_volume_in_sphere;
1420
1421 // If the projection is to be conservative, then the
1422 // volumetric contribution is equal to the volume of the
1423 // particle in the sphere divided by the sum of the
1424 // volumetric contribution of the particle in all spheres
1425 // in the domain. Otherwise, the contribution is just the
1426 // volume of the particle in the sphere which will be
1427 // later divided by the total volume of particles in the
1428 // QCM sphere.
1429
1430 const double volumetric_contribution =
1431 field_qcm.conservative_projection ?
1432 particle_volume_in_sphere /
1433 (particle_properties
1434 [PropertiesIndex::volumetric_contribution]) :
1435 particle_volume_in_sphere;
1436
1437
1438 if constexpr (n_components == 1)
1439 particle_field_in_sphere +=
1440 volumetric_contribution *
1441 particle_properties[property_start_index];
1442 else
1443 {
1444 for (int d = 0; d < n_components; ++d)
1445 {
1446 particle_field_in_sphere[d] +=
1447 volumetric_contribution *
1448 particle_properties[property_start_index + d];
1449 }
1450 }
1451 }
1452 }
1453
1454 for (unsigned int k = 0; k < dofs_per_cell; ++k)
1455 {
1456 if constexpr (n_components == dim)
1457 {
1458 phi_vf[k] = fe_values_field[vector_extractor].value(k, q);
1459 grad_phi_vf[k] =
1460 fe_values_field[vector_extractor].gradient(k, q);
1461 }
1462 if constexpr (n_components == 1)
1463 {
1464 phi_vf[k] = fe_values_field.shape_value(k, q);
1465 grad_phi_vf[k] = fe_values_field.shape_grad(k, q);
1466 }
1467 }
1468
1469 // Normalize the field
1470 // If the field to project is a field in which we want a
1471 // continuous representation, then the normalisation is
1472 // 1/total_volume_particle_in_sphere.
1473
1474 if (field_qcm.conservative_projection == false)
1475 particle_field_in_sphere = particle_field_in_sphere /
1476 total_volume_of_particles_in_sphere;
1477 // Assemble L2 projection with smoothing coefficient.
1478 for (unsigned int i = 0; i < dofs_per_cell; ++i)
1479 {
1480 // We assemble the matrix only when the assembly is required
1481 // This if statement is annoying, but since that bool is not
1482 // changing within the function call, the cost should be
1483 // minimal.
1484 if (field_qcm.matrix_requires_assembly == true)
1485 {
1486 // We extract the component i and j to only calculate the
1487 // matrix when i and j are equal. This is an optimization
1488 // that is only necessary when we have more than 1
1489 // component, but the cost is marginal when there is only
1490 // one component so might as well live with it.
1491 const unsigned int component_i =
1492 field_qcm.fe->system_to_component_index(i).first;
1493 // Matrix assembly
1494 for (unsigned int j = 0; j < dofs_per_cell; ++j)
1495 {
1496 const unsigned int component_j =
1497 field_qcm.fe->system_to_component_index(j).first;
1498 if (component_i == component_j)
1499 {
1500 // If there are particles, assemble a smoothed L2
1501 // projection
1502 if (field_qcm.neumann_boundaries == false ||
1503 total_volume_of_particles_in_sphere > 0)
1504 {
1505 local_matrix(i, j) +=
1506 (phi_vf[j] * phi_vf[i]) *
1507 fe_values_field.JxW(q);
1508 }
1509 local_matrix(i, j) +=
1510 ((this->l2_smoothing_factor *
1511 scalar_product(grad_phi_vf[j],
1512 grad_phi_vf[i]))) *
1513 fe_values_field.JxW(q);
1514 }
1515 }
1516 }
1517
1518 if (total_volume_of_particles_in_sphere > 0)
1519 {
1520 // If the contribution is to be distributed,
1521 // the volume integral over the domain of the field should
1522 // give back the sum of the field over all particles.
1523 // Consequently, the Jacobian of the transformation
1524 // does not appear on the RHS in that case to ensure
1525 // that the integral of the field over the domain
1526 // gives the field to be conserved.
1527 if (field_qcm.conservative_projection)
1528 local_rhs(i) += phi_vf[i] * particle_field_in_sphere;
1529
1530 // Else, the field is not a field for which we wish to
1531 // conserve the total quantity, but a field for which we
1532 // need a smooth representation (e.g. the particle
1533 // velocity). Consequently, we need the jacobian on the
1534 // RHS.
1535 else
1536 local_rhs(i) += phi_vf[i] * particle_field_in_sphere *
1537 fe_values_field.JxW(q);
1538 }
1539 }
1540 }
1541
1542 cell->get_dof_indices(local_dof_indices);
1543 field_qcm.particle_field_constraints.distribute_local_to_global(
1544 local_matrix,
1545 local_rhs,
1546 local_dof_indices,
1547 field_qcm.system_matrix,
1548 field_qcm.system_rhs);
1549 }
1550 }
1551
1552 field_qcm.system_matrix.compress(VectorOperation::add);
1553 field_qcm.system_rhs.compress(VectorOperation::add);
1554
1555
1556
1557 // Calculate rescale metric in case rescale is active.
1558 const double rescale_metric =
1559 linear_solver_parameters.rescale_residual_by_volume ?
1560 std::sqrt(GridTools::volume(*triangulation)) :
1561 1.0;
1562
1563 // Solve the L2 projection system
1564 const double non_rescaled_linear_solver_tolerance =
1565 linear_solver_parameters.minimum_residual;
1566 const double linear_solver_tolerance =
1567 non_rescaled_linear_solver_tolerance / rescale_metric;
1568
1570 {
1571 this->pcout << " -Tolerance of iterative solver is : "
1572 << linear_solver_tolerance << std::endl;
1573 }
1574
1575 // We use the verbosity setting of the void fraction for all projected fields
1576 const bool print_linear_solver_log(linear_solver_parameters.verbosity !=
1578
1579 SolverControl solver_control(linear_solver_parameters.max_iterations,
1580 non_rescaled_linear_solver_tolerance,
1581 print_linear_solver_log,
1582 print_linear_solver_log);
1583
1584 SolverCG<LinearAlgebra::distributed::Vector<double>> solver(solver_control);
1585
1586 //**********************************************
1587 // Trillinos Wrapper ILU Preconditioner
1588 //*********************************************
1589 const unsigned int ilu_fill = linear_solver_parameters.ilu_precond_fill;
1590 const double ilu_atol = linear_solver_parameters.ilu_precond_atol;
1591 const double ilu_rtol = linear_solver_parameters.ilu_precond_rtol;
1592
1593 TrilinosWrappers::PreconditionILU::AdditionalData preconditionerOptions(
1594 ilu_fill, ilu_atol, ilu_rtol, 0);
1595
1596 // If the matrix has just been assembled, we need to recreate the
1597 // preconditioner and initialize it.
1598 if (field_qcm.matrix_requires_assembly)
1599 {
1600 field_qcm.ilu_preconditioner =
1601 std::make_shared<TrilinosWrappers::PreconditionILU>();
1602
1603 field_qcm.ilu_preconditioner->initialize(field_qcm.system_matrix,
1604 preconditionerOptions);
1605 }
1606
1607 // Force the field solution to start from 0. There is no indication
1608 // that the previous solution is a good starting point and this can
1609 // actually create problems when restarting the code with a checkpoint
1610 // since the checkpointing mechanism can become non-deterministic.
1611 // Future Bruno, trust me on this. You were heavily bothered by this
1612 // for three months and it made you doubt your sanity.
1613 field_qcm.particle_field_solution = 0.;
1614
1615 solver.solve(field_qcm.system_matrix,
1616 field_qcm.particle_field_solution,
1617 field_qcm.system_rhs,
1618 *field_qcm.ilu_preconditioner);
1619
1620 // Distribute the constraints to the solution vector. This is necessary
1621 // because of the hanging nodes that can be present in the mesh and would not
1622 // have a correct value only from distributing the values of the local
1623 // solution to the global solution vector.
1624 field_qcm.particle_field_constraints.distribute(
1625 field_qcm.particle_field_solution);
1626
1627 // Now that the solution has been solved for, update the ghost values.
1628 field_qcm.particle_field_solution.update_ghost_values();
1629
1631 {
1632 this->pcout << " -Iterative solver took : "
1633 << solver_control.last_step() / rescale_metric << " steps "
1634 << std::endl;
1635 }
1636
1637 // If the field does not have Neumann boundary condition, then the matrix
1638 // remains unchanged. We thus mark that it does not require assembly and
1639 // we will keep reusing this matrix as long as it is possible.
1640 if (field_qcm.neumann_boundaries == false)
1641 field_qcm.matrix_requires_assembly = false;
1642}
1643
1644
1645
1646template <int dim, typename PropertiesIndex>
1647template <typename VectorType>
1648void
1651 const Parameters::CFDDEM &cfd_dem_parameters,
1652 DoFHandler<dim> &fluid_dof_handler,
1653 const VectorType &present_velocity_pressure_solution,
1654 const std::vector<VectorType> &previous_velocity_pressure_solution,
1655 const Tensor<1, 3> &gravity,
1656 NavierStokesScratchData<dim> scratch_data)
1657{
1658 // If the mode to calculate the void fraction is function, then the VANS
1659 // solver is running with a user defined function so there are no
1660 // particle-fluid force yet the simulation is a valid simulation.
1662 {
1664 return;
1665 }
1666
1667 // If the mode is either SPM or PCM, then information required for the
1668 // projection is not available. Consequently, we should throw and not
1669 // continue.
1670 AssertThrow(
1672 ExcMessage(
1673 "The projection of the particle-fluid force onto the mesh requires that the QCM method be used for the calculation of the void fraction."));
1674
1675
1676 // We aim to project the particle-fluid forces. To maximize code reuse, we
1677 // currently reuse the particle-fluid force model architecture. The
1678 // projection follows the following steps:
1679 // 1. We set up the particle-fluid assemblers that we wish to use
1680 // 2. We loop over the cells:
1681 // A. Reinit the scratch data for the fluid solution
1682 // B. Using the assembler, gather the particle-fluid forces onto the
1683 // particles themselve in the fem_force field. TODO - The drag force will
1684 // need to be seperated into another particle-fluid force if we wish this
1685 // to work for implicit drag formulation.
1686 // At the end of this step, all of the particle forces will have been
1687 // summed/gather onto the particles
1688
1689
1690 // 1. We setup the particle-fluid assemblers that we use.
1691
1692 // Assemblers for the particle_fluid interactions
1693 std::vector<std::shared_ptr<ParticleFluidAssemblerBase<dim, PropertiesIndex>>>
1694 particle_fluid_assemblers;
1695
1696 if (cfd_dem_parameters.drag_force == true)
1697 {
1698 // Particle_Fluid Interactions Assembler
1699 if (cfd_dem_parameters.drag_model == Parameters::DragModel::difelice)
1700 {
1701 // DiFelice Model drag Assembler
1702 particle_fluid_assemblers.push_back(
1704 cfd_dem_parameters));
1705 }
1706
1707 if (cfd_dem_parameters.drag_model == Parameters::DragModel::rong)
1708 {
1709 // Rong Model drag Assembler
1710 particle_fluid_assemblers.push_back(
1712 cfd_dem_parameters));
1713 }
1714
1715 if (cfd_dem_parameters.drag_model == Parameters::DragModel::dallavalle)
1716 {
1717 // Dallavalle Model drag Assembler
1718 particle_fluid_assemblers.push_back(
1720 cfd_dem_parameters));
1721 }
1722
1723 if (cfd_dem_parameters.drag_model == Parameters::DragModel::kochhill)
1724 {
1725 // Koch and Hill Model drag Assembler
1726 particle_fluid_assemblers.push_back(
1728 cfd_dem_parameters));
1729 }
1730 if (cfd_dem_parameters.drag_model == Parameters::DragModel::beetstra)
1731 {
1732 // Beetstra drag model assembler
1733 particle_fluid_assemblers.push_back(
1735 cfd_dem_parameters));
1736 }
1737 if (cfd_dem_parameters.drag_model == Parameters::DragModel::gidaspow)
1738 {
1739 // Gidaspow Model drag Assembler
1740 particle_fluid_assemblers.push_back(
1742 cfd_dem_parameters));
1743 }
1744 }
1745
1746 if (cfd_dem_parameters.buoyancy_force == true)
1747 // Buoyancy Force Assembler
1748 particle_fluid_assemblers.push_back(
1749 std::make_shared<VANSAssemblerBuoyancy<dim, PropertiesIndex>>(gravity));
1750
1751 if (cfd_dem_parameters.saffman_lift_force == true)
1752 // Saffman Mei Lift Force Assembler
1753 particle_fluid_assemblers.push_back(
1755
1756 if (cfd_dem_parameters.magnus_lift_force == true)
1757 // Magnus Lift Force Assembler
1758 particle_fluid_assemblers.push_back(
1759 std::make_shared<VANSAssemblerMagnus<dim, PropertiesIndex>>());
1760
1761 if (cfd_dem_parameters.rotational_viscous_torque == true)
1762 // Viscous Torque Assembler
1763 particle_fluid_assemblers.push_back(
1765
1766 if (cfd_dem_parameters.vortical_viscous_torque == true)
1767 // Vortical Torque Assembler
1768 particle_fluid_assemblers.push_back(
1770
1771
1772 if (cfd_dem_parameters.pressure_force == true)
1773 // Pressure Force
1774 particle_fluid_assemblers.push_back(
1776 cfd_dem_parameters));
1777
1778 if (cfd_dem_parameters.shear_force == true)
1779 // Shear Force
1780 particle_fluid_assemblers.push_back(
1782 cfd_dem_parameters));
1783
1784
1785 scratch_data.enable_void_fraction(*fe, *quadrature, *mapping);
1786
1788 particle_handler->n_global_max_particles_per_cell(), true);
1789
1790 for (const auto &cell : fluid_dof_handler.active_cell_iterators())
1791 {
1792 if (cell->is_locally_owned())
1793 {
1794 // A. We reinit the scratch data at the particle location for the
1795 // void fraction and the velocity. This is what we will require to
1796 // calculate the particle-fluid forces.
1797 typename DoFHandler<dim>::active_cell_iterator void_fraction_cell(
1798 &(this->dof_handler->get_triangulation()),
1799 cell->level(),
1800 cell->index(),
1801 &(*this->dof_handler));
1802
1803 scratch_data.reinit_void_fraction(
1804 void_fraction_cell,
1806 *this->previous_void_fraction);
1807
1808
1809 // Physics properties must be calculated before the particle-fluid
1810 // interaction is calculated.
1811 scratch_data.calculate_physical_properties();
1812
1813 // We need to check if the function is called with deal.II vectors
1814 // or not. If it is called with deal.II vectors, then the vector
1815 // type of the void fraction will not match the vector type of the
1816 // velocity. In that case, we need to use the deal.II vector version
1817 // of the void fraction to ensure consistency.
1818 if constexpr (std::is_same_v<
1819 VectorType,
1820 LinearAlgebra::distributed::Vector<double>>)
1821 {
1822 scratch_data
1823 .template reinit_particle_fluid_interactions<PropertiesIndex>(
1824 cell,
1825 void_fraction_cell,
1826 present_velocity_pressure_solution,
1827 previous_velocity_pressure_solution[0],
1830 cfd_dem_parameters.drag_coupling);
1831 }
1832 else
1833 {
1834 // In this case the global vector type is not a deal.II vector.
1835 scratch_data
1836 .template reinit_particle_fluid_interactions<PropertiesIndex>(
1837 cell,
1838 void_fraction_cell,
1839 present_velocity_pressure_solution,
1840 previous_velocity_pressure_solution[0],
1843 cfd_dem_parameters.drag_coupling);
1844 }
1845
1846
1847 // B. We loop over the particle-fluid assembler and calculate the
1848 // total particle-fluid coupling force.
1849 for (auto &pf_assembler : particle_fluid_assemblers)
1850 {
1851 pf_assembler->calculate_particle_fluid_interactions(scratch_data);
1852 }
1853 }
1854 }
1855
1856 // Ghost particles need to be updated to take into account the new drag
1857 // force
1858 particle_handler->update_ghost_particles();
1859
1860 // We project both the fluid force (without drag) and the drag force.
1861 // We do not announce the string since the projection can be called
1862 // multiple times if this is a non-linear problem and the coupling is
1863 // implicit.
1868}
1869
1870template void
1873 const Parameters::CFDDEM &cfd_dem_parameters,
1874 DoFHandler<2> &dof_handler,
1875 const GlobalVectorType &fluid_solution,
1876 const std::vector<GlobalVectorType> &fluid_previous_solutions,
1877 const Tensor<1, 3> &gravity,
1878 NavierStokesScratchData<2> scratch_data);
1879
1880template void
1883 const Parameters::CFDDEM &cfd_dem_parameters,
1884 DoFHandler<2> &dof_handler,
1885 const GlobalVectorType &fluid_solution,
1886 const std::vector<GlobalVectorType> &fluid_previous_solutions,
1887 const Tensor<1, 3> &gravity,
1888 NavierStokesScratchData<2> scratch_data);
1889
1890template void
1893 const Parameters::CFDDEM &cfd_dem_parameters,
1894 DoFHandler<3> &dof_handler,
1895 const GlobalVectorType &fluid_solution,
1896 const std::vector<GlobalVectorType> &fluid_previous_solutions,
1897 const Tensor<1, 3> &gravity,
1898 NavierStokesScratchData<3> scratch_data);
1899
1900template void
1903 const Parameters::CFDDEM &cfd_dem_parameters,
1904 DoFHandler<3> &dof_handler,
1905 const GlobalVectorType &fluid_solution,
1906 const std::vector<GlobalVectorType> &fluid_previous_solutions,
1907 const Tensor<1, 3> &gravity,
1908 NavierStokesScratchData<3> scratch_data);
1909
1910#ifndef LETHE_USE_LDV
1911template void
1914 const Parameters::CFDDEM &cfd_dem_parameters,
1915 DoFHandler<2> &dof_handler,
1916 const LinearAlgebra::distributed::Vector<double> &fluid_solution,
1917 const std::vector<LinearAlgebra::distributed::Vector<double>>
1918 &fluid_previous_solutions,
1919 const Tensor<1, 3> &gravity,
1920 NavierStokesScratchData<2> scratch_data);
1921
1922template void
1925 const Parameters::CFDDEM &cfd_dem_parameters,
1926 DoFHandler<2> &dof_handler,
1927 const LinearAlgebra::distributed::Vector<double> &fluid_solution,
1928 const std::vector<LinearAlgebra::distributed::Vector<double>>
1929 &fluid_previous_solutions,
1930 const Tensor<1, 3> &gravity,
1931 NavierStokesScratchData<2> scratch_data);
1932
1933template void
1936 const Parameters::CFDDEM &cfd_dem_parameters,
1937 DoFHandler<3> &dof_handler,
1938 const LinearAlgebra::distributed::Vector<double> &fluid_solution,
1939 const std::vector<LinearAlgebra::distributed::Vector<double>>
1940 &fluid_previous_solutions,
1941 const Tensor<1, 3> &gravity,
1942 NavierStokesScratchData<3> scratch_data);
1943
1944template void
1947 const Parameters::CFDDEM &cfd_dem_parameters,
1948 DoFHandler<3> &dof_handler,
1949 const LinearAlgebra::distributed::Vector<double> &fluid_solution,
1950 const std::vector<LinearAlgebra::distributed::Vector<double>>
1951 &fluid_previous_solutions,
1952 const Tensor<1, 3> &gravity,
1953 NavierStokesScratchData<3> scratch_data);
1954#endif
1955
1956template <int dim, typename PropertiesIndex>
1957void
1960{
1961 // Calculate rescale metric as the square root of the volume of the mesh in
1962 // case rescale is active.
1963 const double rescale_metric =
1964 linear_solver_parameters.rescale_residual_by_volume ?
1965 std::sqrt(GridTools::volume(*triangulation)) :
1966 1.0;
1967
1968 // Get the solver's minimum tolerance set in the prm
1969 const double minimum_absolute_residual =
1970 linear_solver_parameters.minimum_residual;
1971 // Get the relative residual set in the prm
1972 const double relative_residual = linear_solver_parameters.relative_residual;
1973 // Get the current residual of the system and scale it by the rescale metric
1974 // if required
1975 const double current_residual =
1976 system_rhs_void_fraction.l2_norm() / rescale_metric;
1977 // Calculate the scaled absolute tolerance of the linear solver
1978 const double linear_solver_tolerance =
1979 std::max(minimum_absolute_residual, relative_residual * current_residual);
1980
1982 {
1983 this->pcout << " -Tolerance of iterative solver is : "
1984 << linear_solver_tolerance << std::endl;
1985 }
1986
1987 const double non_rescaled_linear_solver_tolerance =
1988 linear_solver_tolerance * rescale_metric;
1989
1990 const IndexSet locally_owned_dofs = dof_handler->locally_owned_dofs();
1991
1992 GlobalVectorType completely_distributed_solution(
1993 locally_owned_dofs, this->triangulation->get_mpi_communicator());
1994
1995 // We use the verbosity setting of the void fraction for all projected fields
1996 const bool print_linear_solver_log(linear_solver_parameters.verbosity !=
1998
1999 SolverControl solver_control(linear_solver_parameters.max_iterations,
2000 non_rescaled_linear_solver_tolerance,
2001 print_linear_solver_log,
2002 print_linear_solver_log);
2003
2004 TrilinosWrappers::SolverCG solver(solver_control);
2005
2006 //**********************************************
2007 // Trillinos Wrapper ILU Preconditioner
2008 //*********************************************
2009 const unsigned int ilu_fill = linear_solver_parameters.ilu_precond_fill;
2010 const double ilu_atol = linear_solver_parameters.ilu_precond_atol;
2011 const double ilu_rtol = linear_solver_parameters.ilu_precond_rtol;
2012
2013 TrilinosWrappers::PreconditionILU::AdditionalData preconditionerOptions(
2014 ilu_fill, ilu_atol, ilu_rtol, 0);
2015
2016 ilu_preconditioner = std::make_shared<TrilinosWrappers::PreconditionILU>();
2017
2019 preconditionerOptions);
2020
2021 solver.solve(system_matrix_void_fraction,
2022 completely_distributed_solution,
2025
2027 {
2028 this->pcout << " -Iterative solver took : " << solver_control.last_step()
2029 << " steps to reach a residual norm of "
2030 << solver_control.last_value() / rescale_metric << std::endl;
2031 }
2032
2033 void_fraction_constraints.distribute(completely_distributed_solution);
2034 *this->void_fraction_locally_relevant = completely_distributed_solution;
2035
2036#ifndef LETHE_USE_LDV
2037 // Perform copy between two vector types to ensure there is a deal.II vector
2040 void_fraction_solution.update_ghost_values();
2041#else
2043 void_fraction_solution.update_ghost_values();
2044#endif
2045}
2046
2047template <int dim, typename PropertiesIndex>
2048void
2050 const std::string &folder,
2051 const std::string &prefix,
2052 const unsigned int group_files)
2053{
2055
2056 const double qcm_smoothing_length =
2057 void_fraction_parameters->qcm_smoothing_length;
2058 qp_out.build_patches(
2059 *dof_handler, *mapping, *quadrature, [&](const auto &cell) {
2060 // Same filter length as in the QCM void fraction calculation
2061 return (qcm_smoothing_length > 1e-16) ?
2062 0.5 * qcm_smoothing_length :
2064 });
2065
2066 PVDHandler pvd_handler;
2067 write_vtu_and_pvd(pvd_handler,
2068 qp_out,
2069 folder,
2070 prefix,
2071 /*time*/ 0.,
2072 /*iter*/ 0,
2073 group_files,
2074 triangulation->get_mpi_communicator());
2075}
2076// Pre-compile the 2D and 3D ParticleProjector solver to ensure that the
2077// library is valid before we actually compile the solver This greatly
2078// helps with debugging
unsigned int maximum_number_of_previous_solutions()
Get the maximum number of previous time steps supposed by the BDF schemes implemented in Lethe.
Definition bdf.h:84
Parameters::PeriodicBoundaries periodic_boundaries
Periodic boundary pairs, keyed by the principal periodic boundary id.
std::map< types::boundary_id, BoundaryType > type
Map containing the boundary id and the boundary type.
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....
void enable_void_fraction(const FiniteElement< dim > &fe, const Quadrature< dim > &quadrature, const Mapping< dim > &mapping)
enable_void_fraction Enables the collection of the void fraction data by the scratch
void calculate_physical_properties()
Calculates the physical properties. This function calculates the physical properties that may be requ...
void reinit_void_fraction(const typename DoFHandler< dim >::active_cell_iterator &cell, const VectorType &current_solution, const std::vector< VectorType > &previous_solutions)
Reinitialize the content of the scratch for the void fraction.
void enable_particle_fluid_interactions(const unsigned int n_global_max_particles_per_cell, const bool enable_void_fraction_interpolation)
enable_particle_fluid_interactions Enables the calculation of the fluid information at the particle l...
The PVDHandler class manages the storage of the information required to write pvd file....
Definition pvd_handler.h:17
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
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.
Particle information projection. This class manages the calculation of the projection of the particle...
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...
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.
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.
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 calculate_particle_temperature_projection()
Project the particle temperature onto the fluid mesh with the QCM, then copy it into particle_tempera...
ParticleFieldQCM< dim, 1, DEM::temperature_property_index< PropertiesIndex > > particle_temperature
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.
std::shared_ptr< GlobalVectorType > particle_temperature_locally_relevant
ParticleFieldQCM< dim, 3, PropertiesIndex::fem_drag_x > fluid_drag_on_particles
Build point patches located at quadrature points for visualization, for example to display the QCM fi...
void build_patches(const dealii::DoFHandler< dim > &dof_handler, const dealii::Mapping< dim > &mapping, const dealii::Quadrature< dim > &quadrature, const std::function< double(const typename dealii::DoFHandler< dim >::active_cell_iterator &)> &filter_radius)
Build one point patch per quadrature point of every locally owned cell. Each patch stores the filter ...
Assembler for the drag force using the Beetstra model.
Assembler for the buoyancy force on particles in the VANS equations.
Assembler for the drag force using the Dallavalle model.
Assembler for the drag force using the Di Felice model.
Assembler for the drag force using the Gidaspow model.
Assembler for the drag force using the Koch and Hill drag model.
Assembler for the lift force using the Magnus model.
Assembler for the pressure force on particles.
Assembler for the drag force using the Rong model.
Assembler for the lift force using the Saffman-Mei model.
Assembler for the shear force on particles.
Assembler for the viscous dissipative torque due to particle rotation as defined by Derksen (2004).
Assembler for the viscous dissipative torque due to fluid vorticity as defined by Derksen (2004).
void announce_string(const ConditionalOStream &pcout, const std::string &expression, const char delimiter='-')
Prints a string and then adds a line above and below made with dashes containing as many dashes as th...
Definition utilities.h:500
constexpr bool has_thermal_properties
Whether a properties index set carries thermal properties.
void vertices_cell_mapping(const DoFHandler< dim > &dof_handler, std::map< unsigned int, std::set< typename DoFHandler< dim >::active_cell_iterator > > &vertices_cell_map)
Map the vertex index to the cells that includes that vertex.
void vertices_cell_mapping_with_periodic_boundaries(const DoFHandler< dim > &dof_handler, std::map< unsigned int, std::set< typename DoFHandler< dim >::active_cell_iterator > > &vertices_cell_map)
Map the vertex index to the cells on periodic boundaries that includes the periodic coinciding vertex...
std::vector< typename DoFHandler< dim >::active_cell_iterator > find_cells_around_cell(std::map< unsigned int, std::set< typename DoFHandler< dim >::active_cell_iterator > > &vertices_cell_map, const typename DoFHandler< dim >::active_cell_iterator &cell)
Return a vector of cells around a cell. The vector of cells includes all the cells that share a verte...
@ spm
Satellite point method (divided approach).
@ qcm
Quadrature centered method.
@ function
Void fraction prescribed by an analytical function.
@ pcm
Particle 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).
@ dallavalle
Dallavalle - Valid only for dilute flows.
void write_vtu_and_pvd(PVDHandler &pvd_handler, const DataOutInterface< dim, spacedim > &data_out, const std::string &folder, const std::string &file_prefix, const double time, const unsigned int iter, const unsigned int group_files, const MPI_Comm &mpi_communicator, const unsigned int digits=5)
Output the data out to "group_files" vtu files, with a pvtu file and a pvd to store the timing This f...
Parameters for the CFD-DEM coupled solver.
bool drag_force
Enable drag force on particles.
bool rotational_viscous_torque
Enable rotational viscous torque on particles.
bool saffman_lift_force
Enable Saffman lift force on particles.
bool shear_force
Enable shear force on particles.
bool buoyancy_force
Enable buoyancy force on particles.
bool vortical_viscous_torque
Enable vortical viscous torque on particles.
bool pressure_force
Enable pressure gradient force on particles.
DragModel drag_model
Drag model used for particle-fluid interaction.
DragCoupling drag_coupling
Numerical coupling strategy for drag force computation.
bool magnus_lift_force
Enable Magnus lift force on particles.
GlobalVectorType VectorType
Assemblers for the Volume-Averaged Navier-Stokes (VANS) equations.
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17
void convert_vector_trilinos_to_dealii(dealii::LinearAlgebra::distributed::Vector< number > &out, const dealii::TrilinosWrappers::MPI::Vector &in)
Helper function that allows to convert Trilinos vectors to deal.II vectors.
Definition vector.h:58
void convert_vector_dealii_to_trilinos(dealii::TrilinosWrappers::MPI::Vector &out, const dealii::LinearAlgebra::distributed::Vector< number > &in)
Helper function that allows to convert deal.II vectors to Trilinos vectors.
Definition vector.h:39