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 setSortingThreshold(size_t sortingThreshold) { _cellFunctor.setSortingThreshold(sortingThreshold); }
88
89 protected:
94 std::conditional_t<decltype(utils::isPairwiseFunctor<Functor_T>())::value,
96
101 std::vector<CellOffsetType> _cellOffsets;
102
106 const std::array<unsigned long, 3> _overlap;
107
111 DataLayoutOption _dataLayout;
112
117
118 private:
119 // CellFunctor type for either Pairwise or Triwise Functors.
120 using CellFunctorType =
121 std::conditional_t<decltype(utils::isPairwiseFunctor<Functor_T>())::value,
124
128 CellFunctorType _cellFunctor;
129
133 const double _interactionLength;
134
138 const std::array<double, 3> _cellLength;
139};
140
141template <class ParticleCell_T, class Functor_T>
142inline void LCC08CellHandler<ParticleCell_T, Functor_T>::processBaseCell(std::vector<ParticleCell_T> &cells,
143 unsigned long baseIndex) {
144 if constexpr (utils::isPairwiseFunctor<Functor_T>()) {
145 processBaseCellPairwise(cells, baseIndex);
146 } else if constexpr (utils::isTriwiseFunctor<Functor_T>()) {
147 processBaseCellTriwise(cells, baseIndex);
148 } else {
150 "LCC08CellHandler::processBaseCell(): Given Functor type is not of type PairwiseFunctor or TriwiseFunctor.");
151 }
152}
153
154template <class ParticleCell_T, class Functor_T>
155inline void LCC08CellHandler<ParticleCell_T, Functor_T>::processBaseCellPairwise(std::vector<ParticleCell_T> &cells,
156 unsigned long baseIndex) {
157 for (auto const &[offset1, offset2, r] : _cellOffsets) {
158 const unsigned long cellIndex1 = baseIndex + offset1;
159 const unsigned long cellIndex2 = baseIndex + offset2;
160
161 ParticleCell_T &cell1 = cells[cellIndex1];
162 ParticleCell_T &cell2 = cells[cellIndex2];
163
164 if (cellIndex1 == cellIndex2) {
165 this->_cellFunctor.processCell(cell1);
166 } else {
167 this->_cellFunctor.processCellPair(cell1, cell2, r);
168 }
169 }
170}
171
172template <class ParticleCell_T, class Functor_T>
173inline void LCC08CellHandler<ParticleCell_T, Functor_T>::processBaseCellTriwise(std::vector<ParticleCell_T> &cells,
174 unsigned long baseIndex) {
175 for (auto const &[offset1, offset2, offset3, r] : _cellOffsets) {
176 const unsigned long index1 = baseIndex + offset1;
177 const unsigned long index2 = baseIndex + offset2;
178 const unsigned long index3 = baseIndex + offset3;
179
180 ParticleCell_T &cell1 = cells[index1];
181 ParticleCell_T &cell2 = cells[index2];
182 ParticleCell_T &cell3 = cells[index3];
183
184 if (index1 == index2 and index1 == index3) {
185 this->_cellFunctor.processCell(cell1);
186 } else if (index1 == index2 and index1 != index3) {
187 this->_cellFunctor.processCellPair(cell1, cell3, r);
188 } else if (index1 != index2 and (index1 == index3 or index2 == index3)) {
189 this->_cellFunctor.processCellPair(cell1, cell2, r);
190 } else {
191 this->_cellFunctor.processCellTriple(cell1, cell2, cell3, r);
192 }
193 }
194}
195
196} // 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:95
const std::array< unsigned long, 3 > _overlap
Overlap of interacting cells.
Definition: LCC08CellHandler.h:106
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:111
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:142
void processBaseCellPairwise(std::vector< ParticleCell_T > &cells, unsigned long baseIndex)
Pairwise implementation of processBaseCell().
Definition: LCC08CellHandler.h:155
void setSortingThreshold(size_t sortingThreshold)
Set the sorting-threshold for traversals that use the CellFunctor If the sum of the number of particl...
Definition: LCC08CellHandler.h:87
bool _useNewton3
If newton3 should be used or not.
Definition: LCC08CellHandler.h:116
void processBaseCellTriwise(std::vector< ParticleCell_T > &cells, unsigned long baseIndex)
Triwise implementation of processBaseCell().
Definition: LCC08CellHandler.h:173
std::vector< CellOffsetType > _cellOffsets
Pair sets for processBaseCell().
Definition: LCC08CellHandler.h:101
A cell functor.
Definition: CellFunctor3B.h:24
A cell functor.
Definition: CellFunctor.h:25
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