AutoPas  3.0.0
Loading...
Searching...
No Matches
LCC04HCPTraversal.h
Go to the documentation of this file.
1
7#pragma once
8
15
16namespace autopas {
17
29template <class ParticleCell, class PairwiseFunctor>
30class LCC04HCPTraversal : public C08BasedTraversal<ParticleCell, PairwiseFunctor>, public LCTraversalInterface {
31 public:
42 LCC04HCPTraversal(const std::array<unsigned long, 3> &dims, PairwiseFunctor &pairwiseFunctor,
43 const double interactionLength, const std::array<double, 3> &cellLength,
44 DataLayoutOption dataLayout, bool useNewton3)
45 : C08BasedTraversal<ParticleCell, PairwiseFunctor>(dims, pairwiseFunctor, interactionLength, cellLength,
46 dataLayout, useNewton3),
47 _cellHandler(pairwiseFunctor, this->_cellsPerDimension, interactionLength, cellLength, this->_overlap,
48 dataLayout, useNewton3),
49 _end(utils::ArrayMath::subScalar(utils::ArrayUtils::static_cast_copy_array<long>(this->_cellsPerDimension),
50 1l)) {}
51
52 void traverseParticles() override;
53
54 [[nodiscard]] TraversalOption getTraversalType() const override { return TraversalOption::lc_c04_HCP; }
55
56 [[nodiscard]] bool isApplicableToDomain() const override {
57 // The cellsize cannot be smaller than the cutoff, if OpenMP is used.
58 // Also see: https://github.com/AutoPas/AutoPas/issues/464
59 const double minLength = *std::min_element(this->_cellLength.cbegin(), this->_cellLength.cend());
60
61 return minLength >= this->_interactionLength;
62 }
63
67 void setAoSSortingThreshold(size_t aosSortingThreshold) override {
68 _cellHandler.setAoSSortingThreshold(aosSortingThreshold);
69 }
73 void setSoASortingThreshold(size_t soaSortingThreshold) override {
74 _cellHandler.setSoASortingThreshold(soaSortingThreshold);
75 }
76
77 private:
78 void traverseSingleColor(std::vector<ParticleCell> &cells, int color);
79
80 void processBasePack6(std::vector<ParticleCell> &cells, const std::array<long, 3> &base3DIndex);
81
83
84 const std::array<long, 3> _end;
85};
86
87template <class ParticleCell, class PairwiseFunctor>
88void LCC04HCPTraversal<ParticleCell, PairwiseFunctor>::processBasePack6(std::vector<ParticleCell> &cells,
89 const std::array<long, 3> &base3DIndex) {
91 std::array<long, 3> index{};
92 const std::array<long, 3> signedDims = utils::ArrayUtils::static_cast_copy_array<long>(this->_cellsPerDimension);
93
94 // go through the six cells
95 for (long z = 0; z < 3; ++z) {
96 for (long x = 0; x < 2; ++x) {
97 index[0] = base3DIndex[0] + x;
98 index[1] = base3DIndex[1];
99 index[2] = base3DIndex[2] + z;
100
101 bool isIn = true;
102 for (int d = 0; d < 3; ++d) {
103 // prevent using overlapping cells and cells outside the boundaries
104 isIn &= (index[d] >= 0l) and (index[d] <= (_end[d] - this->_overlap[d]));
105 }
106
107 // skip cells outside radius
108 if (isIn) {
109 const unsigned long ulIndex = threeToOneD(index, signedDims);
110 _cellHandler.processBaseCell(cells, ulIndex);
111 }
112 }
113 }
114}
115
116template <class ParticleCell, class PairwiseFunctor>
118 auto &cells = *(this->_cells);
119 AUTOPAS_OPENMP(parallel) {
120 for (int color = 0; color < 4; ++color) {
121 traverseSingleColor(cells, color);
122
123 if (color < 3) {
124 AUTOPAS_OPENMP(barrier)
125 }
126 }
127 } // close parallel region
128}
129
139template <class ParticleCell, class PairwiseFunctor>
141 int color) {
142 // determine a starting point of one of the grids
143 std::array<long, 3> startOfThisColor{}; // coordinates: {x,y,z}
144
145 // different starting points for different colors
146 // some colors are starting outside the grid because only part of their cuboids are part of the grid
147 // this way the starting points of sticking out cuboids can be determined as well
148 switch (color) {
149 case 0:
150 startOfThisColor = {0l, 0l, 0l};
151 break;
152 case 1:
153 startOfThisColor = {-4l, 0l, 1l};
154 break;
155 case 2:
156 startOfThisColor = {-4l, 0l, -2l};
157 break;
158 case 3:
159 startOfThisColor = {-2l, 0l, -1l};
160 break;
161 default:
162 autopas::utils::ExceptionHandler::exception("LCC04HCPTraversal::traverseSingleColor: invalid color ({})", color);
163 }
164
165 // to fix intel64 icpc compiler complaints about perfectly nested loop.
166 const long startX = startOfThisColor[0], endX = _end[0];
167 const long startY = startOfThisColor[1], endY = _end[1];
168 const long startZ = startOfThisColor[2], endZ = _end[2];
169
170 // iterate over cartesian grid
171 AUTOPAS_OPENMP(for schedule(dynamic, 1) collapse(3) nowait)
172 for (long z = startZ; z < endZ; z += 4) {
173 for (long y = startY; y < endY; y++) {
174 /* color starts every 6th column again, the +4 is needed to prevent ending too early, since it
175 will be shifted back inside the loop */
176 for (long x = startX; x < (endX + 4); x += 6) {
177 long x_index = x;
178 /* shift on x-axis according to z-value: shift two times and then go back to original x-value
179 first: no shift
180 second: -4 shift
181 third: -2 shift
182 fourth: go back to first
183 every 12th z, the shifting pattern repeats again at the origin of x without shift,
184 because z is shifted by 4 in every loop run and every third z-shift the pattern repeats
185 */
186 switch ((z - startZ) % 12 / 4) {
187 case 0:
188 break;
189 case 1:
190 x_index -= 4;
191 break;
192 case 2:
193 x_index -= 2;
194 break;
195 default:
196 break;
197 }
198 // shift x-axis every second y-row
199 if ((y - startY) % 2 != 0) {
200 x_index += 3;
201 }
202 processBasePack6(cells, {x_index, y, z});
203 }
204 }
205 }
206}
207
208} // namespace autopas
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
This class provides the base for traversals using the c08 base step.
Definition: C08BasedTraversal.h:24
std::array< unsigned long, 3 > _cellsPerDimension
The dimensions of the cellblock.
Definition: CellTraversal.h:63
const double _interactionLength
Interaction length (cutoff + skin).
Definition: ColorBasedTraversal.h:111
std::array< unsigned long, 3 > _overlap
overlap of interacting cells.
Definition: ColorBasedTraversal.h:121
const std::array< double, 3 > _cellLength
cell length in CellBlock3D.
Definition: ColorBasedTraversal.h:116
This class provides the c04 hcp traversal.
Definition: LCC04HCPTraversal.h:30
LCC04HCPTraversal(const std::array< unsigned long, 3 > &dims, PairwiseFunctor &pairwiseFunctor, const double interactionLength, const std::array< double, 3 > &cellLength, DataLayoutOption dataLayout, bool useNewton3)
Constructor of c04hcp.
Definition: LCC04HCPTraversal.h:42
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: LCC04HCPTraversal.h:67
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: LCC04HCPTraversal.h:117
TraversalOption getTraversalType() const override
Return a enum representing the name of the traversal class.
Definition: LCC04HCPTraversal.h:54
bool isApplicableToDomain() const override
Checks if the traversal is applicable to the current state of the domain.
Definition: LCC04HCPTraversal.h:56
void setSoASortingThreshold(size_t soaSortingThreshold) override
Set the SoA sorting-threshold for traversals that use the CellFunctor.
Definition: LCC04HCPTraversal.h:73
This class provides the base for traversals using the c08 base step.
Definition: LCC08CellHandler.h:27
void setAoSSortingThreshold(size_t aosSortingThreshold)
Set the aos-sorting-threshold for traversals that use the CellFunctor If the sum of the number of par...
Definition: LCC08CellHandler.h:87
void setSoASortingThreshold(size_t soaSortingThreshold)
Set the SoA sorting-threshold for traversals that use the CellFunctor.
Definition: LCC08CellHandler.h:91
Interface for traversals used by the LinkedCell class.
Definition: LCTraversalInterface.h:18
PairwiseFunctor class.
Definition: PairwiseFunctor.h:45
Class for Cells of Particles.
Definition: ParticleCell.h:49
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:64
constexpr T threeToOneD(T x, T y, T z, const std::array< T, 3 > &dims)
Convert a 3d index to a 1d index.
Definition: ThreeDimensionalMapping.h:29
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34