AutoPas  3.0.0
Loading...
Searching...
No Matches
VerletListsLinkedBase.h
Go to the documentation of this file.
1
7#pragma once
8
15
16namespace autopas {
17
24template <class Particle_T>
26 public:
30 using ParticleType = Particle_T;
31
36
48 VerletListsLinkedBase(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax, const double cutoff,
49 const double skin, const double cellSizeFactor)
50 : ParticleContainerInterface<Particle_T>(skin),
51 _linkedCells(boxMin, boxMax, cutoff, skin, std::max(1.0, cellSizeFactor)) {
52 if (cellSizeFactor < 1.0) {
53 AutoPasLog(DEBUG, "VerletListsLinkedBase: CellSizeFactor smaller 1 detected. Set to 1.");
54 }
55 }
56
61 void setStepsSinceLastRebuild(size_t stepsSinceLastRebuild) override {
62 this->_stepsSinceLastRebuild = stepsSinceLastRebuild;
63 _linkedCells.setStepsSinceLastRebuild(stepsSinceLastRebuild);
64 }
65
66 void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override {
67 _linkedCells.reserve(numParticles, numParticlesHaloEstimate);
68 }
69
74 void addParticleImpl(const Particle_T &p) override {
75 _neighborListIsValid.store(false, std::memory_order_relaxed);
76 // position is already checked, so call impl directly.
77 _linkedCells.addParticleImpl(p);
78 }
79
84 void addHaloParticleImpl(const Particle_T &haloParticle) override {
85 _neighborListIsValid.store(false, std::memory_order_relaxed);
86 // position is already checked, so call impl directly.
87 _linkedCells.addHaloParticleImpl(haloParticle);
88 }
89
93 size_t size() const override { return _linkedCells.size(); }
94
98 [[nodiscard]] size_t getNumberOfParticles(IteratorBehavior behavior) const override {
99 return _linkedCells.getNumberOfParticles(behavior);
100 }
101
106 void deleteHaloParticles() override {
107 _neighborListIsValid.store(false, std::memory_order_relaxed);
108 _linkedCells.deleteHaloParticles();
109 }
110
115 void deleteAllParticles() override {
116 _neighborListIsValid.store(false, std::memory_order_relaxed);
117 _linkedCells.deleteAllParticles();
118 }
119
120 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
121 IteratorBehavior iteratorBehavior,
122 const std::array<double, 3> &boxMin,
123 const std::array<double, 3> &boxMax) const override {
124 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
125 }
126 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
127 IteratorBehavior iteratorBehavior) const override {
128 // this is not a region iter hence we stretch the bounding box to the numeric max
129 constexpr std::array<double, 3> boxMin{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
130 std::numeric_limits<double>::lowest()};
131
132 constexpr std::array<double, 3> boxMax{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
133 std::numeric_limits<double>::max()};
134 return getParticleImpl<false>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
135 }
136
148 template <bool regionIter>
149 std::tuple<const Particle_T *, size_t, size_t> getParticleImpl(size_t cellIndex, size_t particleIndex,
150 IteratorBehavior iteratorBehavior,
151 const std::array<double, 3> &boxMin,
152 const std::array<double, 3> &boxMax) const {
153 return _linkedCells.template getParticleImpl<regionIter>(cellIndex, particleIndex, iteratorBehavior, boxMin,
154 boxMax);
155 }
156
157 bool deleteParticle(Particle_T &particle) override {
158 // This function doesn't actually delete anything as it would mess up the references in the lists.
160 return false;
161 }
162
163 bool deleteParticle(size_t cellIndex, size_t particleIndex) override {
164 // This function doesn't actually delete anything as it would mess up the references in the lists.
165 internal::markParticleAsDeleted(this->_linkedCells.getCells()[cellIndex][particleIndex]);
166 return false;
167 }
168
173 [[nodiscard]] std::vector<Particle_T> updateContainer(bool keepNeighborListsValid) override {
174 if (keepNeighborListsValid) {
176 }
177 _neighborListIsValid.store(false, std::memory_order_relaxed);
178 return _linkedCells.updateContainer(false);
179 }
180
188 bool updateHaloParticle(const Particle_T &haloParticle) override {
189 auto cells = _linkedCells.getCellBlock().getNearbyHaloCells(haloParticle.getR(), this->getVerletSkin());
190 for (auto cellptr : cells) {
191 bool updated = internal::checkParticleInCellAndUpdateByID(*cellptr, haloParticle);
192 if (updated) {
193 return true;
194 }
195 }
196 AutoPasLog(TRACE,
197 "updateHaloParticle was not able to update particle at "
198 "[{}, {}, {}]",
199 haloParticle.getR()[0], haloParticle.getR()[1], haloParticle.getR()[2]);
200 return false;
201 }
202
207 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
208 typename ContainerIterator<Particle_T, true, false>::ParticleVecType *additionalVectors = nullptr) override {
209 return _linkedCells.begin(behavior, additionalVectors);
210 }
211
216 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
218 nullptr) const override {
219 return _linkedCells.begin(behavior, additionalVectors);
220 }
221
225 template <typename Lambda>
226 void forEach(Lambda forEachLambda, IteratorBehavior behavior) {
227 return _linkedCells.forEach(forEachLambda, behavior);
228 }
229
233 template <typename Lambda, typename A>
234 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior) {
235 return _linkedCells.reduce(reduceLambda, result, behavior);
236 }
237
242 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
243 typename ContainerIterator<Particle_T, true, true>::ParticleVecType *additionalVectors = nullptr) override {
244 return _linkedCells.getRegionIterator(lowerCorner, higherCorner, behavior, additionalVectors);
245 }
246
251 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
253 nullptr) const override {
254 return _linkedCells.getRegionIterator(lowerCorner, higherCorner, behavior, additionalVectors);
255 }
256
260 template <typename Lambda>
261 void forEachInRegion(Lambda forEachLambda, const std::array<double, 3> &lowerCorner,
262 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
263 _linkedCells.forEachInRegion(forEachLambda, lowerCorner, higherCorner, behavior);
264 }
265
269 template <typename Lambda, typename A>
270 void reduceInRegion(Lambda reduceLambda, A &result, const std::array<double, 3> &lowerCorner,
271 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
272 _linkedCells.reduceInRegion(reduceLambda, result, lowerCorner, higherCorner, behavior);
273 }
274
279 [[nodiscard]] const std::array<std::size_t, 3> &getCellsPerDimension() const {
280 return _linkedCells.getCellBlock().getCellsPerDimensionWithHalo();
281 }
282
287 [[nodiscard]] TraversalSelectorInfo getTraversalSelectorInfo() const override {
288 return TraversalSelectorInfo(this->_linkedCells.getCellBlock().getCellsPerDimensionWithHalo(),
289 this->getInteractionLength(), this->_linkedCells.getCellBlock().getCellLength(), 0);
290 }
291
295 [[nodiscard]] const std::array<double, 3> &getBoxMax() const final { return _linkedCells.getBoxMax(); }
296
300 [[nodiscard]] const std::array<double, 3> &getBoxMin() const final { return _linkedCells.getBoxMin(); }
301
305 [[nodiscard]] double getCutoff() const final { return _linkedCells.getCutoff(); }
306
310 void setCutoff(double cutoff) final { _linkedCells.setCutoff(cutoff); }
311
315 [[nodiscard]] double getVerletSkin() const final { return _linkedCells.getVerletSkin(); }
316
320 [[nodiscard]] double getInteractionLength() const final { return _linkedCells.getInteractionLength(); }
321
322 protected:
325
327 std::atomic<bool> _neighborListIsValid{false};
328
331};
332
333} // namespace autopas
#define AutoPasLog(lvl, fmt,...)
Macro for logging providing common meta information without filename.
Definition: Logger.h:24
Public iterator class that iterates over a particle container and additional vectors (which are typic...
Definition: ContainerIterator.h:93
std::conditional_t< modifiable, std::vector< std::vector< Particle_T > * >, std::vector< std::vector< Particle_T > const * > > ParticleVecType
Type of the additional vector collection.
Definition: ContainerIterator.h:106
This class handles the storage of particles in their full form.
Definition: FullParticleCell.h:26
LinkedCells class.
Definition: LinkedCells.h:40
The ParticleContainerInterface class provides a basic interface for all Containers within AutoPas.
Definition: ParticleContainerInterface.h:37
size_t _stepsSinceLastRebuild
Stores the number of time-steps since last neighbor list rebuild.
Definition: ParticleContainerInterface.h:422
Info for traversals of a specific container.
Definition: TraversalSelectorInfo.h:14
Base class for Verlet lists which use an underlying linked cells container.
Definition: VerletListsLinkedBase.h:25
bool updateHaloParticle(const Particle_T &haloParticle) override
Searches the provided halo particle and updates the found particle.
Definition: VerletListsLinkedBase.h:188
void addParticleImpl(const Particle_T &p) override
Adds a particle to the container.
Definition: VerletListsLinkedBase.h:74
void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override
Reserve memory for a given number of particles in the container and logic layers.
Definition: VerletListsLinkedBase.h:66
typename LinkedCells< Particle_T >::ParticleCellType ParticleCellType
Type of the ParticleCell used by the underlying linked cells.
Definition: VerletListsLinkedBase.h:35
ContainerIterator< Particle_T, false, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, typename ContainerIterator< Particle_T, false, false >::ParticleVecType *additionalVectors=nullptr) const override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: VerletListsLinkedBase.h:215
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: VerletListsLinkedBase.h:206
void setStepsSinceLastRebuild(size_t stepsSinceLastRebuild) override
Set the number of time-steps since last neighbor list rebuild.
Definition: VerletListsLinkedBase.h:61
void forEach(Lambda forEachLambda, IteratorBehavior behavior)
Execute code on all particles in this container as defined by a lambda function.
Definition: VerletListsLinkedBase.h:226
void deleteAllParticles() override
Deletes all particles.
Definition: VerletListsLinkedBase.h:115
bool _verletBuiltNewton3
specifies if the current verlet list was built for newton3
Definition: VerletListsLinkedBase.h:330
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: VerletListsLinkedBase.h:300
std::tuple< const Particle_T *, size_t, size_t > getParticle(size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior, const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax) const override
Fetch the pointer to a particle, identified via a cell and particle index.
Definition: VerletListsLinkedBase.h:120
const std::array< std::size_t, 3 > & getCellsPerDimension() const
Get the dimension of the used cellblock including the haloboxes.
Definition: VerletListsLinkedBase.h:279
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: VerletListsLinkedBase.h:98
double getVerletSkin() const final
Return the verletSkin of the container verletSkin.
Definition: VerletListsLinkedBase.h:315
void setCutoff(double cutoff) final
Set the cutoff of the container.
Definition: VerletListsLinkedBase.h:310
bool deleteParticle(Particle_T &particle) override
Deletes the given particle as long as this does not compromise the validity of the container.
Definition: VerletListsLinkedBase.h:157
const std::array< double, 3 > & getBoxMax() const final
Get the upper corner of the container without halo.
Definition: VerletListsLinkedBase.h:295
std::vector< Particle_T > updateContainer(bool keepNeighborListsValid) override
Updates the container.
Definition: VerletListsLinkedBase.h:173
void reduceInRegion(Lambda reduceLambda, A &result, const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior)
Execute code on all particles in this container in a certain region as defined by a lambda function.
Definition: VerletListsLinkedBase.h:270
std::tuple< const Particle_T *, size_t, size_t > getParticle(size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior) const override
Fetch the pointer to a particle, identified via a cell and particle index.
Definition: VerletListsLinkedBase.h:126
Particle_T ParticleType
Type of the Particle.
Definition: VerletListsLinkedBase.h:30
std::tuple< const Particle_T *, size_t, size_t > getParticleImpl(size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior, const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax) const
Container specific implementation for getParticle.
Definition: VerletListsLinkedBase.h:149
ContainerIterator< Particle_T, true, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, typename ContainerIterator< Particle_T, true, true >::ParticleVecType *additionalVectors=nullptr) override
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
Definition: VerletListsLinkedBase.h:241
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: VerletListsLinkedBase.h:320
std::atomic< bool > _neighborListIsValid
specifies if the neighbor list is currently valid
Definition: VerletListsLinkedBase.h:327
ContainerIterator< Particle_T, false, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, typename ContainerIterator< Particle_T, false, true >::ParticleVecType *additionalVectors=nullptr) const override
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
Definition: VerletListsLinkedBase.h:250
LinkedCells< Particle_T > _linkedCells
internal linked cells storage, handles Particle storage and used to build verlet lists
Definition: VerletListsLinkedBase.h:324
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: VerletListsLinkedBase.h:287
VerletListsLinkedBase(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, const double cutoff, const double skin, const double cellSizeFactor)
Constructor of the VerletListsLinkedBase class.
Definition: VerletListsLinkedBase.h:48
void deleteHaloParticles() override
Deletes all halo particles.
Definition: VerletListsLinkedBase.h:106
bool deleteParticle(size_t cellIndex, size_t particleIndex) override
Deletes the particle at the given index positions as long as this does not compromise the validity of...
Definition: VerletListsLinkedBase.h:163
void addHaloParticleImpl(const Particle_T &haloParticle) override
Adds a particle to the container that lies in the halo region of the container.
Definition: VerletListsLinkedBase.h:84
double getCutoff() const final
Return the cutoff of the container.
Definition: VerletListsLinkedBase.h:305
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior)
Reduce properties of particles as defined by a lambda function.
Definition: VerletListsLinkedBase.h:234
void forEachInRegion(Lambda forEachLambda, const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior)
Execute code on all particles in this container in a certain region as defined by a lambda function.
Definition: VerletListsLinkedBase.h:261
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: VerletListsLinkedBase.h:93
std::vector< typename ContainerType::ParticleType > collectParticlesAndMarkNonOwnedAsDummy(ContainerType &container)
Collects leaving particles and marks halo particles as dummy.
Definition: LeavingParticleCollector.h:85
static bool checkParticleInCellAndUpdateByID(CellType &cell, const typename CellType::ParticleType &particle)
Updates a found particle within cellI to the values of particleI.
Definition: ParticleCellHelpers.h:21
void markParticleAsDeleted(Particle_T &p)
Marks a particle as deleted.
Definition: markParticleAsDeleted.h:23
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32