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
72 [[nodiscard]] bool isApplicableToDomain() const override { return true; }
73
74 void initTraversal() override {
75 if (this->_dataLayout == DataLayoutOption::soa) {
76 VCLTraversalInterface<ParticleType>::_verletClusterLists->loadParticlesIntoSoAs(_functor);
77 }
78 }
79
80 void endTraversal() override {
81 if (this->_dataLayout == DataLayoutOption::soa) {
82 VCLTraversalInterface<ParticleType>::_verletClusterLists->extractParticlesFromSoAs(_functor);
83 }
84 }
85
86 void traverseParticles() override {
88
89 const auto towersPerColoringCell = clusterList.getNumTowersPerInteractionLength();
90 std::array<unsigned long, 2> coloringCellsPerDim{};
91 for (int i = 0; i < 2; i++) {
92 coloringCellsPerDim[i] =
93 static_cast<unsigned long>(std::ceil(clusterList.getTowersPerDimension()[i] / (double)towersPerColoringCell));
94 }
95
96 auto loopBody = [this, towersPerColoringCell](unsigned long x, unsigned long y, unsigned long z) {
97 processColorCell(x, y, z, towersPerColoringCell);
98 };
99
100 // localStride is necessary because stride is constexpr and colorTraversal() wants a const &
101 auto localStride = _stride;
102 this->colorTraversal(std::forward<decltype(loopBody)>(loopBody),
103 {coloringCellsPerDim[0], coloringCellsPerDim[1], 1}, localStride);
104 }
105
110 void setAoSSortingThreshold(size_t aosSortingThreshold) override {}
114 void setSoASortingThreshold(size_t soaSortingThreshold) override {}
115
116 private:
117 PairwiseFunctor &_functor;
119};
120
121template <class ParticleCell, class PairwiseFunctor>
122void VCLC06Traversal<ParticleCell, PairwiseFunctor>::processColorCell(unsigned long xColorCell,
123 unsigned long yColorCell,
124 unsigned long zColorCell,
125 int towersPerColoringCell) {
126 // We are only doing a 2D coloring.
127 if (zColorCell != 0) {
128 autopas::utils::ExceptionHandler::exception("Coloring should only be 2D, not in z-direction!");
129 }
130
132 const auto towersPerDim = clusterList.getTowersPerDimension();
133
134 for (int yInner = 0; yInner < towersPerColoringCell; yInner++) {
135 for (int xInner = 0; xInner < towersPerColoringCell; xInner++) {
136 const auto y = yColorCell * towersPerColoringCell + yInner;
137 const auto x = xColorCell * towersPerColoringCell + xInner;
138
139 // Not every coloring cell has to have gridsPerColoringCell grids in every direction.
140 if (x >= towersPerDim[0] or y >= towersPerDim[1]) {
141 continue;
142 }
143
144 auto &currentTower = clusterList.getTowerByIndex(x, y);
145 for (auto clusterIter = this->_useNewton3 ? currentTower.getClusters().begin()
146 : currentTower.getFirstOwnedCluster();
147 clusterIter <
148 (this->_useNewton3 ? currentTower.getClusters().end() : currentTower.getFirstTailHaloCluster());
149 ++clusterIter) {
150 const auto isHaloCluster =
151 clusterIter < currentTower.getFirstOwnedCluster() or clusterIter >= currentTower.getFirstTailHaloCluster();
152 _clusterFunctor.processCluster(*clusterIter, isHaloCluster);
153 }
154 }
155 }
156}
157
158} // 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:45
Class for Cells of Particles.
Definition: ParticleCell.h:49
Particle_T ParticleType
The particle type for this cell.
Definition: ParticleCell.h:54
DataLayoutOption _dataLayout
The datalayout used by this traversal.
Definition: TraversalInterface.h:77
A traversal for VerletClusterLists that uses a coloring over the grids of the container.
Definition: VCLC06Traversal.h:28
bool isApplicableToDomain() const override
VCL C06 is always applicable to the domain.
Definition: VCLC06Traversal.h:72
void setSoASortingThreshold(size_t soaSortingThreshold) override
Set the SoA sorting-threshold for traversals that use the CellFunctor.
Definition: VCLC06Traversal.h:114
VCLC06Traversal(PairwiseFunctor &pairwiseFunctor, size_t clusterSize, DataLayoutOption dataLayout, bool useNewton3)
Constructor of the VCLClusterIterationTraversal.
Definition: VCLC06Traversal.h:60
void setAoSSortingThreshold(size_t aosSortingThreshold) override
Set the aos-sorting-threshold for traversals that use the CellFunctor If the sum of the number of par...
Definition: VCLC06Traversal.h:110
void initTraversal() override
Initializes the traversal.
Definition: VCLC06Traversal.h:74
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:80
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: VCLC06Traversal.h:86
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:64
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34