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"
23
24namespace autopas {
25
26// forward declaration
27template <class Particle_T, bool modifiable, bool regionIter>
28class ContainerIterator;
29
37template <class Particle_T>
39 public:
43 using ParticleType = Particle_T;
44
49 ParticleContainerInterface(double skin) : _skin(skin) {}
50
54 virtual ~ParticleContainerInterface() = default;
55
62
70
75 [[nodiscard]] virtual ContainerOption getContainerType() const = 0;
76
82 virtual void reserve(size_t numParticles, size_t numParticlesHaloEstimate) = 0;
83
90 template <bool checkInBox = true>
91 void addParticle(const Particle_T &p) {
92 if constexpr (checkInBox) {
93 if (utils::notInBox(p.getR(), this->getBoxMin(), this->getBoxMax())) {
95 "ParticleContainerInterface: Trying to add a particle that is not in the bounding box.\n"
96 "Box Min {}\n"
97 "Box Max {}\n"
98 "{}",
99 this->getBoxMin(), this->getBoxMax(), p.toString());
100 }
101 }
103 };
104
105 protected:
112 virtual void addParticleImpl(const Particle_T &p) = 0;
113
114 public:
121 template <bool checkInBox = true>
122 void addHaloParticle(const Particle_T &haloParticle) {
123 if constexpr (checkInBox) {
125 if (utils::inBox(haloParticle.getR(), this->getBoxMin(), this->getBoxMax())) {
127 "ParticleContainerInterface: Trying to add a halo particle that is not outside of in the bounding box.\n"
128 "Box Min {}\n"
129 "Box Max {}\n"
130 "{}",
131 this->getBoxMin(), this->getBoxMax(), haloParticle.toString());
132 }
133 }
134 addHaloParticleImpl(haloParticle);
135 }
136
137 protected:
144 virtual void addHaloParticleImpl(const Particle_T &haloParticle) = 0;
145
146 public:
152 virtual bool updateHaloParticle(const Particle_T &haloParticle) = 0;
153
158 virtual void rebuildNeighborLists(TraversalInterface *traversal) = 0;
159
163 virtual void deleteHaloParticles() = 0;
164
168 virtual void deleteAllParticles() = 0;
169
179 [[nodiscard]] virtual size_t getNumberOfParticles(IteratorBehavior behavior = IteratorBehavior::owned) const = 0;
180
185 [[nodiscard]] virtual size_t size() const = 0;
186
196 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
198 std::nullopt) = 0;
199
205 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
207 std::nullopt) const = 0;
208
214 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
216 std::nullopt) const {
217 return begin(behavior, additionalVectors);
218 }
219
230 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
232 std::nullopt) = 0;
233
239 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
241 std::nullopt) const = 0;
242
246 [[nodiscard]] constexpr bool end() const { return false; }
247
252 virtual void computeInteractions(TraversalInterface *traversal) = 0;
253
258 [[nodiscard]] virtual const std::array<double, 3> &getBoxMax() const = 0;
259
264 [[nodiscard]] virtual const std::array<double, 3> &getBoxMin() const = 0;
265
270 [[nodiscard]] virtual double getCutoff() const = 0;
271
276 virtual void setCutoff(double cutoff) = 0;
277
282 [[nodiscard]] virtual double getVerletSkin() const = 0;
283
288 [[nodiscard]] virtual double getInteractionLength() const = 0;
289
297 [[nodiscard]] virtual std::vector<Particle_T> updateContainer(bool keepNeighborListsValid) = 0;
298
303 [[nodiscard]] virtual TraversalSelectorInfo getTraversalSelectorInfo() const = 0;
304
313 [[nodiscard]] std::set<TraversalOption> getAllTraversals(const InteractionTypeOption interactionType) const {
314 return compatibleTraversals::allCompatibleTraversals(this->getContainerType(), interactionType);
315 }
316
337 virtual std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
338 IteratorBehavior iteratorBehavior) const = 0;
339
348 virtual std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
349 IteratorBehavior iteratorBehavior,
350 const std::array<double, 3> &boxMin,
351 const std::array<double, 3> &boxMax) const = 0;
352
353 // clang-format off
359 // clang-format on
360 std::tuple<Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
361 IteratorBehavior iteratorBehavior,
362 const std::array<double, 3> &boxMin,
363 const std::array<double, 3> &boxMax) {
364 const Particle_T *ptr{};
365 size_t nextCellIndex{}, nextParticleIndex{};
366 std::tie(ptr, nextCellIndex, nextParticleIndex) =
367 const_cast<const ParticleContainerInterface<Particle_T> *>(this)->getParticle(cellIndex, particleIndex,
368 iteratorBehavior, boxMin, boxMax);
369 return {const_cast<Particle_T *>(ptr), nextCellIndex, nextParticleIndex};
370 }
371
377 std::tuple<Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
378 IteratorBehavior iteratorBehavior) {
379 const Particle_T *ptr{};
380 size_t nextCellIndex{}, nextParticleIndex{};
381 std::tie(ptr, nextCellIndex, nextParticleIndex) =
382 const_cast<const ParticleContainerInterface<Particle_T> *>(this)->getParticle(cellIndex, particleIndex,
383 iteratorBehavior);
384 return {const_cast<Particle_T *>(ptr), nextCellIndex, nextParticleIndex};
385 }
386
394 virtual bool deleteParticle(Particle_T &particle) = 0;
395
404 virtual bool deleteParticle(size_t cellIndex, size_t particleIndex) = 0;
405
406 protected:
410 double _skin;
411};
412
413} // namespace autopas
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
The ParticleContainerInterface class provides a basic interface for all Containers within AutoPas.
Definition: ParticleContainerInterface.h:38
std::set< TraversalOption > getAllTraversals(const InteractionTypeOption interactionType) const
Generates a list of all traversals that are theoretically applicable to this container.
Definition: ParticleContainerInterface.h:313
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:360
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 ContainerIterator< Particle_T, false, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, utils::optRef< typename ContainerIterator< Particle_T, false, false >::ParticleVecType > additionalVectors=std::nullopt) const =0
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
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 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 =0
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
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:246
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:377
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:43
void addHaloParticle(const Particle_T &haloParticle)
Adds a particle to the container that lies in the halo region of the container.
Definition: ParticleContainerInterface.h:122
virtual void setCutoff(double cutoff)=0
Set the cutoff of the container.
virtual ContainerIterator< Particle_T, true, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, utils::optRef< typename ContainerIterator< Particle_T, true, false >::ParticleVecType > additionalVectors=std::nullopt)=0
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
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.
ContainerIterator< Particle_T, false, false > cbegin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, utils::optRef< typename ContainerIterator< Particle_T, false, false >::ParticleVecType > additionalVectors=std::nullopt) const
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: ParticleContainerInterface.h:213
virtual 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)=0
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
virtual ContainerOption getContainerType() const =0
Get the ContainerType.
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:410
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:91
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:49
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 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:64
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
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:33