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
47 VerletListsLinkedBase(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax, const double cutoff,
48 const double skin, const double cellSizeFactor)
49 : ParticleContainerInterface<Particle_T>(skin),
50 _linkedCells(boxMin, boxMax, cutoff, skin, std::max(1.0, cellSizeFactor)) {
51 if (cellSizeFactor < 1.0) {
52 // Throw exception - this config should have been caught by LogicHandler. Note: This is not a fundamental issue
53 // with the algorithm but simply has not been implemented.
55 "Trying to construct a VerletListsLinkedBase with CSF < 1.0! This should never occur as the LogicHandler "
56 "should reject this (as Configuration::hasCompatibleValues should return false).");
57 }
58 }
59
60 void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override {
61 _linkedCells.reserve(numParticles, numParticlesHaloEstimate);
62 }
63
68 void addParticleImpl(const Particle_T &p) override {
69 _neighborListIsValid.store(false, std::memory_order_relaxed);
70 // position is already checked, so call impl directly.
71 _linkedCells.addParticleImpl(p);
72 }
73
78 void addHaloParticleImpl(const Particle_T &haloParticle) override {
79 _neighborListIsValid.store(false, std::memory_order_relaxed);
80 // position is already checked, so call impl directly.
81 _linkedCells.addHaloParticleImpl(haloParticle);
82 }
83
87 size_t size() const override { return _linkedCells.size(); }
88
92 [[nodiscard]] size_t getNumberOfParticles(IteratorBehavior behavior) const override {
93 return _linkedCells.getNumberOfParticles(behavior);
94 }
95
100 void deleteHaloParticles() override {
101 _neighborListIsValid.store(false, std::memory_order_relaxed);
102 _linkedCells.deleteHaloParticles();
103 }
104
109 void deleteAllParticles() override {
110 _neighborListIsValid.store(false, std::memory_order_relaxed);
111 _linkedCells.deleteAllParticles();
112 }
113
114 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
115 IteratorBehavior iteratorBehavior,
116 const std::array<double, 3> &boxMin,
117 const std::array<double, 3> &boxMax) const override {
118 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
119 }
120 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
121 IteratorBehavior iteratorBehavior) const override {
122 // this is not a region iter hence we stretch the bounding box to the numeric max
123 constexpr std::array<double, 3> boxMin{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
124 std::numeric_limits<double>::lowest()};
125
126 constexpr std::array<double, 3> boxMax{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
127 std::numeric_limits<double>::max()};
128 return getParticleImpl<false>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
129 }
130
142 template <bool regionIter>
143 std::tuple<const Particle_T *, size_t, size_t> getParticleImpl(size_t cellIndex, size_t particleIndex,
144 IteratorBehavior iteratorBehavior,
145 const std::array<double, 3> &boxMin,
146 const std::array<double, 3> &boxMax) const {
147 return _linkedCells.template getParticleImpl<regionIter>(cellIndex, particleIndex, iteratorBehavior, boxMin,
148 boxMax);
149 }
150
151 bool deleteParticle(Particle_T &particle) override {
152 // This function doesn't actually delete anything as it would mess up the references in the lists.
154 return false;
155 }
156
157 bool deleteParticle(size_t cellIndex, size_t particleIndex) override {
158 // This function doesn't actually delete anything as it would mess up the references in the lists.
159 internal::markParticleAsDeleted(this->_linkedCells.getCells()[cellIndex][particleIndex]);
160 return false;
161 }
162
167 [[nodiscard]] std::vector<Particle_T> updateContainer(bool keepNeighborListsValid) override {
168 if (keepNeighborListsValid) {
170 }
171 _neighborListIsValid.store(false, std::memory_order_relaxed);
172 return _linkedCells.updateContainer(false);
173 }
174
182 bool updateHaloParticle(const Particle_T &haloParticle) override {
183 auto cells = _linkedCells.getCellBlock().getNearbyHaloCells(haloParticle.getR(), this->getVerletSkin());
184 for (auto cellptr : cells) {
185 bool updated = internal::checkParticleInCellAndUpdateByID(*cellptr, haloParticle);
186 if (updated) {
187 return true;
188 }
189 }
190 AutoPasLog(TRACE,
191 "updateHaloParticle was not able to update particle at "
192 "[{}, {}, {}]",
193 haloParticle.getR()[0], haloParticle.getR()[1], haloParticle.getR()[2]);
194 return false;
195 }
196
201 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
203 std::nullopt) override {
204 return _linkedCells.begin(behavior, additionalVectors);
205 }
206
211 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
213 std::nullopt) const override {
214 return _linkedCells.begin(behavior, additionalVectors);
215 }
216
220 template <typename Lambda>
221 void forEach(Lambda forEachLambda, IteratorBehavior behavior) {
222 return _linkedCells.forEach(forEachLambda, behavior);
223 }
224
228 template <typename Lambda, typename A>
229 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior) {
230 return _linkedCells.reduce(reduceLambda, result, behavior);
231 }
232
237 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
239 std::nullopt) override {
240 return _linkedCells.getRegionIterator(lowerCorner, higherCorner, behavior, additionalVectors);
241 }
242
247 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
249 std::nullopt) const override {
250 return _linkedCells.getRegionIterator(lowerCorner, higherCorner, behavior, additionalVectors);
251 }
252
256 template <typename Lambda>
257 void forEachInRegion(Lambda forEachLambda, const std::array<double, 3> &lowerCorner,
258 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
259 _linkedCells.forEachInRegion(forEachLambda, lowerCorner, higherCorner, behavior);
260 }
261
265 template <typename Lambda, typename A>
266 void reduceInRegion(Lambda reduceLambda, A &result, const std::array<double, 3> &lowerCorner,
267 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
268 _linkedCells.reduceInRegion(reduceLambda, result, lowerCorner, higherCorner, behavior);
269 }
270
275 [[nodiscard]] const std::array<std::size_t, 3> &getCellsPerDimension() const {
276 return _linkedCells.getCellBlock().getCellsPerDimensionWithHalo();
277 }
278
283 [[nodiscard]] TraversalSelectorInfo getTraversalSelectorInfo() const override {
284 return TraversalSelectorInfo(this->_linkedCells.getCellBlock().getCellsPerDimensionWithHalo(),
285 this->getInteractionLength(), this->_linkedCells.getCellBlock().getCellLength(), 0);
286 }
287
291 [[nodiscard]] const std::array<double, 3> &getBoxMax() const final { return _linkedCells.getBoxMax(); }
292
296 [[nodiscard]] const std::array<double, 3> &getBoxMin() const final { return _linkedCells.getBoxMin(); }
297
301 [[nodiscard]] double getCutoff() const final { return _linkedCells.getCutoff(); }
302
306 void setCutoff(double cutoff) final { _linkedCells.setCutoff(cutoff); }
307
311 [[nodiscard]] double getVerletSkin() const final { return _linkedCells.getVerletSkin(); }
312
316 [[nodiscard]] double getInteractionLength() const final { return _linkedCells.getInteractionLength(); }
317
318 protected:
321
323 std::atomic<bool> _neighborListIsValid{false};
324
327};
328
329} // 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:182
void addParticleImpl(const Particle_T &p) override
Adds a particle to the container.
Definition: VerletListsLinkedBase.h:68
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:200
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:60
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:246
void forEach(Lambda forEachLambda, IteratorBehavior behavior)
Execute code on all particles in this container as defined by a lambda function.
Definition: VerletListsLinkedBase.h:221
void deleteAllParticles() override
Deletes all particles.
Definition: VerletListsLinkedBase.h:109
bool _verletBuiltNewton3
specifies if the current verlet list was built for newton3
Definition: VerletListsLinkedBase.h:326
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: VerletListsLinkedBase.h:296
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:210
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:114
const std::array< std::size_t, 3 > & getCellsPerDimension() const
Get the dimension of the used cellblock including the haloboxes.
Definition: VerletListsLinkedBase.h:275
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: VerletListsLinkedBase.h:92
double getVerletSkin() const final
Return the verletSkin of the container verletSkin.
Definition: VerletListsLinkedBase.h:311
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:236
void setCutoff(double cutoff) final
Set the cutoff of the container.
Definition: VerletListsLinkedBase.h:306
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:151
const std::array< double, 3 > & getBoxMax() const final
Get the upper corner of the container without halo.
Definition: VerletListsLinkedBase.h:291
std::vector< Particle_T > updateContainer(bool keepNeighborListsValid) override
Updates the container.
Definition: VerletListsLinkedBase.h:167
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:266
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:120
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:143
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: VerletListsLinkedBase.h:316
std::atomic< bool > _neighborListIsValid
specifies if the neighbor list is currently valid
Definition: VerletListsLinkedBase.h:323
LinkedCells< Particle_T > _linkedCells
internal linked cells storage, handles Particle storage and used to build verlet lists
Definition: VerletListsLinkedBase.h:320
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: VerletListsLinkedBase.h:283
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:47
void deleteHaloParticles() override
Deletes all halo particles.
Definition: VerletListsLinkedBase.h:100
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:157
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:78
double getCutoff() const final
Return the cutoff of the container.
Definition: VerletListsLinkedBase.h:301
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior)
Reduce properties of particles as defined by a lambda function.
Definition: VerletListsLinkedBase.h:229
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:257
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: VerletListsLinkedBase.h:87
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:64
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