AutoPas  3.0.0
Loading...
Searching...
No Matches
LCC18Traversal.h
Go to the documentation of this file.
1
7#pragma once
8
16
17namespace autopas {
18
30template <class ParticleCell, class PairwiseFunctor>
31class LCC18Traversal : public C18BasedTraversal<ParticleCell, PairwiseFunctor>, public LCTraversalInterface {
32 public:
45 explicit LCC18Traversal(const std::array<unsigned long, 3> &dims, PairwiseFunctor &pairwiseFunctor,
46 const double interactionLength, const std::array<double, 3> &cellLength,
47 DataLayoutOption dataLayout, bool useNewton3)
48 : C18BasedTraversal<ParticleCell, PairwiseFunctor>(dims, pairwiseFunctor, interactionLength, cellLength,
49 dataLayout, useNewton3),
50 _cellFunctor(pairwiseFunctor, interactionLength /*should use cutoff here, if not used to build verlet-lists*/,
51 dataLayout, useNewton3) {
52 computeOffsets();
53 }
54
55 void traverseParticles() override;
56
65 void processBaseCell(std::vector<ParticleCell> &cells, unsigned long x, unsigned long y, unsigned long z);
66
67 [[nodiscard]] TraversalOption getTraversalType() const override { return TraversalOption::lc_c18; }
68
73 [[nodiscard]] bool isApplicableToDomain() const override { return true; }
74
78 void setAoSSortingThreshold(size_t aosSortingThreshold) override {
79 _cellFunctor.setAoSSortingThreshold(aosSortingThreshold);
80 }
84 void setSoASortingThreshold(size_t soaSortingThreshold) override {
85 _cellFunctor.setSoASortingThreshold(soaSortingThreshold);
86 }
87
88 private:
92 void computeOffsets();
93
98 /*bidirectional*/ true>
99 _cellFunctor;
100
106 using offsetArray_t = std::vector<std::pair<unsigned long, std::array<double, 3>>>;
107
111 std::vector<std::vector<offsetArray_t>> _cellOffsets;
112
119 unsigned long getIndex(const unsigned long pos, const unsigned int dim) const;
120};
121
122template <class ParticleCell, class PairwiseFunctor>
123inline void LCC18Traversal<ParticleCell, PairwiseFunctor>::computeOffsets() {
124 _cellOffsets.resize(2 * this->_overlap[1] + 1, std::vector<offsetArray_t>(2 * this->_overlap[0] + 1));
125 const std::array<long, 3> _overlap_s = utils::ArrayUtils::static_cast_copy_array<long>(this->_overlap);
126
127 const auto interactionLengthSquare(this->_interactionLength * this->_interactionLength);
128
129 for (long z = 0l; z <= _overlap_s[2]; ++z) {
130 for (long y = -_overlap_s[1]; y <= _overlap_s[1]; ++y) {
131 for (long x = -_overlap_s[0]; x <= _overlap_s[0]; ++x) {
133 x, y, z, utils::ArrayUtils::static_cast_copy_array<long>(this->_cellsPerDimension));
134
135 if (offset < 0l) {
136 continue;
137 }
138 // add to each applicable special case
139 for (long yArray = -_overlap_s[1]; yArray <= _overlap_s[1]; ++yArray) {
140 if (std::abs(yArray + y) <= _overlap_s[1]) {
141 for (long xArray = -_overlap_s[0]; xArray <= _overlap_s[0]; ++xArray) {
142 if (std::abs(xArray + x) <= _overlap_s[0]) {
143 const std::array<double, 3> pos = {
144 std::max(0l, (std::abs(x) - 1l)) * this->_cellLength[0],
145 std::max(0l, (std::abs(y) - 1l)) * this->_cellLength[1],
146 std::max(0l, (std::abs(z) - 1l)) * this->_cellLength[2],
147 };
148 // calculate distance between the borders of the base cell and the other cell
149 const double distSquare = utils::ArrayMath::dot(pos, pos);
150 // only add cell offset if cell is within cutoff radius
151 if (distSquare <= interactionLengthSquare) {
152 // Calculate the sorting direction from the base cell and the other cell by use of the offset (x, y,
153 // z).
154 // Note: We have to calculate the sorting direction separately from pos, since pos is the offset
155 // between the borders of cells. For neighbouring cells this would be 0 and the sorting direction
156 // would be wrong.
157 std::array<double, 3> sortingDir = {static_cast<double>(x) * this->_cellLength[0],
158 static_cast<double>(y) * this->_cellLength[1],
159 static_cast<double>(z) * this->_cellLength[2]};
160 if (x == 0 and y == 0 and z == 0) {
161 sortingDir = {1., 1., 1.};
162 }
163
164 _cellOffsets[yArray + _overlap_s[1]][xArray + _overlap_s[0]].push_back(
165 std::make_pair(offset, utils::ArrayMath::normalize(sortingDir)));
166 }
167 }
168 }
169 }
170 }
171 }
172 }
173 }
174}
175
176template <class ParticleCell, class PairwiseFunctor>
177unsigned long LCC18Traversal<ParticleCell, PairwiseFunctor>::getIndex(const unsigned long pos,
178 const unsigned int dim) const {
179 unsigned long index;
180 if (pos < this->_overlap[dim]) {
181 index = pos;
182 } else if (pos < this->_cellsPerDimension[dim] - this->_overlap[dim]) {
183 index = this->_overlap[dim];
184 } else {
185 index = pos - this->_cellsPerDimension[dim] + 2 * this->_overlap[dim] + 1ul;
186 }
187 return index;
188}
189
190template <class ParticleCell, class PairwiseFunctor>
191void LCC18Traversal<ParticleCell, PairwiseFunctor>::processBaseCell(std::vector<ParticleCell> &cells, unsigned long x,
192 unsigned long y, unsigned long z) {
193 const unsigned long baseIndex = utils::ThreeDimensionalMapping::threeToOneD(x, y, z, this->_cellsPerDimension);
194
195 const unsigned long xArray = getIndex(x, 0);
196 const unsigned long yArray = getIndex(y, 1);
197
198 ParticleCell &baseCell = cells[baseIndex];
199 offsetArray_t &offsets = this->_cellOffsets[yArray][xArray];
200 for (auto const &[offset, r] : offsets) {
201 unsigned long otherIndex = baseIndex + offset;
202 ParticleCell &otherCell = cells[otherIndex];
203
204 if (baseIndex == otherIndex) {
205 this->_cellFunctor.processCell(baseCell);
206 } else {
207 this->_cellFunctor.processCellPair(baseCell, otherCell, r);
208 }
209 }
210}
211
212template <class ParticleCell, class PairwiseFunctor>
214 auto &cells = *(this->_cells);
215 this->template c18Traversal</*allCells*/ false>(
216 [&](unsigned long x, unsigned long y, unsigned long z) { this->processBaseCell(cells, x, y, z); });
217}
218
219} // namespace autopas
This class provides the base for traversals using the c18 base step.
Definition: C18BasedTraversal.h:23
This class provides the lc_c18 traversal.
Definition: LCC18Traversal.h:31
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: LCC18Traversal.h:78
bool isApplicableToDomain() const override
LC C18 is always applicable to the domain.
Definition: LCC18Traversal.h:73
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: LCC18Traversal.h:213
LCC18Traversal(const std::array< unsigned long, 3 > &dims, PairwiseFunctor &pairwiseFunctor, const double interactionLength, const std::array< double, 3 > &cellLength, DataLayoutOption dataLayout, bool useNewton3)
Constructor of the lc_c18 traversal.
Definition: LCC18Traversal.h:45
void setSoASortingThreshold(size_t soaSortingThreshold) override
Set the SoA sorting-threshold for traversals that use the CellFunctor.
Definition: LCC18Traversal.h:84
TraversalOption getTraversalType() const override
Return a enum representing the name of the traversal class.
Definition: LCC18Traversal.h:67
void processBaseCell(std::vector< ParticleCell > &cells, unsigned long x, unsigned long y, unsigned long z)
Computes all interactions between the base cell and adjacent cells with greater a ID.
Definition: LCC18Traversal.h:191
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
A cell functor.
Definition: CellFunctor.h:29
constexpr T dot(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
Generates the dot product of two arrays.
Definition: ArrayMath.h:233
constexpr std::array< T, SIZE > normalize(const std::array< T, SIZE > &a)
Generates a normalized array (|a| = 1).
Definition: ArrayMath.h:304
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