AutoPas  3.0.0
Loading...
Searching...
No Matches
LCC08CellHandler.h
Go to the documentation of this file.
1
7#pragma once
8
13
14namespace autopas {
15
26template <class ParticleCell_T, class Functor_T>
28 public:
41 explicit LCC08CellHandler(Functor_T &functor, const std::array<unsigned long, 3> &cellsPerDimension,
42 double interactionLength, const std::array<double, 3> &cellLength,
43 const std::array<unsigned long, 3> &overlap, DataLayoutOption dataLayout, bool useNewton3)
44 : _overlap(overlap),
45 _dataLayout(dataLayout),
46 _useNewton3(useNewton3),
47 _cellFunctor(functor, interactionLength /*should use cutoff here, if not used to build verlet-lists*/,
48 dataLayout, useNewton3),
49 _interactionLength(interactionLength),
50 _cellLength(cellLength) {
53 LCC08CellHandlerUtility::computePairwiseCellOffsetsC08<LCC08CellHandlerUtility::C08OffsetMode::sorting>(
54 cellsPerDimension, cellLength, interactionLength);
55 } else if constexpr (utils::isTriwiseFunctor<Functor_T>()) {
57 LCC08CellHandlerUtility::computeTriwiseCellOffsetsC08<LCC08CellHandlerUtility::C08OffsetMode::sorting>(
58 cellsPerDimension, cellLength, interactionLength);
59 } else {
60 utils::ExceptionHandler::exception("LCC08CellHandler::LCC08CellHandler(): Functor is not valid.");
61 }
62 }
63
70 void processBaseCell(std::vector<ParticleCell_T> &cells, unsigned long baseIndex);
71
76 inline void processBaseCellPairwise(std::vector<ParticleCell_T> &cells, unsigned long baseIndex);
77
82 inline void processBaseCellTriwise(std::vector<ParticleCell_T> &cells, unsigned long baseIndex);
83
87 void setAoSSortingThreshold(size_t aosSortingThreshold) { _cellFunctor.setAoSSortingThreshold(aosSortingThreshold); }
91 void setSoASortingThreshold(size_t soaSortingThreshold) { _cellFunctor.setSoASortingThreshold(soaSortingThreshold); }
92
93 protected:
98 std::conditional_t<decltype(utils::isPairwiseFunctor<Functor_T>())::value,
100
105 std::vector<CellOffsetType> _cellOffsets;
106
110 const std::array<unsigned long, 3> _overlap;
111
115 DataLayoutOption _dataLayout;
116
121
122 private:
123 // CellFunctor type for either Pairwise or Triwise Functors.
124 using CellFunctorType =
125 std::conditional_t<decltype(utils::isPairwiseFunctor<Functor_T>())::value,
128
132 CellFunctorType _cellFunctor;
133
137 const double _interactionLength;
138
142 const std::array<double, 3> _cellLength;
143};
144
145template <class ParticleCell_T, class Functor_T>
146inline void LCC08CellHandler<ParticleCell_T, Functor_T>::processBaseCell(std::vector<ParticleCell_T> &cells,
147 unsigned long baseIndex) {
148 if constexpr (utils::isPairwiseFunctor<Functor_T>()) {
149 processBaseCellPairwise(cells, baseIndex);
150 } else if constexpr (utils::isTriwiseFunctor<Functor_T>()) {
151 processBaseCellTriwise(cells, baseIndex);
152 } else {
154 "LCC08CellHandler::processBaseCell(): Given Functor type is not of type PairwiseFunctor or TriwiseFunctor.");
155 }
156}
157
158template <class ParticleCell_T, class Functor_T>
159inline void LCC08CellHandler<ParticleCell_T, Functor_T>::processBaseCellPairwise(std::vector<ParticleCell_T> &cells,
160 unsigned long baseIndex) {
161 for (auto const &[offset1, offset2, r] : _cellOffsets) {
162 const unsigned long cellIndex1 = baseIndex + offset1;
163 const unsigned long cellIndex2 = baseIndex + offset2;
164
165 ParticleCell_T &cell1 = cells[cellIndex1];
166 ParticleCell_T &cell2 = cells[cellIndex2];
167
168 if (cellIndex1 == cellIndex2) {
169 this->_cellFunctor.processCell(cell1);
170 } else {
171 this->_cellFunctor.processCellPair(cell1, cell2, r);
172 }
173 }
174}
175
176template <class ParticleCell_T, class Functor_T>
177inline void LCC08CellHandler<ParticleCell_T, Functor_T>::processBaseCellTriwise(std::vector<ParticleCell_T> &cells,
178 unsigned long baseIndex) {
179 for (auto const &[offset1, offset2, offset3, r] : _cellOffsets) {
180 const unsigned long index1 = baseIndex + offset1;
181 const unsigned long index2 = baseIndex + offset2;
182 const unsigned long index3 = baseIndex + offset3;
183
184 ParticleCell_T &cell1 = cells[index1];
185 ParticleCell_T &cell2 = cells[index2];
186 ParticleCell_T &cell3 = cells[index3];
187
188 if (index1 == index2 and index1 == index3) {
189 this->_cellFunctor.processCell(cell1);
190 } else if (index1 == index2 and index1 != index3) {
191 this->_cellFunctor.processCellPair(cell1, cell3, r);
192 } else if (index1 != index2 and (index1 == index3 or index2 == index3)) {
193 this->_cellFunctor.processCellPair(cell1, cell2, r);
194 } else {
195 this->_cellFunctor.processCellTriple(cell1, cell2, cell3, r);
196 }
197 }
198}
199
200} // namespace autopas
This class provides the base for traversals using the c08 base step.
Definition: LCC08CellHandler.h:27
std::conditional_t< decltype(utils::isPairwiseFunctor< Functor_T >())::value, LCC08CellHandlerUtility::OffsetPairSorting, LCC08CellHandlerUtility::OffsetTripletSorting > CellOffsetType
CellOffset needs to store interaction pairs or triplets depending on the Functor type.
Definition: LCC08CellHandler.h:99
void setAoSSortingThreshold(size_t aosSortingThreshold)
Set the aos-sorting-threshold for traversals that use the CellFunctor If the sum of the number of par...
Definition: LCC08CellHandler.h:87
const std::array< unsigned long, 3 > _overlap
Overlap of interacting cells.
Definition: LCC08CellHandler.h:110
void setSoASortingThreshold(size_t soaSortingThreshold)
Set the SoA sorting-threshold for traversals that use the CellFunctor.
Definition: LCC08CellHandler.h:91
LCC08CellHandler(Functor_T &functor, const std::array< unsigned long, 3 > &cellsPerDimension, double interactionLength, const std::array< double, 3 > &cellLength, const std::array< unsigned long, 3 > &overlap, DataLayoutOption dataLayout, bool useNewton3)
Constructor of the LCC08CellHandler.
Definition: LCC08CellHandler.h:41
DataLayoutOption _dataLayout
The datalayout to be used.
Definition: LCC08CellHandler.h:115
void processBaseCell(std::vector< ParticleCell_T > &cells, unsigned long baseIndex)
Computes one interaction for each spacial direction based on the lower left frontal corner (=base ind...
Definition: LCC08CellHandler.h:146
void processBaseCellPairwise(std::vector< ParticleCell_T > &cells, unsigned long baseIndex)
Pairwise implementation of processBaseCell().
Definition: LCC08CellHandler.h:159
bool _useNewton3
If newton3 should be used or not.
Definition: LCC08CellHandler.h:120
void processBaseCellTriwise(std::vector< ParticleCell_T > &cells, unsigned long baseIndex)
Triwise implementation of processBaseCell().
Definition: LCC08CellHandler.h:177
std::vector< CellOffsetType > _cellOffsets
Pair sets for processBaseCell().
Definition: LCC08CellHandler.h:105
A cell functor.
Definition: CellFunctor3B.h:24
A cell functor.
Definition: CellFunctor.h:29
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:64
std::tuple< unsigned long, unsigned long, std::array< double, 3 > > OffsetPairSorting
Type Alias for the C08 base step containing cell offsets.
Definition: LCC08CellHandlerUtility.h:27
std::tuple< unsigned long, unsigned long, unsigned long, std::array< double, 3 > > OffsetTripletSorting
Type Alias for the C08 base step containing cell offsets for cell triplets.
Definition: LCC08CellHandlerUtility.h:39
decltype(isTriwiseFunctorImpl(std::declval< FunctorT >())) isTriwiseFunctor
Check whether a Functor Type is inheriting from TriwiseFunctor.
Definition: checkFunctorType.h:56
decltype(isPairwiseFunctorImpl(std::declval< FunctorT >())) isPairwiseFunctor
Check whether a Functor Type is inheriting from PairwiseFunctor.
Definition: checkFunctorType.h:49
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34