42template <
class Particle_T>
59 explicit ClusterTower(
size_t clusterSize) : _clusterSize(clusterSize) {}
69 _firstOwnedCluster = _clusters.end();
70 _firstTailHaloCluster = _clusters.end();
71 _numDummyParticles = 0;
86 _firstOwnedCluster = _clusters.end();
87 _firstTailHaloCluster = _clusters.end();
93 const auto sizeLastCluster = this->
_particles.size() % _clusterSize;
94 _numDummyParticles = sizeLastCluster == 0 ? 0 : _clusterSize - sizeLastCluster;
99 for (
size_t i = 0; i < _numDummyParticles; i++) {
104 const size_t numClusters = this->
_particles.size() / _clusterSize;
106 bool foundFirstOwnedCluster =
false;
107 bool foundFirstTailHaloCluster =
false;
109 const auto isAnyOfClusterOwned = [&](
const auto &cluster) {
110 for (
size_t i = 0; i < _clusterSize; ++i) {
111 if (cluster[i].isOwned()) {
118 for (
size_t index = 0; index < numClusters; index++) {
119 _clusters[index].reset(&(this->
_particles[_clusterSize * index]));
121 const bool clusterContainsOwnedParticles =
122 not foundFirstTailHaloCluster and isAnyOfClusterOwned(_clusters[index]);
125 if (not foundFirstOwnedCluster and clusterContainsOwnedParticles) {
126 _firstOwnedCluster = _clusters.begin() + index;
127 foundFirstOwnedCluster =
true;
129 if (not foundFirstTailHaloCluster and foundFirstOwnedCluster and not clusterContainsOwnedParticles) {
130 _firstTailHaloCluster = _clusters.begin() + index;
131 foundFirstTailHaloCluster =
true;
135 if (not foundFirstOwnedCluster) {
136 _firstOwnedCluster = _clusters.end();
138 if (not foundFirstTailHaloCluster) {
139 _firstTailHaloCluster = _clusters.end();
154 for (
size_t index = 1; index <= _numDummyParticles; index++) {
155 auto &
dummy = lastCluster[_clusterSize - index];
156 dummy = lastCluster[0];
158 dummy.setR({dummyStartX, 0, dummyDistZ *
static_cast<double>(index)});
159 dummy.setID(std::numeric_limits<size_t>::max());
168 if (_numDummyParticles > 0) {
170 auto lastActualParticle = lastCluster[_clusterSize - _numDummyParticles - 1];
171 for (
size_t index = 1; index <= _numDummyParticles; index++) {
172 lastCluster[_clusterSize - index] = lastActualParticle;
182 template <
class Functor>
187 cluster.setSoAView({&(this->
_particleSoABuffer), index * _clusterSize, (index + 1) * _clusterSize});
196 template <
class Functor>
227 const std::array<double, 3> &boxMax) {
231 const auto firstOutOfBoundsParticleIter =
232 std::partition(this->
_particles.begin(), this->_particles.end(),
233 [&](
const auto &p) { return utils::inBox(p.getR(), boxMin, boxMax); });
236 std::vector<Particle_T> outOfBoundsParticles(firstOutOfBoundsParticleIter, this->
_particles.end());
239 *this->_particles.begin());
240 return outOfBoundsParticles;
280 [[nodiscard]]
const typename std::vector<autopas::internal::Cluster<Particle_T>>::iterator &
getFirstOwnedCluster()
282 return _firstOwnedCluster;
290 return std::distance(_clusters.cbegin(),
decltype(_clusters.cbegin()){_firstOwnedCluster});
299 return _firstTailHaloCluster;
307 return std::distance(_clusters.cbegin(),
decltype(_clusters.cbegin()){_firstTailHaloCluster});
315 [[nodiscard]]
auto &
getCluster(
size_t index) {
return _clusters[index]; }
320 [[nodiscard]]
auto &
getCluster(
size_t index)
const {
return _clusters[index]; }
327 _numDummyParticles = 0;
344 if (_particleDeletionObserver) {
375 _particleDeletionObserver = observer;
393 std::vector<Cluster<Particle_T>> _clusters;
400 typename decltype(_clusters)::iterator _firstOwnedCluster{_clusters.end()};
405 typename decltype(_clusters)::iterator _firstTailHaloCluster{_clusters.end()};
410 size_t _numDummyParticles{};
412 internal::ParticleDeletedObserver *_particleDeletionObserver{
nullptr};
This class handles the storage of particles in their full form.
Definition: FullParticleCell.h:26
std::vector< Particle_T > StorageType
Type that holds or refers to the actual particles.
Definition: FullParticleCell.h:36
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:40
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:112
void SoAExtractor(ParticleCell &cell, SoA< SoAArraysType > &soa, size_t offset)
Copies the data stored in the soa back into the cell.
Definition: Functor.h:126
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:297
void clear() override
Clears all particles from the tower and resets it to be ready for new particles.
Definition: ClusterTower.h:66
ClusterTower()
Dummy constructor.
Definition: ClusterTower.h:53
size_t size() const override
Get the number of all particles stored in this tower (owned, halo and dummy).
Definition: ClusterTower.h:253
auto & getCluster(size_t index) const
Returns the cluster at position index.
Definition: ClusterTower.h:320
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:280
void setCellLength(std::array< double, 3 > &) override
Set the side lengths of this cell.
Definition: ClusterTower.h:349
void deleteByIndex(size_t index) override
Deletes the index-th particle.
Definition: ClusterTower.h:330
std::array< double, 3 > getCellLength() const override
Get the side lengths of this cell.
Definition: ClusterTower.h:353
size_t getFirstOwnedClusterIndex() const
Returns the index of the first cluster that contains at least one owned particle.
Definition: ClusterTower.h:289
ClusterTower(size_t clusterSize)
Constructor.
Definition: ClusterTower.h:59
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:226
void deleteDummyParticles() override
Deletes all dummy particles in this cell.
Definition: ClusterTower.h:324
size_t generateClusters()
Generates the clusters for the particles in this cluster tower.
Definition: ClusterTower.h:83
CellType getParticleCellTypeAsEnum() override
Get the ParticleCell type as an ParticleCellTypeEnum.
Definition: ClusterTower.h:61
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:207
typename FullParticleCell< Particle_T >::StorageType StorageType
Type that holds or refers to the actual particles.
Definition: ClusterTower.h:48
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:260
void setParticleDeletionObserver(internal::ParticleDeletedObserver *observer)
Set the ParticleDeletionObserver, which is called, when a particle is deleted.
Definition: ClusterTower.h:374
void loadSoA(Functor *functor)
Loads the particles into the SoA stored in this tower and generates the SoAView for each cluster.
Definition: ClusterTower.h:183
auto & getClusters()
Returns a reference to the std::vector holding the clusters of this container.
Definition: ClusterTower.h:274
size_t getNumClusters() const
Returns the number of clusters in the tower.
Definition: ClusterTower.h:268
void extractSoA(Functor *functor)
Extracts the SoA into the particles/clusters.
Definition: ClusterTower.h:197
size_t getClusterSize() const
Get cluster size.
Definition: ClusterTower.h:368
bool isEmpty() const override
Check if the cell is empty.
Definition: ClusterTower.h:322
size_t getFirstTailHaloClusterIndex() const
Returns the index of the first particle after the owned clusters, that contains no owned particles an...
Definition: ClusterTower.h:306
void setDummyParticlesToLastActualParticle()
More or less inverse operation of setDummyValues().
Definition: ClusterTower.h:167
void setDummyValues(double dummyStartX, double dummyDistZ)
Replaces the copies of the last particle made in generateClusters() with dummies.
Definition: ClusterTower.h:152
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:247
void setClusterSize(size_t clusterSize)
Set cluster size.
Definition: ClusterTower.h:362
auto & getCluster(size_t index)
Returns the cluster at position index.
Definition: ClusterTower.h:315
StorageType & particleVector()
Get reference to internal particle vector.
Definition: ClusterTower.h:382
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:63
This namespace is used for implementation specifics.
Definition: CellFunctor.h:14
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!