26template <
class Particle_T>
43 using SoAListType =
typename std::vector<std::vector<SoAPairOfParticleAndList>>;
48 [[nodiscard]] ContainerOption
getContainerType()
const override {
return ContainerOption::verletListsCells; }
54 bool useNewton3)
override {
55 using namespace utils::ArrayMath::literals;
57 if (linkedCells.
getCellBlock().getCellsPerInteractionLength() > 1) {
59 "VLCAllCellsNeighborLists::buildAoSNeighborList() was called with a CSF < 1 but it only supports CSF>=1.");
63 auto &cells = linkedCells.
getCells();
65 const auto interactionLengthSquared = interactionLength * interactionLength;
67 std::array<double, 3>{interactionLength, interactionLength, interactionLength} * 2.;
71 linkedCells.
getNumberOfParticles(IteratorBehavior::ownedOrHalo), boxSizeWithHalo, interactionLength, 1.3);
75 for (
auto &cellLists : neighborLists) {
76 for (
auto &[particlePtr, neighbors] : cellLists) {
77 particlePtr =
nullptr;
81 neighborLists.resize(cells.size());
95 auto insert = [&](
auto &p1,
auto p1Index,
auto &p2,
auto cellIndex1,
auto cellIndexBase,
auto &neighborList) {
97 if (cellIndexBase == cellIndex1) {
98 neighborList[p1Index].second.push_back(&p2);
101 auto iter = std::find_if(neighborList.begin(), neighborList.end(), [&](
const auto &pair) {
102 const auto &[particlePtr, list] = pair;
103 return particlePtr == &p1;
106 if (iter != neighborList.end()) {
107 iter->second.push_back(&p2);
110 if (
auto insertLoc = std::find_if(neighborList.begin(), neighborList.end(),
111 [&](
const auto &pair) {
112 const auto &[particlePtr, list] = pair;
113 return particlePtr == nullptr;
115 insertLoc != neighborList.end()) {
116 auto &[particlePtr, neighbors] = *insertLoc;
118 neighbors.reserve(listLengthEstimate);
119 neighbors.push_back(&p2);
121 neighborList.emplace_back(&p1, std::vector<Particle_T *>{});
122 neighborList.back().second.reserve(listLengthEstimate);
123 neighborList.back().second.push_back(&p2);
129 const auto &cellsPerDim =
130 utils::ArrayUtils::static_cast_copy_array<int>(linkedCells.
getCellBlock().getCellsPerDimensionWithHalo());
139 switch (vlcTraversalOpt) {
140 case TraversalOption::vlc_c08:
146 xEnd = cellsPerDim[0] - 1;
147 yEnd = cellsPerDim[1] - 1;
148 zEnd = cellsPerDim[2] - 1;
151 xEnd = cellsPerDim[0];
152 yEnd = cellsPerDim[1];
153 zEnd = cellsPerDim[2];
159 for (
int z = 0; z < zEnd; ++z) {
160 for (
int y = 0; y < yEnd; ++y) {
161 for (
int x = 0; x < xEnd; ++x) {
164 auto &baseCell = cells[cellIndexBase];
165 auto &baseCellsLists = neighborLists[cellIndexBase];
169 cellIndexBase, useNewton3, cells, offsets,
170 utils::ArrayUtils::static_cast_copy_array<size_t>(cellsPerDim)));
173 const size_t minNumParticlesVsNumLists = std::min(baseCell.size(), baseCellsLists.size());
174 for (
size_t i = 0; i < minNumParticlesVsNumLists; ++i) {
175 auto &[particlePtr, neighbors] = baseCellsLists[i];
176 particlePtr = &baseCell[i];
177 neighbors.reserve(listLengthEstimate);
180 for (
size_t i = minNumParticlesVsNumLists; i < baseCell.size(); ++i) {
181 baseCellsLists.emplace_back(&baseCell[i], std::vector<Particle_T *>{});
182 baseCellsLists.back().second.reserve(listLengthEstimate);
186 for (
const auto &[offset1, offset2, _] : offsets) {
187 const auto cell1Index1D = cellIndexBase + offset1;
188 const auto cell2Index1D = cellIndexBase + offset2;
192 if (cell2Index3D[0] >= cellsPerDim[0] or cell2Index3D[0] < 0 or cell2Index3D[1] >= cellsPerDim[1] or
193 cell2Index3D[1] < 0 or cell2Index3D[2] >= cellsPerDim[2] or cell2Index3D[2] < 0) {
204 for (
size_t particleIndexCell1 = 0; particleIndexCell1 < cells[cell1Index1D].size(); ++particleIndexCell1) {
205 auto &p1 = cells[cell1Index1D][particleIndexCell1];
212 size_t startIndexCell2 = 0;
213 if (cell1Index1D == cell2Index1D and vlcTraversalOpt != TraversalOption::vlc_c01) {
214 startIndexCell2 = particleIndexCell1 + 1;
217 for (
size_t particleIndexCell2 = startIndexCell2; particleIndexCell2 < cells[cell2Index1D].size();
218 ++particleIndexCell2) {
219 auto &p2 = cells[cell2Index1D][particleIndexCell2];
221 if (&p1 == &p2 or p1.isDummy() or p2.isDummy()) {
226 const auto distVec = p2.getR() - p1.getR();
228 if (distSquared < interactionLengthSquared) {
229 insert(p1, particleIndexCell1, p2, cell1Index1D, cellIndexBase, baseCellsLists);
234 if (not useNewton3 and not(vlcTraversalOpt == TraversalOption::vlc_c01)) {
235 insert(p2, particleIndexCell2, p1, cell2Index1D, cellIndexBase, baseCellsLists);
246 for (
auto &cellLists : neighborLists) {
247 cellLists.erase(std::remove_if(cellLists.begin(), cellLists.end(),
248 [](
const auto &pair) {
249 const auto &[particlePtr, neighbors] = pair;
250 return particlePtr == nullptr;
260 for (
const auto &cellsLists : _aosNeighborList) {
261 for (
const auto &particlesLists : cellsLists) {
262 if (particlesLists.first == particle) {
263 return particlesLists.second.size();
275 return _aosNeighborList;
288 _soaNeighborList.clear();
291 std::unordered_map<Particle_T *, size_t> particlePtrToIndex;
292 particlePtrToIndex.reserve(linkedCells.
size());
294 for (
auto iter = linkedCells.
begin(IteratorBehavior::ownedOrHaloOrDummy); iter.isValid(); ++iter, ++i) {
295 particlePtrToIndex[&(*iter)] = i;
298 _soaNeighborList.resize(linkedCells.
getCells().size());
301 for (
size_t firstCellIndex = 0; firstCellIndex < _aosNeighborList.size(); ++firstCellIndex) {
302 const auto &aosLists = _aosNeighborList[firstCellIndex];
303 auto &soaLists = _soaNeighborList[firstCellIndex];
304 soaLists.reserve(aosLists.size());
307 for (
const auto &[particlePtr, neighbors] : aosLists) {
309 size_t currentParticleGlobalIndex = particlePtrToIndex.at(particlePtr);
312 std::vector<size_t, autopas::AlignedAllocator<size_t>> currentSoANeighborList{};
313 currentSoANeighborList.reserve(neighbors.size());
316 for (
const auto &neighborOfCurrentParticle : neighbors) {
317 currentSoANeighborList.emplace_back(particlePtrToIndex.at(neighborOfCurrentParticle));
321 soaLists.emplace_back(currentParticleGlobalIndex, currentSoANeighborList);
333 "Trying to use a traversal of wrong type in VerletListCells.h. TraversalID: {}",
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
const std::array< double, 3 > & getBoxMax() const final
Get the upper corner of the container without halo.
Definition: CellBasedParticleContainer.h:71
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: CellBasedParticleContainer.h:115
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: CellBasedParticleContainer.h:133
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: CellBasedParticleContainer.h:76
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: CellBasedParticleContainer.h:91
LinkedCells class.
Definition: LinkedCells.h:40
internal::CellBlock3D< ParticleCellType > & getCellBlock()
Get the cell block, not supposed to be used except by verlet lists.
Definition: LinkedCells.h:487
std::vector< ParticleCellType > & getCells()
Returns a non-const reference to the cell data structure.
Definition: LinkedCells.h:499
ContainerIterator< Particle_T, true, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, typename ContainerIterator< Particle_T, true, false >::ParticleVecType *additionalVectors=nullptr) override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: LinkedCells.h:327
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
virtual TraversalOption getTraversalType() const =0
Return a enum representing the name of the traversal class.
Neighbor list to be used with VerletListsCells container.
Definition: VLCAllCellsNeighborList.h:27
void generateSoAFromAoS(LinkedCells< Particle_T > &linkedCells) override
Generates neighbor list in SoA layout from available neighbor list in AoS layout.
Definition: VLCAllCellsNeighborList.h:287
size_t getNumberOfPartners(const Particle_T *particle) const override
Gets the number of neighbors over all neighbor lists that belong to this particle.
Definition: VLCAllCellsNeighborList.h:259
ContainerOption getContainerType() const override
Returns the container type of this neighbor list and the container it belongs to.
Definition: VLCAllCellsNeighborList.h:48
void setUpTraversal(TraversalInterface *traversal) override
Assigns the current traversal to the correct traversal interface.
Definition: VLCAllCellsNeighborList.h:326
VerletListsCellsHelpers::AllCellsNeighborListsType< Particle_T > & getAoSNeighborList()
Returns the neighbor list in AoS layout.
Definition: VLCAllCellsNeighborList.h:274
std::pair< size_t, std::vector< size_t, autopas::AlignedAllocator< size_t > > > SoAPairOfParticleAndList
Helper type definition.
Definition: VLCAllCellsNeighborList.h:37
typename VerletListsCellsHelpers::AllCellsNeighborListsType< Particle_T > ListType
Type of the data structure used to save the neighbor lists.
Definition: VLCAllCellsNeighborList.h:32
typename std::vector< std::vector< SoAPairOfParticleAndList > > SoAListType
Helper type definition.
Definition: VLCAllCellsNeighborList.h:43
void buildAoSNeighborList(TraversalOption vlcTraversalOpt, LinkedCells< Particle_T > &linkedCells, bool useNewton3) override
Builds AoS neighbor list from underlying linked cells object.
Definition: VLCAllCellsNeighborList.h:53
auto & getSoANeighborList()
Returns the neighbor list in SoA layout.
Definition: VLCAllCellsNeighborList.h:282
Interface of neighbor lists to be used with VerletListsCells container.
Definition: VLCNeighborListInterface.h:24
void setLinkedCellsPointer(LinkedCells< Particle_T > *linkedCells)
Set the Linked Cells Pointer for this List.
Definition: VLCNeighborListInterface.h:115
This class provides the Traversal Interface for the verlet lists cells container.
Definition: VLCTraversalInterface.h:38
virtual void setVerletList(NeighborList &verlet)
Sets the verlet list for the traversal to iterate over.
Definition: VLCTraversalInterface.h:52
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
std::vector< std::vector< std::pair< Particle_T *, std::vector< Particle_T * > > > > AllCellsNeighborListsType
Cell wise verlet lists for neighbors from all adjacent cells: For every cell, a vector of pairs.
Definition: VerletListsCellsHelpers.h:30
size_t estimateNumLists(size_t baseCellIndex, bool useNewton3, const Cells &cells, const std::vector< BaseStepOffsets > &offsetsC08, const std::array< size_t, 3 > cellsPerDim)
Function to estimate the number of neighbor lists for one base step.
Definition: VerletListsCellsHelpers.h:127
size_t estimateListLength(size_t numParticles, const std::array< double, 3 > &boxSize, double interactionLength, double correctionFactor)
Simple heuristic to calculate the average number of particles per verlet list assuming particles are ...
Definition: VerletListsCellsHelpers.cpp:16
std::vector< BaseStepOffsets > buildBaseStep(const std::array< int, 3 > &cellsPerDim, const TraversalOption traversal)
Builds the list of offsets from the base cell for the c01, c08, and c18 base step.
Definition: VerletListsCellsHelpers.cpp:26
constexpr T dot(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
Generates the dot product of two arrays.
Definition: ArrayMath.h:233
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
constexpr T threeToOneD(T x, T y, T z, const std::array< T, 3 > &dims)
Convert a 3d index to a 1d index.
Definition: ThreeDimensionalMapping.h:29
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
int autopas_get_max_threads()
Dummy for omp_get_max_threads() when no OpenMP is available.
Definition: WrapOpenMP.h:144
@ owned
Owned state, a particle with this state is an actual particle and owned by the current AutoPas object...