AutoPas  3.0.0
Loading...
Searching...
No Matches
LCC08CellHandler.h
Go to the documentation of this file.
1
7#pragma once
8
14
15namespace autopas {
16
27template <class ParticleCell_T, class Functor_T>
29 public:
42 explicit LCC08CellHandler(Functor_T &functor, const std::array<unsigned long, 3> &cellsPerDimension,
43 double interactionLength, const std::array<double, 3> &cellLength,
44 const std::array<unsigned long, 3> &overlap, DataLayoutOption dataLayout, bool useNewton3)
45 : _overlap(overlap),
46 _dataLayout(dataLayout),
47 _useNewton3(useNewton3),
48 _cellFunctor(functor, interactionLength /*should use cutoff here, if not used to build verlet-lists*/,
49 dataLayout, useNewton3),
50 _interactionLength(interactionLength),
51 _cellLength(cellLength) {
54 LCC08CellHandlerUtility::computePairwiseCellOffsetsC08<LCC08CellHandlerUtility::C08OffsetMode::sorting>(
55 cellsPerDimension, cellLength, interactionLength);
56 } else if constexpr (utils::isTriwiseFunctor<Functor_T>()) {
58 LCC08CellHandlerUtility::computeTriwiseCellOffsetsC08<LCC08CellHandlerUtility::C08OffsetMode::sorting>(
59 cellsPerDimension, cellLength, interactionLength);
60 } else {
61 utils::ExceptionHandler::exception("LCC08CellHandler::LCC08CellHandler(): Functor is not valid.");
62 }
63 }
64
71 void processBaseCell(std::vector<ParticleCell_T> &cells, unsigned long baseIndex);
72
77 inline void processBaseCellPairwise(std::vector<ParticleCell_T> &cells, unsigned long baseIndex);
78
83 inline void processBaseCellTriwise(std::vector<ParticleCell_T> &cells, unsigned long baseIndex);
84
88 void setAoSSortingThresholds(const SortingThresholdInfoInterface &aosSortingThreshold) {
89 _cellFunctor.setAoSSortingThresholds(aosSortingThreshold);
90 }
91
95 void setSoASortingThresholds(const SortingThresholdInfoInterface &soaSortingThreshold) {
96 _cellFunctor.setSoASortingThresholds(soaSortingThreshold);
97 }
98
99 protected:
104 std::conditional_t<decltype(utils::isPairwiseFunctor<Functor_T>())::value,
106
111 std::vector<CellOffsetType> _cellOffsets;
112
116 const std::array<unsigned long, 3> _overlap;
117
121 DataLayoutOption _dataLayout;
122
127
128 private:
129 // CellFunctor type for either Pairwise or Triwise Functors.
130 using CellFunctorType =
131 std::conditional_t<decltype(utils::isPairwiseFunctor<Functor_T>())::value,
134
138 CellFunctorType _cellFunctor;
139
143 const double _interactionLength;
144
148 const std::array<double, 3> _cellLength;
149};
150
151template <class ParticleCell_T, class Functor_T>
152inline void LCC08CellHandler<ParticleCell_T, Functor_T>::processBaseCell(std::vector<ParticleCell_T> &cells,
153 unsigned long baseIndex) {
154 if constexpr (utils::isPairwiseFunctor<Functor_T>()) {
155 processBaseCellPairwise(cells, baseIndex);
156 } else if constexpr (utils::isTriwiseFunctor<Functor_T>()) {
157 processBaseCellTriwise(cells, baseIndex);
158 } else {
160 "LCC08CellHandler::processBaseCell(): Given Functor type is not of type PairwiseFunctor or TriwiseFunctor.");
161 }
162}
163
164template <class ParticleCell_T, class Functor_T>
165inline void LCC08CellHandler<ParticleCell_T, Functor_T>::processBaseCellPairwise(std::vector<ParticleCell_T> &cells,
166 unsigned long baseIndex) {
167 for (auto const &[offset1, offset2, r] : _cellOffsets) {
168 const unsigned long cellIndex1 = baseIndex + offset1;
169 const unsigned long cellIndex2 = baseIndex + offset2;
170
171 ParticleCell_T &cell1 = cells[cellIndex1];
172 ParticleCell_T &cell2 = cells[cellIndex2];
173
174 if (cellIndex1 == cellIndex2) {
175 this->_cellFunctor.processCell(cell1);
176 } else {
177 this->_cellFunctor.processCellPair(cell1, cell2, r);
178 }
179 }
180}
181
182template <class ParticleCell_T, class Functor_T>
183inline void LCC08CellHandler<ParticleCell_T, Functor_T>::processBaseCellTriwise(std::vector<ParticleCell_T> &cells,
184 unsigned long baseIndex) {
185 for (auto const &[offset1, offset2, offset3, r] : _cellOffsets) {
186 const unsigned long index1 = baseIndex + offset1;
187 const unsigned long index2 = baseIndex + offset2;
188 const unsigned long index3 = baseIndex + offset3;
189
190 ParticleCell_T &cell1 = cells[index1];
191 ParticleCell_T &cell2 = cells[index2];
192 ParticleCell_T &cell3 = cells[index3];
193
194 if (index1 == index2 and index1 == index3) {
195 this->_cellFunctor.processCell(cell1);
196 } else if (index1 == index2 and index1 != index3) {
197 this->_cellFunctor.processCellPair(cell1, cell3, r);
198 } else if (index1 != index2 and (index1 == index3 or index2 == index3)) {
199 this->_cellFunctor.processCellPair(cell1, cell2, r);
200 } else {
201 this->_cellFunctor.processCellTriple(cell1, cell2, cell3, r);
202 }
203 }
204}
205
206} // namespace autopas
This class provides the base for traversals using the c08 base step.
Definition: LCC08CellHandler.h:28
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:105
void setAoSSortingThresholds(const SortingThresholdInfoInterface &aosSortingThreshold)
Set the aos-sorting-threshold for traversals that use the CellFunctor.
Definition: LCC08CellHandler.h:88
const std::array< unsigned long, 3 > _overlap
Overlap of interacting cells.
Definition: LCC08CellHandler.h:116
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:42
DataLayoutOption _dataLayout
The datalayout to be used.
Definition: LCC08CellHandler.h:121
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:152
void processBaseCellPairwise(std::vector< ParticleCell_T > &cells, unsigned long baseIndex)
Pairwise implementation of processBaseCell().
Definition: LCC08CellHandler.h:165
bool _useNewton3
If newton3 should be used or not.
Definition: LCC08CellHandler.h:126
void processBaseCellTriwise(std::vector< ParticleCell_T > &cells, unsigned long baseIndex)
Triwise implementation of processBaseCell().
Definition: LCC08CellHandler.h:183
std::vector< CellOffsetType > _cellOffsets
Pair sets for processBaseCell().
Definition: LCC08CellHandler.h:111
void setSoASortingThresholds(const SortingThresholdInfoInterface &soaSortingThreshold)
Set the SoA sorting-threshold for traversals that use the CellFunctor.
Definition: LCC08CellHandler.h:95
A cell functor.
Definition: CellFunctor3B.h:25
A cell functor.
Definition: CellFunctor.h:32
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
Polymorphic base for sorting-threshold storage.
Definition: SortingThresholdInfoInterface.h:18