8#include <deal.II/base/quadrature_lib.h>
10#include <deal.II/distributed/tria.h>
12#include <deal.II/fe/fe_q.h>
13#include <deal.II/fe/fe_values.h>
18#include <unordered_map>
41 std::array<bool, dim> direction_is_used{};
44 AssertThrow(std::cmp_less(boundary.direction, dim),
46 "PeriodicBoundariesManipulator: periodic direction " +
47 std::to_string(boundary.direction) +
48 " configured for boundary id " + std::to_string(
id) +
49 " is out of range for a " + std::to_string(dim) +
52 !direction_is_used[boundary.direction],
54 "PeriodicBoundariesManipulator: more than one periodic boundary "
55 "pair is configured for direction " +
56 std::to_string(boundary.direction) +
57 ". At most one periodic boundary pair per direction is "
59 direction_is_used[boundary.direction] =
true;
76 typename Triangulation<dim>::cell_iterator cell,
77 const unsigned int face_id,
82 const FE_Q<dim> fe(1);
83 QGauss<dim - 1> face_quadrature_formula(1);
84 FEFaceValues<dim> fe_face_values(fe,
85 face_quadrature_formula,
86 update_values | update_quadrature_points |
87 update_normal_vectors);
88 Tensor<1, dim> normal_vector;
89 Point<dim> quad_point;
92 boundaries_information.
cell = cell;
93 boundaries_information.
boundary_id = cell->face(face_id)->boundary_id();
96 boundaries_information.
periodic_cell = cell->periodic_neighbor(face_id);
99 fe_face_values.reinit(cell, face_id);
100 boundaries_information.
normal_vector = fe_face_values.normal_vector(0);
101 boundaries_information.
point_on_face = fe_face_values.quadrature_point(0);
106 cell->periodic_neighbor_face_no(face_id));
107 normal_vector = fe_face_values.normal_vector(0);
108 quad_point = fe_face_values.quadrature_point(0);
116 const parallel::distributed::Triangulation<dim> &triangulation,
118 &periodic_boundaries_cells_information)
123 periodic_boundaries_cells_information.clear();
127 std::map<types::boundary_id, bool> offset_calculated;
129 offset_calculated[primary_mesh_id] =
false;
132 for (
const auto &cell : triangulation.active_cell_iterators())
134 if (cell->is_locally_owned() || cell->is_ghost())
136 if (cell->at_boundary())
139 for (
const auto &face : cell->face_iterators())
141 const types::boundary_id face_boundary_id =
149 const unsigned int current_direction =
150 it->second.direction;
153 boundaries_information;
154 unsigned int face_id = cell->face_iterator_to_index(face);
158 boundaries_information);
162 periodic_boundaries_cells_information.insert(
163 {boundaries_information.
cell
164 ->global_active_cell_index(),
165 boundaries_information});
169 if (!offset_calculated[face_boundary_id])
171 Tensor<1, dim> offset;
172 offset[current_direction] =
173 boundaries_information
175 boundaries_information
179 offset_calculated[face_boundary_id] =
true;
196 const bool &particles_in_pb0_cell,
197 typename Particles::ParticleHandler<dim>::particle_iterator_range
199 bool &particle_has_been_moved)
209 Tensor<1, dim> relevant_offset;
216 relevant_offset = offset_it->second;
224 "PeriodicBoundariesManipulator: no periodic offset found "
226 std::to_string(boundaries_cells_content.
boundary_id) +
227 ". This means map_periodic_cells() did not populate "
228 "periodic_offsets for this boundary."));
231 for (
auto particle = particles_in_cell.begin();
232 particle != particles_in_cell.end();
236 Point<dim> particle_position = particle->get_location();
240 Point<dim> point_on_face;
241 Tensor<1, dim> normal_vector, distance_between_faces;
243 if (particles_in_pb0_cell)
247 distance_between_faces = relevant_offset;
253 distance_between_faces = -relevant_offset;
258 double distance_with_face =
259 scalar_product(particle_position - point_on_face, normal_vector);
264 if (distance_with_face >= 0.0)
267 particle_position += distance_between_faces;
268 particle->set_location(particle_position);
271 particle_has_been_moved =
true;
280 std::array<double, dim> offset_per_direction{};
292 for (
int d = 0; d < dim; ++d)
293 offset_per_direction[d] += offset[d];
301 const Particles::ParticleHandler<dim> &particle_handler,
303 &periodic_boundaries_cells_information)
308 bool particle_has_been_moved =
false;
310 if (!periodic_boundaries_cells_information.empty())
315 for (
auto boundaries_cells_information_iterator =
316 periodic_boundaries_cells_information.begin();
317 boundaries_cells_information_iterator !=
318 periodic_boundaries_cells_information.end();
319 ++boundaries_cells_information_iterator)
322 auto boundaries_cells_content =
323 boundaries_cells_information_iterator->second;
324 auto cell = boundaries_cells_content.cell;
325 auto periodic_cell = boundaries_cells_content.periodic_cell;
330 if (cell->is_locally_owned())
332 typename Particles::ParticleHandler<dim>::particle_iterator_range
333 particles_in_cell = particle_handler.particles_in_cell(cell);
334 const bool particles_exist_in_main_cell =
335 !particles_in_cell.empty();
337 if (particles_exist_in_main_cell)
339 bool particles_in_pb0_cell =
true;
341 particles_in_pb0_cell,
343 particle_has_been_moved);
348 if (periodic_cell->is_locally_owned())
350 typename Particles::ParticleHandler<dim>::particle_iterator_range
351 particles_in_periodic_cell =
352 particle_handler.particles_in_cell(periodic_cell);
353 const bool particles_exist_in_periodic_cell =
354 !particles_in_periodic_cell.empty();
356 if (particles_exist_in_periodic_cell)
358 bool particles_in_pb0_cell =
false;
360 particles_in_pb0_cell,
361 particles_in_periodic_cell,
362 particle_has_been_moved);
368 return particle_has_been_moved;
static DEMActionManager * get_action_manager()
Getter of the unique instance of the DEMActionManager.
void set_periodic_boundaries_enabled()
Flag that there are periodic boundary in the simulation.
std::array< double, dim > periodic_offset_per_direction
Signed periodic distance associated with each periodic boundary pairs. The component d of this array ...
void compute_periodic_offset_per_direction()
Compute the signed periodic offset for every direction and store it in periodic_offset_per_direction.
bool periodic_boundaries_enabled
Flag for periodic boundary conditions in simulation. Useful to exit function when there are no period...
PeriodicBoundariesManipulator()
std::unordered_map< types::boundary_id, Tensor< 1, dim > > periodic_offsets
Map storing offset distance between periodic boundaries, keyed by the boundary ID (pb0)....
Parameters::PeriodicBoundaries periodic_boundaries
Periodic boundary pairs of the simulation. Each entry carries the neighbor boundary id of the pair an...
void get_periodic_boundaries_info(typename Triangulation< dim >::cell_iterator cell, const unsigned int face_id, periodic_boundaries_cells_info_struct< dim > &boundaries_information)
Get boundary information related to a face at a periodic boundary and store it in a periodic_boundari...
void map_periodic_cells(const parallel::distributed::Triangulation< dim > &triangulation, typename DEM::dem_data_structures< dim >::periodic_boundaries_cells_info &periodic_boundaries_cells_information)
Execute the mapping of the cells on periodic boundaries and store information in periodic_boundaries_...
void set_periodic_boundaries_information(const Parameters::PeriodicBoundaries &periodic_boundaries)
Sets the periodic boundaries parameters.
void check_and_move_particles(const periodic_boundaries_cells_info_struct< dim > &boundaries_cells_content, const bool &particles_in_pb0_cell, typename Particles::ParticleHandler< dim >::particle_iterator_range &particles_in_cell, bool &particle_has_been_moved)
Check if particle is outside the cell, if so, modify the location of the particle using the relevant ...
bool execute_particles_displacement(const Particles::ParticleHandler< dim > &particle_handler, const typename DEM::dem_data_structures< dim >::periodic_boundaries_cells_info &periodic_boundaries_cells_information)
Moves particles crossing periodic boundaries (any side) particle_handler doesn't allow automated part...
std::map< dealii::types::boundary_id, PeriodicBoundary > PeriodicBoundaries
The periodic boundary pairs of a simulation, keyed by the principal (first) boundary id of each pair.
std::unordered_multimap< types::global_cell_index, periodic_boundaries_cells_info_struct< dim > > periodic_boundaries_cells_info
Handle the information related to the periodic boundary cells which will be used for particle-wall co...
Point< dim > point_on_periodic_face
types::boundary_id boundary_id
Triangulation< dim >::active_cell_iterator periodic_cell
Tensor< 1, dim > periodic_normal_vector
Tensor< 1, dim > normal_vector
Point< dim > point_on_face
Triangulation< dim >::active_cell_iterator cell