AutoPas  3.0.0
Loading...
Searching...
No Matches
TraversalSelector.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <memory>
10
48
49namespace autopas {
50
55 public:
67 template <class ParticleCell_T, class Functor_T>
68 static std::unique_ptr<TraversalInterface> generateTraversal(TraversalOption traversalType, Functor_T &functor,
69 const TraversalSelectorInfo &traversalInfo,
70 DataLayoutOption dataLayout, bool useNewton3);
71
83 template <class ParticleCell_T, class PairwiseFunctor_T>
84 static std::unique_ptr<TraversalInterface> generatePairwiseTraversal(TraversalOption traversalType,
85 PairwiseFunctor_T &pairwiseFunctor,
86 const TraversalSelectorInfo &traversalInfo,
87 DataLayoutOption dataLayout, bool useNewton3);
88
100 template <class ParticleCell_T, class TriwiseFunctor_T>
101 static std::unique_ptr<TraversalInterface> generateTriwiseTraversal(TraversalOption traversalType,
102 TriwiseFunctor_T &triwiseFunctor,
103 const TraversalSelectorInfo &traversalInfo,
104 DataLayoutOption dataLayout, bool useNewton3);
105
115 template <class Particle_T, class Functor_T>
116 static std::unique_ptr<TraversalInterface> generateTraversalFromConfig(const Configuration &config,
117 Functor_T &functor,
118 const TraversalSelectorInfo &traversalInfo);
119};
120
121template <class ParticleCell_T, class PairwiseFunctor_T>
122std::unique_ptr<TraversalInterface> TraversalSelector::generatePairwiseTraversal(
123 TraversalOption traversalType, PairwiseFunctor_T &pairwiseFunctor, const TraversalSelectorInfo &traversalInfo,
124 DataLayoutOption dataLayout, bool useNewton3) {
125 std::unique_ptr<TraversalInterface> traversal;
126 switch (traversalType) {
127 // Direct sum
128 case TraversalOption::ds_sequential: {
129 traversal = std::make_unique<DSSequentialTraversal<ParticleCell_T, PairwiseFunctor_T>>(
130 pairwiseFunctor,
131 traversalInfo
132 .interactionLength /*this is the cutoff, as generated by DirectSum::getTraversalSelectorInfo()!*/,
133 dataLayout, useNewton3);
134 break;
135 }
136 // Linked cell
137 case TraversalOption::lc_sliced: {
138 traversal = std::make_unique<LCSlicedTraversal<ParticleCell_T, PairwiseFunctor_T>>(
139 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
140 dataLayout, useNewton3);
141 break;
142 }
143 case TraversalOption::lc_sliced_c02: {
144 traversal = std::make_unique<LCSlicedC02Traversal<ParticleCell_T, PairwiseFunctor_T>>(
145 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
146 dataLayout, useNewton3);
147 break;
148 }
149 case TraversalOption::lc_sliced_balanced: {
150 traversal = std::make_unique<LCSlicedBalancedTraversal<ParticleCell_T, PairwiseFunctor_T>>(
151 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
152 dataLayout, useNewton3);
153 break;
154 }
155 case TraversalOption::lc_c01: {
156 traversal = std::make_unique<LCC01Traversal<ParticleCell_T, PairwiseFunctor_T, false>>(
157 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
158 dataLayout, useNewton3);
159 break;
160 }
161 case TraversalOption::lc_c01_combined_SoA: {
162 traversal = std::make_unique<LCC01Traversal<ParticleCell_T, PairwiseFunctor_T, true>>(
163 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
164 dataLayout, useNewton3);
165 break;
166 }
167 case TraversalOption::lc_c04_combined_SoA: {
168 traversal = std::make_unique<LCC04CombinedSoATraversal<ParticleCell_T, PairwiseFunctor_T>>(
169 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
170 dataLayout, useNewton3);
171 break;
172 }
173 case TraversalOption::lc_c04: {
174 traversal = std::make_unique<LCC04Traversal<ParticleCell_T, PairwiseFunctor_T>>(
175 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
176 dataLayout, useNewton3);
177 break;
178 }
179 case TraversalOption::lc_c04_HCP: {
180 traversal = std::make_unique<LCC04HCPTraversal<ParticleCell_T, PairwiseFunctor_T>>(
181 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
182 dataLayout, useNewton3);
183 break;
184 }
185 case TraversalOption::lc_c08: {
186 traversal = std::make_unique<LCC08Traversal<ParticleCell_T, PairwiseFunctor_T>>(
187 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
188 dataLayout, useNewton3);
189 break;
190 }
191 case TraversalOption::lc_c18: {
192 traversal = std::make_unique<LCC18Traversal<ParticleCell_T, PairwiseFunctor_T>>(
193 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
194 dataLayout, useNewton3);
195 break;
196 }
197 // Verlet
198 case TraversalOption::vl_list_iteration: {
199 traversal = std::make_unique<VLListIterationTraversal<ParticleCell_T, PairwiseFunctor_T>>(pairwiseFunctor,
200 dataLayout, useNewton3);
201 break;
202 }
203 case TraversalOption::vl_list_iteration_c27: {
204 traversal = std::make_unique<VLListIterationC27Traversal<ParticleCell_T, PairwiseFunctor_T>>(
205 pairwiseFunctor, dataLayout, useNewton3, traversalInfo.cellsPerDim);
206 break;
207 }
208 // Var Verlet Lists
209 case TraversalOption::vvl_as_built: {
210 traversal = std::make_unique<
212 pairwiseFunctor, dataLayout, useNewton3);
213 break;
214 }
215 // Verlet List Cells
216 case TraversalOption::vlc_sliced: {
217 traversal = std::make_unique<VLCSlicedTraversal<ParticleCell_T, PairwiseFunctor_T,
219 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
220 dataLayout, useNewton3, ContainerOption::verletListsCells);
221 break;
222 }
223 case TraversalOption::vlc_sliced_c02: {
224 traversal =
225 std::make_unique<VLCSlicedC02Traversal<ParticleCell_T, PairwiseFunctor_T,
227 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
228 dataLayout, useNewton3, ContainerOption::verletListsCells);
229 break;
230 }
231 case TraversalOption::vlc_sliced_balanced: {
232 traversal =
233 std::make_unique<VLCSlicedBalancedTraversal<ParticleCell_T, PairwiseFunctor_T,
235 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
236 dataLayout, useNewton3, ContainerOption::verletListsCells);
237 break;
238 }
239 case TraversalOption::vlc_c01: {
240 traversal = std::make_unique<VLCC01Traversal<ParticleCell_T, PairwiseFunctor_T,
242 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
243 dataLayout, useNewton3, ContainerOption::verletListsCells);
244 break;
245 }
246 case TraversalOption::vlc_c18: {
247 traversal = std::make_unique<VLCC18Traversal<ParticleCell_T, PairwiseFunctor_T,
249 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
250 dataLayout, useNewton3, ContainerOption::verletListsCells);
251 break;
252 }
253 case TraversalOption::vlc_c08: {
254 traversal = std::make_unique<VLCC08Traversal<ParticleCell_T, PairwiseFunctor_T,
256 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
257 dataLayout, useNewton3);
258 break;
259 }
260 // Verlet Cluster Lists
261 case TraversalOption::vcl_cluster_iteration: {
262 traversal = std::make_unique<VCLClusterIterationTraversal<ParticleCell_T, PairwiseFunctor_T>>(
263 pairwiseFunctor, traversalInfo.clusterSize, dataLayout, useNewton3);
264 break;
265 }
266 case TraversalOption::vcl_c01_balanced: {
267 traversal = std::make_unique<VCLC01BalancedTraversal<typename ParticleCell_T::ParticleType, PairwiseFunctor_T>>(
268 pairwiseFunctor, traversalInfo.clusterSize, dataLayout, useNewton3);
269 break;
270 }
271 case TraversalOption::vcl_sliced: {
272 traversal = std::make_unique<VCLSlicedTraversal<ParticleCell_T, PairwiseFunctor_T>>(
273 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
274 traversalInfo.clusterSize, dataLayout, useNewton3);
275 break;
276 }
277 case TraversalOption::vcl_sliced_c02: {
278 traversal = std::make_unique<VCLSlicedC02Traversal<ParticleCell_T, PairwiseFunctor_T>>(
279 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
280 traversalInfo.clusterSize, dataLayout, useNewton3);
281 break;
282 }
283 case TraversalOption::vcl_sliced_balanced: {
284 traversal = std::make_unique<VCLSlicedBalancedTraversal<ParticleCell_T, PairwiseFunctor_T>>(
285 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
286 traversalInfo.clusterSize, dataLayout, useNewton3);
287 break;
288 }
289 case TraversalOption::vcl_c06: {
290 traversal = std::make_unique<VCLC06Traversal<ParticleCell_T, PairwiseFunctor_T>>(
291 pairwiseFunctor, traversalInfo.clusterSize, dataLayout, useNewton3);
292 break;
293 }
294 // Pairwise Verlet Lists
295 case TraversalOption::vlp_sliced: {
296 traversal = std::make_unique<VLCSlicedTraversal<ParticleCell_T, PairwiseFunctor_T,
298 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
299 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
300 break;
301 }
302 case TraversalOption::vlp_sliced_c02: {
303 traversal =
304 std::make_unique<VLCSlicedC02Traversal<ParticleCell_T, PairwiseFunctor_T,
306 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
307 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
308 break;
309 }
310 case TraversalOption::vlp_sliced_balanced: {
311 traversal =
312 std::make_unique<VLCSlicedBalancedTraversal<ParticleCell_T, PairwiseFunctor_T,
314 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
315 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
316 break;
317 }
318 case TraversalOption::vlp_c01: {
319 traversal = std::make_unique<VLCC01Traversal<ParticleCell_T, PairwiseFunctor_T,
321 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
322 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
323 break;
324 }
325 case TraversalOption::vlp_c18: {
326 traversal = std::make_unique<VLCC18Traversal<ParticleCell_T, PairwiseFunctor_T,
328 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
329 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
330 break;
331 }
332 case TraversalOption::vlp_c08: {
333 traversal = std::make_unique<VLCCellPairC08Traversal<ParticleCell_T, PairwiseFunctor_T>>(
334 traversalInfo.cellsPerDim, pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
335 dataLayout, useNewton3);
336 break;
337 }
338 // Octree
339 case TraversalOption::ot_c18: {
340 using ParticleType = typename ParticleCell_T::ParticleType;
341 traversal = std::make_unique<OTC18Traversal<ParticleType, PairwiseFunctor_T>>(
342 pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.interactionLength, dataLayout, useNewton3);
343 break;
344 }
345
346 case TraversalOption::ot_c01: {
347 using ParticleType = typename ParticleCell_T::ParticleType;
348 traversal = std::make_unique<OTC01Traversal<ParticleType, PairwiseFunctor_T>>(
349 pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.interactionLength, dataLayout, useNewton3);
350 break;
351 }
352 default: {
353 utils::ExceptionHandler::exception("Traversal type {} is not a known pairwise traversal type!",
354 traversalType.to_string());
355 return nullptr;
356 }
357 }
358 // Check if the traversal is applicable.
359 if (not traversal->isApplicableToDomain()) {
360 return nullptr;
361 }
362 // If applicable, return the traversal.
363 return std::move(traversal);
364}
365
366template <class ParticleCell_T, class TriwiseFunctor_T>
367std::unique_ptr<TraversalInterface> TraversalSelector::generateTriwiseTraversal(
368 TraversalOption traversalType, TriwiseFunctor_T &triwiseFunctor, const TraversalSelectorInfo &traversalInfo,
369 DataLayoutOption dataLayout, bool useNewton3) {
370 std::unique_ptr<TraversalInterface> traversal;
371 switch (traversalType) {
372 // Direct sum
373 case TraversalOption::ds_sequential: {
374 traversal = std::make_unique<DSSequentialTraversal<ParticleCell_T, TriwiseFunctor_T>>(
375 triwiseFunctor,
376 traversalInfo
377 .interactionLength /*this is the cutoff, as generated by DirectSum::getTraversalSelectorInfo()!*/,
378 dataLayout, useNewton3);
379 break;
380 }
381 // Linked Cells
382 case TraversalOption::lc_c01: {
383 traversal = std::make_unique<LCC01Traversal<ParticleCell_T, TriwiseFunctor_T, /*combineSoA*/ false>>(
384 traversalInfo.cellsPerDim, triwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
385 dataLayout, useNewton3);
386 break;
387 }
388 case TraversalOption::lc_c08: {
389 traversal = std::make_unique<LCC08Traversal<ParticleCell_T, TriwiseFunctor_T>>(
390 traversalInfo.cellsPerDim, triwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
391 dataLayout, useNewton3);
392 break;
393 }
394 case TraversalOption::lc_c04: {
395 traversal = std::make_unique<LCC04Traversal<ParticleCell_T, TriwiseFunctor_T>>(
396 traversalInfo.cellsPerDim, triwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
397 dataLayout, useNewton3);
398 break;
399 }
400 case TraversalOption::lc_sliced: {
401 traversal = std::make_unique<LCSlicedTraversal<ParticleCell_T, TriwiseFunctor_T>>(
402 traversalInfo.cellsPerDim, triwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
403 dataLayout, useNewton3);
404 break;
405 }
406 case TraversalOption::lc_sliced_c02: {
407 traversal = std::make_unique<LCSlicedC02Traversal<ParticleCell_T, TriwiseFunctor_T>>(
408 traversalInfo.cellsPerDim, triwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
409 dataLayout, useNewton3);
410 break;
411 }
412 default: {
413 utils::ExceptionHandler::exception("Traversal type {} is not a known triwise traversal type!",
414 traversalType.to_string());
415 return nullptr;
416 }
417 }
418 // Check if the traversal is applicable.
419 if (not traversal->isApplicableToDomain()) {
420 return nullptr;
421 }
422 // If applicable, return the traversal.
423 return std::move(traversal);
424}
425
426template <class ParticleCell_T, class Functor_T>
427std::unique_ptr<TraversalInterface> TraversalSelector::generateTraversal(TraversalOption traversalType,
428 Functor_T &functor,
429 const TraversalSelectorInfo &traversalInfo,
430 DataLayoutOption dataLayout, bool useNewton3) {
431 if constexpr (utils::isPairwiseFunctor<Functor_T>()) {
432 return generatePairwiseTraversal<ParticleCell_T, Functor_T>(traversalType, functor, traversalInfo, dataLayout,
433 useNewton3);
434 } else if constexpr (utils::isTriwiseFunctor<Functor_T>()) {
435 return generateTriwiseTraversal<ParticleCell_T, Functor_T>(traversalType, functor, traversalInfo, dataLayout,
436 useNewton3);
437 }
439 "TraversalSelector::generateTraversal(): No Traversals exist for the given Functor: {}", functor.getName());
440 return nullptr;
441}
442
443template <class Particle_T, class Functor_T>
444std::unique_ptr<TraversalInterface> TraversalSelector::generateTraversalFromConfig(
445 const Configuration &config, Functor_T &functor, const TraversalSelectorInfo &traversalInfo) {
446 switch (config.container) {
447 case ContainerOption::Value::linkedCellsReferences:
448 return TraversalSelector::generateTraversal<ReferenceParticleCell<Particle_T>, Functor_T>(
449 config.traversal, functor, traversalInfo, config.dataLayout, config.newton3);
450 default:
451 return TraversalSelector::generateTraversal<FullParticleCell<Particle_T>, Functor_T>(
452 config.traversal, functor, traversalInfo, config.dataLayout, config.newton3);
453 }
454}
455} // namespace autopas
Class containing multiple options that form an algorithm configuration for the pairwise iteration.
Definition: Configuration.h:30
TraversalOption traversal
Traversal option.
Definition: Configuration.h:151
DataLayoutOption dataLayout
Data Layout option.
Definition: Configuration.h:163
ContainerOption container
Container option.
Definition: Configuration.h:147
Newton3Option newton3
Newton 3 option.
Definition: Configuration.h:167
This class provides the c01 traversal and the c01 traversal with combined SoA buffers.
Definition: LCC01Traversal.h:82
Info for traversals of a specific container.
Definition: TraversalSelectorInfo.h:14
const std::array< double, 3 > cellLength
cell length
Definition: TraversalSelectorInfo.h:49
const unsigned int clusterSize
This specifies the size of verlet clusters.
Definition: TraversalSelectorInfo.h:54
const std::array< unsigned long, 3 > cellsPerDim
Number of cells in the domain per dimension.
Definition: TraversalSelectorInfo.h:39
const double interactionLength
Interaction length.
Definition: TraversalSelectorInfo.h:44
Selector for a container traversal.
Definition: TraversalSelector.h:54
static std::unique_ptr< TraversalInterface > generatePairwiseTraversal(TraversalOption traversalType, PairwiseFunctor_T &pairwiseFunctor, const TraversalSelectorInfo &traversalInfo, DataLayoutOption dataLayout, bool useNewton3)
Generates a given pairwise Traversal for the given properties.
Definition: TraversalSelector.h:122
static std::unique_ptr< TraversalInterface > generateTriwiseTraversal(TraversalOption traversalType, TriwiseFunctor_T &triwiseFunctor, const TraversalSelectorInfo &traversalInfo, DataLayoutOption dataLayout, bool useNewton3)
Generates a given triwise Traversal for the given properties.
Definition: TraversalSelector.h:367
static std::unique_ptr< TraversalInterface > generateTraversalFromConfig(const Configuration &config, Functor_T &functor, const TraversalSelectorInfo &traversalInfo)
Generates a traversal from the given configuration.
Definition: TraversalSelector.h:444
static std::unique_ptr< TraversalInterface > generateTraversal(TraversalOption traversalType, Functor_T &functor, const TraversalSelectorInfo &traversalInfo, DataLayoutOption dataLayout, bool useNewton3)
Generates a given Traversal for the given properties.
Definition: TraversalSelector.h:427
Neighbor list to be used with VerletListsCells container.
Definition: VLCAllCellsNeighborList.h:27
This class provides the c01 traversal.
Definition: VLCC01Traversal.h:26
This class provides the vlc_c08 traversal.
Definition: VLCC08Traversal.h:29
This class provides the lc_c18 traversal.
Definition: VLCC18Traversal.h:29
Neighbor list to be used with VerletListsCells container.
Definition: VLCCellPairNeighborList.h:23
This class provides the balanced sliced traversal.
Definition: VLCSlicedBalancedTraversal.h:34
This class provides the colored sliced traversal.
Definition: VLCSlicedC02Traversal.h:32
This class provides the (locked) sliced traversal.
Definition: VLCSlicedTraversal.h:38
Traversal for VarVerletLists with VerletNeighborListAsBuild as neighbor list.
Definition: VVLAsBuildTraversal.h:25
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:64
decltype(isTriwiseFunctorImpl(std::declval< FunctorT >())) isTriwiseFunctor
Check whether a Functor Type is inheriting from TriwiseFunctor.
Definition: checkFunctorType.h:56
decltype(isPairwiseFunctorImpl(std::declval< FunctorT >())) isPairwiseFunctor
Check whether a Functor Type is inheriting from PairwiseFunctor.
Definition: checkFunctorType.h:49
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34