AutoPas  3.0.0
Loading...
Searching...
No Matches
VCLC06Traversal.h
Go to the documentation of this file.
1
7#pragma once
8
13
14namespace autopas {
15
26template <class ParticleCell, class PairwiseFunctor>
27class VCLC06Traversal : public ColorBasedTraversal<ParticleCell, PairwiseFunctor>,
28 public VCLTraversalInterface<typename ParticleCell::ParticleType> {
29 private:
30 using ParticleType = typename ParticleCell::ParticleType;
31
40 static constexpr std::array<unsigned long, 3> _stride{3ul, 2ul, 1ul};
41
49 void processColorCell(unsigned long xColorCell, unsigned long yColorCell, unsigned long zColorCell,
50 int towersPerColoringCell);
51
52 public:
60 explicit VCLC06Traversal(PairwiseFunctor *pairwiseFunctor, size_t clusterSize, DataLayoutOption dataLayout,
61 bool useNewton3)
62 : ColorBasedTraversal<ParticleCell, PairwiseFunctor>({0, 0, 0}, pairwiseFunctor, 0, {}, dataLayout, useNewton3),
63 _functor(pairwiseFunctor),
64 _clusterFunctor(pairwiseFunctor, clusterSize, dataLayout, useNewton3) {}
65
66 [[nodiscard]] TraversalOption getTraversalType() const override { return TraversalOption::vcl_c06; }
67
68 [[nodiscard]] bool isApplicable() const override {
69 return (this->_dataLayout == DataLayoutOption::aos || this->_dataLayout == DataLayoutOption::soa);
70 }
71
72 void initTraversal() override {
73 if (this->_dataLayout == DataLayoutOption::soa) {
74 VCLTraversalInterface<ParticleType>::_verletClusterLists->loadParticlesIntoSoAs(_functor);
75 }
76 }
77
78 void endTraversal() override {
79 if (this->_dataLayout == DataLayoutOption::soa) {
80 VCLTraversalInterface<ParticleType>::_verletClusterLists->extractParticlesFromSoAs(_functor);
81 }
82 }
83
84 void traverseParticles() override {
86
87 const auto towersPerColoringCell = clusterList.getNumTowersPerInteractionLength();
88 std::array<unsigned long, 2> coloringCellsPerDim{};
89 for (int i = 0; i < 2; i++) {
90 coloringCellsPerDim[i] =
91 static_cast<unsigned long>(std::ceil(clusterList.getTowersPerDimension()[i] / (double)towersPerColoringCell));
92 }
93
94 auto loopBody = [this, towersPerColoringCell](unsigned long x, unsigned long y, unsigned long z) {
95 processColorCell(x, y, z, towersPerColoringCell);
96 };
97
98 // localStride is necessary because stride is constexpr and colorTraversal() wants a const &
99 auto localStride = _stride;
100 this->colorTraversal(std::forward<decltype(loopBody)>(loopBody),
101 {coloringCellsPerDim[0], coloringCellsPerDim[1], 1}, localStride);
102 }
103
108 void setSortingThreshold(size_t sortingThreshold) override {}
109
110 private:
111 PairwiseFunctor *_functor;
113};
114
115template <class ParticleCell, class PairwiseFunctor>
116void VCLC06Traversal<ParticleCell, PairwiseFunctor>::processColorCell(unsigned long xColorCell,
117 unsigned long yColorCell,
118 unsigned long zColorCell,
119 int towersPerColoringCell) {
120 // We are only doing a 2D coloring.
121 if (zColorCell != 0) {
122 autopas::utils::ExceptionHandler::exception("Coloring should only be 2D, not in z-direction!");
123 }
124
126 const auto towersPerDim = clusterList.getTowersPerDimension();
127
128 for (int yInner = 0; yInner < towersPerColoringCell; yInner++) {
129 for (int xInner = 0; xInner < towersPerColoringCell; xInner++) {
130 const auto y = yColorCell * towersPerColoringCell + yInner;
131 const auto x = xColorCell * towersPerColoringCell + xInner;
132
133 // Not every coloring cell has to have gridsPerColoringCell grids in every direction.
134 if (x >= towersPerDim[0] or y >= towersPerDim[1]) {
135 continue;
136 }
137
138 auto &currentTower = clusterList.getTowerByIndex(x, y);
139 for (auto clusterIter = this->_useNewton3 ? currentTower.getClusters().begin()
140 : currentTower.getFirstOwnedCluster();
141 clusterIter <
142 (this->_useNewton3 ? currentTower.getClusters().end() : currentTower.getFirstTailHaloCluster());
143 ++clusterIter) {
144 const auto isHaloCluster =
145 clusterIter < currentTower.getFirstOwnedCluster() or clusterIter >= currentTower.getFirstTailHaloCluster();
146 _clusterFunctor.processCluster(*clusterIter, isHaloCluster);
147 }
148 }
149 }
150}
151
152} // namespace autopas
This class provides the base for traversals using base steps based on cell coloring.
Definition: ColorBasedTraversal.h:27
void colorTraversal(LoopBody &&loopBody, const std::array< unsigned long, 3 > &end, const std::array< unsigned long, 3 > &stride, const std::array< unsigned long, 3 > &offset={0ul, 0ul, 0ul})
The main traversal of the ColorBasedTraversal.
Definition: ColorBasedTraversal.h:132
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
DataLayoutOption _dataLayout
The datalayout used by this traversal.
Definition: TraversalInterface.h:75
A traversal for VerletClusterLists that uses a coloring over the grids of the container.
Definition: VCLC06Traversal.h:28
void initTraversal() override
Initializes the traversal.
Definition: VCLC06Traversal.h:72
bool isApplicable() const override
Checks if the traversal is applicable to the current state of the domain.
Definition: VCLC06Traversal.h:68
TraversalOption getTraversalType() const override
Return a enum representing the name of the traversal class.
Definition: VCLC06Traversal.h:66
void endTraversal() override
Finalizes the traversal.
Definition: VCLC06Traversal.h:78
void setSortingThreshold(size_t sortingThreshold) override
Set the sorting-threshold for traversals that use the CellFunctor If the sum of the number of particl...
Definition: VCLC06Traversal.h:108
VCLC06Traversal(PairwiseFunctor *pairwiseFunctor, size_t clusterSize, DataLayoutOption dataLayout, bool useNewton3)
Constructor of the VCLClusterIterationTraversal.
Definition: VCLC06Traversal.h:60
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: VCLC06Traversal.h:84
Interface for traversals of the VerletClusterLists container.
Definition: VCLTraversalInterface.h:20
VerletClusterLists< Particle_T > * _verletClusterLists
The cluster list to iterate over.
Definition: VCLTraversalInterface.h:53
Provides methods to traverse a single cluster and a pair of clusters.
Definition: VCLClusterFunctor.h:21
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32