AutoPas  3.0.0
Loading...
Searching...
No Matches
ParticleContainerInterface.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <array>
11#include <vector>
12
21#include "autopas/utils/inBox.h"
22
23namespace autopas {
24
25// forward declaration
26template <class Particle_T, bool modifiable, bool regionIter>
27class ContainerIterator;
28
36template <class Particle_T>
38 public:
42 using ParticleType = Particle_T;
43
48 virtual CellType getParticleCellTypeEnum() const = 0;
49
54 ParticleContainerInterface(double skin) : _skin(skin) {}
55
59 virtual ~ParticleContainerInterface() = default;
60
67
75
80 [[nodiscard]] virtual ContainerOption getContainerType() const = 0;
81
87 virtual void reserve(size_t numParticles, size_t numParticlesHaloEstimate) = 0;
88
95 template <bool checkInBox = true>
96 void addParticle(const Particle_T &p) {
97 if constexpr (checkInBox) {
98 if (utils::notInBox(p.getR(), this->getBoxMin(), this->getBoxMax())) {
100 "ParticleContainerInterface: Trying to add a particle that is not in the bounding box.\n"
101 "Box Min {}\n"
102 "Box Max {}\n"
103 "{}",
104 this->getBoxMin(), this->getBoxMax(), p.toString());
105 }
106 }
108 };
109
110 protected:
117 virtual void addParticleImpl(const Particle_T &p) = 0;
118
119 public:
126 template <bool checkInBox = true>
127 void addHaloParticle(const Particle_T &haloParticle) {
128 if constexpr (checkInBox) {
130 if (utils::inBox(haloParticle.getR(), this->getBoxMin(), this->getBoxMax())) {
132 "ParticleContainerInterface: Trying to add a halo particle that is not outside of in the bounding box.\n"
133 "Box Min {}\n"
134 "Box Max {}\n"
135 "{}",
136 this->getBoxMin(), this->getBoxMax(), haloParticle.toString());
137 }
138 }
139 addHaloParticleImpl(haloParticle);
140 }
141
142 protected:
149 virtual void addHaloParticleImpl(const Particle_T &haloParticle) = 0;
150
151 public:
157 virtual bool updateHaloParticle(const Particle_T &haloParticle) = 0;
158
163 virtual void rebuildNeighborLists(TraversalInterface *traversal) = 0;
164
168 virtual void deleteHaloParticles() = 0;
169
173 virtual void deleteAllParticles() = 0;
174
184 [[nodiscard]] virtual size_t getNumberOfParticles(IteratorBehavior behavior = IteratorBehavior::owned) const = 0;
185
190 [[nodiscard]] virtual size_t size() const = 0;
191
201 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHalo,
202 typename ContainerIterator<ParticleType, true, false>::ParticleVecType *additionalVectors = nullptr) = 0;
203
209 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHalo,
210 typename ContainerIterator<ParticleType, false, false>::ParticleVecType *additionalVectors = nullptr) const = 0;
211
217 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHalo,
219 nullptr) const final {
220 return begin(behavior);
221 };
222
233 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
234 typename ContainerIterator<ParticleType, true, true>::ParticleVecType *additionalVectors = nullptr) = 0;
235
241 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
242 typename ContainerIterator<ParticleType, false, true>::ParticleVecType *additionalVectors = nullptr) const = 0;
243
247 [[nodiscard]] constexpr bool end() const { return false; }
248
253 virtual void computeInteractions(TraversalInterface *traversal) = 0;
254
259 [[nodiscard]] virtual const std::array<double, 3> &getBoxMax() const = 0;
260
265 [[nodiscard]] virtual const std::array<double, 3> &getBoxMin() const = 0;
266
271 [[nodiscard]] virtual double getCutoff() const = 0;
272
277 virtual void setCutoff(double cutoff) = 0;
278
283 [[nodiscard]] virtual double getVerletSkin() const = 0;
284
291 [[nodiscard]] virtual size_t getStepsSinceLastRebuild() const { return _stepsSinceLastRebuild; }
292
297 virtual void setStepsSinceLastRebuild(size_t stepsSinceLastRebuild) {
298 _stepsSinceLastRebuild = stepsSinceLastRebuild;
299 }
300
305 [[nodiscard]] virtual double getInteractionLength() const = 0;
306
314 [[nodiscard]] virtual std::vector<ParticleType> updateContainer(bool keepNeighborListsValid) = 0;
315
320 [[nodiscard]] virtual TraversalSelectorInfo getTraversalSelectorInfo() const = 0;
321
330 [[nodiscard]] std::set<TraversalOption> getAllTraversals(const InteractionTypeOption interactionType) const {
331 return compatibleTraversals::allCompatibleTraversals(this->getContainerType(), interactionType);
332 }
333
354 virtual std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
355 IteratorBehavior iteratorBehavior) const = 0;
356
365 virtual std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
366 IteratorBehavior iteratorBehavior,
367 const std::array<double, 3> &boxMin,
368 const std::array<double, 3> &boxMax) const = 0;
369
370 // clang-format off
376 // clang-format on
377 std::tuple<Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
378 IteratorBehavior iteratorBehavior,
379 const std::array<double, 3> &boxMin,
380 const std::array<double, 3> &boxMax) {
381 const Particle_T *ptr{};
382 size_t nextCellIndex{}, nextParticleIndex{};
383 std::tie(ptr, nextCellIndex, nextParticleIndex) =
384 const_cast<const ParticleContainerInterface<Particle_T> *>(this)->getParticle(cellIndex, particleIndex,
385 iteratorBehavior, boxMin, boxMax);
386 return {const_cast<Particle_T *>(ptr), nextCellIndex, nextParticleIndex};
387 }
388
394 std::tuple<Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
395 IteratorBehavior iteratorBehavior) {
396 const Particle_T *ptr{};
397 size_t nextCellIndex{}, nextParticleIndex{};
398 std::tie(ptr, nextCellIndex, nextParticleIndex) =
399 const_cast<const ParticleContainerInterface<Particle_T> *>(this)->getParticle(cellIndex, particleIndex,
400 iteratorBehavior);
401 return {const_cast<Particle_T *>(ptr), nextCellIndex, nextParticleIndex};
402 }
403
411 virtual bool deleteParticle(Particle_T &particle) = 0;
412
421 virtual bool deleteParticle(size_t cellIndex, size_t particleIndex) = 0;
422
423 protected:
430
434 double _skin;
435};
436
437} // namespace autopas
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
The ParticleContainerInterface class provides a basic interface for all Containers within AutoPas.
Definition: ParticleContainerInterface.h:37
std::set< TraversalOption > getAllTraversals(const InteractionTypeOption interactionType) const
Generates a list of all traversals that are theoretically applicable to this container.
Definition: ParticleContainerInterface.h:330
virtual void rebuildNeighborLists(TraversalInterface *traversal)=0
Rebuilds the neighbor lists for the next traversals.
std::tuple< 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)
Fetch the pointer to a particle, identified via a cell and particle index.
Definition: ParticleContainerInterface.h:377
virtual const std::array< double, 3 > & getBoxMin() const =0
Get the lower corner of the container without halo.
ParticleContainerInterface & operator=(const ParticleContainerInterface &other)=delete
Delete the copy assignment operator to prevent unwanted copies.
virtual double getCutoff() const =0
Return the cutoff of the container.
virtual const std::array< double, 3 > & getBoxMax() const =0
Get the upper corner of the container without halo.
virtual TraversalSelectorInfo getTraversalSelectorInfo() const =0
Generates a traversal selector info for this container.
constexpr bool end() const
Dummy to make range-based for loops work.
Definition: ParticleContainerInterface.h:247
virtual double getVerletSkin() const =0
Return the verletSkin of the container verletSkin.
virtual ContainerIterator< ParticleType, true, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, typename ContainerIterator< ParticleType, true, true >::ParticleVecType *additionalVectors=nullptr)=0
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
std::tuple< Particle_T *, size_t, size_t > getParticle(size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior)
Fetch the pointer to a particle, identified via a cell and particle index.
Definition: ParticleContainerInterface.h:394
virtual double getInteractionLength() const =0
Return the interaction length (cutoff+skin) of the container.
virtual bool deleteParticle(size_t cellIndex, size_t particleIndex)=0
Deletes the particle at the given index positions as long as this does not compromise the validity of...
Particle_T ParticleType
Type of the Particle.
Definition: ParticleContainerInterface.h:42
void addHaloParticle(const Particle_T &haloParticle)
Adds a particle to the container that lies in the halo region of the container.
Definition: ParticleContainerInterface.h:127
virtual ContainerIterator< ParticleType, true, false > begin(IteratorBehavior behavior=autopas::IteratorBehavior::ownedOrHalo, typename ContainerIterator< ParticleType, true, false >::ParticleVecType *additionalVectors=nullptr)=0
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
virtual void setCutoff(double cutoff)=0
Set the cutoff of the container.
size_t _stepsSinceLastRebuild
Stores the number of time-steps since last neighbor list rebuild.
Definition: ParticleContainerInterface.h:429
virtual void deleteAllParticles()=0
Deletes all particles.
virtual size_t getNumberOfParticles(IteratorBehavior behavior=IteratorBehavior::owned) const =0
Get the number of particles with respect to the specified IteratorBehavior.
virtual bool updateHaloParticle(const Particle_T &haloParticle)=0
Update a halo particle of the container with the given haloParticle.
virtual void reserve(size_t numParticles, size_t numParticlesHaloEstimate)=0
Reserve memory for a given number of particles in the container and logic layers.
virtual std::vector< ParticleType > updateContainer(bool keepNeighborListsValid)=0
Updates the container.
virtual ContainerOption getContainerType() const =0
Get the ContainerType.
virtual void setStepsSinceLastRebuild(size_t stepsSinceLastRebuild)
Set the number of time-steps since last neighbor list rebuild.
Definition: ParticleContainerInterface.h:297
virtual void addParticleImpl(const Particle_T &p)=0
Adds a particle to the container.
double _skin
Skin distance a particle is allowed to move in one time-step.
Definition: ParticleContainerInterface.h:434
virtual CellType getParticleCellTypeEnum() const =0
Get the ParticleCell type as an Enum.
virtual ContainerIterator< ParticleType, false, false > cbegin(IteratorBehavior behavior=autopas::IteratorBehavior::ownedOrHalo, typename ContainerIterator< ParticleType, false, false >::ParticleVecType *additionalVectors=nullptr) const final
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: ParticleContainerInterface.h:216
virtual std::tuple< const Particle_T *, size_t, size_t > getParticle(size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior) const =0
Fetch the pointer to a particle, identified via a cell and particle index.
void addParticle(const Particle_T &p)
Adds a particle to the container.
Definition: ParticleContainerInterface.h:96
virtual void computeInteractions(TraversalInterface *traversal)=0
Iterates over all particle multiples (e.g.
virtual void deleteHaloParticles()=0
Deletes all halo particles.
virtual ContainerIterator< ParticleType, false, false > begin(IteratorBehavior behavior=autopas::IteratorBehavior::ownedOrHalo, typename ContainerIterator< ParticleType, false, false >::ParticleVecType *additionalVectors=nullptr) const =0
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
virtual bool deleteParticle(Particle_T &particle)=0
Deletes the given particle as long as this does not compromise the validity of the container.
ParticleContainerInterface(double skin)
Constructor.
Definition: ParticleContainerInterface.h:54
virtual 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 =0
Fetch the pointer to a particle, identified via a cell and particle index.
virtual size_t getStepsSinceLastRebuild() const
Return the number of time-steps since last neighbor list rebuild.
Definition: ParticleContainerInterface.h:291
virtual void addHaloParticleImpl(const Particle_T &haloParticle)=0
Adds a particle to the container that lies in the halo region of the container.
ParticleContainerInterface(const ParticleContainerInterface &obj)=delete
Delete the copy constructor to prevent unwanted copies.
virtual size_t size() const =0
Get the total number of particles saved in the container (owned + halo + dummy).
virtual ContainerIterator< ParticleType, false, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, typename ContainerIterator< ParticleType, false, true >::ParticleVecType *additionalVectors=nullptr) const =0
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
virtual ~ParticleContainerInterface()=default
Destructor of ParticleContainerInterface.
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
Info for traversals of a specific container.
Definition: TraversalSelectorInfo.h:14
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
bool notInBox(const std::array< T, 3 > &position, const std::array< T, 3 > &low, const std::array< T, 3 > &high)
Checks if position is not inside of a box defined by low and high.
Definition: inBox.h:50
bool inBox(const std::array< T, 3 > &position, const std::array< T, 3 > &low, const std::array< T, 3 > &high)
Checks if position is inside of a box defined by low and high.
Definition: inBox.h:26
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
CellType
The ParticleCell Type as an Enum.
Definition: ParticleCell.h:19