13#include <deal.II/base/timer.h>
15#include <deal.II/dofs/dof_tools.h>
17#include <deal.II/fe/fe_values.h>
19#include <deal.II/grid/grid_generator.h>
20#include <deal.II/grid/grid_tools.h>
22#include <deal.II/lac/solver_cg.h>
23#include <deal.II/lac/sparsity_tools.h>
24#include <deal.II/lac/trilinos_solver.h>
26#include <deal.II/numerics/vector_tools.h>
32template <
int dim,
int n_components,
int component_start>
38 const MPI_Comm mpi_communicator =
dof_handler->get_mpi_communicator();
49 DoFTools::extract_locally_active_dofs(
58 DoFTools::make_hanging_node_constraints(*
dof_handler,
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)
73 coupling_table[i][j] = DoFTools::Coupling::none;
75 coupling_table[i][j] = DoFTools::Coupling::always;
79 DoFTools::make_sparsity_pattern(
82 SparsityTools::distribute_sparsity_pattern(dsp,
101template <
int dim,
typename PropertiesIndex>
109 const MPI_Comm mpi_communicator =
dof_handler->get_mpi_communicator();
120 DoFTools::make_hanging_node_constraints(*
dof_handler,
145 DoFTools::extract_locally_active_dofs(*
dof_handler),
146 this->triangulation->get_mpi_communicator());
154 DoFTools::extract_locally_active_dofs(*
dof_handler),
155 this->triangulation->get_mpi_communicator());
164 SparsityTools::distribute_sparsity_pattern(
210template <
int dim,
typename PropertiesIndex>
214 &boundary_conditions)
221 DoFTools::make_hanging_node_constraints(*
dof_handler,
225 for (
auto const &[
id, type] : boundary_conditions.
type)
229 const auto &periodic_boundary =
232 DoFTools::make_periodicity_constraints(
235 periodic_boundary.neighbor_id,
236 periodic_boundary.direction,
237 this->void_fraction_constraints);
244 this->void_fraction_parameters->mode ==
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"));
265 void_fraction_constraints,
268 SparsityTools::distribute_sparsity_pattern(
271 this->triangulation->get_mpi_communicator(),
274 system_matrix_void_fraction.reinit(
278 this->triangulation->get_mpi_communicator());
280 if (has_periodic_boundaries)
282 *this->
dof_handler, this->vertices_to_periodic_cell);
286template <
int dim,
typename PropertiesIndex>
326template <
int dim,
typename PropertiesIndex>
347 temporary_solution_vector,
360template <
int dim,
typename PropertiesIndex>
372 VectorTools::interpolate(*
mapping,
390template <
int dim,
typename PropertiesIndex>
395 FEValues<dim> fe_values_void_fraction(*
mapping,
398 update_values | update_JxW_values |
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);
412 for (
const auto &cell : this->
dof_handler->active_cell_iterators())
414 if (cell->is_locally_owned())
416 fe_values_void_fraction.reinit(cell);
418 local_matrix_void_fraction = 0;
419 local_rhs_void_fraction = 0;
421 double solid_volume_in_cell = 0;
426 for (
auto &particle : pic)
428 auto particle_properties = particle.get_properties();
429 if constexpr (dim == 2)
431 solid_volume_in_cell +=
433 Utilities::fixed_power<2>(
434 particle_properties[PropertiesIndex::dp]);
436 if constexpr (dim == 3)
438 solid_volume_in_cell +=
440 Utilities::fixed_power<3>(
441 particle_properties[PropertiesIndex::dp]);
444 double cell_volume = cell->measure();
447 double cell_void_fraction =
448 (cell_volume - solid_volume_in_cell) / cell_volume;
450 for (
unsigned int q = 0; q < n_q_points; ++q)
452 const double JxW = fe_values_void_fraction.JxW(q);
454 for (
unsigned int k = 0; k < dofs_per_cell; ++k)
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);
459 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
463 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
465 local_matrix_void_fraction(i, j) +=
471 local_rhs_void_fraction(i) +=
472 phi_vf[i] * cell_void_fraction * JxW;
475 cell->get_dof_indices(local_dof_indices);
477 local_matrix_void_fraction,
478 local_rhs_void_fraction,
488template <
int dim,
typename PropertiesIndex>
493 FEValues<dim> fe_values_void_fraction(*
mapping,
496 update_values | update_JxW_values |
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);
515 QGauss<dim> quadrature_particle(1);
516 Triangulation<dim> particle_triangulation;
520 GridGenerator::hyper_ball(particle_triangulation, center, 1);
521 particle_triangulation.refine_global(
524 DoFHandler<dim> dof_handler_particle(particle_triangulation);
526 FEValues<dim> fe_values_particle(*
mapping,
530 update_quadrature_points);
532 dof_handler_particle.distribute_dofs(*
fe);
534 std::vector<Point<dim>> reference_quadrature_location(
535 quadrature_particle.size() *
536 particle_triangulation.n_global_active_cells());
538 std::vector<double> reference_quadrature_weights(
539 quadrature_particle.size() *
540 particle_triangulation.n_global_active_cells());
542 std::vector<Point<dim>> quadrature_particle_location(
543 quadrature_particle.size() *
544 particle_triangulation.n_global_active_cells());
546 std::vector<double> quadrature_particle_weights(
547 quadrature_particle.size() *
548 particle_triangulation.n_global_active_cells());
551 for (
const auto &particle_cell : dof_handler_particle.active_cell_iterators())
553 fe_values_particle.reinit(particle_cell);
554 for (
unsigned int q = 0; q < quadrature_particle.size(); ++q)
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);
569 for (
const auto &cell : this->
dof_handler->active_cell_iterators())
571 if (cell->is_locally_owned())
573 fe_values_void_fraction.reinit(cell);
575 local_matrix_void_fraction = 0;
576 local_rhs_void_fraction = 0;
578 double solid_volume_in_cell = 0;
581 auto active_neighbors =
584 for (
unsigned int m = 0; m < active_neighbors.size(); m++)
590 for (
auto &particle : pic)
592 auto particle_properties = particle.get_properties();
593 auto particle_location = particle.get_location();
600 double translational_factor =
601 particle_properties[PropertiesIndex::dp] * 0.5;
606 for (
unsigned int l = 0;
607 l < reference_quadrature_location.size();
614 quadrature_particle_weights[l] =
615 Utilities::fixed_power<dim>(translational_factor) *
616 reference_quadrature_weights[l];
630 quadrature_particle_location[l] =
631 (translational_factor *
632 reference_quadrature_location[l]) +
635 if (cell->point_inside(quadrature_particle_location[l]))
636 solid_volume_in_cell += quadrature_particle_weights[l];
643 auto active_periodic_neighbors =
647 for (
unsigned int m = 0; m < active_periodic_neighbors.size(); m++)
650 active_periodic_neighbors[m]);
651 for (
auto &particle : pic)
653 auto particle_properties = particle.get_properties();
655 unsigned int neighbor_dir = 0;
656 Tensor<1, dim> neighbor_offset = Tensor<1, dim>();
659 if (std::abs(active_periodic_neighbors[m]->center()[d] -
660 cell->center()[d]) > cell->diameter())
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;
674 double translational_factor =
675 particle_properties[PropertiesIndex::dp] * 0.5;
677 for (
unsigned int l = 0;
678 l < reference_quadrature_location.size();
681 quadrature_particle_weights[l] =
682 Utilities::fixed_power<dim>(translational_factor) *
683 reference_quadrature_weights[l];
685 quadrature_particle_location[l] =
686 (translational_factor *
687 reference_quadrature_location[l]) +
690 if (cell->point_inside(quadrature_particle_location[l]))
691 solid_volume_in_cell += quadrature_particle_weights[l];
696 double cell_volume = cell->measure();
699 double cell_void_fraction =
700 (cell_volume - solid_volume_in_cell) / cell_volume;
702 for (
unsigned int q = 0; q < n_q_points; ++q)
704 for (
unsigned int k = 0; k < dofs_per_cell; ++k)
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);
709 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
712 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
714 local_matrix_void_fraction(i, j) +=
715 (phi_vf[j] * phi_vf[i]) *
716 fe_values_void_fraction.JxW(q) +
718 grad_phi_vf[i] * fe_values_void_fraction.JxW(q));
720 local_rhs_void_fraction(i) += phi_vf[i] * cell_void_fraction *
721 fe_values_void_fraction.JxW(q);
724 cell->get_dof_indices(local_dof_indices);
726 local_matrix_void_fraction,
727 local_rhs_void_fraction,
738template <
int dim,
typename PropertiesIndex>
754 ExcMessage(
"Unhandled QCMFilterType in QCM dispatcher."));
758template <
int dim,
typename PropertiesIndex>
759template <Parameters::QCMFilterType filter_type>
763 FEValues<dim> fe_values_void_fraction(*
mapping,
767 update_quadrature_points |
768 update_JxW_values | update_gradients);
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);
782 double filter_length = 0.0;
783 double particles_volume_in_kernel;
784 double quadrature_void_fraction;
790 bool calculate_filter_length_from_cell =
true;
791 if (qcm_smoothing_length > 1e-16)
793 filter_length = 0.5 * qcm_smoothing_length;
794 calculate_filter_length_from_cell =
false;
801 for (
const auto &cell :
dof_handler->active_cell_iterators())
803 if (cell->is_locally_owned())
807 for (
auto &particle : pic)
809 auto particle_properties = particle.get_properties();
811 particle_properties[PropertiesIndex::volumetric_contribution] = 0;
818 for (
const auto &cell :
dof_handler->active_cell_iterators())
820 if (cell->is_locally_owned())
822 fe_values_void_fraction.reinit(cell);
825 auto active_neighbors =
828 auto active_periodic_neighbors =
833 std::vector<std::vector<Point<dim>>>
834 neighbor_quadrature_point_location(
835 active_neighbors.size(), std::vector<Point<dim>>(n_q_points));
837 for (
unsigned int m = 0; m < active_neighbors.size(); m++)
839 fe_values_void_fraction.reinit(active_neighbors[m]);
841 neighbor_quadrature_point_location[m] =
842 fe_values_void_fraction.get_quadrature_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));
852 for (
unsigned int m = 0; m < active_periodic_neighbors.size(); m++)
854 fe_values_void_fraction.reinit(active_periodic_neighbors[m]);
856 periodic_neighbor_quadrature_point_location[m] =
857 fe_values_void_fraction.get_quadrature_points();
862 for (
auto &particle : pic)
864 auto particle_properties = particle.get_properties();
865 const double r_particle =
866 0.5 * particle_properties[PropertiesIndex::dp];
872 for (
unsigned int m = 0; m < active_neighbors.size(); m++)
879 if (calculate_filter_length_from_cell)
882 active_neighbors[m]->measure());
886 for (
unsigned int k = 0; k < n_q_points; ++k)
889 double neighbor_distance =
890 particle.get_location().distance(
891 neighbor_quadrature_point_location[m][k]);
896 [PropertiesIndex::volumetric_contribution] +=
907 for (
unsigned int m = 0; m < active_periodic_neighbors.size();
910 if (calculate_filter_length_from_cell)
913 active_periodic_neighbors[m]->measure());
917 for (
unsigned int k = 0; k < n_q_points; ++k)
924 unsigned int neighbor_dir = 0;
925 Tensor<1, dim> neighbor_offset = Tensor<1, dim>();
929 active_periodic_neighbors[m]->center()[d] -
930 cell->center()[d]) > cell->diameter())
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;
946 double periodic_neighbor_distance =
947 particle_location.distance(
948 periodic_neighbor_quadrature_point_location[m][k]);
953 [PropertiesIndex::volumetric_contribution] +=
957 periodic_neighbor_distance);
968 for (
const auto &cell :
dof_handler->active_cell_iterators())
970 if (cell->is_locally_owned())
972 fe_values_void_fraction.reinit(cell);
974 local_matrix_void_fraction = 0;
975 local_rhs_void_fraction = 0;
977 double sum_quadrature_weights = 0;
979 for (
unsigned int q = 0; q < n_q_points; ++q)
981 sum_quadrature_weights += fe_values_void_fraction.JxW(q);
985 sum_quadrature_weights > 0,
987 "The sum of the quadrature weight should be strictly positive."));
990 if (calculate_filter_length_from_cell)
997 std::vector<Point<dim>> quadrature_point_location;
999 quadrature_point_location =
1000 fe_values_void_fraction.get_quadrature_points();
1003 auto active_neighbors =
1007 auto active_periodic_neighbors =
1011 for (
unsigned int q = 0; q < n_q_points; ++q)
1013 particles_volume_in_kernel = 0;
1014 quadrature_void_fraction = 0;
1016 for (
unsigned int m = 0; m < active_neighbors.size(); m++)
1022 for (
auto &particle : pic)
1024 auto particle_properties = particle.get_properties();
1025 const double r_particle =
1026 particle_properties[PropertiesIndex::dp] * 0.5;
1030 const double particle_volume_ratio =
1031 (M_PI * Utilities::fixed_power<dim>(r_particle * 2.0) /
1034 [PropertiesIndex::volumetric_contribution];
1038 const double distance = particle.get_location().distance(
1039 quadrature_point_location[q]);
1042 particles_volume_in_kernel +=
1043 particle_volume_ratio *
1056 for (
unsigned int m = 0; m < active_periodic_neighbors.size();
1061 active_periodic_neighbors[m]);
1062 for (
auto &particle : pic)
1064 auto particle_properties = particle.get_properties();
1065 const double r_particle =
1066 particle_properties[PropertiesIndex::dp] * 0.5;
1075 unsigned int neighbor_dir = 0;
1076 Tensor<1, dim> neighbor_offset = Tensor<1, dim>();
1080 active_periodic_neighbors[m]->center()[d] -
1081 cell->center()[d]) > cell->diameter())
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;
1098 const double distance = particle_location.distance(
1099 quadrature_point_location[q]);
1103 const double particle_volume_ratio =
1104 (M_PI * Utilities::fixed_power<dim>(r_particle * 2.0) /
1107 [PropertiesIndex::volumetric_contribution];
1110 particles_volume_in_kernel +=
1111 particle_volume_ratio *
1116 if (particles_volume_in_kernel > 1.001)
1118 std::cout <<
"WARNING: particles_volume_in_kernel = "
1119 << particles_volume_in_kernel <<
" at cell "
1120 << cell->center() << std::endl;
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);
1133 for (
unsigned int k = 0; k < dofs_per_cell; ++k)
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);
1139 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
1143 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
1145 local_matrix_void_fraction(i, j) +=
1146 ((phi_vf[j] * phi_vf[i]) +
1149 fe_values_void_fraction.JxW(q);
1152 local_rhs_void_fraction(i) += phi_vf[i] *
1153 quadrature_void_fraction *
1154 fe_values_void_fraction.JxW(q);
1158 cell->get_dof_indices(local_dof_indices);
1160 local_matrix_void_fraction,
1161 local_rhs_void_fraction,
1173template <
int dim,
typename PropertiesIndex>
1175template <
int n_components,
int property_start_index>
1194 "Unhandled QCMFilterType in calculate_field_projection dispatcher."));
1199template <
int dim,
typename PropertiesIndex>
1203 int property_start_index>
1208 AssertThrow(n_components == 1 || n_components == dim,
1210 "QCM projection of a field only supports 1 or dim components"));
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."));
1219 FEValues<dim> fe_values_field(*
mapping,
1222 update_values | update_quadrature_points |
1223 update_JxW_values | update_gradients);
1226 FEValuesExtractors::Vector vector_extractor;
1227 vector_extractor.first_vector_component = 0;
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);
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);
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;
1255 bool calculate_filter_length_from_cell =
true;
1256 if (qcm_smoothing_length > 1e-16)
1258 filter_length = 0.5 * qcm_smoothing_length;
1259 calculate_filter_length_from_cell =
false;
1270 for (
const auto &cell : field_qcm.
dof_handler->active_cell_iterators())
1272 if (cell->is_locally_owned())
1274 fe_values_field.reinit(cell);
1280 std::vector<Point<dim>> quadrature_point_location;
1282 quadrature_point_location = fe_values_field.get_quadrature_points();
1285 auto active_neighbors =
1289 auto active_periodic_neighbors =
1294 if (calculate_filter_length_from_cell)
1300 for (
unsigned int q = 0; q < n_q_points; ++q)
1302 total_volume_of_particles_in_sphere = 0;
1303 particle_field_in_sphere = 0;
1305 for (
unsigned int m = 0; m < active_neighbors.size(); m++)
1311 for (
auto &particle : pic)
1313 double distance = 0;
1314 auto particle_properties = particle.get_properties();
1315 const double r_particle =
1316 particle_properties[PropertiesIndex::dp] * 0.5;
1320 distance = particle.get_location().distance(
1321 quadrature_point_location[q]);
1323 const double particle_volume_in_sphere =
1328 total_volume_of_particles_in_sphere +=
1329 particle_volume_in_sphere;
1338 const double volumetric_contribution =
1340 particle_volume_in_sphere /
1341 (particle_properties
1342 [PropertiesIndex::volumetric_contribution]) :
1343 particle_volume_in_sphere;
1345 if constexpr (n_components == 1)
1346 particle_field_in_sphere +=
1347 volumetric_contribution *
1348 particle_properties[property_start_index];
1351 for (
int d = 0; d < n_components; ++d)
1353 particle_field_in_sphere[d] +=
1354 volumetric_contribution *
1355 particle_properties[property_start_index + d];
1367 for (
unsigned int m = 0; m < active_periodic_neighbors.size();
1372 active_periodic_neighbors[m]);
1373 for (
auto &particle : pic)
1375 double distance = 0;
1376 auto particle_properties = particle.get_properties();
1377 const double r_particle =
1378 particle_properties[PropertiesIndex::dp] * 0.5;
1387 unsigned int neighbor_dir = 0;
1388 Tensor<1, dim> neighbor_offset = Tensor<1, dim>();
1392 active_periodic_neighbors[m]->center()[d] -
1393 cell->center()[d]) > cell->diameter())
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;
1410 distance = particle_location.distance(
1411 quadrature_point_location[q]);
1413 const double particle_volume_in_sphere =
1418 total_volume_of_particles_in_sphere +=
1419 particle_volume_in_sphere;
1430 const double volumetric_contribution =
1432 particle_volume_in_sphere /
1433 (particle_properties
1434 [PropertiesIndex::volumetric_contribution]) :
1435 particle_volume_in_sphere;
1438 if constexpr (n_components == 1)
1439 particle_field_in_sphere +=
1440 volumetric_contribution *
1441 particle_properties[property_start_index];
1444 for (
int d = 0; d < n_components; ++d)
1446 particle_field_in_sphere[d] +=
1447 volumetric_contribution *
1448 particle_properties[property_start_index + d];
1454 for (
unsigned int k = 0; k < dofs_per_cell; ++k)
1456 if constexpr (n_components == dim)
1458 phi_vf[k] = fe_values_field[vector_extractor].value(k, q);
1460 fe_values_field[vector_extractor].gradient(k, q);
1462 if constexpr (n_components == 1)
1464 phi_vf[k] = fe_values_field.shape_value(k, q);
1465 grad_phi_vf[k] = fe_values_field.shape_grad(k, q);
1475 particle_field_in_sphere = particle_field_in_sphere /
1476 total_volume_of_particles_in_sphere;
1478 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
1491 const unsigned int component_i =
1492 field_qcm.
fe->system_to_component_index(i).first;
1494 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
1496 const unsigned int component_j =
1497 field_qcm.
fe->system_to_component_index(j).first;
1498 if (component_i == component_j)
1503 total_volume_of_particles_in_sphere > 0)
1505 local_matrix(i, j) +=
1506 (phi_vf[j] * phi_vf[i]) *
1507 fe_values_field.JxW(q);
1509 local_matrix(i, j) +=
1511 scalar_product(grad_phi_vf[j],
1513 fe_values_field.JxW(q);
1518 if (total_volume_of_particles_in_sphere > 0)
1528 local_rhs(i) += phi_vf[i] * particle_field_in_sphere;
1536 local_rhs(i) += phi_vf[i] * particle_field_in_sphere *
1537 fe_values_field.JxW(q);
1542 cell->get_dof_indices(local_dof_indices);
1553 field_qcm.
system_rhs.compress(VectorOperation::add);
1558 const double rescale_metric =
1564 const double non_rescaled_linear_solver_tolerance =
1566 const double linear_solver_tolerance =
1567 non_rescaled_linear_solver_tolerance / rescale_metric;
1571 this->
pcout <<
" -Tolerance of iterative solver is : "
1572 << linear_solver_tolerance << std::endl;
1580 non_rescaled_linear_solver_tolerance,
1581 print_linear_solver_log,
1582 print_linear_solver_log);
1584 SolverCG<LinearAlgebra::distributed::Vector<double>> solver(solver_control);
1593 TrilinosWrappers::PreconditionILU::AdditionalData preconditionerOptions(
1594 ilu_fill, ilu_atol, ilu_rtol, 0);
1601 std::make_shared<TrilinosWrappers::PreconditionILU>();
1604 preconditionerOptions);
1632 this->
pcout <<
" -Iterative solver took : "
1633 << solver_control.last_step() / rescale_metric <<
" steps "
1646template <
int dim,
typename PropertiesIndex>
1647template <
typename VectorType>
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,
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."));
1693 std::vector<std::shared_ptr<ParticleFluidAssemblerBase<dim, PropertiesIndex>>>
1694 particle_fluid_assemblers;
1702 particle_fluid_assemblers.push_back(
1704 cfd_dem_parameters));
1710 particle_fluid_assemblers.push_back(
1712 cfd_dem_parameters));
1718 particle_fluid_assemblers.push_back(
1720 cfd_dem_parameters));
1726 particle_fluid_assemblers.push_back(
1728 cfd_dem_parameters));
1733 particle_fluid_assemblers.push_back(
1735 cfd_dem_parameters));
1740 particle_fluid_assemblers.push_back(
1742 cfd_dem_parameters));
1748 particle_fluid_assemblers.push_back(
1753 particle_fluid_assemblers.push_back(
1758 particle_fluid_assemblers.push_back(
1763 particle_fluid_assemblers.push_back(
1768 particle_fluid_assemblers.push_back(
1774 particle_fluid_assemblers.push_back(
1776 cfd_dem_parameters));
1780 particle_fluid_assemblers.push_back(
1782 cfd_dem_parameters));
1790 for (
const auto &cell : fluid_dof_handler.active_cell_iterators())
1792 if (cell->is_locally_owned())
1797 typename DoFHandler<dim>::active_cell_iterator void_fraction_cell(
1801 &(*this->dof_handler));
1818 if constexpr (std::is_same_v<
1820 LinearAlgebra::distributed::Vector<double>>)
1823 .template reinit_particle_fluid_interactions<PropertiesIndex>(
1826 present_velocity_pressure_solution,
1827 previous_velocity_pressure_solution[0],
1836 .template reinit_particle_fluid_interactions<PropertiesIndex>(
1839 present_velocity_pressure_solution,
1840 previous_velocity_pressure_solution[0],
1849 for (
auto &pf_assembler : particle_fluid_assemblers)
1851 pf_assembler->calculate_particle_fluid_interactions(scratch_data);
1874 DoFHandler<2> &dof_handler,
1876 const std::vector<GlobalVectorType> &fluid_previous_solutions,
1877 const Tensor<1, 3> &gravity,
1884 DoFHandler<2> &dof_handler,
1886 const std::vector<GlobalVectorType> &fluid_previous_solutions,
1887 const Tensor<1, 3> &gravity,
1894 DoFHandler<3> &dof_handler,
1896 const std::vector<GlobalVectorType> &fluid_previous_solutions,
1897 const Tensor<1, 3> &gravity,
1904 DoFHandler<3> &dof_handler,
1906 const std::vector<GlobalVectorType> &fluid_previous_solutions,
1907 const Tensor<1, 3> &gravity,
1910#ifndef LETHE_USE_LDV
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,
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,
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,
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,
1956template <
int dim,
typename PropertiesIndex>
1963 const double rescale_metric =
1969 const double minimum_absolute_residual =
1975 const double current_residual =
1978 const double linear_solver_tolerance =
1979 std::max(minimum_absolute_residual, relative_residual * current_residual);
1983 this->
pcout <<
" -Tolerance of iterative solver is : "
1984 << linear_solver_tolerance << std::endl;
1987 const double non_rescaled_linear_solver_tolerance =
1988 linear_solver_tolerance * rescale_metric;
2000 non_rescaled_linear_solver_tolerance,
2001 print_linear_solver_log,
2002 print_linear_solver_log);
2004 TrilinosWrappers::SolverCG solver(solver_control);
2013 TrilinosWrappers::PreconditionILU::AdditionalData preconditionerOptions(
2014 ilu_fill, ilu_atol, ilu_rtol, 0);
2019 preconditionerOptions);
2022 completely_distributed_solution,
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;
2036#ifndef LETHE_USE_LDV
2047template <
int dim,
typename PropertiesIndex>
2050 const std::string &folder,
2051 const std::string &prefix,
2052 const unsigned int group_files)
2056 const double qcm_smoothing_length =
2061 return (qcm_smoothing_length > 1e-16) ?
2062 0.5 * qcm_smoothing_length :
unsigned int maximum_number_of_previous_solutions()
Get the maximum number of previous time steps supposed by the BDF schemes implemented in Lethe.
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 ¤t_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....
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.
bool multigrid_level_dofs_required
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.
bool matrix_requires_assembly
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).
bool particle_have_been_projected
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
bool multigrid_level_dofs_required
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
const ConditionalOStream pcout
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...
constexpr bool has_thermal_properties
Whether a properties index set carries thermal properties.
@ 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
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.
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.