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
47
48namespace autopas {
49
54 public:
66 template <class ParticleCell_T, class Functor_T>
67 static std::unique_ptr<TraversalInterface> generateTraversal(TraversalOption traversalType, Functor_T &functor,
68 const TraversalSelectorInfo &traversalInfo,
69 DataLayoutOption dataLayout, bool useNewton3);
70
82 template <class ParticleCell_T, class PairwiseFunctor_T>
83 static std::unique_ptr<TraversalInterface> generatePairwiseTraversal(TraversalOption traversalType,
84 PairwiseFunctor_T &pairwiseFunctor,
85 const TraversalSelectorInfo &traversalInfo,
86 DataLayoutOption dataLayout, bool useNewton3);
87
99 template <class ParticleCell_T, class TriwiseFunctor_T>
100 static std::unique_ptr<TraversalInterface> generateTriwiseTraversal(TraversalOption traversalType,
101 TriwiseFunctor_T &triwiseFunctor,
102 const TraversalSelectorInfo &traversalInfo,
103 DataLayoutOption dataLayout, bool useNewton3);
104
114 template <class Particle_T, class Functor_T>
115 static std::unique_ptr<TraversalInterface> generateTraversalFromConfig(const Configuration &config,
116 Functor_T &functor,
117 const TraversalSelectorInfo &traversalInfo);
118};
119
120template <class ParticleCell_T, class PairwiseFunctor_T>
121std::unique_ptr<TraversalInterface> TraversalSelector::generatePairwiseTraversal(
122 TraversalOption traversalType, PairwiseFunctor_T &pairwiseFunctor, const TraversalSelectorInfo &traversalInfo,
123 DataLayoutOption dataLayout, bool useNewton3) {
124 std::unique_ptr<TraversalInterface> traversal;
125 switch (traversalType) {
126 // Direct sum
127 case TraversalOption::ds_sequential: {
128 traversal = std::make_unique<DSSequentialTraversal<ParticleCell_T, PairwiseFunctor_T>>(
129 &pairwiseFunctor,
130 traversalInfo
131 .interactionLength /*this is the cutoff, as generated by DirectSum::getTraversalSelectorInfo()!*/,
132 dataLayout, useNewton3);
133 break;
134 }
135 // Linked cell
136 case TraversalOption::lc_sliced: {
137 traversal = std::make_unique<LCSlicedTraversal<ParticleCell_T, PairwiseFunctor_T>>(
138 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
139 dataLayout, useNewton3);
140 break;
141 }
142 case TraversalOption::lc_sliced_c02: {
143 traversal = std::make_unique<LCSlicedC02Traversal<ParticleCell_T, PairwiseFunctor_T>>(
144 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
145 dataLayout, useNewton3);
146 break;
147 }
148 case TraversalOption::lc_sliced_balanced: {
149 traversal = std::make_unique<LCSlicedBalancedTraversal<ParticleCell_T, PairwiseFunctor_T>>(
150 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
151 dataLayout, useNewton3);
152 break;
153 }
154 case TraversalOption::lc_c01: {
155 traversal = std::make_unique<LCC01Traversal<ParticleCell_T, PairwiseFunctor_T, false>>(
156 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
157 dataLayout, useNewton3);
158 break;
159 }
160 case TraversalOption::lc_c01_combined_SoA: {
161 traversal = std::make_unique<LCC01Traversal<ParticleCell_T, PairwiseFunctor_T, true>>(
162 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
163 dataLayout, useNewton3);
164 break;
165 }
166 case TraversalOption::lc_c04_combined_SoA: {
167 traversal = std::make_unique<LCC04CombinedSoATraversal<ParticleCell_T, PairwiseFunctor_T>>(
168 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
169 dataLayout, useNewton3);
170 break;
171 }
172 case TraversalOption::lc_c04: {
173 traversal = std::make_unique<LCC04Traversal<ParticleCell_T, PairwiseFunctor_T>>(
174 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
175 dataLayout, useNewton3);
176 break;
177 }
178 case TraversalOption::lc_c04_HCP: {
179 traversal = std::make_unique<LCC04HCPTraversal<ParticleCell_T, PairwiseFunctor_T>>(
180 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
181 dataLayout, useNewton3);
182 break;
183 }
184 case TraversalOption::lc_c08: {
185 traversal = std::make_unique<LCC08Traversal<ParticleCell_T, PairwiseFunctor_T>>(
186 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
187 dataLayout, useNewton3);
188 break;
189 }
190 case TraversalOption::lc_c18: {
191 traversal = std::make_unique<LCC18Traversal<ParticleCell_T, PairwiseFunctor_T>>(
192 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
193 dataLayout, useNewton3);
194 break;
195 }
196 // Verlet
197 case TraversalOption::vl_list_iteration: {
198 traversal = std::make_unique<VLListIterationTraversal<ParticleCell_T, PairwiseFunctor_T>>(&pairwiseFunctor,
199 dataLayout, useNewton3);
200 break;
201 }
202 // Var Verlet Lists
203 case TraversalOption::vvl_as_built: {
204 traversal = std::make_unique<
206 &pairwiseFunctor, dataLayout, useNewton3);
207 break;
208 }
209 // Verlet List Cells
210 case TraversalOption::vlc_sliced: {
211 traversal = std::make_unique<VLCSlicedTraversal<ParticleCell_T, PairwiseFunctor_T,
213 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
214 dataLayout, useNewton3, ContainerOption::verletListsCells);
215 break;
216 }
217 case TraversalOption::vlc_sliced_c02: {
218 traversal =
219 std::make_unique<VLCSlicedC02Traversal<ParticleCell_T, PairwiseFunctor_T,
221 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
222 dataLayout, useNewton3, ContainerOption::verletListsCells);
223 break;
224 }
225 case TraversalOption::vlc_sliced_balanced: {
226 traversal =
227 std::make_unique<VLCSlicedBalancedTraversal<ParticleCell_T, PairwiseFunctor_T,
229 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
230 dataLayout, useNewton3, ContainerOption::verletListsCells);
231 break;
232 }
233 case TraversalOption::vlc_c01: {
234 traversal = std::make_unique<VLCC01Traversal<ParticleCell_T, PairwiseFunctor_T,
236 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
237 dataLayout, useNewton3, ContainerOption::verletListsCells);
238 break;
239 }
240 case TraversalOption::vlc_c18: {
241 traversal = std::make_unique<VLCC18Traversal<ParticleCell_T, PairwiseFunctor_T,
243 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
244 dataLayout, useNewton3, ContainerOption::verletListsCells);
245 break;
246 }
247 case TraversalOption::vlc_c08: {
248 traversal = std::make_unique<VLCC08Traversal<ParticleCell_T, PairwiseFunctor_T,
250 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
251 dataLayout, useNewton3);
252 break;
253 }
254 // Verlet Cluster Lists
255 case TraversalOption::vcl_cluster_iteration: {
256 traversal = std::make_unique<VCLClusterIterationTraversal<ParticleCell_T, PairwiseFunctor_T>>(
257 &pairwiseFunctor, traversalInfo.clusterSize, dataLayout, useNewton3);
258 break;
259 }
260 case TraversalOption::vcl_c01_balanced: {
261 traversal = std::make_unique<VCLC01BalancedTraversal<typename ParticleCell_T::ParticleType, PairwiseFunctor_T>>(
262 &pairwiseFunctor, traversalInfo.clusterSize, dataLayout, useNewton3);
263 break;
264 }
265 case TraversalOption::vcl_sliced: {
266 traversal = std::make_unique<VCLSlicedTraversal<ParticleCell_T, PairwiseFunctor_T>>(
267 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
268 traversalInfo.clusterSize, dataLayout, useNewton3);
269 break;
270 }
271 case TraversalOption::vcl_sliced_c02: {
272 traversal = std::make_unique<VCLSlicedC02Traversal<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_balanced: {
278 traversal = std::make_unique<VCLSlicedBalancedTraversal<ParticleCell_T, PairwiseFunctor_T>>(
279 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
280 traversalInfo.clusterSize, dataLayout, useNewton3);
281 break;
282 }
283 case TraversalOption::vcl_c06: {
284 traversal = std::make_unique<VCLC06Traversal<ParticleCell_T, PairwiseFunctor_T>>(
285 &pairwiseFunctor, traversalInfo.clusterSize, dataLayout, useNewton3);
286 break;
287 }
288 // Pairwise Verlet Lists
289 case TraversalOption::vlp_sliced: {
290 traversal = std::make_unique<VLCSlicedTraversal<ParticleCell_T, PairwiseFunctor_T,
292 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
293 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
294 break;
295 }
296 case TraversalOption::vlp_sliced_c02: {
297 traversal =
298 std::make_unique<VLCSlicedC02Traversal<ParticleCell_T, PairwiseFunctor_T,
300 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
301 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
302 break;
303 }
304 case TraversalOption::vlp_sliced_balanced: {
305 traversal =
306 std::make_unique<VLCSlicedBalancedTraversal<ParticleCell_T, PairwiseFunctor_T,
308 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
309 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
310 break;
311 }
312 case TraversalOption::vlp_c01: {
313 traversal = std::make_unique<VLCC01Traversal<ParticleCell_T, PairwiseFunctor_T,
315 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
316 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
317 break;
318 }
319 case TraversalOption::vlp_c18: {
320 traversal = std::make_unique<VLCC18Traversal<ParticleCell_T, PairwiseFunctor_T,
322 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
323 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
324 break;
325 }
326 case TraversalOption::vlp_c08: {
327 traversal = std::make_unique<VLCCellPairC08Traversal<ParticleCell_T, PairwiseFunctor_T>>(
328 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
329 dataLayout, useNewton3);
330 break;
331 }
332 // Octree
333 case TraversalOption::ot_c18: {
334 using ParticleType = typename ParticleCell_T::ParticleType;
335 traversal = std::make_unique<OTC18Traversal<ParticleType, PairwiseFunctor_T>>(
336 &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.interactionLength, dataLayout, useNewton3);
337 break;
338 }
339
340 case TraversalOption::ot_c01: {
341 using ParticleType = typename ParticleCell_T::ParticleType;
342 traversal = std::make_unique<OTC01Traversal<ParticleType, PairwiseFunctor_T>>(
343 &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.interactionLength, dataLayout, useNewton3);
344 break;
345 }
346 default: {
347 utils::ExceptionHandler::exception("Traversal type {} is not a known pairwise traversal type!",
348 traversalType.to_string());
349 return nullptr;
350 }
351 }
352 // Check if the traversal is applicable.
353 if (not traversal->isApplicable()) {
354 return nullptr;
355 }
356 // If applicable, return the traversal.
357 return std::move(traversal);
358}
359
360template <class ParticleCell_T, class TriwiseFunctor_T>
361std::unique_ptr<TraversalInterface> TraversalSelector::generateTriwiseTraversal(
362 TraversalOption traversalType, TriwiseFunctor_T &triwiseFunctor, const TraversalSelectorInfo &traversalInfo,
363 DataLayoutOption dataLayout, bool useNewton3) {
364 std::unique_ptr<TraversalInterface> traversal;
365 switch (traversalType) {
366 // Direct sum
367 case TraversalOption::ds_sequential: {
368 traversal = std::make_unique<DSSequentialTraversal<ParticleCell_T, TriwiseFunctor_T>>(
369 &triwiseFunctor,
370 traversalInfo
371 .interactionLength /*this is the cutoff, as generated by DirectSum::getTraversalSelectorInfo()!*/,
372 dataLayout, useNewton3);
373 break;
374 }
375 // Linked Cells
376 case TraversalOption::lc_c01: {
377 traversal = std::make_unique<LCC01Traversal<ParticleCell_T, TriwiseFunctor_T, /*combineSoA*/ false>>(
378 traversalInfo.cellsPerDim, &triwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
379 dataLayout, useNewton3);
380 break;
381 }
382 default: {
383 utils::ExceptionHandler::exception("Traversal type {} is not a known triwise traversal type!",
384 traversalType.to_string());
385 return nullptr;
386 }
387 }
388 // Check if the traversal is applicable.
389 if (not traversal->isApplicable()) {
390 return nullptr;
391 }
392 // If applicable, return the traversal.
393 return std::move(traversal);
394}
395
396template <class ParticleCell_T, class Functor_T>
397std::unique_ptr<TraversalInterface> TraversalSelector::generateTraversal(TraversalOption traversalType,
398 Functor_T &functor,
399 const TraversalSelectorInfo &traversalInfo,
400 DataLayoutOption dataLayout, bool useNewton3) {
401 if constexpr (utils::isPairwiseFunctor<Functor_T>()) {
402 return generatePairwiseTraversal<ParticleCell_T, Functor_T>(traversalType, functor, traversalInfo, dataLayout,
403 useNewton3);
404 } else if constexpr (utils::isTriwiseFunctor<Functor_T>()) {
405 return generateTriwiseTraversal<ParticleCell_T, Functor_T>(traversalType, functor, traversalInfo, dataLayout,
406 useNewton3);
407 }
409 "TraversalSelector::generateTraversal(): No Traversals exist for the given Functor: {}", functor.getName());
410 return nullptr;
411}
412
413template <class Particle_T, class Functor_T>
414std::unique_ptr<TraversalInterface> TraversalSelector::generateTraversalFromConfig(
415 const Configuration &config, Functor_T &functor, const TraversalSelectorInfo &traversalInfo) {
416 switch (config.container) {
417 case ContainerOption::Value::linkedCellsReferences:
418 return TraversalSelector::generateTraversal<ReferenceParticleCell<Particle_T>, Functor_T>(
419 config.traversal, functor, traversalInfo, config.dataLayout, config.newton3);
420 default:
421 return TraversalSelector::generateTraversal<FullParticleCell<Particle_T>, Functor_T>(
422 config.traversal, functor, traversalInfo, config.dataLayout, config.newton3);
423 }
424}
425} // namespace autopas
Class containing multiple options that form an algorithm configuration for the pairwise iteration.
Definition: Configuration.h:24
TraversalOption traversal
Traversal option.
Definition: Configuration.h:122
DataLayoutOption dataLayout
Data Layout option.
Definition: Configuration.h:130
ContainerOption container
Container option.
Definition: Configuration.h:118
Newton3Option newton3
Newton 3 option.
Definition: Configuration.h:134
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:53
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:121
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:361
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:414
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:397
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:63
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:32