Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
update_local_particle_containers.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020, 2022-2025 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
6
7#include <deal.II/particles/particle_handler.h>
8
9using namespace dealii;
10
11template <int dim>
12void
15 &particle_container,
16 const Particles::ParticleHandler<dim> *particle_handler)
17{
18 // Clear the current particle container
19 particle_container.clear();
20
21 // Update the local particle container with local particles
22 for (auto particle_iterator = particle_handler->begin();
23 particle_iterator != particle_handler->end();
24 ++particle_iterator)
25 {
26 particle_container.emplace(particle_iterator->get_id(),
27 particle_iterator);
28 }
29
30 // Update the local particle container with ghost particles
31 for (auto particle_iterator = particle_handler->begin_ghost();
32 particle_iterator != particle_handler->end_ghost();
33 ++particle_iterator)
34 {
35 particle_container.emplace(particle_iterator->get_id(),
36 particle_iterator);
37 }
38}
39
40template <int dim, typename pairs_structure, ContactType contact_type>
41void
43 pairs_structure &pairs_in_contact,
45 &particle_container)
46{
47 // Get trigger for clearing contact structures
48 auto *action_manager = DEMActionManager::get_action_manager();
49 const bool clear_tangential_displacement =
50 action_manager->check_clear_tangential_displacement();
51
52 // Loop over particle-object (particle/wall/line/point) pairs in contact
53 for (auto pairs_in_contact_iterator = pairs_in_contact.begin();
54 pairs_in_contact_iterator != pairs_in_contact.end();)
55 {
56 // Get the adjacent objects content
57 auto adjacent_pairs_content = &pairs_in_contact_iterator->second;
58
59 if constexpr (contact_type == ContactType::local_particle_particle ||
61 contact_type ==
63 contact_type ==
65 contact_type ==
67 contact_type == ContactType::particle_wall ||
69 {
70 // Get current particle id
71 unsigned int particle_id = pairs_in_contact_iterator->first;
72
73 // Find if particle one is still on this process
74 auto particle_one_container = particle_container.find(particle_id);
75
76 // Particle one is not on this process anymore, remove the container
77 // and move on
78 if (particle_one_container == particle_container.end())
79 {
80 pairs_in_contact_iterator =
81 pairs_in_contact.erase(pairs_in_contact_iterator);
82 continue;
83 }
84
85 // For particle-particle contacts, the iterator to particle one is
86 // shared by all its contact candidates (potential contacts)
87 // and stored once in the adjacency value,
88 // while its map of contacts is held in second_particles. For the
89 // other contact types, adjacent_pairs_content is directly the map of
90 // objects in contact. Select the map to loop over accordingly.
91 auto &second_objects = [&]() -> auto & {
92 if constexpr (contact_type ==
94 contact_type ==
96 contact_type ==
98 contact_type ==
100 contact_type ==
102 return adjacent_pairs_content->second_particles;
103 else
104 return *adjacent_pairs_content;
105 }();
106
107 // Update the shared iterator to particle one once for the whole list
108 if constexpr (contact_type == ContactType::local_particle_particle ||
109 contact_type == ContactType::ghost_particle_particle ||
110 contact_type ==
112 contact_type ==
114 contact_type ==
116 {
117 adjacent_pairs_content->particle_one =
118 particle_one_container->second;
119 }
120
121 // Loop over all the other objects of contact_type in contact
122 for (auto adjacent_map_iterator = second_objects.begin();
123 adjacent_map_iterator != second_objects.end();)
124 {
125 if constexpr (contact_type ==
127 contact_type ==
129 contact_type ==
131 contact_type ==
133 contact_type ==
134 ContactType::
135 ghost_local_periodic_particle_particle)
136 {
137 unsigned int particle_two_id = adjacent_map_iterator->first;
138
139 // Find if particle two is still on this process
140 auto particle_two_container =
141 particle_container.find(particle_two_id);
142
143 // Particle two is not on this process anymore, remove the
144 // container and move on
145 if (particle_two_container == particle_container.end())
146 {
147 adjacent_map_iterator =
148 second_objects.erase(adjacent_map_iterator);
149 continue;
150 }
151
152 // Both particles are still on this process, update the
153 // iterator to particle two
154 adjacent_map_iterator->second.particle_two =
155 particle_two_container->second;
156
157 if (clear_tangential_displacement)
158 {
159 adjacent_map_iterator->second.tangential_displacement
160 .clear();
161 adjacent_map_iterator->second
162 .rolling_resistance_spring_torque.clear();
163 }
164 ++adjacent_map_iterator;
165 }
166
167 if constexpr (contact_type == ContactType::particle_wall ||
169 {
170 // Particle iterator is updated
171 adjacent_map_iterator->second.particle =
172 particle_container.at(particle_id);
173 ++adjacent_map_iterator;
174 }
175 }
176 }
177
178 if constexpr (contact_type == ContactType::particle_floating_mesh)
179 {
180 for (auto adjacent_map_iterator = adjacent_pairs_content->begin();
181 adjacent_map_iterator != adjacent_pairs_content->end();
182 ++adjacent_map_iterator)
183 {
184 // Get the particle in contact with the solid of the floating mesh
185 unsigned int particle_id = adjacent_map_iterator->first;
186
187 // Update the particle of the contact
188 adjacent_map_iterator->second.particle =
189 particle_container.at(particle_id);
190
191 // Note : particle_triangle_cell_from_mesh_potentially_in_contact
192 // is stored as <cell iterator, <particle id, particle-wall info>>
193 // and particle_wall_in_contact as is stored as <particle id,
194 // <face id, particle-wall info>>, which restrains to use the same
195 // iterator loop logic
196 }
197 }
198
199 if constexpr (contact_type == ContactType::particle_line ||
200 contact_type == ContactType::particle_point)
201 {
202 // Get current particle id
203 unsigned int particle_id = pairs_in_contact_iterator->first;
204
205 // Find if particle one is still a particle on this process
206 auto particle_one_container = particle_container.find(particle_id);
207
208 // Particle one is not on this process anymore, remove the container
209 // and move on
210 if (particle_one_container == particle_container.end())
211 {
212 pairs_in_contact_iterator =
213 pairs_in_contact.erase(pairs_in_contact_iterator);
214 continue;
215 }
216
217 // Get current particle id and particle iterator is updated
218 adjacent_pairs_content->particle = particle_container.at(particle_id);
219 }
220
221 ++pairs_in_contact_iterator;
222 }
223}
224
225// Particle container
226template void
229 const Particles::ParticleHandler<2> *particle_handler);
230
231template void
234 const Particles::ParticleHandler<3> *particle_handler);
235
236// Local particle-particle contact container
237template void
239 2,
244 &particle_container);
245
246template void
248 3,
253 &particle_container);
254
255// Ghost particle-particle contact container
256template void
258 2,
263 &particle_container);
264
265template void
267 3,
272 &particle_container);
273
274// Local-local particle-particle periodic contact container
275template void
277 2,
281 &pairs_in_contact,
283 &particle_container);
284
285template void
287 3,
291 &pairs_in_contact,
293 &particle_container);
294
295// Local-ghost particle-particle periodic contact container
296template void
298 2,
302 &pairs_in_contact,
304 &particle_container);
305
306template void
308 3,
312 &pairs_in_contact,
314 &particle_container);
315
316// Ghost-local particle-particle periodic contact container
317template void
319 2,
323 &pairs_in_contact,
325 &particle_container);
326
327template void
329 3,
333 &pairs_in_contact,
335 &particle_container);
336
337// Particle-wall contact container
338template void
340 2,
345 &particle_container);
346
347template void
349 3,
354 &particle_container);
355
356// Particle-floating wall contact container
357template void
359 2,
364 &particle_container);
365
366template void
368 3,
373 &particle_container);
374
375// Particle-floating mesh contact container
376template void
378 2,
380 2>::particle_triangle_cell_from_mesh_potentially_in_contact,
383 particle_triangle_cell_from_mesh_potentially_in_contact &pairs_in_contact,
385 &particle_container);
386
387template void
389 3,
391 3>::particle_triangle_cell_from_mesh_potentially_in_contact,
394 particle_triangle_cell_from_mesh_potentially_in_contact &pairs_in_contact,
396 &particle_container);
397
398// Particle-point contact container
399template void
401 2,
406 &particle_container);
407
408template void
410 3,
415 &particle_container);
416
417// Particle-line contact container
418template void
420 2,
425 &particle_container);
426
427template void
429 3,
434 &particle_container);
static DEMActionManager * get_action_manager()
Getter of the unique instance of the DEMActionManager.
@ ghost_periodic_particle_particle
@ ghost_particle_particle
@ particle_floating_mesh
@ local_particle_particle
@ ghost_local_periodic_particle_particle
@ particle_line
@ particle_floating_wall
@ local_periodic_particle_particle
@ particle_wall
@ particle_point
DEM data structure containers To improve readability of containers, there's a simple description abov...
ankerl::unordered_dense::map< types::particle_index, ankerl::unordered_dense::map< global_face_id, particle_wall_contact_info< dim > > > particle_wall_in_contact
ankerl::unordered_dense::map< types::particle_index, Particles::ParticleIterator< dim > > particle_index_iterator_map
ankerl::unordered_dense::map< types::particle_index, periodic_adjacent_particle_pairs_value > periodic_adjacent_particle_pairs
std::unordered_map< types::particle_index, particle_line_contact_info< dim > > particle_line_in_contact
ankerl::unordered_dense::map< types::particle_index, adjacent_particle_pairs_value > adjacent_particle_pairs
std::unordered_map< types::particle_index, particle_point_contact_info< dim > > particle_point_in_contact
void update_contact_container_iterators(pairs_structure &pairs_in_contact, const typename DEM::dem_data_structures< dim >::particle_index_iterator_map &particle_container)
Update the iterators to particles in pairs_in_contact (output of particle-object fine search).
void update_particle_container(typename DEM::dem_data_structures< dim >::particle_index_iterator_map &particle_container, const Particles::ParticleHandler< dim > *particle_handler)
Update the iterators to local particles in a map of particles (particle_container).
void update_contact_container_iterators(pairs_structure &pairs_in_contact, const typename DEM::dem_data_structures< dim >::particle_index_iterator_map &particle_container)
Update the iterators to particles in pairs_in_contact (output of particle-object fine search).