AutoPas  3.0.0
Loading...
Searching...
No Matches
VLCCellPairC08CellHandler.h
Go to the documentation of this file.
1
6#pragma once
7
12
13namespace autopas {
19template <class ParticleCell, class PairwiseFunctor>
21 public:
29 VLCCellPairC08CellHandler(const std::array<unsigned long, 3> &dims, double interactionLength,
30 const std::array<double, 3> &cellLength)
31 : _cellPairOffsets{LCC08CellHandlerUtility::computePairwiseCellOffsetsC08<
32 LCC08CellHandlerUtility::C08OffsetMode::c08CellPairs>(dims, cellLength, interactionLength)} {}
33
45 unsigned long cellIndex, PairwiseFunctor *pairwiseFunctor, DataLayoutOption layout,
47 const auto &aosNeighborList = neighborList.getAoSNeighborList();
48 const auto &soaNeighborList = neighborList.getSoANeighborList();
49 const auto &globalToLocalIndex = neighborList.getGlobalToLocalMap();
50
51 // for all interaction pairs defined via the c08 base step
52 for (const auto &[offsetA, offsetB] : this->_cellPairOffsets) {
53 // the lists are built with a c18 traversal
54 // the interaction will always be saved in the smaller cell's neighbor list
55 // std::minmax(a, b) returns references. Hence, we can't use temporaries as arguments.
56 const auto offsetCellA = cellIndex + offsetA;
57 const auto offsetCellB = cellIndex + offsetB;
58 const auto [offsetCell1, offsetCell2] = std::minmax(offsetCellA, offsetCellB);
59
60 const auto cell2Local = globalToLocalIndex[offsetCell1].find(offsetCell2);
61
62 // check if cell2 exists (in cell1's neighbor list)
63 if (cell2Local != globalToLocalIndex[offsetCell1].end()) {
64 // if aos, send every pair of interacting particles to functor
65 if (layout == DataLayoutOption::aos) {
66 // vector of pairs {particle, list}
67 const auto &currentList = aosNeighborList[offsetCell1][cell2Local->second];
68 for (auto &[particleBasePtr, particleList] : currentList) {
69 for (auto *particlePartnerPtr : particleList) {
70 pairwiseFunctor->AoSFunctor(*particleBasePtr, *particlePartnerPtr, useNewton3);
71 }
72 }
73 }
74
75 // if soa, send particle and corresponding neighbor list to the functor
76 else if (layout == DataLayoutOption::soa) {
77 // vector of pairs {particle, list}
78 const auto &currentList = soaNeighborList[offsetCell1][cell2Local->second];
79 for (const auto &[particleIndex, particleList] : currentList) {
80 if (not particleList.empty()) {
81 pairwiseFunctor->SoAFunctorVerlet(*soa, particleIndex, particleList, useNewton3);
82 }
83 }
84 }
85 }
86
87 // if newton3 is off, find cell1 in cell2's neighbor list ("switch" the pair from above) and repeat the
88 // interaction from above
89 if (not useNewton3) {
90 const auto cell2LocalNoN3 = globalToLocalIndex[offsetCell2].find(offsetCell1);
91 // exclude interaction within same cell - already handled in
92 if (cell2LocalNoN3 != globalToLocalIndex[offsetCell2].end() and offsetCell1 != offsetCell2) {
93 // if aos, send every pair of interacting particles to functor
94 if (layout == DataLayoutOption::aos) {
95 // vector of pairs {particle, list}
96 const auto &currentList = aosNeighborList[offsetCell2][cell2LocalNoN3->second];
97 for (auto &[particleBasePtr, particleList] : currentList) {
98 for (auto *particlePartnerPtr : particleList) {
99 pairwiseFunctor->AoSFunctor(*particleBasePtr, *particlePartnerPtr, useNewton3);
100 }
101 }
102 }
103
104 // if soa, send particle and corresponding neighbor list to the functor
105 else if (layout == DataLayoutOption::soa) {
106 // vector of pairs {particle, list}
107 const auto &currentList = soaNeighborList[offsetCell2][cell2LocalNoN3->second];
108 for (const auto &[particleIndex, particleList] : currentList) {
109 if (not particleList.empty()) {
110 pairwiseFunctor->SoAFunctorVerlet(*soa, particleIndex, particleList, useNewton3);
111 }
112 }
113 }
114 }
115 }
116 }
117 }
118
119 private:
123 std::vector<LCC08CellHandlerUtility::OffsetPair> _cellPairOffsets;
124};
125} // namespace autopas
PairwiseFunctor class.
Definition: PairwiseFunctor.h:31
virtual void AoSFunctor(Particle_T &i, Particle_T &j, bool newton3)
PairwiseFunctor for arrays of structures (AoS).
Definition: PairwiseFunctor.h:56
virtual void SoAFunctorVerlet(SoAView< SoAArraysType > soa, const size_t indexFirst, const std::vector< size_t, AlignedAllocator< size_t > > &neighborList, bool newton3)
PairwiseFunctor for structure of arrays (SoA) for neighbor lists.
Definition: PairwiseFunctor.h:86
Structur of the array class.
Definition: SoA.h:28
This class provides the base logic for the c08 traversal for VLCCellPairNeighborList.
Definition: VLCCellPairC08CellHandler.h:20
void processCellListsC08(VLCCellPairNeighborList< typename ParticleCell::ParticleType > &neighborList, unsigned long cellIndex, PairwiseFunctor *pairwiseFunctor, DataLayoutOption layout, SoA< typename ParticleCell::ParticleType::SoAArraysType > *soa, bool useNewton3)
Executes a c08 base step for the cell at cellIndex.
Definition: VLCCellPairC08CellHandler.h:44
VLCCellPairC08CellHandler(const std::array< unsigned long, 3 > &dims, double interactionLength, const std::array< double, 3 > &cellLength)
Constructor of the VLCCellPairC08CellHandler.
Definition: VLCCellPairC08CellHandler.h:29
Neighbor list to be used with VerletListsCells container.
Definition: VLCCellPairNeighborList.h:31
auto & getSoANeighborList()
Returns the neighbor list in SoA layout.
Definition: VLCCellPairNeighborList.h:80
VerletListsCellsHelpers::PairwiseNeighborListsType< Particle_T > & getAoSNeighborList()
Returns the neighbor list in AoS layout.
Definition: VLCCellPairNeighborList.h:64
auto & getGlobalToLocalMap()
Returns a map of each cell's global index to its local index in another cell's neighbor list.
Definition: VLCCellPairNeighborList.h:74
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32