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 _dims{dims} {}
34
46 unsigned long cellIndex, PairwiseFunctor *pairwiseFunctor, DataLayoutOption layout,
48 using namespace utils::ArrayMath::literals;
49 const auto &aosNeighborList = neighborList.getAoSNeighborList();
50 const auto &soaNeighborList = neighborList.getSoANeighborList();
51
52 // Helper lambda to compute the relative index from two cells
53 auto relIdx = [&](auto cellIndex1, auto cellIndex2) {
54 const auto threeDPosCell1 = utils::ThreeDimensionalMapping::oneToThreeD(cellIndex1, _dims);
55 const auto threeDPosCell2 = utils::ThreeDimensionalMapping::oneToThreeD(cellIndex2, _dims);
56 const auto offset = threeDPosCell2 - threeDPosCell1;
57 return (offset[0] + 1) * 9 + (offset[1] + 1) * 3 + (offset[2] + 1);
58 };
59
60 // for all interaction pairs defined via the c08 base step
61 for (const auto &[offsetA, offsetB] : this->_cellPairOffsets) {
62 // the lists are built with a c18 traversal
63 // the interaction will always be saved in the smaller cell's neighbor list
64 // std::minmax(a, b) returns references. Hence, we can't use temporaries as arguments.
65 const auto offsetCellA = cellIndex + offsetA;
66 const auto offsetCellB = cellIndex + offsetB;
67 const auto [offsetCell1, offsetCell2] = std::minmax(offsetCellA, offsetCellB);
68
69 const auto cell2Local = relIdx(offsetCell1, offsetCell2);
70
71 // if aos, send every pair of interacting particles to functor
72 if (layout == DataLayoutOption::aos) {
73 // vector of pairs {particle, list}
74 const auto &currentList = aosNeighborList[offsetCell1][cell2Local];
75 for (auto &[particleBasePtr, particleList] : currentList) {
76 for (auto *particlePartnerPtr : particleList) {
77 pairwiseFunctor->AoSFunctor(*particleBasePtr, *particlePartnerPtr, useNewton3);
78 }
79 }
80 }
81
82 // if soa, send particle and corresponding neighbor list to the functor
83 else if (layout == DataLayoutOption::soa) {
84 // vector of pairs {particle, list}
85 const auto &currentList = soaNeighborList[offsetCell1][cell2Local];
86 for (const auto &[particleIndex, particleList] : currentList) {
87 if (not particleList.empty()) {
88 pairwiseFunctor->SoAFunctorVerlet(*soa, particleIndex, particleList, useNewton3);
89 }
90 }
91 }
92
93 // if newton3 is off, find cell1 in cell2's neighbor list ("switch" the pair from above) and repeat the
94 // interaction from above
95 if (not useNewton3) {
96 const auto cell2LocalNoN3 = relIdx(offsetCell2, offsetCell1);
97 // exclude interaction within same cell - already handled in
98 if (offsetCell1 != offsetCell2) {
99 // if aos, send every pair of interacting particles to functor
100 if (layout == DataLayoutOption::aos) {
101 // vector of pairs {particle, list}
102 const auto &currentList = aosNeighborList[offsetCell2][cell2LocalNoN3];
103 for (auto &[particleBasePtr, particleList] : currentList) {
104 for (auto *particlePartnerPtr : particleList) {
105 pairwiseFunctor->AoSFunctor(*particleBasePtr, *particlePartnerPtr, useNewton3);
106 }
107 }
108 }
109
110 // if soa, send particle and corresponding neighbor list to the functor
111 else if (layout == DataLayoutOption::soa) {
112 // vector of pairs {particle, list}
113 const auto &currentList = soaNeighborList[offsetCell2][cell2LocalNoN3];
114 for (const auto &[particleIndex, particleList] : currentList) {
115 if (not particleList.empty()) {
116 pairwiseFunctor->SoAFunctorVerlet(*soa, particleIndex, particleList, useNewton3);
117 }
118 }
119 }
120 }
121 }
122 }
123 }
124
125 private:
129 std::vector<LCC08CellHandlerUtility::OffsetPair> _cellPairOffsets;
130
131 std::array<unsigned long, 3> _dims;
132};
133} // 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:45
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:30
auto & getSoANeighborList()
Returns the neighbor list in SoA layout.
Definition: VLCCellPairNeighborList.h:88
VerletListsCellsHelpers::PairwiseNeighborListsType< Particle_T > & getAoSNeighborList()
Returns the neighbor list in AoS layout.
Definition: VLCCellPairNeighborList.h:80
constexpr std::array< T, 3 > oneToThreeD(T ind, const std::array< T, 3 > &dims)
Convert a 1d index to a 3d index.
Definition: ThreeDimensionalMapping.h:55
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32