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; }
78 void setSortingThreshold(
size_t sortingThreshold)
override { _cellFunctor.setSortingThreshold(sortingThreshold); }
84 void computeOffsets();
98 using offsetArray_t = std::vector<std::pair<unsigned long, std::array<double, 3>>>;
103 std::vector<std::vector<offsetArray_t>> _cellOffsets;
111 unsigned long getIndex(
const unsigned long pos,
const unsigned int dim)
const;
114template <
class ParticleCell,
class PairwiseFunctor>
115inline void LCC18Traversal<ParticleCell, PairwiseFunctor>::computeOffsets() {
116 _cellOffsets.resize(2 * this->_overlap[1] + 1, std::vector<offsetArray_t>(2 * this->_overlap[0] + 1));
117 const std::array<long, 3> _overlap_s = utils::ArrayUtils::static_cast_copy_array<long>(this->_overlap);
119 const auto interactionLengthSquare(this->_interactionLength * this->_interactionLength);
121 for (
long z = 0l; z <= _overlap_s[2]; ++z) {
122 for (
long y = -_overlap_s[1]; y <= _overlap_s[1]; ++y) {
123 for (
long x = -_overlap_s[0]; x <= _overlap_s[0]; ++x) {
125 x, y, z, utils::ArrayUtils::static_cast_copy_array<long>(this->_cellsPerDimension));
131 for (
long yArray = -_overlap_s[1]; yArray <= _overlap_s[1]; ++yArray) {
132 if (std::abs(yArray + y) <= _overlap_s[1]) {
133 for (
long xArray = -_overlap_s[0]; xArray <= _overlap_s[0]; ++xArray) {
134 if (std::abs(xArray + x) <= _overlap_s[0]) {
135 const std::array<double, 3> pos = {
136 std::max(0l, (std::abs(x) - 1l)) * this->_cellLength[0],
137 std::max(0l, (std::abs(y) - 1l)) * this->_cellLength[1],
138 std::max(0l, (std::abs(z) - 1l)) * this->_cellLength[2],
143 if (distSquare <= interactionLengthSquare) {
149 std::array<double, 3> sortingDir = {
static_cast<double>(x) * this->_cellLength[0],
150 static_cast<double>(y) * this->_cellLength[1],
151 static_cast<double>(z) * this->_cellLength[2]};
152 if (x == 0 and y == 0 and z == 0) {
153 sortingDir = {1., 1., 1.};
156 _cellOffsets[yArray + _overlap_s[1]][xArray + _overlap_s[0]].push_back(
168template <
class ParticleCell,
class PairwiseFunctor>
169unsigned long LCC18Traversal<ParticleCell, PairwiseFunctor>::getIndex(
const unsigned long pos,
170 const unsigned int dim)
const {
172 if (pos < this->_overlap[dim]) {
174 }
else if (pos < this->_cellsPerDimension[dim] - this->_overlap[dim]) {
175 index = this->_overlap[dim];
177 index = pos - this->_cellsPerDimension[dim] + 2 * this->_overlap[dim] + 1ul;
182template <
class ParticleCell,
class PairwiseFunctor>
184 unsigned long y,
unsigned long z) {
187 const unsigned long xArray = getIndex(x, 0);
188 const unsigned long yArray = getIndex(y, 1);
191 offsetArray_t &offsets = this->_cellOffsets[yArray][xArray];
192 for (
auto const &[offset, r] : offsets) {
193 unsigned long otherIndex = baseIndex + offset;
196 if (baseIndex == otherIndex) {
197 this->_cellFunctor.processCell(baseCell);
199 this->_cellFunctor.processCellPair(baseCell, otherCell, r);
204template <
class ParticleCell,
class PairwiseFunctor>
206 auto &cells = *(this->_cells);
207 this->
template c18Traversal<
false>(
208 [&](
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 setSortingThreshold(size_t sortingThreshold) override
Set the sorting-threshold for traversals that use the CellFunctor If the sum of the number of particl...
Definition: LCC18Traversal.h:78
bool isApplicable() const override
C18 traversal is always usable.
Definition: LCC18Traversal.h:73
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: LCC18Traversal.h:205
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
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:183
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
A cell functor.
Definition: CellFunctor.h:25
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:32