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:
39 CellBasedParticleContainer(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax,
40 const double cutoff, const double skin, const size_t aosSortingThreshold,
41 const size_t soaSortingThreshold)
42 : ParticleContainerInterface<ParticleType>(skin),
43 _cells(),
44 _boxMin(boxMin),
45 _boxMax(boxMax),
46 _cutoff(cutoff),
47 _skin(skin),
48 _aosSortingThreshold(aosSortingThreshold),
49 _soaSortingThreshold(soaSortingThreshold) {}
50
54 ~CellBasedParticleContainer() override = default;
55
62
70
74 [[nodiscard]] const std::array<double, 3> &getBoxMax() const final { return _boxMax; }
75
79 [[nodiscard]] const std::array<double, 3> &getBoxMin() const final { return _boxMin; }
80
84 [[nodiscard]] double getCutoff() const final { return _cutoff; }
85
89 void setCutoff(double cutoff) final { _cutoff = cutoff; }
90
94 [[nodiscard]] double getInteractionLength() const final { return _cutoff + _skin; }
99 [[nodiscard]] double getVerletSkin() const final { return _skin; }
100
104 void deleteAllParticles() override {
107 AUTOPAS_OPENMP(parallel for num_threads(std::clamp(static_cast<int>(this->_cells.size()) / 1000, \
108 1, \
110 for (size_t i = 0; i < this->_cells.size(); ++i) {
111 this->_cells[i].clear();
112 }
113 }
114
118 [[nodiscard]] size_t getNumberOfParticles(IteratorBehavior behavior) const override {
119 size_t numParticles = 0ul;
120 // parallelizing this loop is only worth it if we have LOTS of cells.
121 // numThreads should be at least 1 and maximal max_threads
122 AUTOPAS_OPENMP(parallel for num_threads(std::clamp(static_cast<int>(this->_cells.size()) / 100000, \
123 1, \
125 reduction(+ : numParticles))
126 for (size_t index = 0; index < _cells.size(); ++index) {
127 numParticles += _cells[index].getNumberOfParticles(behavior);
128 }
129 return numParticles;
130 }
131
136 [[nodiscard]] size_t size() const override {
137 size_t numParticles = 0ul;
138 // parallelizing this loop is only worth it if we have LOTS of cells.
139 // numThreads should be at least 1 and maximal max_threads
140 AUTOPAS_OPENMP(parallel for num_threads(std::clamp(static_cast<int>(this->_cells.size()) / 100000, \
141 1, \
143 reduction(+ : numParticles))
144 for (size_t index = 0; index < _cells.size(); ++index) {
145 numParticles += _cells[index].size();
146 }
147 return numParticles;
148 }
149
154 [[nodiscard]] const std::vector<ParticleCellType> &getCells() const { return _cells; }
155
156 protected:
162 std::vector<ParticleCellType> _cells;
172
173 private:
174 std::array<double, 3> _boxMin;
175 std::array<double, 3> _boxMax;
176 double _cutoff;
177 double _skin;
178};
179
180} // 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:74
~CellBasedParticleContainer() override=default
Destructor of CellBasedParticleContainer.
void setCutoff(double cutoff) final
Set the cutoff of the container.
Definition: CellBasedParticleContainer.h:89
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: CellBasedParticleContainer.h:118
CellBasedParticleContainer(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, const double cutoff, const double skin, const size_t aosSortingThreshold, const size_t soaSortingThreshold)
Constructor of CellBasedParticleContainer.
Definition: CellBasedParticleContainer.h:39
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: CellBasedParticleContainer.h:136
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:99
double getCutoff() const final
Return the cutoff of the container.
Definition: CellBasedParticleContainer.h:84
const std::vector< ParticleCellType > & getCells() const
Get immutable vector of cells.
Definition: CellBasedParticleContainer.h:154
void deleteAllParticles() override
Deletes all particles from the container.
Definition: CellBasedParticleContainer.h:104
size_t _aosSortingThreshold
If the number of particles in a cell or cell pair exceeds this threshold, the particles will be sorte...
Definition: CellBasedParticleContainer.h:167
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: CellBasedParticleContainer.h:79
CellBasedParticleContainer & operator=(const CellBasedParticleContainer &other)=delete
Delete the copy assignment operator to prevent unwanted copies No particle container should ever be c...
size_t _soaSortingThreshold
If the sum of the SoA buffer sizes of two cells exceeds this threshold, SoAFunctorPairSorted is used.
Definition: CellBasedParticleContainer.h:171
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: CellBasedParticleContainer.h:94
std::vector< ParticleCellType > _cells
Vector of particle cells.
Definition: CellBasedParticleContainer.h:162
The ParticleContainerInterface class provides a basic interface for all Containers within AutoPas.
Definition: ParticleContainerInterface.h:38
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34
int autopas_get_max_threads()
Dummy for omp_get_max_threads() when no OpenMP is available.
Definition: WrapOpenMP.h:144