42template <
class Particle_T>
54 explicit ClusterTower(
size_t clusterSize) : _clusterSize(clusterSize) {}
64 _firstOwnedCluster = _clusters.end();
65 _firstTailHaloCluster = _clusters.end();
66 _numDummyParticles = 0;
81 _firstOwnedCluster = _clusters.end();
82 _firstTailHaloCluster = _clusters.end();
88 const auto sizeLastCluster = this->
_particles.size() % _clusterSize;
89 _numDummyParticles = sizeLastCluster == 0 ? 0 : _clusterSize - sizeLastCluster;
94 for (
size_t i = 0; i < _numDummyParticles; i++) {
99 const size_t numClusters = this->
_particles.size() / _clusterSize;
101 bool foundFirstOwnedCluster =
false;
102 bool foundFirstTailHaloCluster =
false;
104 const auto isAnyOfClusterOwned = [&](
const auto &cluster) {
105 for (
size_t i = 0; i < _clusterSize; ++i) {
106 if (cluster[i].isOwned()) {
113 for (
size_t index = 0; index < numClusters; index++) {
114 _clusters[index].reset(&(this->
_particles[_clusterSize * index]));
116 const bool clusterContainsOwnedParticles =
117 not foundFirstTailHaloCluster and isAnyOfClusterOwned(_clusters[index]);
120 if (not foundFirstOwnedCluster and clusterContainsOwnedParticles) {
121 _firstOwnedCluster = _clusters.begin() + index;
122 foundFirstOwnedCluster =
true;
124 if (not foundFirstTailHaloCluster and foundFirstOwnedCluster and not clusterContainsOwnedParticles) {
125 _firstTailHaloCluster = _clusters.begin() + index;
126 foundFirstTailHaloCluster =
true;
130 if (not foundFirstOwnedCluster) {
131 _firstOwnedCluster = _clusters.end();
133 if (not foundFirstTailHaloCluster) {
134 _firstTailHaloCluster = _clusters.end();
149 for (
size_t index = 1; index <= _numDummyParticles; index++) {
150 auto &
dummy = lastCluster[_clusterSize - index];
151 dummy = lastCluster[0];
153 dummy.setR({dummyStartX, 0, dummyDistZ *
static_cast<double>(index)});
154 dummy.setID(std::numeric_limits<size_t>::max());
163 if (_numDummyParticles > 0) {
165 auto lastActualParticle = lastCluster[_clusterSize - _numDummyParticles - 1];
166 for (
size_t index = 1; index <= _numDummyParticles; index++) {
167 lastCluster[_clusterSize - index] = lastActualParticle;
177 template <
class Functor>
182 cluster.setSoAView({&(this->
_particleSoABuffer), index * _clusterSize, (index + 1) * _clusterSize});
191 template <
class Functor>
222 const std::array<double, 3> &boxMax) {
226 const auto firstOutOfBoundsParticleIter =
227 std::partition(this->
_particles.begin(), this->_particles.end(),
228 [&](
const auto &p) { return utils::inBox(p.getR(), boxMin, boxMax); });
231 std::vector<Particle_T> outOfBoundsParticles(firstOutOfBoundsParticleIter, this->
_particles.end());
234 *this->_particles.begin());
235 return outOfBoundsParticles;
275 [[nodiscard]]
const typename std::vector<autopas::internal::Cluster<Particle_T>>::iterator &
getFirstOwnedCluster()
277 return _firstOwnedCluster;
285 return std::distance(_clusters.cbegin(),
decltype(_clusters.cbegin()){_firstOwnedCluster});
294 return _firstTailHaloCluster;
302 return std::distance(_clusters.cbegin(),
decltype(_clusters.cbegin()){_firstTailHaloCluster});
310 [[nodiscard]]
auto &
getCluster(
size_t index) {
return _clusters[index]; }
315 [[nodiscard]]
auto &
getCluster(
size_t index)
const {
return _clusters[index]; }
322 _numDummyParticles = 0;
339 if (_particleDeletionObserver) {
370 _particleDeletionObserver = observer;
388 std::vector<Cluster<Particle_T>> _clusters;
395 typename decltype(_clusters)::iterator _firstOwnedCluster{_clusters.end()};
400 typename decltype(_clusters)::iterator _firstTailHaloCluster{_clusters.end()};
405 size_t _numDummyParticles{};
407 internal::ParticleDeletedObserver *_particleDeletionObserver{
nullptr};
This class handles the storage of particles in their full form.
Definition: FullParticleCell.h:26
void deleteDummyParticles() override
Deletes all dummy particles in this cell.
Definition: FullParticleCell.h:227
StorageType _particles
Storage of the molecules of the cell.
Definition: FullParticleCell.h:274
void sortByDim(const size_t dim)
Sort the particles in the cell by a dimension.
Definition: FullParticleCell.h:260
void clear() override
Deletes all particles in this cell.
Definition: FullParticleCell.h:225
void addParticle(const Particle_T &p) override
Adds a Particle to the cell.
Definition: FullParticleCell.h:51
SoA< SoAArraysType > _particleSoABuffer
SoA buffer of this cell.
Definition: FullParticleCell.h:279
Functor base class.
Definition: Functor.h:41
void SoALoader(ParticleCell &cell, SoA< SoAArraysType > &soa, size_t offset, bool skipSoAResize)
Copies the AoS data of the given cell in the given soa.
Definition: Functor.h:127
void SoAExtractor(ParticleCell &cell, SoA< SoAArraysType > &soa, size_t offset)
Copies the data stored in the soa back into the cell.
Definition: Functor.h:141
This class represents one tower for clusters in the VerletClusterLists container.
Definition: ClusterTower.h:43
const std::vector< autopas::internal::Cluster< Particle_T > >::iterator & getFirstTailHaloCluster() const
Returns an iterator to the first particle after the owned clusters, that contains no owned particles ...
Definition: ClusterTower.h:292
void clear() override
Clears all particles from the tower and resets it to be ready for new particles.
Definition: ClusterTower.h:61
ClusterTower()
Dummy constructor.
Definition: ClusterTower.h:48
size_t size() const override
Get the number of all particles stored in this tower (owned, halo and dummy).
Definition: ClusterTower.h:248
auto & getCluster(size_t index) const
Returns the cluster at position index.
Definition: ClusterTower.h:315
const std::vector< autopas::internal::Cluster< Particle_T > >::iterator & getFirstOwnedCluster() const
Returns an iterator to the first cluster that contains at least one owned particle.
Definition: ClusterTower.h:275
void setCellLength(std::array< double, 3 > &) override
Set the side lengths of this cell.
Definition: ClusterTower.h:344
void deleteByIndex(size_t index) override
Deletes the index-th particle.
Definition: ClusterTower.h:325
std::array< double, 3 > getCellLength() const override
Get the side lengths of this cell.
Definition: ClusterTower.h:348
std::vector< Particle_T > & particleVector()
Get reference to internal particle vector.
Definition: ClusterTower.h:377
void loadSoA(Functor &functor)
Loads the particles into the SoA stored in this tower and generates the SoAView for each cluster.
Definition: ClusterTower.h:178
size_t getFirstOwnedClusterIndex() const
Returns the index of the first cluster that contains at least one owned particle.
Definition: ClusterTower.h:284
ClusterTower(size_t clusterSize)
Constructor.
Definition: ClusterTower.h:54
std::vector< Particle_T > collectOutOfBoundsParticles(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax)
Collect all particles that should not be in this tower based on their current position.
Definition: ClusterTower.h:221
void deleteDummyParticles() override
Deletes all dummy particles in this cell.
Definition: ClusterTower.h:319
size_t generateClusters()
Generates the clusters for the particles in this cluster tower.
Definition: ClusterTower.h:78
CellType getParticleCellTypeAsEnum() override
Get the ParticleCell type as an ParticleCellTypeEnum.
Definition: ClusterTower.h:56
std::vector< Particle_T > && collectAllActualParticles()
Returns a rvalue reference to a std::vector containing all particles of this tower that are not dummi...
Definition: ClusterTower.h:202
unsigned long getNumActualParticles() const
Get the number of all particles saved in the tower without tailing dummies that are used to fill up c...
Definition: ClusterTower.h:255
void setParticleDeletionObserver(internal::ParticleDeletedObserver *observer)
Set the ParticleDeletionObserver, which is called, when a particle is deleted.
Definition: ClusterTower.h:369
auto & getClusters()
Returns a reference to the std::vector holding the clusters of this container.
Definition: ClusterTower.h:269
size_t getNumClusters() const
Returns the number of clusters in the tower.
Definition: ClusterTower.h:263
size_t getClusterSize() const
Get cluster size.
Definition: ClusterTower.h:363
bool isEmpty() const override
Check if the cell is empty.
Definition: ClusterTower.h:317
size_t getFirstTailHaloClusterIndex() const
Returns the index of the first particle after the owned clusters, that contains no owned particles an...
Definition: ClusterTower.h:301
void extractSoA(Functor &functor)
Extracts the SoA into the particles/clusters.
Definition: ClusterTower.h:192
void setDummyParticlesToLastActualParticle()
More or less inverse operation of setDummyValues().
Definition: ClusterTower.h:162
void setDummyValues(double dummyStartX, double dummyDistZ)
Replaces the copies of the last particle made in generateClusters() with dummies.
Definition: ClusterTower.h:147
size_t getNumTailDummyParticles() const
Returns the number of dummy particles in the tower that were inserted in the tower to fill the last c...
Definition: ClusterTower.h:242
void setClusterSize(size_t clusterSize)
Set cluster size.
Definition: ClusterTower.h:357
auto & getCluster(size_t index)
Returns the cluster at position index.
Definition: ClusterTower.h:310
This class represents a cluster in the VerletClusterLists container.
Definition: Cluster.h:26
Class that is notified when a particle is deleted.
Definition: ParticleDeletedObserver.h:15
virtual void notifyParticleDeleted()=0
This function is called when a particle is deleted.
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:64
This namespace is used for implementation specifics.
Definition: CellFunctor.h:21
void markParticleAsDeleted(Particle_T &p)
Marks a particle as deleted.
Definition: markParticleAsDeleted.h:23
CellType
The ParticleCell Type as an Enum.
Definition: ParticleCell.h:19
@ ClusterTower
ClusterTower : Tower for the 2D tower structure of VerletClusterLists.
@ dummy
Dummy or deleted state, a particle with this state is not an actual particle!