AutoPas  3.0.0
Loading...
Searching...
No Matches
TraversalSelector.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <array>
10#include <numeric>
11#include <unordered_map>
12#include <vector>
13
54
55namespace autopas {
56
61template <class ParticleCell>
63 public:
74 template <class Functor>
75 static std::unique_ptr<TraversalInterface> generateTraversal(TraversalOption traversalType, Functor &functor,
76 const TraversalSelectorInfo &traversalInfo,
77 DataLayoutOption dataLayout, bool useNewton3);
78
89 template <class PairwiseFunctor>
90 static std::unique_ptr<TraversalInterface> generatePairwiseTraversal(TraversalOption traversalType,
91 PairwiseFunctor &pairwiseFunctor,
92 const TraversalSelectorInfo &traversalInfo,
93 DataLayoutOption dataLayout, bool useNewton3);
94
105 template <class TriwiseFunctor>
106 static std::unique_ptr<TraversalInterface> generateTriwiseTraversal(TraversalOption traversalType,
107 TriwiseFunctor &triwiseFunctor,
108 const TraversalSelectorInfo &traversalInfo,
109 DataLayoutOption dataLayout, bool useNewton3);
110};
111
112template <class ParticleCell>
113template <class PairwiseFunctor>
115 TraversalOption traversalType, PairwiseFunctor &pairwiseFunctor, const TraversalSelectorInfo &traversalInfo,
116 DataLayoutOption dataLayout, bool useNewton3) {
117 switch (traversalType) {
118 // Direct sum
119 case TraversalOption::ds_sequential: {
120 return std::make_unique<DSSequentialTraversal<ParticleCell, PairwiseFunctor>>(
121 &pairwiseFunctor,
122 traversalInfo
123 .interactionLength /*this is the cutoff, as generated by DirectSum::getTraversalSelectorInfo()!*/,
124 dataLayout, useNewton3);
125 }
126 // Linked cell
127 case TraversalOption::lc_sliced: {
128 return std::make_unique<LCSlicedTraversal<ParticleCell, PairwiseFunctor>>(
129 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
130 dataLayout, useNewton3);
131 }
132 case TraversalOption::lc_sliced_c02: {
133 return std::make_unique<LCSlicedC02Traversal<ParticleCell, PairwiseFunctor>>(
134 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
135 dataLayout, useNewton3);
136 }
137 case TraversalOption::lc_sliced_balanced: {
138 return std::make_unique<LCSlicedBalancedTraversal<ParticleCell, PairwiseFunctor>>(
139 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
140 dataLayout, useNewton3);
141 }
142 case TraversalOption::lc_c01: {
143 return std::make_unique<LCC01Traversal<ParticleCell, PairwiseFunctor, false>>(
144 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
145 dataLayout, useNewton3);
146 }
147 case TraversalOption::lc_c01_combined_SoA: {
148 return std::make_unique<LCC01Traversal<ParticleCell, PairwiseFunctor, true>>(
149 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
150 dataLayout, useNewton3);
151 }
152 case TraversalOption::lc_c04_combined_SoA: {
153 return std::make_unique<LCC04CombinedSoATraversal<ParticleCell, PairwiseFunctor>>(
154 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
155 dataLayout, useNewton3);
156 }
157 case TraversalOption::lc_c04: {
158 return std::make_unique<LCC04Traversal<ParticleCell, PairwiseFunctor>>(
159 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
160 dataLayout, useNewton3);
161 }
162 case TraversalOption::lc_c04_HCP: {
163 return std::make_unique<LCC04HCPTraversal<ParticleCell, PairwiseFunctor>>(
164 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
165 dataLayout, useNewton3);
166 }
167 case TraversalOption::lc_c08: {
168 return std::make_unique<LCC08Traversal<ParticleCell, PairwiseFunctor>>(
169 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
170 dataLayout, useNewton3);
171 }
172 case TraversalOption::lc_c18: {
173 return std::make_unique<LCC18Traversal<ParticleCell, PairwiseFunctor>>(
174 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
175 dataLayout, useNewton3);
176 }
177 // Verlet
178 case TraversalOption::vl_list_iteration: {
179 return std::make_unique<VLListIterationTraversal<ParticleCell, PairwiseFunctor>>(&pairwiseFunctor, dataLayout,
180 useNewton3);
181 }
182 // Var Verlet Lists
183 case TraversalOption::vvl_as_built: {
184 return std::make_unique<VVLAsBuildTraversal<ParticleCell, typename ParticleCell::ParticleType, PairwiseFunctor>>(
185 &pairwiseFunctor, dataLayout, useNewton3);
186 }
187 // Verlet List Cells
188 case TraversalOption::vlc_sliced: {
189 return std::make_unique<VLCSlicedTraversal<ParticleCell, PairwiseFunctor,
191 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
192 dataLayout, useNewton3, ContainerOption::verletListsCells);
193 }
194 case TraversalOption::vlc_sliced_c02: {
195 return std::make_unique<VLCSlicedC02Traversal<ParticleCell, PairwiseFunctor,
197 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
198 dataLayout, useNewton3, ContainerOption::verletListsCells);
199 }
200 case TraversalOption::vlc_sliced_balanced: {
203 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
204 dataLayout, useNewton3, ContainerOption::verletListsCells);
205 }
206 case TraversalOption::vlc_c01: {
207 return std::make_unique<
209 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
210 dataLayout, useNewton3, ContainerOption::verletListsCells);
211 }
212 case TraversalOption::vlc_c18: {
213 return std::make_unique<
215 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
216 dataLayout, useNewton3, ContainerOption::verletListsCells);
217 }
218 case TraversalOption::vlc_c08: {
219 return std::make_unique<
221 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
222 dataLayout, useNewton3);
223 }
224 // Verlet Cluster Lists
225 case TraversalOption::vcl_cluster_iteration: {
226 return std::make_unique<VCLClusterIterationTraversal<ParticleCell, PairwiseFunctor>>(
227 &pairwiseFunctor, traversalInfo.clusterSize, dataLayout, useNewton3);
228 }
229 case TraversalOption::vcl_c01_balanced: {
230 return std::make_unique<VCLC01BalancedTraversal<typename ParticleCell::ParticleType, PairwiseFunctor>>(
231 &pairwiseFunctor, traversalInfo.clusterSize, dataLayout, useNewton3);
232 }
233 case TraversalOption::vcl_sliced: {
234 return std::make_unique<VCLSlicedTraversal<ParticleCell, PairwiseFunctor>>(
235 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
236 traversalInfo.clusterSize, dataLayout, useNewton3);
237 }
238 case TraversalOption::vcl_sliced_c02: {
239 return std::make_unique<VCLSlicedC02Traversal<ParticleCell, PairwiseFunctor>>(
240 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
241 traversalInfo.clusterSize, dataLayout, useNewton3);
242 }
243 case TraversalOption::vcl_sliced_balanced: {
244 return std::make_unique<VCLSlicedBalancedTraversal<ParticleCell, PairwiseFunctor>>(
245 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
246 traversalInfo.clusterSize, dataLayout, useNewton3);
247 }
248 case TraversalOption::vcl_c06: {
249 return std::make_unique<VCLC06Traversal<ParticleCell, PairwiseFunctor>>(
250 &pairwiseFunctor, traversalInfo.clusterSize, dataLayout, useNewton3);
251 }
252 // Pairwise Verlet Lists
253 case TraversalOption::vlp_sliced: {
254 return std::make_unique<VLCSlicedTraversal<ParticleCell, PairwiseFunctor,
256 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
257 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
258 }
259 case TraversalOption::vlp_sliced_c02: {
260 return std::make_unique<VLCSlicedC02Traversal<ParticleCell, PairwiseFunctor,
262 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
263 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
264 }
265 case TraversalOption::vlp_sliced_balanced: {
268 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
269 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
270 }
271 case TraversalOption::vlp_c01: {
272 return std::make_unique<
274 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
275 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
276 }
277 case TraversalOption::vlp_c18: {
278 return std::make_unique<
280 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
281 dataLayout, useNewton3, ContainerOption::pairwiseVerletLists);
282 }
283 case TraversalOption::vlp_c08: {
284 return std::make_unique<VLCCellPairC08Traversal<ParticleCell, PairwiseFunctor>>(
285 traversalInfo.cellsPerDim, &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
286 dataLayout, useNewton3);
287 }
288 // Octree
289 case TraversalOption::ot_c18: {
290 using ParticleType = typename ParticleCell::ParticleType;
291 return std::make_unique<OTC18Traversal<ParticleType, PairwiseFunctor>>(
292 &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.interactionLength, dataLayout, useNewton3);
293 }
294
295 case TraversalOption::ot_c01: {
296 using ParticleType = typename ParticleCell::ParticleType;
297 return std::make_unique<OTC01Traversal<ParticleType, PairwiseFunctor>>(
298 &pairwiseFunctor, traversalInfo.interactionLength, traversalInfo.interactionLength, dataLayout, useNewton3);
299 }
300 default: {
301 autopas::utils::ExceptionHandler::exception("Traversal type {} is not a known pairwise traversal type!",
302 traversalType.to_string());
303 return {nullptr};
304 }
305 }
306}
307
308template <class ParticleCell>
309template <class TriwiseFunctor>
311 TraversalOption traversalType, TriwiseFunctor &triwiseFunctor, const TraversalSelectorInfo &traversalInfo,
312 DataLayoutOption dataLayout, bool useNewton3) {
313 switch (traversalType) {
314 // Direct sum
315 case TraversalOption::ds_sequential: {
316 return std::make_unique<DSSequentialTraversal<ParticleCell, TriwiseFunctor>>(
317 &triwiseFunctor,
318 traversalInfo
319 .interactionLength /*this is the cutoff, as generated by DirectSum::getTraversalSelectorInfo()!*/,
320 dataLayout, useNewton3);
321 }
322 // Linked Cells
323 case TraversalOption::lc_c01: {
324 return std::make_unique<LCC01Traversal<ParticleCell, TriwiseFunctor, /*combineSoA*/ false>>(
325 traversalInfo.cellsPerDim, &triwiseFunctor, traversalInfo.interactionLength, traversalInfo.cellLength,
326 dataLayout, useNewton3);
327 }
328 default: {
329 autopas::utils::ExceptionHandler::exception("Traversal type {} is not a known triwise traversal type!",
330 traversalType.to_string());
331 return {nullptr};
332 }
333 }
334}
335
336template <class ParticleCell>
337template <class Functor>
338std::unique_ptr<TraversalInterface> TraversalSelector<ParticleCell>::generateTraversal(
339 TraversalOption traversalType, Functor &functor, const TraversalSelectorInfo &traversalInfo,
340 DataLayoutOption dataLayout, bool useNewton3) {
341 if constexpr (utils::isPairwiseFunctor<Functor>()) {
342 auto pairTraversal =
343 generatePairwiseTraversal<Functor>(traversalType, functor, traversalInfo, dataLayout, useNewton3);
344 return std::unique_ptr<TraversalInterface>(dynamic_cast<TraversalInterface *>(pairTraversal.release()));
345 } else if constexpr (utils::isTriwiseFunctor<Functor>()) {
346 auto triTraversal =
347 generateTriwiseTraversal<Functor>(traversalType, functor, traversalInfo, dataLayout, useNewton3);
348 return std::unique_ptr<TraversalInterface>(dynamic_cast<TraversalInterface *>(triTraversal.release()));
349 }
351 "TraversalSelector::generateTraversal(): No Traversals exist for the given Functor: {}", functor.getName());
352 return {nullptr};
353}
354} // namespace autopas
Functor base class.
Definition: Functor.h:40
virtual std::string getName()=0
Returns name of functor.
This class provides the c01 traversal and the c01 traversal with combined SoA buffers.
Definition: LCC01Traversal.h:82
PairwiseFunctor class.
Definition: PairwiseFunctor.h:31
Class for Cells of Particles.
Definition: ParticleCell.h:51
Particle_T ParticleType
The particle type for this cell.
Definition: ParticleCell.h:56
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
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
TraversalSelector is used for the construction of the list in the applyBuildFunctor method.
Definition: TraversalSelector.h:62
static std::unique_ptr< TraversalInterface > generateTraversal(TraversalOption traversalType, Functor &functor, const TraversalSelectorInfo &traversalInfo, DataLayoutOption dataLayout, bool useNewton3)
Generates a given Traversal for the given properties.
Definition: TraversalSelector.h:338
static std::unique_ptr< TraversalInterface > generateTriwiseTraversal(TraversalOption traversalType, TriwiseFunctor &triwiseFunctor, const TraversalSelectorInfo &traversalInfo, DataLayoutOption dataLayout, bool useNewton3)
Generates a given triwise Traversal for the given properties.
Definition: TraversalSelector.h:310
static std::unique_ptr< TraversalInterface > generatePairwiseTraversal(TraversalOption traversalType, PairwiseFunctor &pairwiseFunctor, const TraversalSelectorInfo &traversalInfo, DataLayoutOption dataLayout, bool useNewton3)
Generates a given pairwise Traversal for the given properties.
Definition: TraversalSelector.h:114
TriwiseFunctor class.
Definition: TriwiseFunctor.h:28
Neighbor list to be used with VerletListsCells container.
Definition: VLCAllCellsNeighborList.h:37
This class provides the c01 traversal.
Definition: VLCC01Traversal.h:27
This class provides the vlc_c08 traversal.
Definition: VLCC08Traversal.h:32
This class provides the lc_c18 traversal.
Definition: VLCC18Traversal.h:29
Neighbor list to be used with VerletListsCells container.
Definition: VLCCellPairNeighborList.h:30
This class provides the balanced sliced traversal.
Definition: VLCSlicedBalancedTraversal.h:36
This class provides the colored sliced traversal.
Definition: VLCSlicedC02Traversal.h:34
This class provides the (locked) sliced traversal.
Definition: VLCSlicedTraversal.h:39
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