25template <
class Particle_T>
42 : _cellLength({std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
43 std::numeric_limits<double>::max()}) {}
49 explicit FullParticleCell(
const std::array<double, 3> &cellLength) : _cellLength(cellLength) {}
52 std::lock_guard<AutoPasLock> guard(this->
_cellLock);
56 if ((not
toInt64(p.getOwnershipState() & this->_ownershipState)) and
59 "FullParticleCell::addParticle() can not add a particle with OwnershipState {} to a cell with OwnershipState "
61 p.getOwnershipState(), this->_ownershipState);
104 template <
typename Lambda>
106 const std::array<double, 3>
dummy{};
107 forEachImpl<false, false>(forEachLambda,
dummy,
dummy);
116 template <
typename Lambda>
117 void forEach(Lambda forEachLambda, IteratorBehavior behavior) {
118 const std::array<double, 3>
dummy{};
119 forEachImpl<true, false>(forEachLambda,
dummy,
dummy, behavior);
130 template <
typename Lambda>
131 void forEach(Lambda forEachLambda,
const std::array<double, 3> &lowerCorner,
132 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
133 forEachImpl<true, true>(forEachLambda, lowerCorner, higherCorner, behavior);
143 template <
typename Lambda,
typename A>
144 void reduce(Lambda reduceLambda, A &result) {
145 const std::array<double, 3>
dummy{};
146 reduceImpl<false, false>(reduceLambda, result,
dummy,
dummy);
157 template <
typename Lambda,
typename A>
158 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior) {
159 const std::array<double, 3>
dummy{};
160 reduceImpl<true, false>(reduceLambda, result,
dummy,
dummy, behavior);
173 template <
typename Lambda,
typename A>
174 void reduce(Lambda reduceLambda, A &result,
const std::array<double, 3> &lowerCorner,
175 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
176 reduceImpl<true, true>(reduceLambda, result, lowerCorner, higherCorner, behavior);
189 std::lock_guard<AutoPasLock> guard(this->
_cellLock);
190 return std::count_if(
_particles.begin(),
_particles.end(), [&behavior](
auto p) { return behavior.contains(p); });
221 const Particle_T &
at(
size_t index)
const {
return _particles.at(index); }
223 [[nodiscard]]
bool isEmpty()
const override {
return size() == 0; }
229 std::remove_if(
_particles.begin(),
_particles.end(), [](
const auto &particle) { return particle.isDummy(); }),
234 std::lock_guard<AutoPasLock> lock(this->
_cellLock);
235 if (index >=
size()) {
239 if (index <
size() - 1) {
245 void setCellLength(std::array<double, 3> &cellLength)
override { _cellLength = cellLength; }
247 [[nodiscard]] std::array<double, 3>
getCellLength()
const override {
return _cellLength; }
262 [dim](
const Particle_T &a,
const Particle_T &b) ->
bool { return a.getR()[dim] < b.getR()[dim]; });
282 std::array<double, 3> _cellLength;
284 template <
bool ownershipCheck,
bool regionCheck,
typename Lambda>
285 void forEachImpl(Lambda forEachLambda,
const std::array<double, 3> &lowerCorner,
286 const std::array<double, 3> &higherCorner,
287 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHaloOrDummy) {
289 if ((not ownershipCheck) or behavior.contains(p)) {
290 if ((not regionCheck) or
utils::inBox(p.getR(), lowerCorner, higherCorner)) {
297 template <
bool ownershipCheck,
bool regionCheck,
typename Lambda,
typename A>
298 void reduceImpl(Lambda reduceLambda, A &result,
const std::array<double, 3> &lowerCorner,
299 const std::array<double, 3> &higherCorner,
300 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHaloOrDummy) {
302 if ((not ownershipCheck) or behavior.contains(p)) {
303 if ((not regionCheck) or
utils::inBox(p.getR(), lowerCorner, higherCorner)) {
304 reduceLambda(p, result);
Wraps the iterator of arbitrary cells to provide a common interface.
Definition: CellIterator.h:19
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
void deleteByIndex(size_t index) override
Deletes the index-th particle.
Definition: FullParticleCell.h:233
Particle_T & at(size_t index)
Returns the particle at position index.
Definition: FullParticleCell.h:212
StorageType _particles
Storage of the molecules of the cell.
Definition: FullParticleCell.h:274
size_t size() const override
Get the number of all particles stored in this cell (owned, halo and dummy).
Definition: FullParticleCell.h:183
void forEach(Lambda forEachLambda)
Executes code for every particle in this cell as defined by lambda function.
Definition: FullParticleCell.h:105
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: FullParticleCell.h:131
void sortByDim(const size_t dim)
Sort the particles in the cell by a dimension.
Definition: FullParticleCell.h:260
bool isEmpty() const override
Check if the cell is empty.
Definition: FullParticleCell.h:223
void clear() override
Deletes all particles in this cell.
Definition: FullParticleCell.h:225
typename Particle_T::SoAArraysType SoAArraysType
The structure of the SoAs is defined by the particle.
Definition: FullParticleCell.h:31
void reserve(size_t n)
Requests that the vector capacity be at least enough to contain n elements.
Definition: FullParticleCell.h:269
std::array< double, 3 > getCellLength() const override
Get the side lengths of this cell.
Definition: FullParticleCell.h:247
CellIterator< StorageType, false > end() const
Get an iterator to the end of a ParticleCell.
Definition: FullParticleCell.h:95
void setCellLength(std::array< double, 3 > &cellLength) override
Set the side lengths of this cell.
Definition: FullParticleCell.h:245
void addParticle(const Particle_T &p) override
Adds a Particle to the cell.
Definition: FullParticleCell.h:51
Particle_T & operator[](size_t n)
Returns a reference to the element at position n in the cell.
Definition: FullParticleCell.h:198
void forEach(Lambda forEachLambda, IteratorBehavior behavior)
Executes code for every particle in this cell as defined by lambda function.
Definition: FullParticleCell.h:117
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: FullParticleCell.h:174
CellIterator< StorageType, false > begin() const
Get an iterator to the start of a ParticleCell.
Definition: FullParticleCell.h:79
CellType getParticleCellTypeAsEnum() override
Get the ParticleCell type as an ParticleCellTypeEnum.
Definition: FullParticleCell.h:214
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: FullParticleCell.h:188
void reduce(Lambda reduceLambda, A &result)
Reduce properties of particles as defined by a lambda function.
Definition: FullParticleCell.h:144
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior)
Reduce properties of particles as defined by a lambda function.
Definition: FullParticleCell.h:158
const Particle_T & operator[](size_t n) const
Returns a const reference to the element at position n in the cell.
Definition: FullParticleCell.h:205
CellIterator< StorageType, true > end()
Get an iterator to the end of a ParticleCell.
Definition: FullParticleCell.h:89
SoA< SoAArraysType > _particleSoABuffer
SoA buffer of this cell.
Definition: FullParticleCell.h:279
void resize(size_t n, const Particle_T &toInsert)
Resizes the container so that it contains n elements.
Definition: FullParticleCell.h:254
const Particle_T & at(size_t index) const
Returns the const particle at position index.
Definition: FullParticleCell.h:221
FullParticleCell(const std::array< double, 3 > &cellLength)
Constructs a new FullParticleCell with the given cell side length.
Definition: FullParticleCell.h:49
FullParticleCell()
Constructs a new FullParticleCell.
Definition: FullParticleCell.h:41
CellIterator< StorageType, true > begin()
Get an iterator to the start of a ParticleCell.
Definition: FullParticleCell.h:73
Class for Cells of Particles.
Definition: ParticleCell.h:51
AutoPasLock _cellLock
Lock object for exclusive access to this cell.
Definition: ParticleCell.h:184
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
@ FullParticleCell
FullParticleCell : Default cell type for almost everything.
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!