AutoPas  3.0.0
Loading...
Searching...
No Matches
CellBasedParticleContainer.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <algorithm>
10#include <array>
11
15
16namespace autopas {
17
18// consider multiple inheritance or delegation to avoid virtual call to Functor
24template <class ParticleCell_T>
25class CellBasedParticleContainer : public ParticleContainerInterface<typename ParticleCell_T::ParticleType> {
26 using ParticleType = typename ParticleCell_T::ParticleType;
27 using ParticleCellType = ParticleCell_T;
28
29 public:
38 CellBasedParticleContainer(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax,
39 const double cutoff, const double skin, const size_t sortingThreshold)
40 : ParticleContainerInterface<ParticleType>(skin),
41 _cells(),
42 _boxMin(boxMin),
43 _boxMax(boxMax),
44 _cutoff(cutoff),
45 _skin(skin),
46 _sortingThreshold(sortingThreshold) {}
47
51 ~CellBasedParticleContainer() override = default;
52
59
67
71 [[nodiscard]] const std::array<double, 3> &getBoxMax() const final { return _boxMax; }
72
76 [[nodiscard]] const std::array<double, 3> &getBoxMin() const final { return _boxMin; }
77
81 [[nodiscard]] double getCutoff() const final { return _cutoff; }
82
86 void setCutoff(double cutoff) final { _cutoff = cutoff; }
87
91 [[nodiscard]] double getInteractionLength() const final { return _cutoff + _skin; }
96 [[nodiscard]] double getVerletSkin() const final { return _skin; }
97
101 void deleteAllParticles() override {
104 AUTOPAS_OPENMP(parallel for num_threads(std::clamp(static_cast<int>(this->_cells.size()) / 1000, \
105 1, \
107 for (size_t i = 0; i < this->_cells.size(); ++i) {
108 this->_cells[i].clear();
109 }
110 }
111
115 [[nodiscard]] size_t getNumberOfParticles(IteratorBehavior behavior) const override {
116 size_t numParticles = 0ul;
117 // parallelizing this loop is only worth it if we have LOTS of cells.
118 // numThreads should be at least 1 and maximal max_threads
119 AUTOPAS_OPENMP(parallel for num_threads(std::clamp(static_cast<int>(this->_cells.size()) / 100000, \
120 1, \
122 reduction(+ : numParticles))
123 for (size_t index = 0; index < _cells.size(); ++index) {
124 numParticles += _cells[index].getNumberOfParticles(behavior);
125 }
126 return numParticles;
127 }
128
133 [[nodiscard]] size_t size() const override {
134 size_t numParticles = 0ul;
135 // parallelizing this loop is only worth it if we have LOTS of cells.
136 // numThreads should be at least 1 and maximal max_threads
137 AUTOPAS_OPENMP(parallel for num_threads(std::clamp(static_cast<int>(this->_cells.size()) / 100000, \
138 1, \
140 reduction(+ : numParticles))
141 for (size_t index = 0; index < _cells.size(); ++index) {
142 numParticles += _cells[index].size();
143 }
144 return numParticles;
145 }
146
151 [[nodiscard]] const std::vector<ParticleCellType> &getCells() const { return _cells; }
152
153 protected:
159 std::vector<ParticleCellType> _cells;
165
166 private:
167 std::array<double, 3> _boxMin;
168 std::array<double, 3> _boxMax;
169 double _cutoff;
170 double _skin;
171};
172
173} // namespace autopas
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
The CellBasedParticleContainer class stores particles in some object and provides methods to iterate ...
Definition: CellBasedParticleContainer.h:25
const std::array< double, 3 > & getBoxMax() const final
Get the upper corner of the container without halo.
Definition: CellBasedParticleContainer.h:71
~CellBasedParticleContainer() override=default
Destructor of CellBasedParticleContainer.
void setCutoff(double cutoff) final
Set the cutoff of the container.
Definition: CellBasedParticleContainer.h:86
size_t _sortingThreshold
If the number of particles in a cell or cell pair exceeds this threshold, the particles will be sorte...
Definition: CellBasedParticleContainer.h:164
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: CellBasedParticleContainer.h:115
CellBasedParticleContainer(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, const double cutoff, const double skin, const size_t sortingThreshold)
Constructor of CellBasedParticleContainer.
Definition: CellBasedParticleContainer.h:38
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: CellBasedParticleContainer.h:133
CellBasedParticleContainer(const CellBasedParticleContainer &obj)=delete
Delete the copy constructor to prevent unwanted copies.
double getVerletSkin() const final
Returns the verlet Skin length.
Definition: CellBasedParticleContainer.h:96
double getCutoff() const final
Return the cutoff of the container.
Definition: CellBasedParticleContainer.h:81
const std::vector< ParticleCellType > & getCells() const
Get immutable vector of cells.
Definition: CellBasedParticleContainer.h:151
void deleteAllParticles() override
Deletes all particles from the container.
Definition: CellBasedParticleContainer.h:101
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: CellBasedParticleContainer.h:76
CellBasedParticleContainer & operator=(const CellBasedParticleContainer &other)=delete
Delete the copy assignment operator to prevent unwanted copies No particle container should ever be c...
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: CellBasedParticleContainer.h:91
std::vector< ParticleCellType > _cells
Vector of particle cells.
Definition: CellBasedParticleContainer.h:159
The ParticleContainerInterface class provides a basic interface for all Containers within AutoPas.
Definition: ParticleContainerInterface.h:37
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
int autopas_get_max_threads()
Dummy for omp_get_max_threads() when no OpenMP is available.
Definition: WrapOpenMP.h:144