AutoPas  3.0.0
Loading...
Searching...
No Matches
VerletListsCells.h
Go to the documentation of this file.
1
7#pragma once
8
17
18namespace autopas {
19
31template <class Particle_T, class NeighborList>
32class VerletListsCells : public VerletListsLinkedBase<Particle_T> {
33 public:
45 VerletListsCells(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax, const double cutoff,
46 const double skin = 0, const double cellSizeFactor = 1.0,
48 typename VerletListsCellsHelpers::VLCBuildType dataLayoutDuringListRebuild =
49 VerletListsCellsHelpers::VLCBuildType::soaBuild)
50 : VerletListsLinkedBase<Particle_T>(boxMin, boxMax, cutoff, skin, cellSizeFactor),
51 _loadEstimator(loadEstimator),
52 _dataLayoutDuringListRebuild(dataLayoutDuringListRebuild) {}
53
57 [[nodiscard]] ContainerOption getContainerType() const override { return _neighborList.getContainerType(); }
58
64 // (Explicit) static cast required for Apple Clang (last tested version: 17.0.0)
65 switch (static_cast<LoadEstimatorOption::Value>(this->_loadEstimator)) {
67 return [&](const std::array<unsigned long, 3> &cellsPerDimension,
68 const std::array<unsigned long, 3> &lowerCorner, const std::array<unsigned long, 3> &upperCorner) {
69 return loadEstimators::squaredParticlesPerCell((this->_linkedCells).getCells(), cellsPerDimension,
70 lowerCorner, upperCorner);
71 };
72 }
74 return [&](const std::array<unsigned long, 3> &cellsPerDimension,
75 const std::array<unsigned long, 3> &lowerCorner, const std::array<unsigned long, 3> &upperCorner) {
76 return loadEstimators::neighborListLength<Particle_T, NeighborList>(_neighborList, cellsPerDimension,
77 lowerCorner, upperCorner);
78 };
79 }
80
82 [[fallthrough]];
83 default: {
84 return
85 [&](const std::array<unsigned long, 3> &cellsPerDimension, const std::array<unsigned long, 3> &lowerCorner,
86 const std::array<unsigned long, 3> &upperCorner) { return 1; };
87 }
88 }
89 }
90
91 void computeInteractions(TraversalInterface *traversal) override {
92 // Check if traversal is allowed for this container and give it the data it needs.
93 _neighborList.setUpTraversal(traversal);
94 if (auto *balancedTraversal = dynamic_cast<BalancedTraversal *>(traversal)) {
95 balancedTraversal->setLoadEstimator(getLoadEstimatorFunction());
96 }
97
98 traversal->initTraversal();
99 traversal->traverseParticles();
100 traversal->endTraversal();
101 }
102
108 size_t getNumberOfPartners(const Particle_T *particle) const { return _neighborList.getNumberOfPartners(particle); }
109
115 void rebuildNeighborLists(TraversalInterface *traversal) override {
116 this->_verletBuiltNewton3 = traversal->getUseNewton3();
117
118 _neighborList.buildAoSNeighborList(traversal->getTraversalType(), this->_linkedCells, this->_verletBuiltNewton3);
119
120 if (traversal->getDataLayout() == DataLayoutOption::soa) {
121 _neighborList.generateSoAFromAoS(this->_linkedCells);
122 }
123
124 // the neighbor list is now valid
125 this->_neighborListIsValid.store(true, std::memory_order_relaxed);
126 }
127
132 [[nodiscard]] const std::array<double, 3> &getCellLength() const {
133 return this->_linkedCells.getCellBlock().getCellLength();
134 }
135
136 private:
140 NeighborList _neighborList;
141
145 LoadEstimatorOption _loadEstimator;
146
150 typename VerletListsCellsHelpers::VLCBuildType _dataLayoutDuringListRebuild;
151};
152} // namespace autopas
Base class for traversals utilising load balancing.
Definition: BalancedTraversal.h:19
std::function< unsigned long(const std::array< unsigned long, 3 > &, const std::array< unsigned long, 3 > &, const std::array< unsigned long, 3 > &)> EstimatorFunction
Type signature for load estimators.
Definition: BalancedTraversal.h:26
Class representing the load estimator choices.
Definition: LoadEstimatorOption.h:18
Value
Possible choices for the load estimation algorithm.
Definition: LoadEstimatorOption.h:23
@ squaredParticlesPerCell
Number of particles per cell squared.
Definition: LoadEstimatorOption.h:31
@ neighborListLength
Sum of neighbor list lengths.
Definition: LoadEstimatorOption.h:35
@ none
No load estimator.
Definition: LoadEstimatorOption.h:27
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
virtual void endTraversal()=0
Finalizes the traversal.
virtual TraversalOption getTraversalType() const =0
Return a enum representing the name of the traversal class.
virtual void traverseParticles()=0
Traverse the particles by pairs, triplets etc.
virtual void initTraversal()=0
Initializes the traversal.
DataLayoutOption getDataLayout() const
Return the data layout option.
Definition: TraversalInterface.h:69
bool getUseNewton3() const
Return whether the traversal uses newton 3.
Definition: TraversalInterface.h:63
Linked Cells with Verlet Lists container.
Definition: VerletListsCells.h:32
void rebuildNeighborLists(TraversalInterface *traversal) override
Rebuilds the neighbor lists and marks them valid.
Definition: VerletListsCells.h:115
VerletListsCells(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, const double cutoff, const double skin=0, const double cellSizeFactor=1.0, const LoadEstimatorOption loadEstimator=LoadEstimatorOption::squaredParticlesPerCell, typename VerletListsCellsHelpers::VLCBuildType dataLayoutDuringListRebuild=VerletListsCellsHelpers::VLCBuildType::soaBuild)
Constructor of the VerletListsCells class.
Definition: VerletListsCells.h:45
const std::array< double, 3 > & getCellLength() const
Return the cell length of the underlying linked cells structure, normally needed only for unit tests.
Definition: VerletListsCells.h:132
ContainerOption getContainerType() const override
Get the ContainerType.
Definition: VerletListsCells.h:57
size_t getNumberOfPartners(const Particle_T *particle) const
Gets the number of neighbors over all neighbor lists that belong to this particle.
Definition: VerletListsCells.h:108
BalancedTraversal::EstimatorFunction getLoadEstimatorFunction()
Generates the load estimation function depending on _loadEstimator.
Definition: VerletListsCells.h:63
void computeInteractions(TraversalInterface *traversal) override
Iterates over all particle multiples (e.g.
Definition: VerletListsCells.h:91
Base class for Verlet lists which use an underlying linked cells container.
Definition: VerletListsLinkedBase.h:25
bool _verletBuiltNewton3
specifies if the current verlet list was built for newton3
Definition: VerletListsLinkedBase.h:330
std::atomic< bool > _neighborListIsValid
specifies if the neighbor list is currently valid
Definition: VerletListsLinkedBase.h:327
LinkedCells< Particle_T > _linkedCells
internal linked cells storage, handles Particle storage and used to build verlet lists
Definition: VerletListsLinkedBase.h:324
VLCBuildType
Indicates which build functor should be used for the generation of the neighbor list.
Definition: VerletListsCellsHelpers.h:47
unsigned long squaredParticlesPerCell(const std::vector< ParticleCell > &cells, const std::array< unsigned long, 3 > &cellsPerDimension, const std::array< unsigned long, 3 > &lowerCorner, const std::array< unsigned long, 3 > &upperCorner)
Sums up the squared number of particles for all cells within region.
Definition: LoadEstimators.h:31
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32