30template <
class ParticleCell,
class PairwiseFunctor>
46 const double interactionLength,
const std::array<double, 3> &cellLength,
47 DataLayoutOption dataLayout,
bool useNewton3)
49 dataLayout, useNewton3),
50 _cellFunctor(pairwiseFunctor, interactionLength ,
51 dataLayout, useNewton3) {
65 void processBaseCell(std::vector<ParticleCell> &cells,
unsigned long x,
unsigned long y,
unsigned long z);
67 [[nodiscard]] TraversalOption
getTraversalType()
const override {
return TraversalOption::lc_c18; }
79 _cellFunctor.setAoSSortingThreshold(aosSortingThreshold);
85 _cellFunctor.setSoASortingThreshold(soaSortingThreshold);
92 void computeOffsets();
106 using offsetArray_t = std::vector<std::pair<unsigned long, std::array<double, 3>>>;
111 std::vector<std::vector<offsetArray_t>> _cellOffsets;
119 unsigned long getIndex(
const unsigned long pos,
const unsigned int dim)
const;
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);
127 const auto interactionLengthSquare(this->_interactionLength * this->_interactionLength);
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));
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],
151 if (distSquare <= interactionLengthSquare) {
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.};
164 _cellOffsets[yArray + _overlap_s[1]][xArray + _overlap_s[0]].push_back(
176template <
class ParticleCell,
class PairwiseFunctor>
177unsigned long LCC18Traversal<ParticleCell, PairwiseFunctor>::getIndex(
const unsigned long pos,
178 const unsigned int dim)
const {
180 if (pos < this->_overlap[dim]) {
182 }
else if (pos < this->_cellsPerDimension[dim] - this->_overlap[dim]) {
183 index = this->_overlap[dim];
185 index = pos - this->_cellsPerDimension[dim] + 2 * this->_overlap[dim] + 1ul;
190template <
class ParticleCell,
class PairwiseFunctor>
192 unsigned long y,
unsigned long z) {
195 const unsigned long xArray = getIndex(x, 0);
196 const unsigned long yArray = getIndex(y, 1);
199 offsetArray_t &offsets = this->_cellOffsets[yArray][xArray];
200 for (
auto const &[offset, r] : offsets) {
201 unsigned long otherIndex = baseIndex + offset;
204 if (baseIndex == otherIndex) {
205 this->_cellFunctor.processCell(baseCell);
207 this->_cellFunctor.processCellPair(baseCell, otherCell, r);
212template <
class ParticleCell,
class PairwiseFunctor>
214 auto &cells = *(this->_cells);
215 this->
template c18Traversal<
false>(
216 [&](
unsigned long x,
unsigned long y,
unsigned long z) { this->processBaseCell(cells, x, y, z); });
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