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#include <memory>
12
18
19namespace autopas {
20
21// consider multiple inheritance or delegation to avoid virtual call to Functor
27template <class ParticleCell_T>
28class CellBasedParticleContainer : public ParticleContainerInterface<typename ParticleCell_T::ParticleType> {
29 using ParticleType = typename ParticleCell_T::ParticleType;
30 using ParticleCellType = ParticleCell_T;
31
32 public:
44 CellBasedParticleContainer(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax,
45 const double cutoff, const double skin, const size_t aosSortingThresholdFallback,
46 const size_t soaSortingThresholdFallback)
47 : ParticleContainerInterface<ParticleType>(skin),
48 _cells(),
49 _boxMin(boxMin),
50 _boxMax(boxMax),
51 _cutoff(cutoff),
52 _skin(skin),
53 _aosSortingThresholds(std::make_shared<const SortingThresholdInfoSingle>(aosSortingThresholdFallback)),
54 _soaSortingThresholds(std::make_shared<const SortingThresholdInfoSingle>(soaSortingThresholdFallback)) {}
55
59 ~CellBasedParticleContainer() override = default;
60
67
75
79 [[nodiscard]] const std::array<double, 3> &getBoxMax() const final { return _boxMax; }
80
84 [[nodiscard]] const std::array<double, 3> &getBoxMin() const final { return _boxMin; }
85
89 [[nodiscard]] double getCutoff() const final { return _cutoff; }
90
94 void setCutoff(double cutoff) final { _cutoff = cutoff; }
95
99 [[nodiscard]] double getInteractionLength() const final { return _cutoff + _skin; }
104 [[nodiscard]] double getVerletSkin() const final { return _skin; }
105
109 void deleteAllParticles() override {
112 AUTOPAS_OPENMP(parallel for num_threads(std::clamp(static_cast<int>(this->_cells.size()) / 1000, \
113 1, \
115 for (size_t i = 0; i < this->_cells.size(); ++i) {
116 this->_cells[i].clear();
117 }
118 }
119
123 [[nodiscard]] size_t getNumberOfParticles(IteratorBehavior behavior) const override {
124 size_t numParticles = 0ul;
125 // parallelizing this loop is only worth it if we have LOTS of cells.
126 // numThreads should be at least 1 and maximal max_threads
127 AUTOPAS_OPENMP(parallel for num_threads(std::clamp(static_cast<int>(this->_cells.size()) / 100000, \
128 1, \
130 reduction(+ : numParticles))
131 for (size_t index = 0; index < _cells.size(); ++index) {
132 numParticles += _cells[index].getNumberOfParticles(behavior);
133 }
134 return numParticles;
135 }
136
141 [[nodiscard]] size_t size() const override {
142 size_t numParticles = 0ul;
143 // parallelizing this loop is only worth it if we have LOTS of cells.
144 // numThreads should be at least 1 and maximal max_threads
145 AUTOPAS_OPENMP(parallel for num_threads(std::clamp(static_cast<int>(this->_cells.size()) / 100000, \
146 1, \
148 reduction(+ : numParticles))
149 for (size_t index = 0; index < _cells.size(); ++index) {
150 numParticles += _cells[index].size();
151 }
152 return numParticles;
153 }
154
159 [[nodiscard]] const std::vector<ParticleCellType> &getCells() const { return _cells; }
160
164 void setAoSSortingThresholds(std::shared_ptr<const SortingThresholdInfoInterface> aosSortingThresholds) override {
165 _aosSortingThresholds = std::move(aosSortingThresholds);
166 }
167
171 void setSoASortingThresholds(std::shared_ptr<const SortingThresholdInfoInterface> soaSortingThresholds) override {
172 _soaSortingThresholds = std::move(soaSortingThresholds);
173 }
174
175 protected:
181 std::vector<ParticleCellType> _cells;
188 std::shared_ptr<const SortingThresholdInfoInterface> _aosSortingThresholds;
192 std::shared_ptr<const SortingThresholdInfoInterface> _soaSortingThresholds;
193
194 private:
195 std::array<double, 3> _boxMin;
196 std::array<double, 3> _boxMax;
197 double _cutoff;
198 double _skin;
199};
200
201} // 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:28
const std::array< double, 3 > & getBoxMax() const final
Get the upper corner of the container without halo.
Definition: CellBasedParticleContainer.h:79
~CellBasedParticleContainer() override=default
Destructor of CellBasedParticleContainer.
void setCutoff(double cutoff) final
Set the cutoff of the container.
Definition: CellBasedParticleContainer.h:94
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: CellBasedParticleContainer.h:123
void setSoASortingThresholds(std::shared_ptr< const SortingThresholdInfoInterface > soaSortingThresholds) override
Set the SoA sorting-threshold for traversals that use the CellFunctor.
Definition: CellBasedParticleContainer.h:171
void setAoSSortingThresholds(std::shared_ptr< const SortingThresholdInfoInterface > aosSortingThresholds) override
Set the aos-sorting-threshold for traversals that use the CellFunctor.
Definition: CellBasedParticleContainer.h:164
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: CellBasedParticleContainer.h:141
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:104
CellBasedParticleContainer(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, const double cutoff, const double skin, const size_t aosSortingThresholdFallback, const size_t soaSortingThresholdFallback)
Constructor of CellBasedParticleContainer.
Definition: CellBasedParticleContainer.h:44
double getCutoff() const final
Return the cutoff of the container.
Definition: CellBasedParticleContainer.h:89
const std::vector< ParticleCellType > & getCells() const
Get immutable vector of cells.
Definition: CellBasedParticleContainer.h:159
std::shared_ptr< const SortingThresholdInfoInterface > _soaSortingThresholds
Current AoS pair-sorting threshold, forwarded to freshly generated traversals in prepareTraversal().
Definition: CellBasedParticleContainer.h:192
void deleteAllParticles() override
Deletes all particles from the container.
Definition: CellBasedParticleContainer.h:109
std::shared_ptr< const SortingThresholdInfoInterface > _aosSortingThresholds
Current AoS pair-sorting threshold, forwarded to freshly generated traversals in prepareTraversal().
Definition: CellBasedParticleContainer.h:188
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: CellBasedParticleContainer.h:84
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:99
std::vector< ParticleCellType > _cells
Vector of particle cells.
Definition: CellBasedParticleContainer.h:181
The ParticleContainerInterface class provides a basic interface for all Containers within AutoPas.
Definition: ParticleContainerInterface.h:40
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:33
int autopas_get_max_threads()
Dummy for omp_get_max_threads() when no OpenMP is available.
Definition: WrapOpenMP.h:144
Single threshold value struct.
Definition: SortingThresholdInfoSingle.h:18