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
64 void setAoSSortingThresholds(std::shared_ptr<const SortingThresholdInfoInterface> aosSortingThresholds) override {}
65
70 void setSoASortingThresholds(std::shared_ptr<const SortingThresholdInfoInterface> soaSortingThresholds) override {}
71
72 void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override {
73 _linkedCells.reserve(numParticles, numParticlesHaloEstimate);
74 }
75
80 void addParticleImpl(const Particle_T &p) override {
81 _neighborListIsValid.store(false, std::memory_order_relaxed);
82 // position is already checked, so call impl directly.
83 _linkedCells.addParticleImpl(p);
84 }
85
90 void addHaloParticleImpl(const Particle_T &haloParticle) override {
91 _neighborListIsValid.store(false, std::memory_order_relaxed);
92 // position is already checked, so call impl directly.
93 _linkedCells.addHaloParticleImpl(haloParticle);
94 }
95
99 size_t size() const override { return _linkedCells.size(); }
100
104 [[nodiscard]] size_t getNumberOfParticles(IteratorBehavior behavior) const override {
105 return _linkedCells.getNumberOfParticles(behavior);
106 }
107
112 void deleteHaloParticles() override {
113 _neighborListIsValid.store(false, std::memory_order_relaxed);
114 _linkedCells.deleteHaloParticles();
115 }
116
121 void deleteAllParticles() override {
122 _neighborListIsValid.store(false, std::memory_order_relaxed);
123 _linkedCells.deleteAllParticles();
124 }
125
126 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
127 IteratorBehavior iteratorBehavior,
128 const std::array<double, 3> &boxMin,
129 const std::array<double, 3> &boxMax) const override {
130 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
131 }
132 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
133 IteratorBehavior iteratorBehavior) const override {
134 // this is not a region iter hence we stretch the bounding box to the numeric max
135 constexpr std::array<double, 3> boxMin{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
136 std::numeric_limits<double>::lowest()};
137
138 constexpr std::array<double, 3> boxMax{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
139 std::numeric_limits<double>::max()};
140 return getParticleImpl<false>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
141 }
142
154 template <bool regionIter>
155 std::tuple<const Particle_T *, size_t, size_t> getParticleImpl(size_t cellIndex, size_t particleIndex,
156 IteratorBehavior iteratorBehavior,
157 const std::array<double, 3> &boxMin,
158 const std::array<double, 3> &boxMax) const {
159 return _linkedCells.template getParticleImpl<regionIter>(cellIndex, particleIndex, iteratorBehavior, boxMin,
160 boxMax);
161 }
162
163 bool deleteParticle(Particle_T &particle) override {
164 // This function doesn't actually delete anything as it would mess up the references in the lists.
166 return false;
167 }
168
169 bool deleteParticle(size_t cellIndex, size_t particleIndex) override {
170 // This function doesn't actually delete anything as it would mess up the references in the lists.
171 internal::markParticleAsDeleted(this->_linkedCells.getCells()[cellIndex][particleIndex]);
172 return false;
173 }
174
179 [[nodiscard]] std::vector<Particle_T> updateContainer(bool keepNeighborListsValid) override {
180 if (keepNeighborListsValid) {
182 }
183 _neighborListIsValid.store(false, std::memory_order_relaxed);
184 return _linkedCells.updateContainer(false);
185 }
186
194 bool updateHaloParticle(const Particle_T &haloParticle) override {
195 auto cells = _linkedCells.getCellBlock().getNearbyHaloCells(haloParticle.getR(), this->getVerletSkin());
196 for (auto cellptr : cells) {
197 bool updated = internal::checkParticleInCellAndUpdateByID(*cellptr, haloParticle);
198 if (updated) {
199 return true;
200 }
201 }
202 AutoPasLog(TRACE,
203 "updateHaloParticle was not able to update particle at "
204 "[{}, {}, {}]",
205 haloParticle.getR()[0], haloParticle.getR()[1], haloParticle.getR()[2]);
206 return false;
207 }
208
213 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
215 std::nullopt) override {
216 return _linkedCells.begin(behavior, additionalVectors);
217 }
218
223 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
225 std::nullopt) const override {
226 return _linkedCells.begin(behavior, additionalVectors);
227 }
228
232 template <typename Lambda>
233 void forEach(Lambda forEachLambda, IteratorBehavior behavior) {
234 return _linkedCells.forEach(forEachLambda, behavior);
235 }
236
240 template <typename Lambda, typename A>
241 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior) {
242 return _linkedCells.reduce(reduceLambda, result, behavior);
243 }
244
249 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
251 std::nullopt) override {
252 return _linkedCells.getRegionIterator(lowerCorner, higherCorner, behavior, additionalVectors);
253 }
254
259 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
261 std::nullopt) const override {
262 return _linkedCells.getRegionIterator(lowerCorner, higherCorner, behavior, additionalVectors);
263 }
264
268 template <typename Lambda>
269 void forEachInRegion(Lambda forEachLambda, const std::array<double, 3> &lowerCorner,
270 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
271 _linkedCells.forEachInRegion(forEachLambda, lowerCorner, higherCorner, behavior);
272 }
273
277 template <typename Lambda, typename A>
278 void reduceInRegion(Lambda reduceLambda, A &result, const std::array<double, 3> &lowerCorner,
279 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
280 _linkedCells.reduceInRegion(reduceLambda, result, lowerCorner, higherCorner, behavior);
281 }
282
287 [[nodiscard]] const std::array<std::size_t, 3> &getCellsPerDimension() const {
288 return _linkedCells.getCellBlock().getCellsPerDimensionWithHalo();
289 }
290
295 [[nodiscard]] TraversalSelectorInfo getTraversalSelectorInfo() const override {
296 return TraversalSelectorInfo(this->_linkedCells.getCellBlock().getCellsPerDimensionWithHalo(),
297 this->getInteractionLength(), this->_linkedCells.getCellBlock().getCellLength(), 0);
298 }
299
303 [[nodiscard]] const std::array<double, 3> &getBoxMax() const final { return _linkedCells.getBoxMax(); }
304
308 [[nodiscard]] const std::array<double, 3> &getBoxMin() const final { return _linkedCells.getBoxMin(); }
309
313 [[nodiscard]] double getCutoff() const final { return _linkedCells.getCutoff(); }
314
318 void setCutoff(double cutoff) final { _linkedCells.setCutoff(cutoff); }
319
323 [[nodiscard]] double getVerletSkin() const final { return _linkedCells.getVerletSkin(); }
324
328 [[nodiscard]] double getInteractionLength() const final { return _linkedCells.getInteractionLength(); }
329
330 protected:
333
335 std::atomic<bool> _neighborListIsValid{false};
336
339};
340
341} // namespace autopas
#define AutoPasLog(lvl, fmt,...)
Macro for logging providing common meta information without filename.
Definition: Logger.h:74
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:40
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:194
void addParticleImpl(const Particle_T &p) override
Adds a particle to the container.
Definition: VerletListsLinkedBase.h:80
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:212
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:72
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:258
void forEach(Lambda forEachLambda, IteratorBehavior behavior)
Execute code on all particles in this container as defined by a lambda function.
Definition: VerletListsLinkedBase.h:233
void deleteAllParticles() override
Deletes all particles.
Definition: VerletListsLinkedBase.h:121
bool _verletBuiltNewton3
specifies if the current verlet list was built for newton3
Definition: VerletListsLinkedBase.h:338
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: VerletListsLinkedBase.h:308
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:222
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:126
const std::array< std::size_t, 3 > & getCellsPerDimension() const
Get the dimension of the used cellblock including the haloboxes.
Definition: VerletListsLinkedBase.h:287
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: VerletListsLinkedBase.h:104
double getVerletSkin() const final
Return the verletSkin of the container verletSkin.
Definition: VerletListsLinkedBase.h:323
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:248
void setSoASortingThresholds(std::shared_ptr< const SortingThresholdInfoInterface > soaSortingThresholds) override
Set the SoA sorting-threshold for traversals that use the CellFunctor.
Definition: VerletListsLinkedBase.h:70
void setCutoff(double cutoff) final
Set the cutoff of the container.
Definition: VerletListsLinkedBase.h:318
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:163
const std::array< double, 3 > & getBoxMax() const final
Get the upper corner of the container without halo.
Definition: VerletListsLinkedBase.h:303
std::vector< Particle_T > updateContainer(bool keepNeighborListsValid) override
Updates the container.
Definition: VerletListsLinkedBase.h:179
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:278
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:132
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:155
void setAoSSortingThresholds(std::shared_ptr< const SortingThresholdInfoInterface > aosSortingThresholds) override
Set the aos-sorting-threshold for traversals that use the CellFunctor.
Definition: VerletListsLinkedBase.h:64
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: VerletListsLinkedBase.h:328
std::atomic< bool > _neighborListIsValid
specifies if the neighbor list is currently valid
Definition: VerletListsLinkedBase.h:335
LinkedCells< Particle_T > _linkedCells
internal linked cells storage, handles Particle storage and used to build verlet lists
Definition: VerletListsLinkedBase.h:332
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: VerletListsLinkedBase.h:295
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:112
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:169
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:90
double getCutoff() const final
Return the cutoff of the container.
Definition: VerletListsLinkedBase.h:313
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior)
Reduce properties of particles as defined by a lambda function.
Definition: VerletListsLinkedBase.h:241
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:269
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: VerletListsLinkedBase.h:99
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