23template <
class Particle_T>
39 : _cellLength({std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
40 std::numeric_limits<double>::max()}) {}
58 if ((not
toInt64(p->getOwnershipState() & this->_ownershipState)) and
61 "ReferenceParticleCell::addParticleReference() can not add a particle with OwnershipState {} to a cell with "
63 p->getOwnershipState(), this->_ownershipState);
66 std::lock_guard<AutoPasLock> guard(this->
_cellLock);
102 template <
typename Lambda>
103 void forEach(Lambda forEachLambda, IteratorBehavior behavior) {
104 const std::array<double, 3>
dummy{};
105 forEachImpl<false>(forEachLambda,
dummy,
dummy, behavior);
116 template <
typename Lambda>
117 void forEach(Lambda forEachLambda,
const std::array<double, 3> &lowerCorner,
118 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
119 forEachImpl<true>(forEachLambda, lowerCorner, higherCorner, behavior);
129 template <
typename Lambda,
typename A>
130 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior) {
131 const std::array<double, 3>
dummy{};
132 reduceImpl<true, false>(reduceLambda, result,
dummy,
dummy, behavior);
145 template <
typename Lambda,
typename A>
146 void reduce(Lambda reduceLambda, A &result,
const std::array<double, 3> &lowerCorner,
147 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
148 reduceImpl<true, true>(reduceLambda, result, lowerCorner, higherCorner, behavior);
161 std::lock_guard<AutoPasLock> guard(this->
_cellLock);
163 size_t numParticles{0};
165 std::count_if(
_particles.begin(),
_particles.end(), [&behavior](
auto p) { return behavior.contains(*p); });
194 [[nodiscard]] Particle_T &
at(
size_t index) {
return *(
_particles.at(index)); }
201 [[nodiscard]]
const Particle_T &
at(
size_t index)
const {
return *(
_particles.at(index)); }
203 [[nodiscard]]
bool isEmpty()
const override {
return size() == 0; }
209 std::remove_if(
_particles.begin(),
_particles.end(), [](
const auto &particle) { return particle->isDummy(); }),
214 std::lock_guard<AutoPasLock> lock(this->
_cellLock);
215 if (index >=
size()) {
221 if (index <
size() - 1) {
227 void setCellLength(std::array<double, 3> &cellLength)
override { _cellLength = cellLength; }
229 [[nodiscard]] std::array<double, 3>
getCellLength()
const override {
return _cellLength; }
236 void resize(
size_t n,
const Particle_T &toInsert) {
_particles.resize(n, std::unique_ptr<Particle_T>(toInsert)); }
244 [dim](
const auto *a,
const auto *b) ->
bool { return a->getR()[dim] < b->getR()[dim]; });
264 std::array<double, 3> _cellLength;
266 template <
bool regionCheck,
typename Lambda>
267 void forEachImpl(Lambda forEachLambda,
const std::array<double, 3> &lowerCorner,
268 const std::array<double, 3> &higherCorner,
269 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHaloOrDummy) {
271 if (behavior.contains(*p)) {
272 if ((not regionCheck) or
utils::inBox(p->getR(), lowerCorner, higherCorner)) {
279 template <
bool ownershipCheck,
bool regionCheck,
typename Lambda,
typename A>
280 void reduceImpl(Lambda reduceLambda, A &result,
const std::array<double, 3> &lowerCorner,
281 const std::array<double, 3> &higherCorner,
282 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHaloOrDummy) {
284 if ((not ownershipCheck) or behavior.contains(*p)) {
285 if ((not regionCheck) or
utils::inBox(p->getR(), lowerCorner, higherCorner)) {
286 reduceLambda(*p, result);
Wraps the iterator of arbitrary cells to provide a common interface.
Definition: CellIterator.h:19
Class for Cells of Particles.
Definition: ParticleCell.h:51
AutoPasLock _cellLock
Lock object for exclusive access to this cell.
Definition: ParticleCell.h:184
This class handles the storage of particles in their full form.
Definition: ReferenceParticleCell.h:24
void clear() override
Deletes all particles in this cell.
Definition: ReferenceParticleCell.h:205
ReferenceParticleCell(const std::array< double, 3 > &cellLength)
Constructs a new ReferenceParticleCell with the given cell side length.
Definition: ReferenceParticleCell.h:46
std::vector< Particle_T * > StorageType
Type that holds or refers to the actual particles.
Definition: ReferenceParticleCell.h:33
Particle_T & at(size_t index)
Returns the particle at position index.
Definition: ReferenceParticleCell.h:194
void deleteByIndex(size_t index) override
Deletes the index-th particle.
Definition: ReferenceParticleCell.h:213
bool isEmpty() const override
Check if the cell is empty.
Definition: ReferenceParticleCell.h:203
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: ReferenceParticleCell.h:160
void addParticleReference(Particle_T *p)
Adds a Particle to the cell.
Definition: ReferenceParticleCell.h:55
void forEach(Lambda forEachLambda, IteratorBehavior behavior)
Executes code for every particle in this cell as defined by lambda function.
Definition: ReferenceParticleCell.h:103
StorageType _particles
Storage of the molecules of the cell.
Definition: ReferenceParticleCell.h:256
void setCellLength(std::array< double, 3 > &cellLength) override
Set the side lengths of this cell.
Definition: ReferenceParticleCell.h:227
void forEach(Lambda forEachLambda, const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior)
Executes code for every particle in this cell as defined by lambda function.
Definition: ReferenceParticleCell.h:117
CellIterator< StorageType, false > end() const
Get an iterator to the end of a ParticleCell.
Definition: ReferenceParticleCell.h:92
void reserve(size_t n)
Requests that the vector capacity be at least enough to contain n elements.
Definition: ReferenceParticleCell.h:251
void resize(size_t n, const Particle_T &toInsert)
Resizes the container so that it contains n elements.
Definition: ReferenceParticleCell.h:236
const Particle_T & at(size_t index) const
Returns the const particle at position index.
Definition: ReferenceParticleCell.h:201
size_t size() const override
Get the number of all particles stored in this cell (owned, halo and dummy).
Definition: ReferenceParticleCell.h:155
void reduce(Lambda reduceLambda, A &result, const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior)
Reduce properties of particles as defined by a lambda function.
Definition: ReferenceParticleCell.h:146
SoA< SoAArraysType > _particleSoABuffer
SoA buffer of this cell.
Definition: ReferenceParticleCell.h:261
CellIterator< StorageType, true > end()
Get an iterator to the end of a ParticleCell.
Definition: ReferenceParticleCell.h:86
CellIterator< StorageType, false > begin() const
Get an iterator to the start of a ParticleCell.
Definition: ReferenceParticleCell.h:79
void addParticle(const Particle_T &p) override
Adds a Particle to the cell.
Definition: ReferenceParticleCell.h:48
ReferenceParticleCell()
Constructs a new ReferenceParticleCell.
Definition: ReferenceParticleCell.h:38
void deleteDummyParticles() override
Deletes all dummy particles in this cell.
Definition: ReferenceParticleCell.h:207
CellType getParticleCellTypeAsEnum() override
Get the ParticleCell type as an ParticleCellTypeEnum.
Definition: ReferenceParticleCell.h:180
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior)
Reduce properties of particles as defined by a lambda function.
Definition: ReferenceParticleCell.h:130
const Particle_T & operator[](size_t n) const
Returns a const reference to the element at position n in the cell.
Definition: ReferenceParticleCell.h:187
void sortByDim(const size_t dim)
Sort the particles in the cell by a dimension.
Definition: ReferenceParticleCell.h:242
CellIterator< StorageType, true > begin()
Get an iterator to the start of a ParticleCell.
Definition: ReferenceParticleCell.h:73
std::array< double, 3 > getCellLength() const override
Get the side lengths of this cell.
Definition: ReferenceParticleCell.h:229
typename Particle_T::SoAArraysType SoAArraysType
The structure of the SoAs is defined by the particle.
Definition: ReferenceParticleCell.h:29
Particle_T & operator[](size_t n)
Returns a reference to the element at position n in the cell.
Definition: ReferenceParticleCell.h:175
Structur of the array class.
Definition: SoA.h:28
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
bool inBox(const std::array< T, 3 > &position, const std::array< T, 3 > &low, const std::array< T, 3 > &high)
Checks if position is inside of a box defined by low and high.
Definition: inBox.h:26
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
CellType
The ParticleCell Type as an Enum.
Definition: ParticleCell.h:19
@ ReferenceParticleCell
ReferenceParticleCell : Cell holding only references instead of actual particle objects.
constexpr int64_t toInt64(const OwnershipState a)
Returns the int64_t value of a given OwnershipState.
Definition: OwnershipState.h:56
@ dummy
Dummy or deleted state, a particle with this state is not an actual particle!