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 isApplicable() 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 setSortingThreshold(size_t sortingThreshold) override { _cellHandler.setSortingThreshold(sortingThreshold); }
68
69 private:
70 void traverseSingleColor(std::vector<ParticleCell> &cells, int color);
71
72 void processBasePack6(std::vector<ParticleCell> &cells, const std::array<long, 3> &base3DIndex);
73
75
76 const std::array<long, 3> _end;
77};
78
79template <class ParticleCell, class PairwiseFunctor>
80void LCC04HCPTraversal<ParticleCell, PairwiseFunctor>::processBasePack6(std::vector<ParticleCell> &cells,
81 const std::array<long, 3> &base3DIndex) {
83 std::array<long, 3> index{};
84 const std::array<long, 3> signedDims = utils::ArrayUtils::static_cast_copy_array<long>(this->_cellsPerDimension);
85
86 // go through the six cells
87 for (long z = 0; z < 3; ++z) {
88 for (long x = 0; x < 2; ++x) {
89 index[0] = base3DIndex[0] + x;
90 index[1] = base3DIndex[1];
91 index[2] = base3DIndex[2] + z;
92
93 bool isIn = true;
94 for (int d = 0; d < 3; ++d) {
95 // prevent using overlapping cells and cells outside the boundaries
96 isIn &= (index[d] >= 0l) and (index[d] <= (_end[d] - this->_overlap[d]));
97 }
98
99 // skip cells outside radius
100 if (isIn) {
101 const unsigned long ulIndex = threeToOneD(index, signedDims);
102 _cellHandler.processBaseCell(cells, ulIndex);
103 }
104 }
105 }
106}
107
108template <class ParticleCell, class PairwiseFunctor>
110 auto &cells = *(this->_cells);
111 AUTOPAS_OPENMP(parallel) {
112 for (int color = 0; color < 4; ++color) {
113 traverseSingleColor(cells, color);
114
115 if (color < 3) {
116 AUTOPAS_OPENMP(barrier)
117 }
118 }
119 } // close parallel region
120}
121
131template <class ParticleCell, class PairwiseFunctor>
133 int color) {
134 // determine a starting point of one of the grids
135 std::array<long, 3> startOfThisColor{}; // coordinates: {x,y,z}
136
137 // different starting points for different colors
138 // some colors are starting outside the grid because only part of their cuboids are part of the grid
139 // this way the starting points of sticking out cuboids can be determined as well
140 switch (color) {
141 case 0:
142 startOfThisColor = {0l, 0l, 0l};
143 break;
144 case 1:
145 startOfThisColor = {-4l, 0l, 1l};
146 break;
147 case 2:
148 startOfThisColor = {-4l, 0l, -2l};
149 break;
150 case 3:
151 startOfThisColor = {-2l, 0l, -1l};
152 break;
153 default:
154 autopas::utils::ExceptionHandler::exception("LCC04HCPTraversal::traverseSingleColor: invalid color ({})", color);
155 }
156
157 // to fix intel64 icpc compiler complaints about perfectly nested loop.
158 const long startX = startOfThisColor[0], endX = _end[0];
159 const long startY = startOfThisColor[1], endY = _end[1];
160 const long startZ = startOfThisColor[2], endZ = _end[2];
161
162 // iterate over cartesian grid
163 AUTOPAS_OPENMP(for schedule(dynamic, 1) collapse(3) nowait)
164 for (long z = startZ; z < endZ; z += 4) {
165 for (long y = startY; y < endY; y++) {
166 /* color starts every 6th column again, the +4 is needed to prevent ending too early, since it
167 will be shifted back inside the loop */
168 for (long x = startX; x < (endX + 4); x += 6) {
169 long x_index = x;
170 /* shift on x-axis according to z-value: shift two times and then go back to original x-value
171 first: no shift
172 second: -4 shift
173 third: -2 shift
174 fourth: go back to first
175 every 12th z, the shifting pattern repeats again at the origin of x without shift,
176 because z is shifted by 4 in every loop run and every third z-shift the pattern repeats
177 */
178 switch ((z - startZ) % 12 / 4) {
179 case 0:
180 break;
181 case 1:
182 x_index -= 4;
183 break;
184 case 2:
185 x_index -= 2;
186 break;
187 default:
188 break;
189 }
190 // shift x-axis every second y-row
191 if ((y - startY) % 2 != 0) {
192 x_index += 3;
193 }
194 processBasePack6(cells, {x_index, y, z});
195 }
196 }
197 }
198}
199
200} // 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:55
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 traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: LCC04HCPTraversal.h:109
TraversalOption getTraversalType() const override
Return a enum representing the name of the traversal class.
Definition: LCC04HCPTraversal.h:54
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: LCC04HCPTraversal.h:67
bool isApplicable() const override
Checks if the traversal is applicable to the current state of the domain.
Definition: LCC04HCPTraversal.h:56
This class provides the base for traversals using the c08 base step.
Definition: LCC08CellHandler.h:28
Interface for traversals used by the LinkedCell class.
Definition: LCTraversalInterface.h:18
PairwiseFunctor class.
Definition: PairwiseFunctor.h:31
Class for Cells of Particles.
Definition: ParticleCell.h:51
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
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:32