AutoPas  3.0.0
Loading...
Searching...
No Matches
Cluster.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <algorithm>
10#include <iterator>
11#include <vector>
12
14
15namespace autopas::internal {
16
25template <class Particle_T>
26class Cluster {
27 public:
36 explicit Cluster(Particle_T *firstParticle, size_t clusterSize)
37 : _firstParticle(firstParticle), _clusterSize(clusterSize) {}
38
47 Particle_T &operator[](size_t index) { return *(_firstParticle + index); }
48
52 const Particle_T &operator[](size_t index) const { return *(_firstParticle + index); }
53
58 bool empty() const {
59 const auto firstNonDummy = std::find_if(_firstParticle, _firstParticle + _clusterSize,
60 [](const auto &particle) { return not particle.isDummy(); });
61 return firstNonDummy > &_firstParticle[_clusterSize - 1];
62 }
63
70 [[nodiscard]] std::tuple<double, double, bool> getZMinMax() const {
71 // Find first particle which is not a dummy and get its z-value.
72 auto *begin = &operator[](0);
73 auto *end = &operator[](_clusterSize);
74 auto pfirst = std::find_if(begin, end, [](const auto &particle) { return not particle.isDummy(); });
75 double min = pfirst != end ? pfirst->getR()[2] : std::numeric_limits<double>::max();
76
77 // Find last particle which is not a dummy and get its z-value.
78 auto rbegin = std::make_reverse_iterator(end);
79 auto rend = std::make_reverse_iterator(begin);
80 auto plast = std::find_if(rbegin, rend, [](const auto &particle) { return not particle.isDummy(); });
81 double max = plast != rend ? plast->getR()[2] : std::numeric_limits<double>::min();
82
83 return {min, max, pfirst != end};
84 }
85
90 auto getSoAView() { return _soaView; }
91
96 void setSoAView(const SoAView<typename Particle_T::SoAArraysType> &view) { _soaView = view; }
97
102 void setNeighborList(std::vector<Cluster<Particle_T> *> *neighborList) { _neighborClusters = neighborList; }
103
108 std::vector<Cluster<Particle_T> *> *getNeighbors() { return _neighborClusters; }
109
114 void addNeighbor(Cluster<Particle_T> &neighbor) { _neighborClusters->push_back(&neighbor); }
115
120 if (_neighborClusters) {
121 _neighborClusters->clear();
122 }
123 }
124
129 void reset(Particle_T *firstParticle) { _firstParticle = firstParticle; }
130
135 [[nodiscard]] std::tuple<std::array<double, 3>, std::array<double, 3>> getBoundingBox() const {
136 auto lowerCorner = _firstParticle->getR();
137 auto upperCorner = _firstParticle[_clusterSize - 1].getR();
138
139 for (size_t i = 0; i < _clusterSize; ++i) {
140 const auto &pos = _firstParticle[i].getR();
141 // no need to check z direction, this is already correct by initialization thanks to the particles being sorted in
142 // z dimension.
143 for (size_t dim = 0; dim < 2; ++dim) {
144 lowerCorner[dim] = std::min(lowerCorner[dim], pos[dim]);
145 upperCorner[dim] = std::max(upperCorner[dim], pos[dim]);
146 }
147 }
148 return {lowerCorner, upperCorner};
149 }
150
151 private:
155 size_t _clusterSize;
156
160 Particle_T *_firstParticle = nullptr;
168 std::vector<Cluster *> *_neighborClusters = nullptr;
169};
170
171} // namespace autopas::internal
View on a fixed part of a SoA between a start index and an end index.
Definition: SoAView.h:23
This class represents a cluster in the VerletClusterLists container.
Definition: Cluster.h:26
std::vector< Cluster< Particle_T > * > * getNeighbors()
Returns the reference to the neighbor list for this cluster.
Definition: Cluster.h:108
Particle_T & operator[](size_t index)
Returns the particle at position index in the cluster.
Definition: Cluster.h:47
const Particle_T & operator[](size_t index) const
Returns the particle at position index in the cluster.
Definition: Cluster.h:52
bool empty() const
Indicates if the cluster contains any non-dummy particles.
Definition: Cluster.h:58
std::tuple< double, double, bool > getZMinMax() const
Get Minimum and Maximum of the particles in z-direction.
Definition: Cluster.h:70
void addNeighbor(Cluster< Particle_T > &neighbor)
Adds the given cluster to the neighbor list of this cluster.
Definition: Cluster.h:114
void reset(Particle_T *firstParticle)
Definition: Cluster.h:129
Cluster(Particle_T *firstParticle, size_t clusterSize)
Constructs a cluster starting from firstParticle and going on for clusterSize particles.
Definition: Cluster.h:36
void setNeighborList(std::vector< Cluster< Particle_T > * > *neighborList)
Set the internal neighbor list pointer to an allocated, but not necessarily complete,...
Definition: Cluster.h:102
std::tuple< std::array< double, 3 >, std::array< double, 3 > > getBoundingBox() const
Get the bounding box of this cluster.
Definition: Cluster.h:135
auto getSoAView()
Returns the SoAView for this cluster.
Definition: Cluster.h:90
void clearNeighbors()
Remove all neighbors.
Definition: Cluster.h:119
void setSoAView(const SoAView< typename Particle_T::SoAArraysType > &view)
Set the SoAView for this cluster.
Definition: Cluster.h:96
This namespace is used for implementation specifics.
Definition: CellFunctor.h:14