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
57 void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override {
58 _linkedCells.reserve(numParticles, numParticlesHaloEstimate);
59 }
60
65 void addParticleImpl(const Particle_T &p) override {
66 _neighborListIsValid.store(false, std::memory_order_relaxed);
67 // position is already checked, so call impl directly.
68 _linkedCells.addParticleImpl(p);
69 }
70
75 void addHaloParticleImpl(const Particle_T &haloParticle) override {
76 _neighborListIsValid.store(false, std::memory_order_relaxed);
77 // position is already checked, so call impl directly.
78 _linkedCells.addHaloParticleImpl(haloParticle);
79 }
80
84 size_t size() const override { return _linkedCells.size(); }
85
89 [[nodiscard]] size_t getNumberOfParticles(IteratorBehavior behavior) const override {
90 return _linkedCells.getNumberOfParticles(behavior);
91 }
92
97 void deleteHaloParticles() override {
98 _neighborListIsValid.store(false, std::memory_order_relaxed);
99 _linkedCells.deleteHaloParticles();
100 }
101
106 void deleteAllParticles() override {
107 _neighborListIsValid.store(false, std::memory_order_relaxed);
108 _linkedCells.deleteAllParticles();
109 }
110
111 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
112 IteratorBehavior iteratorBehavior,
113 const std::array<double, 3> &boxMin,
114 const std::array<double, 3> &boxMax) const override {
115 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
116 }
117 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
118 IteratorBehavior iteratorBehavior) const override {
119 // this is not a region iter hence we stretch the bounding box to the numeric max
120 constexpr std::array<double, 3> boxMin{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
121 std::numeric_limits<double>::lowest()};
122
123 constexpr std::array<double, 3> boxMax{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
124 std::numeric_limits<double>::max()};
125 return getParticleImpl<false>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
126 }
127
139 template <bool regionIter>
140 std::tuple<const Particle_T *, size_t, size_t> getParticleImpl(size_t cellIndex, size_t particleIndex,
141 IteratorBehavior iteratorBehavior,
142 const std::array<double, 3> &boxMin,
143 const std::array<double, 3> &boxMax) const {
144 return _linkedCells.template getParticleImpl<regionIter>(cellIndex, particleIndex, iteratorBehavior, boxMin,
145 boxMax);
146 }
147
148 bool deleteParticle(Particle_T &particle) override {
149 // This function doesn't actually delete anything as it would mess up the references in the lists.
151 return false;
152 }
153
154 bool deleteParticle(size_t cellIndex, size_t particleIndex) override {
155 // This function doesn't actually delete anything as it would mess up the references in the lists.
156 internal::markParticleAsDeleted(this->_linkedCells.getCells()[cellIndex][particleIndex]);
157 return false;
158 }
159
164 [[nodiscard]] std::vector<Particle_T> updateContainer(bool keepNeighborListsValid) override {
165 if (keepNeighborListsValid) {
167 }
168 _neighborListIsValid.store(false, std::memory_order_relaxed);
169 return _linkedCells.updateContainer(false);
170 }
171
179 bool updateHaloParticle(const Particle_T &haloParticle) override {
180 auto cells = _linkedCells.getCellBlock().getNearbyHaloCells(haloParticle.getR(), this->getVerletSkin());
181 for (auto cellptr : cells) {
182 bool updated = internal::checkParticleInCellAndUpdateByID(*cellptr, haloParticle);
183 if (updated) {
184 return true;
185 }
186 }
187 AutoPasLog(TRACE,
188 "updateHaloParticle was not able to update particle at "
189 "[{}, {}, {}]",
190 haloParticle.getR()[0], haloParticle.getR()[1], haloParticle.getR()[2]);
191 return false;
192 }
193
198 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
200 std::nullopt) override {
201 return _linkedCells.begin(behavior, additionalVectors);
202 }
203
208 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
210 std::nullopt) const override {
211 return _linkedCells.begin(behavior, additionalVectors);
212 }
213
217 template <typename Lambda>
218 void forEach(Lambda forEachLambda, IteratorBehavior behavior) {
219 return _linkedCells.forEach(forEachLambda, behavior);
220 }
221
225 template <typename Lambda, typename A>
226 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior) {
227 return _linkedCells.reduce(reduceLambda, result, behavior);
228 }
229
234 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
236 std::nullopt) override {
237 return _linkedCells.getRegionIterator(lowerCorner, higherCorner, behavior, additionalVectors);
238 }
239
244 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
246 std::nullopt) const override {
247 return _linkedCells.getRegionIterator(lowerCorner, higherCorner, behavior, additionalVectors);
248 }
249
253 template <typename Lambda>
254 void forEachInRegion(Lambda forEachLambda, const std::array<double, 3> &lowerCorner,
255 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
256 _linkedCells.forEachInRegion(forEachLambda, lowerCorner, higherCorner, behavior);
257 }
258
262 template <typename Lambda, typename A>
263 void reduceInRegion(Lambda reduceLambda, A &result, const std::array<double, 3> &lowerCorner,
264 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
265 _linkedCells.reduceInRegion(reduceLambda, result, lowerCorner, higherCorner, behavior);
266 }
267
272 [[nodiscard]] const std::array<std::size_t, 3> &getCellsPerDimension() const {
273 return _linkedCells.getCellBlock().getCellsPerDimensionWithHalo();
274 }
275
280 [[nodiscard]] TraversalSelectorInfo getTraversalSelectorInfo() const override {
281 return TraversalSelectorInfo(this->_linkedCells.getCellBlock().getCellsPerDimensionWithHalo(),
282 this->getInteractionLength(), this->_linkedCells.getCellBlock().getCellLength(), 0);
283 }
284
288 [[nodiscard]] const std::array<double, 3> &getBoxMax() const final { return _linkedCells.getBoxMax(); }
289
293 [[nodiscard]] const std::array<double, 3> &getBoxMin() const final { return _linkedCells.getBoxMin(); }
294
298 [[nodiscard]] double getCutoff() const final { return _linkedCells.getCutoff(); }
299
303 void setCutoff(double cutoff) final { _linkedCells.setCutoff(cutoff); }
304
308 [[nodiscard]] double getVerletSkin() const final { return _linkedCells.getVerletSkin(); }
309
313 [[nodiscard]] double getInteractionLength() const final { return _linkedCells.getInteractionLength(); }
314
315 protected:
318
320 std::atomic<bool> _neighborListIsValid{false};
321
324};
325
326} // 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:95
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:108
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:38
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:179
void addParticleImpl(const Particle_T &p) override
Adds a particle to the container.
Definition: VerletListsLinkedBase.h:65
ContainerIterator< Particle_T, true, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, utils::optRef< typename ContainerIterator< Particle_T, true, false >::ParticleVecType > additionalVectors=std::nullopt) override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: VerletListsLinkedBase.h:197
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:57
typename LinkedCells< Particle_T >::ParticleCellType ParticleCellType
Type of the ParticleCell used by the underlying linked cells.
Definition: VerletListsLinkedBase.h:35
ContainerIterator< Particle_T, false, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, utils::optRef< typename ContainerIterator< Particle_T, false, true >::ParticleVecType > additionalVectors=std::nullopt) const override
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
Definition: VerletListsLinkedBase.h:243
void forEach(Lambda forEachLambda, IteratorBehavior behavior)
Execute code on all particles in this container as defined by a lambda function.
Definition: VerletListsLinkedBase.h:218
void deleteAllParticles() override
Deletes all particles.
Definition: VerletListsLinkedBase.h:106
bool _verletBuiltNewton3
specifies if the current verlet list was built for newton3
Definition: VerletListsLinkedBase.h:323
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: VerletListsLinkedBase.h:293
ContainerIterator< Particle_T, false, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, utils::optRef< typename ContainerIterator< Particle_T, false, false >::ParticleVecType > additionalVectors=std::nullopt) const override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: VerletListsLinkedBase.h:207
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:111
const std::array< std::size_t, 3 > & getCellsPerDimension() const
Get the dimension of the used cellblock including the haloboxes.
Definition: VerletListsLinkedBase.h:272
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: VerletListsLinkedBase.h:89
double getVerletSkin() const final
Return the verletSkin of the container verletSkin.
Definition: VerletListsLinkedBase.h:308
ContainerIterator< Particle_T, true, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, utils::optRef< typename ContainerIterator< Particle_T, true, true >::ParticleVecType > additionalVectors=std::nullopt) override
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
Definition: VerletListsLinkedBase.h:233
void setCutoff(double cutoff) final
Set the cutoff of the container.
Definition: VerletListsLinkedBase.h:303
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:148
const std::array< double, 3 > & getBoxMax() const final
Get the upper corner of the container without halo.
Definition: VerletListsLinkedBase.h:288
std::vector< Particle_T > updateContainer(bool keepNeighborListsValid) override
Updates the container.
Definition: VerletListsLinkedBase.h:164
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:263
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:117
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:140
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: VerletListsLinkedBase.h:313
std::atomic< bool > _neighborListIsValid
specifies if the neighbor list is currently valid
Definition: VerletListsLinkedBase.h:320
LinkedCells< Particle_T > _linkedCells
internal linked cells storage, handles Particle storage and used to build verlet lists
Definition: VerletListsLinkedBase.h:317
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: VerletListsLinkedBase.h:280
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:97
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:154
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:75
double getCutoff() const final
Return the cutoff of the container.
Definition: VerletListsLinkedBase.h:298
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior)
Reduce properties of particles as defined by a lambda function.
Definition: VerletListsLinkedBase.h:226
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:254
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: VerletListsLinkedBase.h:84
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
std::optional< std::reference_wrapper< T > > optRef
Short alias for std::optional<std::reference_wrapper<T>>
Definition: optRef.h:16
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34