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 ParticleContainerInterface(double skin) : _skin(skin) {}
49
53 virtual ~ParticleContainerInterface() = default;
54
61
69
74 [[nodiscard]] virtual ContainerOption getContainerType() const = 0;
75
81 virtual void reserve(size_t numParticles, size_t numParticlesHaloEstimate) = 0;
82
89 template <bool checkInBox = true>
90 void addParticle(const Particle_T &p) {
91 if constexpr (checkInBox) {
92 if (utils::notInBox(p.getR(), this->getBoxMin(), this->getBoxMax())) {
94 "ParticleContainerInterface: Trying to add a particle that is not in the bounding box.\n"
95 "Box Min {}\n"
96 "Box Max {}\n"
97 "{}",
98 this->getBoxMin(), this->getBoxMax(), p.toString());
99 }
100 }
102 };
103
104 protected:
111 virtual void addParticleImpl(const Particle_T &p) = 0;
112
113 public:
120 template <bool checkInBox = true>
121 void addHaloParticle(const Particle_T &haloParticle) {
122 if constexpr (checkInBox) {
124 if (utils::inBox(haloParticle.getR(), this->getBoxMin(), this->getBoxMax())) {
126 "ParticleContainerInterface: Trying to add a halo particle that is not outside of in the bounding box.\n"
127 "Box Min {}\n"
128 "Box Max {}\n"
129 "{}",
130 this->getBoxMin(), this->getBoxMax(), haloParticle.toString());
131 }
132 }
133 addHaloParticleImpl(haloParticle);
134 }
135
136 protected:
143 virtual void addHaloParticleImpl(const Particle_T &haloParticle) = 0;
144
145 public:
151 virtual bool updateHaloParticle(const Particle_T &haloParticle) = 0;
152
157 virtual void rebuildNeighborLists(TraversalInterface *traversal) = 0;
158
162 virtual void deleteHaloParticles() = 0;
163
167 virtual void deleteAllParticles() = 0;
168
178 [[nodiscard]] virtual size_t getNumberOfParticles(IteratorBehavior behavior = IteratorBehavior::owned) const = 0;
179
184 [[nodiscard]] virtual size_t size() const = 0;
185
195 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
196 typename ContainerIterator<Particle_T, true, false>::ParticleVecType *additionalVectors = nullptr) = 0;
197
203 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
204 typename ContainerIterator<Particle_T, false, false>::ParticleVecType *additionalVectors = nullptr) const = 0;
205
211 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
212 typename ContainerIterator<Particle_T, false, false>::ParticleVecType *additionalVectors = nullptr) const {
213 return begin(behavior, additionalVectors);
214 }
215
226 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
227 typename ContainerIterator<Particle_T, true, true>::ParticleVecType *additionalVectors = nullptr) = 0;
228
234 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
235 typename ContainerIterator<Particle_T, false, true>::ParticleVecType *additionalVectors = nullptr) const = 0;
236
240 [[nodiscard]] constexpr bool end() const { return false; }
241
246 virtual void computeInteractions(TraversalInterface *traversal) = 0;
247
252 [[nodiscard]] virtual const std::array<double, 3> &getBoxMax() const = 0;
253
258 [[nodiscard]] virtual const std::array<double, 3> &getBoxMin() const = 0;
259
264 [[nodiscard]] virtual double getCutoff() const = 0;
265
270 virtual void setCutoff(double cutoff) = 0;
271
276 [[nodiscard]] virtual double getVerletSkin() const = 0;
277
284 [[nodiscard]] virtual size_t getStepsSinceLastRebuild() const { return _stepsSinceLastRebuild; }
285
290 virtual void setStepsSinceLastRebuild(size_t stepsSinceLastRebuild) {
291 _stepsSinceLastRebuild = stepsSinceLastRebuild;
292 }
293
298 [[nodiscard]] virtual double getInteractionLength() const = 0;
299
307 [[nodiscard]] virtual std::vector<Particle_T> updateContainer(bool keepNeighborListsValid) = 0;
308
313 [[nodiscard]] virtual TraversalSelectorInfo getTraversalSelectorInfo() const = 0;
314
323 [[nodiscard]] std::set<TraversalOption> getAllTraversals(const InteractionTypeOption interactionType) const {
324 return compatibleTraversals::allCompatibleTraversals(this->getContainerType(), interactionType);
325 }
326
347 virtual std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
348 IteratorBehavior iteratorBehavior) const = 0;
349
358 virtual std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
359 IteratorBehavior iteratorBehavior,
360 const std::array<double, 3> &boxMin,
361 const std::array<double, 3> &boxMax) const = 0;
362
363 // clang-format off
369 // clang-format on
370 std::tuple<Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
371 IteratorBehavior iteratorBehavior,
372 const std::array<double, 3> &boxMin,
373 const std::array<double, 3> &boxMax) {
374 const Particle_T *ptr{};
375 size_t nextCellIndex{}, nextParticleIndex{};
376 std::tie(ptr, nextCellIndex, nextParticleIndex) =
377 const_cast<const ParticleContainerInterface<Particle_T> *>(this)->getParticle(cellIndex, particleIndex,
378 iteratorBehavior, boxMin, boxMax);
379 return {const_cast<Particle_T *>(ptr), nextCellIndex, nextParticleIndex};
380 }
381
387 std::tuple<Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
388 IteratorBehavior iteratorBehavior) {
389 const Particle_T *ptr{};
390 size_t nextCellIndex{}, nextParticleIndex{};
391 std::tie(ptr, nextCellIndex, nextParticleIndex) =
392 const_cast<const ParticleContainerInterface<Particle_T> *>(this)->getParticle(cellIndex, particleIndex,
393 iteratorBehavior);
394 return {const_cast<Particle_T *>(ptr), nextCellIndex, nextParticleIndex};
395 }
396
404 virtual bool deleteParticle(Particle_T &particle) = 0;
405
414 virtual bool deleteParticle(size_t cellIndex, size_t particleIndex) = 0;
415
416 protected:
423
427 double _skin;
428};
429
430} // 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:323
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:370
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.
virtual 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 =0
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
constexpr bool end() const
Dummy to make range-based for loops work.
Definition: ParticleContainerInterface.h:240
virtual double getVerletSkin() const =0
Return the verletSkin of the container verletSkin.
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:387
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...
virtual std::vector< Particle_T > updateContainer(bool keepNeighborListsValid)=0
Updates the container.
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:121
virtual 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)=0
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
ContainerIterator< Particle_T, false, false > cbegin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, typename ContainerIterator< Particle_T, false, false >::ParticleVecType *additionalVectors=nullptr) const
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: ParticleContainerInterface.h:210
virtual void setCutoff(double cutoff)=0
Set the cutoff of the container.
virtual ContainerIterator< Particle_T, false, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, typename ContainerIterator< Particle_T, false, false >::ParticleVecType *additionalVectors=nullptr) const =0
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
size_t _stepsSinceLastRebuild
Stores the number of time-steps since last neighbor list rebuild.
Definition: ParticleContainerInterface.h:422
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 ContainerIterator< Particle_T, true, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, typename ContainerIterator< Particle_T, true, false >::ParticleVecType *additionalVectors=nullptr)=0
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
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:290
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:427
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:90
virtual void computeInteractions(TraversalInterface *traversal)=0
Iterates over all particle multiples (e.g.
virtual void deleteHaloParticles()=0
Deletes all halo particles.
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:48
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:284
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 ~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