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>
25class CellBasedParticleContainer : public ParticleContainerInterface<typename ParticleCell::ParticleType> {
26 using ParticleType = typename ParticleCell::ParticleType;
27
28 public:
37 CellBasedParticleContainer(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax,
38 const double cutoff, double skin, unsigned int rebuildFrequency)
39 : ParticleContainerInterface<ParticleType>(skin),
40 _cells(),
41 _boxMin(boxMin),
42 _boxMax(boxMax),
43 _cutoff(cutoff),
44 _skin(skin) {}
45
49 ~CellBasedParticleContainer() override = default;
50
57
65
69 [[nodiscard]] const std::array<double, 3> &getBoxMax() const final { return _boxMax; }
70
74 [[nodiscard]] const std::array<double, 3> &getBoxMin() const final { return _boxMin; }
75
79 [[nodiscard]] double getCutoff() const final { return _cutoff; }
80
84 void setCutoff(double cutoff) final { _cutoff = cutoff; }
85
89 [[nodiscard]] double getInteractionLength() const final { return _cutoff + _skin; }
94 [[nodiscard]] double getVerletSkin() const final { return _skin; }
95
99 void deleteAllParticles() override {
102 AUTOPAS_OPENMP(parallel for num_threads(std::clamp(static_cast<int>(this->_cells.size()) / 1000, \
103 1, \
105 for (size_t i = 0; i < this->_cells.size(); ++i) {
106 this->_cells[i].clear();
107 }
108 }
109
113 [[nodiscard]] size_t getNumberOfParticles(IteratorBehavior behavior) const override {
114 size_t numParticles = 0ul;
115 // parallelizing this loop is only worth it if we have LOTS of cells.
116 // numThreads should be at least 1 and maximal max_threads
117 AUTOPAS_OPENMP(parallel for num_threads(std::clamp(static_cast<int>(this->_cells.size()) / 100000, \
118 1, \
120 reduction(+ : numParticles))
121 for (size_t index = 0; index < _cells.size(); ++index) {
122 numParticles += _cells[index].getNumberOfParticles(behavior);
123 }
124 return numParticles;
125 }
126
131 [[nodiscard]] size_t size() const override {
132 size_t numParticles = 0ul;
133 // parallelizing this loop is only worth it if we have LOTS of cells.
134 // numThreads should be at least 1 and maximal max_threads
135 AUTOPAS_OPENMP(parallel for num_threads(std::clamp(static_cast<int>(this->_cells.size()) / 100000, \
136 1, \
138 reduction(+ : numParticles))
139 for (size_t index = 0; index < _cells.size(); ++index) {
140 numParticles += _cells[index].size();
141 }
142 return numParticles;
143 }
144
149 [[nodiscard]] const std::vector<ParticleCell> &getCells() const { return _cells; }
150
151 protected:
157 std::vector<ParticleCell> _cells;
158
159 private:
160 std::array<double, 3> _boxMin;
161 std::array<double, 3> _boxMax;
162 double _cutoff;
163 double _skin;
164};
165
166} // 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
double getVerletSkin() const final
Returns the verlet Skin length.
Definition: CellBasedParticleContainer.h:94
CellBasedParticleContainer(const CellBasedParticleContainer &obj)=delete
Delete the copy constructor to prevent unwanted copies.
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: CellBasedParticleContainer.h:89
std::vector< ParticleCell > _cells
Vector of particle cells.
Definition: CellBasedParticleContainer.h:157
double getCutoff() const final
Return the cutoff of the container.
Definition: CellBasedParticleContainer.h:79
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: CellBasedParticleContainer.h:113
void setCutoff(double cutoff) final
Set the cutoff of the container.
Definition: CellBasedParticleContainer.h:84
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: CellBasedParticleContainer.h:131
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: CellBasedParticleContainer.h:74
const std::vector< ParticleCell > & getCells() const
Get immutable vector of cells.
Definition: CellBasedParticleContainer.h:149
CellBasedParticleContainer(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, const double cutoff, double skin, unsigned int rebuildFrequency)
Constructor of CellBasedParticleContainer.
Definition: CellBasedParticleContainer.h:37
const std::array< double, 3 > & getBoxMax() const final
Get the upper corner of the container without halo.
Definition: CellBasedParticleContainer.h:69
CellBasedParticleContainer & operator=(const CellBasedParticleContainer &other)=delete
Delete the copy assignment operator to prevent unwanted copies No particle container should ever be c...
void deleteAllParticles() override
Deletes all particles from the container.
Definition: CellBasedParticleContainer.h:99
~CellBasedParticleContainer() override=default
Destructor of CellBasedParticleContainer.
Particle_T ParticleType
The particle type for this cell.
Definition: ParticleCell.h:56
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