Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
update_fine_search_candidates.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
7using namespace dealii;
8
9template <int dim,
10 typename pairs_structure,
11 typename candidates_structure,
12 ContactType contact_type>
13void
14update_fine_search_candidates(pairs_structure &pairs_in_contact,
15 candidates_structure &contact_candidates)
16{
17 for (auto pairs_in_contact_iterator = pairs_in_contact.begin();
18 pairs_in_contact_iterator != pairs_in_contact.end();)
19 {
20 // Get the current particle id from fine search history
21 auto particle_id = pairs_in_contact_iterator->first;
22
23 // Get the reference to all the object (particle/wall/face) contact
24 // candidates of the current particle from the new broad search
25 auto contact_candidate_element = contact_candidates.find(particle_id);
26
27 // Get adjacent object (particle/wall/face) content of the current
28 // particle (from the fine search history)
29 auto adjacent_pairs_content = &pairs_in_contact_iterator->second;
30
31 // For particle-particle contacts, the map of objects in contact is held
32 // in second_particles (the iterator to particle one is stored alongside
33 // it in the adjacency value). For the other contact types,
34 // adjacent_pairs_content is directly the map of objects in contact.
35 // Select the map to loop over accordingly.
36 auto &second_objects = [&]() -> auto & {
37 if constexpr (contact_type == ContactType::local_particle_particle ||
39 contact_type ==
41 contact_type ==
43 contact_type ==
45 return adjacent_pairs_content->second_particles;
46 else
47 return *adjacent_pairs_content;
48 }();
49
50 // Loop over all the adjacent objects
51 for (auto adjacent_map_iterator = second_objects.begin();
52 adjacent_map_iterator != second_objects.end();)
53 {
54 // Get the object (2nd particle/wall/face) id in the history list
55 auto object_id = adjacent_map_iterator->first;
56
57 // The handling of the update of the fine search candidate list is
58 // different when the contact is particle-particle compared to
59 // particle-wall
60 if constexpr (contact_type == ContactType::local_particle_particle ||
62 contact_type ==
64 contact_type ==
66 contact_type ==
68 {
69 if (contact_candidate_element != contact_candidates.end())
70 {
71 // Check if the adjacent particle from history is a particle
72 // candidate of the current particle and get the iterator to
73 // that object if so
74 auto search_iterator =
75 std::find(contact_candidate_element->second.begin(),
76 contact_candidate_element->second.end(),
77 object_id);
78
79 // Particle-particle pairs are removed from the list of the
80 // new broad search candidates or from the list of the history
81 // of the fine search candidate list depending on the last
82 // checks
83 if (search_iterator !=
84 contact_candidate_element->second.end())
85 {
86 // The current 2nd is a candidate to the current particle.
87 // The 2nd particle is then removed from the new broad
88 // search particle-particle contact candidates list but
89 // kept as history in the fine search list
90 contact_candidate_element->second.erase(search_iterator);
91
92 ++adjacent_map_iterator;
93
94 // To prevent searching through the contact_candidates a
95 // second time if there is a deletion in the first search,
96 // we continue here instead of using an if, else if or
97 // else statement
98 continue;
99 }
100 }
101
102 // Get the reference to all the 2nd particle contact
103 // candidates of the current particle from the new broad search
104 auto object_contact_candidates =
105 contact_candidates.find(object_id);
106
107 if (object_contact_candidates != contact_candidates.end())
108 {
109 // Check if the current particle is a particle candidate
110 // of the adjacent particle in history
111 auto search_object_to_particle_iterator =
112 std::find(object_contact_candidates->second.begin(),
113 object_contact_candidates->second.end(),
114 particle_id);
115
116 if (search_object_to_particle_iterator !=
117 object_contact_candidates->second.end())
118 {
119 if constexpr (contact_type ==
121 contact_type ==
122 ContactType::
123 local_periodic_particle_particle)
124 {
125 // The current particle from history list is still a
126 // candidate to the 2nd particle and the contact is
127 // local The 2nd particle is then removed from the new
128 // broad search particle-particle contact candidates
129 // list but kept as history in the fine search list
130 object_contact_candidates->second.erase(
131 search_object_to_particle_iterator);
132 ++adjacent_map_iterator;
133 continue;
134 }
135
136 if constexpr (
137 contact_type == ContactType::ghost_particle_particle ||
138 contact_type ==
140 contact_type ==
142 {
143 // The current particle from history list is still a
144 // candidate to the 2nd particle and the contact is
145 // not local The 2nd particle is then removed from the
146 // history in the fine search list particle-particle
147 // contact candidates list but kept in new broad
148 // search list
149 adjacent_map_iterator =
150 second_objects.erase(adjacent_map_iterator);
151 continue;
152 }
153 }
154 }
155
156 // Current particles are no longer contact candidates.
157 // The particle is then removed as a candidate for fine
158 // search contact candidates list
159 adjacent_map_iterator =
160 second_objects.erase(adjacent_map_iterator);
161 }
162
163 if constexpr (contact_type == ContactType::particle_wall ||
164 contact_type == ContactType::particle_floating_wall ||
166 {
167 if (contact_candidate_element != contact_candidates.end())
168 {
169 // Check if the wall/face is a candidate of the current
170 // particle and get the iterator to that object if so
171 auto search_iterator =
172 contact_candidate_element->second.find(object_id);
173
174 // Particle-wall/face pair is removed from the list of the new
175 // broad search candidates or from the list of the history of
176 // the fine search candidate list depending on the last check
177 if (search_iterator !=
178 contact_candidate_element->second.end())
179 {
180 // Current wall/face (from new broad search) is a
181 // candidate to the current particle. The wall/face is
182 // then removed from the new broad search
183 // particle-wall/face contact candidates list but kept as
184 // history in the fine search list
185 contact_candidate_element->second.erase(search_iterator);
186 ++adjacent_map_iterator;
187 continue;
188 }
189 }
190
191 // Current wall/face (from new broad search) is no longer a
192 // candidate to the current particle. The wall/face is then
193 // removed as a candidate for fine search contact candidates
194 // list
195 adjacent_map_iterator =
196 second_objects.erase(adjacent_map_iterator);
197 }
198 }
199
200 // If there are still particle/wall/face in the adjacent_pairs_content
201 // then the pairs_in_contact_iterator remains in memory
202 if (second_objects.size() > 0)
203 ++pairs_in_contact_iterator;
204
205 // Otherwise it is deleted. This is necessary to prevent memory inflation.
206 // If this is not done, pairs_in_contact keeps on growing until it reaches
207 // the total number of particles in the simulation.
208 else
209 pairs_in_contact_iterator =
210 pairs_in_contact.erase(pairs_in_contact_iterator);
211 }
212}
213
214// Local particle-particle contacts
215template void
217 2,
223 &contact_pair_candidates);
224
225template void
227 3,
233 &contact_candidates);
234
235// Ghost particle-particle contacts
236template void
238 2,
244 &contact_pair_candidates);
245
246template void
248 3,
254 &contact_candidates);
255
256// Local periodic particle-particle contacts
257template void
259 2,
264 &adjacent_particles,
266 &contact_pair_candidates);
267
268template void
270 3,
275 &pairs_in_contact,
277 &contact_candidates);
278
279// Local-ghost particle-particle contacts
280template void
282 2,
287 &adjacent_particles,
289 &contact_pair_candidates);
290
291template void
293 3,
298 &pairs_in_contact,
300 &contact_candidates);
301
302// Ghost-local particle-particle contacts
303template void
305 2,
310 &adjacent_particles,
312 &contact_pair_candidates);
313
314template void
316 3,
321 &pairs_in_contact,
323 &contact_candidates);
324
325// Particle-wall contacts
326template void
328 2,
334 &contact_pair_candidates);
335
336template void
338 3,
344 &contact_pair_candidates);
345
346// Particle-floating wall contacts
347template void
349 2,
355 &contact_pair_candidates);
356
357template void
359 3,
365 &contact_pair_candidates);
366
367// Particle-floating mesh contacts
368template void
370 2,
372 2>::particle_triangle_cell_from_mesh_potentially_in_contact,
376 particle_triangle_cell_from_mesh_potentially_in_contact &adjacent_particles,
378 &contact_pair_candidates);
379
380template void
382 3,
384 3>::particle_triangle_cell_from_mesh_potentially_in_contact,
388 particle_triangle_cell_from_mesh_potentially_in_contact &adjacent_particles,
390 &contact_pair_candidates);
ContactType
Label for particle-object contact type.
@ ghost_periodic_particle_particle
@ ghost_particle_particle
@ particle_floating_mesh
@ local_particle_particle
@ ghost_local_periodic_particle_particle
@ particle_floating_wall
@ local_periodic_particle_particle
@ particle_wall
DEM data structure containers To improve readability of containers, there's a simple description abov...
std::map< typename Triangulation< dim - 1, dim >::active_cell_iterator, ankerl::unordered_dense::map< types::particle_index, Particles::ParticleIterator< dim > >, cut_cell_comparison< dim > > particle_floating_wall_from_mesh_candidates
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, std::unordered_map< global_face_id, Particles::ParticleIterator< dim > > > particle_floating_wall_candidates
ankerl::unordered_dense::map< types::particle_index, periodic_adjacent_particle_pairs_value > periodic_adjacent_particle_pairs
ankerl::unordered_dense::map< types::particle_index, std::vector< types::particle_index > > particle_particle_candidates
ankerl::unordered_dense::map< types::particle_index, ankerl::unordered_dense::map< global_face_id, std::tuple< Particles::ParticleIterator< dim >, Tensor< 1, dim >, Point< dim >, global_face_id > > > particle_wall_candidates
ankerl::unordered_dense::map< types::particle_index, adjacent_particle_pairs_value > adjacent_particle_pairs
void update_fine_search_candidates(pairs_structure &pairs_in_contact, candidates_structure &contact_candidates)
Manage removing repetitions and adding new contact pairs to the contact containers when particles are...
void update_fine_search_candidates(pairs_structure &pairs_in_contact, candidates_structure &contact_candidates)
Manage removing repetitions and adding new contact pairs to the contact containers when particles are...