AutoPas  3.0.0
Loading...
Searching...
No Matches
SlicedBasedTraversal.h
Go to the documentation of this file.
1
8#pragma once
9
14#include "autopas/utils/Timer.h"
16
17namespace autopas {
18
29template <class ParticleCell, class Functor>
30class SlicedBasedTraversal : public CellTraversal<ParticleCell>, public TraversalInterface {
31 public:
44 explicit SlicedBasedTraversal(const std::array<unsigned long, 3> &dims, Functor *functor,
45 const double interactionLength, const std::array<double, 3> &cellLength,
46 DataLayoutOption dataLayout, bool useNewton3, bool spaciallyForward)
48 TraversalInterface(dataLayout, useNewton3),
49 _overlap{},
51 _interactionLength(interactionLength),
52 _cellLength(cellLength),
55 _spaciallyForward(spaciallyForward),
56 _dataLayoutConverter(functor, dataLayout) {
57 this->init(dims);
58 }
59
64 [[nodiscard]] bool isApplicable() const override {
65 auto minSliceThickness = _overlapLongestAxis + 1;
66 auto maxNumSlices = this->_cellsPerDimension[_dimsPerLength[0]] / minSliceThickness;
67 return maxNumSlices > 0;
68 }
69
74 virtual void initSliceThickness(unsigned long minSliceThickness) {
75 auto numSlices = this->_cellsPerDimension[_dimsPerLength[0]] / minSliceThickness;
76 _sliceThickness.clear();
77
78 // abort if domain is too small -> cleared _sliceThickness array indicates non applicability
79 if (numSlices < 1) return;
80
81 _sliceThickness.insert(_sliceThickness.begin(), numSlices, minSliceThickness);
82 auto rest = this->_cellsPerDimension[_dimsPerLength[0]] - _sliceThickness[0] * numSlices;
83 // remaining slices to distribute the remaining layers on
84 auto remSlices = std::min(rest, numSlices);
85 for (size_t i = 0; i < remSlices; ++i) {
86 _sliceThickness[i] += rest / (remSlices - i);
87 rest -= rest / (remSlices - i);
88 }
90 // decreases last _sliceThickness by _overlapLongestAxis to account for the way we handle base cells
92 }
93 }
94
98 void initTraversal() override {
100 // split domain across its longest dimension
101 auto minSliceThickness = _overlapLongestAxis + 1;
102 initSliceThickness(minSliceThickness);
103 }
104
108 void endTraversal() override {
109 if (this->_cells) {
110 auto &cells = *(this->_cells);
112 AUTOPAS_OPENMP(parallel for)
113 for (size_t i = 0; i < cells.size(); ++i) {
114 _dataLayoutConverter.storeDataLayout(cells[i]);
115 }
116 }
117 }
118
119 protected:
124 void init(const std::array<unsigned long, 3> &dims);
125
129 virtual void loadDataLayout() {
130 if (this->_cells) {
131 auto &cells = *(this->_cells);
133 AUTOPAS_OPENMP(parallel for)
134 for (size_t i = 0; i < cells.size(); ++i) {
135 _dataLayoutConverter.loadDataLayout(cells[i]);
136 }
137 }
138 }
142 std::array<unsigned long, 3> _overlap;
143
147 std::array<int, 3> _dimsPerLength;
148
152 unsigned long _overlapLongestAxis;
153
157 std::vector<unsigned long> _sliceThickness;
158
163
164 private:
168 double _interactionLength;
169
173 std::array<double, 3> _cellLength;
174
178 utils::DataLayoutConverter<Functor> _dataLayoutConverter;
179};
180
181template <class ParticleCell, class Functor>
182inline void SlicedBasedTraversal<ParticleCell, Functor>::init(const std::array<unsigned long, 3> &dims) {
183 for (unsigned int d = 0; d < 3; d++) {
184 _overlap[d] = std::ceil(_interactionLength / _cellLength[d]);
185 if (not _spaciallyForward) {
186 // there is potentially overlap in both directions.
187 _overlap[d] *= 2;
188 }
189 }
190
191 // find longest dimension
192 auto minMaxElem = std::minmax_element(this->_cellsPerDimension.begin(), this->_cellsPerDimension.end());
193 _dimsPerLength[0] = (int)std::distance(this->_cellsPerDimension.begin(), minMaxElem.second);
194 _dimsPerLength[2] = (int)std::distance(this->_cellsPerDimension.begin(), minMaxElem.first);
195 _dimsPerLength[1] = 3 - (_dimsPerLength[0] + _dimsPerLength[2]);
196
197 _overlapLongestAxis = _overlap[_dimsPerLength[0]];
198}
199
200} // namespace autopas
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
A cell pair traversal.
Definition: CellTraversal.h:23
std::vector< ParticleCell > * _cells
The cells to traverse.
Definition: CellTraversal.h:60
std::array< unsigned long, 3 > _cellsPerDimension
The dimensions of the cellblock.
Definition: CellTraversal.h:55
Functor base class.
Definition: Functor.h:40
Class for Cells of Particles.
Definition: ParticleCell.h:51
This class provides base for locked- and colored sliced traversals.
Definition: SlicedBasedTraversal.h:30
void initTraversal() override
Load Data Layouts and sets up slice thicknesses.
Definition: SlicedBasedTraversal.h:98
std::array< unsigned long, 3 > _overlap
Overlap of interacting cells.
Definition: SlicedBasedTraversal.h:142
std::array< int, 3 > _dimsPerLength
Store ids of dimensions ordered by number of cells per dimensions.
Definition: SlicedBasedTraversal.h:147
std::vector< unsigned long > _sliceThickness
The number of cells per slice in the dimension that was sliced.
Definition: SlicedBasedTraversal.h:157
virtual void loadDataLayout()
Load Data Layouts required for this Traversal if cells have been set through setCellsToTraverse().
Definition: SlicedBasedTraversal.h:129
virtual void initSliceThickness(unsigned long minSliceThickness)
Sets up the slice thicknesses to create as many slices as possible while respecting minSliceThickness...
Definition: SlicedBasedTraversal.h:74
bool _spaciallyForward
Whether the base step only covers neigboring cells tha are spacially forward (for example c08).
Definition: SlicedBasedTraversal.h:162
unsigned long _overlapLongestAxis
Overlap of interacting cells along the longest axis.
Definition: SlicedBasedTraversal.h:152
bool isApplicable() const override
Checks if the traversal is applicable to the current state of the domain.
Definition: SlicedBasedTraversal.h:64
void endTraversal() override
Write Data to AoS if cells have been set through setCellsToTraverse().
Definition: SlicedBasedTraversal.h:108
void init(const std::array< unsigned long, 3 > &dims)
Resets the cell structure of the traversal.
Definition: SlicedBasedTraversal.h:182
SlicedBasedTraversal(const std::array< unsigned long, 3 > &dims, Functor *functor, const double interactionLength, const std::array< double, 3 > &cellLength, DataLayoutOption dataLayout, bool useNewton3, bool spaciallyForward)
Constructor of the sliced traversal.
Definition: SlicedBasedTraversal.h:44
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
This converts cells to the target data Layout using the given functor.
Definition: DataLayoutConverter.h:19
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32