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 setAoSSortingThresholds(const SortingThresholdInfoInterface &aosSortingThreshold) override {
68 _cellHandler.setAoSSortingThresholds(aosSortingThreshold);
69 }
70
74 void setSoASortingThresholds(const SortingThresholdInfoInterface &soaSortingThreshold) override {
75 _cellHandler.setSoASortingThresholds(soaSortingThreshold);
76 }
77
78 private:
79 void traverseSingleColor(std::vector<ParticleCell> &cells, int color);
80
81 void processBasePack6(std::vector<ParticleCell> &cells, const std::array<long, 3> &base3DIndex);
82
84
85 const std::array<long, 3> _end;
86};
87
88template <class ParticleCell, class PairwiseFunctor>
89void LCC04HCPTraversal<ParticleCell, PairwiseFunctor>::processBasePack6(std::vector<ParticleCell> &cells,
90 const std::array<long, 3> &base3DIndex) {
92 std::array<long, 3> index{};
93 const std::array<long, 3> signedDims = utils::ArrayUtils::static_cast_copy_array<long>(this->_cellsPerDimension);
94
95 // go through the six cells
96 for (long z = 0; z < 3; ++z) {
97 for (long x = 0; x < 2; ++x) {
98 index[0] = base3DIndex[0] + x;
99 index[1] = base3DIndex[1];
100 index[2] = base3DIndex[2] + z;
101
102 bool isIn = true;
103 for (int d = 0; d < 3; ++d) {
104 // prevent using overlapping cells and cells outside the boundaries
105 isIn &= (index[d] >= 0l) and (index[d] <= (_end[d] - this->_overlap[d]));
106 }
107
108 // skip cells outside radius
109 if (isIn) {
110 const unsigned long ulIndex = threeToOneD(index, signedDims);
111 _cellHandler.processBaseCell(cells, ulIndex);
112 }
113 }
114 }
115}
116
117template <class ParticleCell, class PairwiseFunctor>
119 auto &cells = *(this->_cells);
120 AUTOPAS_OPENMP(parallel) {
121 for (int color = 0; color < 4; ++color) {
122 traverseSingleColor(cells, color);
123
124 if (color < 3) {
125 AUTOPAS_OPENMP(barrier)
126 }
127 }
128 } // close parallel region
129}
130
140template <class ParticleCell, class PairwiseFunctor>
142 int color) {
143 // determine a starting point of one of the grids
144 std::array<long, 3> startOfThisColor{}; // coordinates: {x,y,z}
145
146 // different starting points for different colors
147 // some colors are starting outside the grid because only part of their cuboids are part of the grid
148 // this way the starting points of sticking out cuboids can be determined as well
149 switch (color) {
150 case 0:
151 startOfThisColor = {0l, 0l, 0l};
152 break;
153 case 1:
154 startOfThisColor = {-4l, 0l, 1l};
155 break;
156 case 2:
157 startOfThisColor = {-4l, 0l, -2l};
158 break;
159 case 3:
160 startOfThisColor = {-2l, 0l, -1l};
161 break;
162 default:
163 autopas::utils::ExceptionHandler::exception("LCC04HCPTraversal::traverseSingleColor: invalid color ({})", color);
164 }
165
166 // to fix intel64 icpc compiler complaints about perfectly nested loop.
167 const long startX = startOfThisColor[0], endX = _end[0];
168 const long startY = startOfThisColor[1], endY = _end[1];
169 const long startZ = startOfThisColor[2], endZ = _end[2];
170
171 // iterate over cartesian grid
172 AUTOPAS_OPENMP(for schedule(dynamic, 1) collapse(3) nowait)
173 for (long z = startZ; z < endZ; z += 4) {
174 for (long y = startY; y < endY; y++) {
175 /* color starts every 6th column again, the +4 is needed to prevent ending too early, since it
176 will be shifted back inside the loop */
177 for (long x = startX; x < (endX + 4); x += 6) {
178 long x_index = x;
179 /* shift on x-axis according to z-value: shift two times and then go back to original x-value
180 first: no shift
181 second: -4 shift
182 third: -2 shift
183 fourth: go back to first
184 every 12th z, the shifting pattern repeats again at the origin of x without shift,
185 because z is shifted by 4 in every loop run and every third z-shift the pattern repeats
186 */
187 switch ((z - startZ) % 12 / 4) {
188 case 0:
189 break;
190 case 1:
191 x_index -= 4;
192 break;
193 case 2:
194 x_index -= 2;
195 break;
196 default:
197 break;
198 }
199 // shift x-axis every second y-row
200 if ((y - startY) % 2 != 0) {
201 x_index += 3;
202 }
203 processBasePack6(cells, {x_index, y, z});
204 }
205 }
206 }
207}
208
209} // 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:70
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
void setSoASortingThresholds(const SortingThresholdInfoInterface &soaSortingThreshold) override
Set the SoA sorting-threshold for traversals that use the CellFunctor.
Definition: LCC04HCPTraversal.h:74
void setAoSSortingThresholds(const SortingThresholdInfoInterface &aosSortingThreshold) override
Set the aos-sorting-threshold for traversals that use the CellFunctor.
Definition: LCC04HCPTraversal.h:67
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:118
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
This class provides the base for traversals using the c08 base step.
Definition: LCC08CellHandler.h:28
void setAoSSortingThresholds(const SortingThresholdInfoInterface &aosSortingThreshold)
Set the aos-sorting-threshold for traversals that use the CellFunctor.
Definition: LCC08CellHandler.h:88
void setSoASortingThresholds(const SortingThresholdInfoInterface &soaSortingThreshold)
Set the SoA sorting-threshold for traversals that use the CellFunctor.
Definition: LCC08CellHandler.h:95
Interface for traversals used by the LinkedCell class.
Definition: LCTraversalInterface.h:18
PairwiseFunctor class.
Definition: PairwiseFunctor.h:66
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
Polymorphic base for sorting-threshold storage.
Definition: SortingThresholdInfoInterface.h:18