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
25template <class Particle_T>
27 public:
41 VerletListsLinkedBase(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax, const double cutoff,
42 const double skin, const unsigned int rebuildFrequency,
43 const std::set<TraversalOption> &applicableTraversals, const double cellSizeFactor)
44 : ParticleContainerInterface<Particle_T>(skin),
45 _linkedCells(boxMin, boxMax, cutoff, skin, rebuildFrequency, std::max(1.0, cellSizeFactor)) {
46 if (cellSizeFactor < 1.0) {
47 AutoPasLog(DEBUG, "VerletListsLinkedBase: CellSizeFactor smaller 1 detected. Set to 1.");
48 }
49 }
50
54 CellType getParticleCellTypeEnum() const override { return _linkedCells.getParticleCellTypeEnum(); };
55
60 void setStepsSinceLastRebuild(size_t stepsSinceLastRebuild) override {
61 this->_stepsSinceLastRebuild = stepsSinceLastRebuild;
62 _linkedCells.setStepsSinceLastRebuild(stepsSinceLastRebuild);
63 }
64
65 void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override {
66 _linkedCells.reserve(numParticles, numParticlesHaloEstimate);
67 }
68
73 void addParticleImpl(const Particle_T &p) override {
74 _neighborListIsValid.store(false, std::memory_order_relaxed);
75 // position is already checked, so call impl directly.
76 _linkedCells.addParticleImpl(p);
77 }
78
83 void addHaloParticleImpl(const Particle_T &haloParticle) override {
84 _neighborListIsValid.store(false, std::memory_order_relaxed);
85 // position is already checked, so call impl directly.
86 _linkedCells.addHaloParticleImpl(haloParticle);
87 }
88
92 size_t size() const override { return _linkedCells.size(); }
93
97 [[nodiscard]] size_t getNumberOfParticles(IteratorBehavior behavior) const override {
98 return _linkedCells.getNumberOfParticles(behavior);
99 }
100
105 void deleteHaloParticles() override {
106 _neighborListIsValid.store(false, std::memory_order_relaxed);
107 _linkedCells.deleteHaloParticles();
108 }
109
114 void deleteAllParticles() override {
115 _neighborListIsValid.store(false, std::memory_order_relaxed);
116 _linkedCells.deleteAllParticles();
117 }
118
119 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
120 IteratorBehavior iteratorBehavior,
121 const std::array<double, 3> &boxMin,
122 const std::array<double, 3> &boxMax) const override {
123 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
124 }
125 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
126 IteratorBehavior iteratorBehavior) const override {
127 // this is not a region iter hence we stretch the bounding box to the numeric max
128 constexpr std::array<double, 3> boxMin{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
129 std::numeric_limits<double>::lowest()};
130
131 constexpr std::array<double, 3> boxMax{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
132 std::numeric_limits<double>::max()};
133 return getParticleImpl<false>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
134 }
135
147 template <bool regionIter>
148 std::tuple<const Particle_T *, size_t, size_t> getParticleImpl(size_t cellIndex, size_t particleIndex,
149 IteratorBehavior iteratorBehavior,
150 const std::array<double, 3> &boxMin,
151 const std::array<double, 3> &boxMax) const {
152 return _linkedCells.template getParticleImpl<regionIter>(cellIndex, particleIndex, iteratorBehavior, boxMin,
153 boxMax);
154 }
155
156 bool deleteParticle(Particle_T &particle) override {
157 // This function doesn't actually delete anything as it would mess up the references in the lists.
159 return false;
160 }
161
162 bool deleteParticle(size_t cellIndex, size_t particleIndex) override {
163 // This function doesn't actually delete anything as it would mess up the references in the lists.
164 internal::markParticleAsDeleted(this->_linkedCells.getCells()[cellIndex][particleIndex]);
165 return false;
166 }
167
172 [[nodiscard]] std::vector<Particle_T> updateContainer(bool keepNeighborListsValid) override {
173 if (keepNeighborListsValid) {
175 }
176 _neighborListIsValid.store(false, std::memory_order_relaxed);
177 return _linkedCells.updateContainer(false);
178 }
179
187 bool updateHaloParticle(const Particle_T &haloParticle) override {
188 auto cells = _linkedCells.getCellBlock().getNearbyHaloCells(haloParticle.getR(), this->getVerletSkin());
189 for (auto cellptr : cells) {
190 bool updated = internal::checkParticleInCellAndUpdateByID(*cellptr, haloParticle);
191 if (updated) {
192 return true;
193 }
194 }
195 AutoPasLog(TRACE,
196 "updateHaloParticle was not able to update particle at "
197 "[{}, {}, {}]",
198 haloParticle.getR()[0], haloParticle.getR()[1], haloParticle.getR()[2]);
199 return false;
200 }
201
206 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
207 typename ContainerIterator<Particle_T, true, false>::ParticleVecType *additionalVectors = nullptr) override {
208 return _linkedCells.begin(behavior, additionalVectors);
209 }
210
215 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
217 nullptr) const override {
218 return _linkedCells.begin(behavior, additionalVectors);
219 }
220
224 template <typename Lambda>
225 void forEach(Lambda forEachLambda, IteratorBehavior behavior) {
226 return _linkedCells.forEach(forEachLambda, behavior);
227 }
228
232 template <typename Lambda, typename A>
233 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior) {
234 return _linkedCells.reduce(reduceLambda, result, behavior);
235 }
236
241 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
242 typename ContainerIterator<Particle_T, true, true>::ParticleVecType *additionalVectors = nullptr) override {
243 return _linkedCells.getRegionIterator(lowerCorner, higherCorner, behavior, additionalVectors);
244 }
245
250 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
252 nullptr) const override {
253 return _linkedCells.getRegionIterator(lowerCorner, higherCorner, behavior, additionalVectors);
254 }
255
259 template <typename Lambda>
260 void forEachInRegion(Lambda forEachLambda, const std::array<double, 3> &lowerCorner,
261 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
262 _linkedCells.forEachInRegion(forEachLambda, lowerCorner, higherCorner, behavior);
263 }
264
268 template <typename Lambda, typename A>
269 void reduceInRegion(Lambda reduceLambda, A &result, const std::array<double, 3> &lowerCorner,
270 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
271 _linkedCells.reduceInRegion(reduceLambda, result, lowerCorner, higherCorner, behavior);
272 }
273
278 [[nodiscard]] const std::array<std::size_t, 3> &getCellsPerDimension() const {
279 return _linkedCells.getCellBlock().getCellsPerDimensionWithHalo();
280 }
281
286 [[nodiscard]] TraversalSelectorInfo getTraversalSelectorInfo() const override {
287 return TraversalSelectorInfo(this->_linkedCells.getCellBlock().getCellsPerDimensionWithHalo(),
288 this->getInteractionLength(), this->_linkedCells.getCellBlock().getCellLength(), 0);
289 }
290
294 [[nodiscard]] const std::array<double, 3> &getBoxMax() const final { return _linkedCells.getBoxMax(); }
295
299 [[nodiscard]] const std::array<double, 3> &getBoxMin() const final { return _linkedCells.getBoxMin(); }
300
304 [[nodiscard]] double getCutoff() const final { return _linkedCells.getCutoff(); }
305
309 void setCutoff(double cutoff) final { _linkedCells.setCutoff(cutoff); }
310
314 [[nodiscard]] double getVerletSkin() const final { return _linkedCells.getVerletSkin(); }
315
319 [[nodiscard]] double getInteractionLength() const final { return _linkedCells.getInteractionLength(); }
320
321 protected:
324
326 std::atomic<bool> _neighborListIsValid{false};
327
330};
331
332} // 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
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:429
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:26
bool updateHaloParticle(const Particle_T &haloParticle) override
Searches the provided halo particle and updates the found particle.
Definition: VerletListsLinkedBase.h:187
void addParticleImpl(const Particle_T &p) override
Adds a particle to the container.
Definition: VerletListsLinkedBase.h:73
VerletListsLinkedBase(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, const double cutoff, const double skin, const unsigned int rebuildFrequency, const std::set< TraversalOption > &applicableTraversals, const double cellSizeFactor)
Constructor of the VerletListsLinkedBase class.
Definition: VerletListsLinkedBase.h:41
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:65
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:214
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:205
void setStepsSinceLastRebuild(size_t stepsSinceLastRebuild) override
Set the number of time-steps since last neighbor list rebuild.
Definition: VerletListsLinkedBase.h:60
void forEach(Lambda forEachLambda, IteratorBehavior behavior)
Execute code on all particles in this container as defined by a lambda function.
Definition: VerletListsLinkedBase.h:225
void deleteAllParticles() override
Deletes all particles.
Definition: VerletListsLinkedBase.h:114
bool _verletBuiltNewton3
specifies if the current verlet list was built for newton3
Definition: VerletListsLinkedBase.h:329
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: VerletListsLinkedBase.h:299
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:119
const std::array< std::size_t, 3 > & getCellsPerDimension() const
Get the dimension of the used cellblock including the haloboxes.
Definition: VerletListsLinkedBase.h:278
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: VerletListsLinkedBase.h:97
double getVerletSkin() const final
Return the verletSkin of the container verletSkin.
Definition: VerletListsLinkedBase.h:314
void setCutoff(double cutoff) final
Set the cutoff of the container.
Definition: VerletListsLinkedBase.h:309
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:156
const std::array< double, 3 > & getBoxMax() const final
Get the upper corner of the container without halo.
Definition: VerletListsLinkedBase.h:294
std::vector< Particle_T > updateContainer(bool keepNeighborListsValid) override
Updates the container.
Definition: VerletListsLinkedBase.h:172
CellType getParticleCellTypeEnum() const override
Get the ParticleCell type as an Enum.
Definition: VerletListsLinkedBase.h:54
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:269
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:125
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:148
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:240
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: VerletListsLinkedBase.h:319
std::atomic< bool > _neighborListIsValid
specifies if the neighbor list is currently valid
Definition: VerletListsLinkedBase.h:326
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:249
LinkedCells< Particle_T > _linkedCells
internal linked cells storage, handles Particle storage and used to build verlet lists
Definition: VerletListsLinkedBase.h:323
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: VerletListsLinkedBase.h:286
void deleteHaloParticles() override
Deletes all halo particles.
Definition: VerletListsLinkedBase.h:105
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:162
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:83
double getCutoff() const final
Return the cutoff of the container.
Definition: VerletListsLinkedBase.h:304
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior)
Reduce properties of particles as defined by a lambda function.
Definition: VerletListsLinkedBase.h:233
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:260
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: VerletListsLinkedBase.h:92
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
CellType
The ParticleCell Type as an Enum.
Definition: ParticleCell.h:19