45template <
class Particle_T>
66 DirectSum(
const std::array<double, 3> &boxMin,
const std::array<double, 3> &boxMax,
double cutoff,
double skin,
67 unsigned int verletRebuildFrequency)
69 _cellBorderFlagManager() {
70 using namespace autopas::utils::ArrayMath::literals;
74 std::for_each(++this->
_cells.begin(), this->_cells.end(),
75 [&](
auto &cell) { cell.setPossibleParticleOwnerships(OwnershipState::halo); });
76 auto boxLength = boxMax - boxMin;
77 this->
_cells[0].setCellLength(boxLength);
83 [[nodiscard]] ContainerOption
getContainerType()
const override {
return ContainerOption::directSum; }
85 void reserve(
size_t numParticles,
size_t numParticlesHaloEstimate)
override {
86 this->getOwnedCell().
reserve(numParticles);
87 for (
auto cellIt = ++this->
_cells.begin(); cellIt != this->
_cells.end(); cellIt++) {
88 cellIt->reserve(numParticlesHaloEstimate);
103 const auto pos = haloParticle.getR();
105 for (
size_t dim = 0; dim < 3; ++dim) {
106 if (pos[dim] < boxMin[dim]) {
107 this->
_cells[2 * dim + 1].addParticle(haloParticle);
109 }
else if (pos[dim] >= boxMax[dim]) {
110 this->
_cells[2 * dim + 2].addParticle(haloParticle);
122 const auto pos = haloParticle.getR();
126 for (
size_t dim = 0; dim < 3; ++dim) {
127 if (pos[dim] < boxMin[dim] + skinHalf) {
131 }
else if (pos[dim] >= boxMax[dim] - skinHalf) {
141 for (
auto cellIt = ++this->
_cells.begin(); cellIt != this->
_cells.end(); cellIt++) {
153 prepareTraversal(traversal);
160 [[nodiscard]] std::vector<ParticleType>
updateContainer(
bool keepNeighborListsValid)
override {
161 if (keepNeighborListsValid) {
168 std::vector<ParticleType> invalidParticles{};
169 auto &particleVec = getOwnedCell().
_particles;
170 for (
auto iter = particleVec.begin(); iter != particleVec.end();) {
171 if (
utils::notInBox(iter->getR(), this->getBoxMin(), this->getBoxMax())) {
172 invalidParticles.push_back(*iter);
174 *iter = particleVec.back();
175 particleVec.pop_back();
180 return invalidParticles;
187 using namespace autopas::utils::ArrayMath::literals;
198 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHalo,
204 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHalo,
206 nullptr)
const override {
213 template <
typename Lambda>
214 void forEach(Lambda forEachLambda, IteratorBehavior behavior) {
215 if (behavior & IteratorBehavior::owned) {
216 getOwnedCell().
forEach(forEachLambda);
218 if (behavior & IteratorBehavior::halo) {
219 for (
auto cellIt = ++this->
_cells.begin(); cellIt != this->
_cells.end(); cellIt++) {
220 cellIt->forEach(forEachLambda);
224 if (not(behavior & IteratorBehavior::ownedOrHalo)) {
232 template <
typename Lambda,
typename A>
233 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior) {
234 if (behavior & IteratorBehavior::owned) {
235 getOwnedCell().
reduce(reduceLambda, result);
237 if (behavior & IteratorBehavior::halo) {
238 for (
auto cellIt = ++this->
_cells.begin(); cellIt != this->
_cells.end(); cellIt++) {
239 cellIt->reduce(reduceLambda, result);
243 if (not(behavior & IteratorBehavior::ownedOrHalo)) {
249 const std::array<double, 3> &lowerCorner,
const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
255 const std::array<double, 3> &lowerCorner,
const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
257 nullptr)
const override {
264 template <
typename Lambda>
266 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
267 if (behavior & IteratorBehavior::owned) {
268 getOwnedCell().
forEach(forEachLambda, lowerCorner, higherCorner, behavior);
270 if (behavior & IteratorBehavior::halo) {
271 for (
auto cellIt = ++this->
_cells.begin(); cellIt != this->
_cells.end(); cellIt++) {
272 cellIt->forEach(forEachLambda, lowerCorner, higherCorner, behavior);
276 if (not(behavior & IteratorBehavior::ownedOrHalo)) {
284 template <
typename Lambda,
typename A>
285 void reduceInRegion(Lambda reduceLambda, A &result,
const std::array<double, 3> &lowerCorner,
286 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
287 if (behavior & IteratorBehavior::owned) {
288 getOwnedCell().
reduce(reduceLambda, result, lowerCorner, higherCorner, behavior);
290 if (behavior & IteratorBehavior::halo) {
291 for (
auto cellIt = ++this->
_cells.begin(); cellIt != this->
_cells.end(); cellIt++) {
292 cellIt->reduce(reduceLambda, result, lowerCorner, higherCorner, behavior);
296 if (not(behavior & IteratorBehavior::ownedOrHalo)) {
301 std::tuple<const Particle_T *, size_t, size_t>
getParticle(
size_t cellIndex,
size_t particleIndex,
302 IteratorBehavior iteratorBehavior,
303 const std::array<double, 3> &boxMin,
304 const std::array<double, 3> &boxMax)
const override {
305 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
307 std::tuple<const Particle_T *, size_t, size_t>
getParticle(
size_t cellIndex,
size_t particleIndex,
308 IteratorBehavior iteratorBehavior)
const override {
310 constexpr std::array<double, 3> boxMin{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
311 std::numeric_limits<double>::lowest()};
313 constexpr std::array<double, 3> boxMax{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
314 std::numeric_limits<double>::max()};
315 return getParticleImpl<false>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
320 auto swapDelFromCell = [&](
auto &particleCell) ->
bool {
321 auto &particleVec = particleCell._particles;
322 const bool isRearParticle = &particle == &particleVec.back();
323 particle = particleVec.back();
324 particleVec.pop_back();
325 return isRearParticle;
329 if (particle.isOwned()) {
330 return swapDelFromCell(getOwnedCell());
331 }
else if (particle.isHalo()) {
335 const auto pos = particle.getR();
338 for (
size_t dim = 0; dim < 3; ++dim) {
339 if (pos[dim] < boxMin[dim] + skinHalf) {
340 if (swapDelFromCell(this->
_cells[2 * dim + 1])) {
343 }
else if (pos[dim] >= boxMax[dim] - skinHalf) {
344 if (swapDelFromCell(this->
_cells[2 * dim + 2])) {
354 auto &particleVec = this->
_cells[cellIndex]._particles;
355 auto &particle = particleVec[particleIndex];
357 particle = particleVec.back();
358 particleVec.pop_back();
359 return particleIndex < particleVec.size();
367 using index_t = std::size_t;
370 [[nodiscard]]
bool cellCanContainHaloParticles(index_t index1d)
const override {
371 return index1d >= 1 and index1d <= 6;
374 [[nodiscard]]
bool cellCanContainOwnedParticles(index_t index1d)
const override {
return index1d == 0; }
376 } _cellBorderFlagManager;
389 template <
bool regionIter>
390 std::tuple<const Particle_T *, size_t, size_t> getParticleImpl(
size_t cellIndex,
size_t particleIndex,
391 IteratorBehavior iteratorBehavior,
392 const std::array<double, 3> &boxMin,
393 const std::array<double, 3> &boxMax)
const {
395 const auto [startCellIndex, endCellIndex] = [&]() -> std::tuple<size_t, size_t> {
397 if (not(iteratorBehavior & IteratorBehavior::halo)) {
401 if (not(iteratorBehavior & IteratorBehavior::owned)) {
405 if constexpr (regionIter) {
416 if (cellIndex == 0 and particleIndex == 0) {
421 if (cellIndex >= this->
_cells.size()) {
422 return {
nullptr, 0, 0};
425 if (particleIndex >= this->
_cells[cellIndex].
size() or
426 not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
427 this->
_cells[cellIndex][particleIndex], iteratorBehavior, boxMin, boxMax)) {
429 std::tie(cellIndex, particleIndex) =
430 advanceIteratorIndices<regionIter>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
434 if (cellIndex >= this->
_cells.size()) {
435 return {
nullptr, 0, 0};
437 const Particle_T *retPtr = &this->
_cells[cellIndex][particleIndex];
439 return {retPtr, cellIndex, particleIndex};
453 template <
bool regionIter>
454 std::tuple<size_t, size_t> advanceIteratorIndices(
size_t cellIndex,
size_t particleIndex,
455 IteratorBehavior iteratorBehavior,
456 const std::array<double, 3> &boxMin,
457 const std::array<double, 3> &boxMax)
const {
465 while (particleIndex >= this->
_cells[cellIndex].
size()) {
469 if (cellIndex > ((not(iteratorBehavior & IteratorBehavior::halo)) ? 0 : (this->
_cells.
size() - 1))) {
470 return {std::numeric_limits<
decltype(cellIndex)>::max(), std::numeric_limits<
decltype(particleIndex)>::max()};
473 }
while (not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
474 this->
_cells[cellIndex][particleIndex], iteratorBehavior, boxMin, boxMax));
477 return {cellIndex, particleIndex};
485 template <
typename Traversal>
486 void prepareTraversal(Traversal &traversal) {
489 if (dsTraversal && cellTraversal) {
493 "The selected traversal is not compatible with the DirectSum container. TraversalID: {}",
494 traversal->getTraversalType());
The CellBasedParticleContainer class stores particles in some object and provides methods to iterate ...
Definition: CellBasedParticleContainer.h:25
double getVerletSkin() const final
Returns the verlet Skin length.
Definition: CellBasedParticleContainer.h:94
std::vector< FullParticleCell< Particle_T > > _cells
Vector of particle cells.
Definition: CellBasedParticleContainer.h:157
double getCutoff() const final
Return the cutoff of the container.
Definition: CellBasedParticleContainer.h:79
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: CellBasedParticleContainer.h:131
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: CellBasedParticleContainer.h:74
const std::array< double, 3 > & getBoxMax() const final
Get the upper corner of the container without halo.
Definition: CellBasedParticleContainer.h:69
A cell pair traversal.
Definition: CellTraversal.h:23
virtual void setCellsToTraverse(std::vector< ParticleCell > &cells)
Sets the cells to iterate over.
Definition: CellTraversal.h:40
Public iterator class that iterates over a particle container and additional vectors (which are typic...
Definition: ContainerIterator.h:93
std::conditional_t< modifiable, std::vector< std::vector< Particle_T > * >, std::vector< std::vector< Particle_T > const * > > ParticleVecType
Type of the additional vector collection.
Definition: ContainerIterator.h:106
Interface for traversals used by the DirectSum container.
Definition: DSTraversalInterface.h:18
This class stores all owned particles in a single cell.
Definition: DirectSum.h:46
bool deleteParticle(size_t cellIndex, size_t particleIndex) override
Deletes the particle at the given index positions as long as this does not compromise the validity of...
Definition: DirectSum.h:353
std::tuple< const Particle_T *, size_t, size_t > getParticle(size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior) const override
Fetch the pointer to a particle, identified via a cell and particle index.
Definition: DirectSum.h:307
DirectSum(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, double cutoff, double skin, unsigned int verletRebuildFrequency)
Constructor of the DirectSum class.
Definition: DirectSum.h:66
bool deleteParticle(Particle_T &particle) override
Deletes the given particle as long as this does not compromise the validity of the container.
Definition: DirectSum.h:318
void reduceInRegion(Lambda reduceLambda, A &result, const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior)
Execute code on all particles in this container in a certain region as defined by a lambda function.
Definition: DirectSum.h:285
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: DirectSum.h:186
void forEachInRegion(Lambda forEachLambda, const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior)
Execute code on all particles in this container in a certain region as defined by a lambda function.
Definition: DirectSum.h:265
ContainerIterator< ParticleType, true, false > begin(IteratorBehavior behavior=autopas::IteratorBehavior::ownedOrHalo, typename ContainerIterator< ParticleType, true, false >::ParticleVecType *additionalVectors=nullptr) override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: DirectSum.h:197
void addHaloParticleImpl(const ParticleType &haloParticle) override
Adds a particle to the container that lies in the halo region of the container.
Definition: DirectSum.h:100
std::vector< ParticleType > updateContainer(bool keepNeighborListsValid) override
Updates the container.
Definition: DirectSum.h:160
void rebuildNeighborLists(TraversalInterface *traversal) override
Rebuilds the neighbor lists for the next traversals.
Definition: DirectSum.h:146
ContainerIterator< ParticleType, false, false > begin(IteratorBehavior behavior=autopas::IteratorBehavior::ownedOrHalo, typename ContainerIterator< ParticleType, false, false >::ParticleVecType *additionalVectors=nullptr) const override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: DirectSum.h:203
bool updateHaloParticle(const ParticleType &haloParticle) override
Update a halo particle of the container with the given haloParticle.
Definition: DirectSum.h:119
ContainerIterator< ParticleType, true, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, typename ContainerIterator< ParticleType, true, true >::ParticleVecType *additionalVectors=nullptr) override
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
Definition: DirectSum.h:248
void deleteHaloParticles() override
Deletes all halo particles.
Definition: DirectSum.h:140
CellType getParticleCellTypeEnum() const override
Get the ParticleCell type as an Enum.
Definition: DirectSum.h:150
void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override
Reserve memory for a given number of particles in the container and logic layers.
Definition: DirectSum.h:85
std::tuple< const Particle_T *, size_t, size_t > getParticle(size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior, const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax) const override
Fetch the pointer to a particle, identified via a cell and particle index.
Definition: DirectSum.h:301
void computeInteractions(TraversalInterface *traversal) override
Iterates over all particle multiples (e.g.
Definition: DirectSum.h:152
void forEach(Lambda forEachLambda, IteratorBehavior behavior)
Execute code on all particles in this container as defined by a lambda function.
Definition: DirectSum.h:214
ContainerIterator< ParticleType, false, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, typename ContainerIterator< ParticleType, false, true >::ParticleVecType *additionalVectors=nullptr) const override
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
Definition: DirectSum.h:254
void addParticleImpl(const ParticleType &p) override
Adds a particle to the container.
Definition: DirectSum.h:95
ContainerOption getContainerType() const override
Get the ContainerType.
Definition: DirectSum.h:83
Particle_T ParticleType
Type of the Particle.
Definition: DirectSum.h:56
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior)
Reduce properties of particles as defined by a lambda function.
Definition: DirectSum.h:233
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 forEach(Lambda forEachLambda)
Executes code for every particle in this cell as defined by lambda function.
Definition: FullParticleCell.h:105
void reserve(size_t n)
Requests that the vector capacity be at least enough to contain n elements.
Definition: FullParticleCell.h:269
void addParticle(const Particle_T &p) override
Adds a Particle to the cell.
Definition: FullParticleCell.h:51
void reduce(Lambda reduceLambda, A &result)
Reduce properties of particles as defined by a lambda function.
Definition: FullParticleCell.h:144
Class for Cells of Particles.
Definition: ParticleCell.h:51
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
virtual void endTraversal()=0
Finalizes the traversal.
virtual void traverseParticles()=0
Traverse the particles by pairs, triplets etc.
virtual void initTraversal()=0
Initializes the traversal.
Info for traversals of a specific container.
Definition: TraversalSelectorInfo.h:14
Interface class to handle cell borders and cell types of cells.
Definition: CellBorderAndFlagManager.h:17
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
std::vector< typename ContainerType::ParticleType > collectParticlesAndMarkNonOwnedAsDummy(ContainerType &container)
Collects leaving particles and marks halo particles as dummy.
Definition: LeavingParticleCollector.h:85
static bool checkParticleInCellAndUpdateByIDAndPosition(CellType &cell, const typename CellType::ParticleType &particle, double absError)
Same as checkParticleInCellAndUpdateByID(CellType, ParticleType), but additionally checks whether the...
Definition: ParticleCellHelpers.h:39
constexpr bool less(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
True iff for all d the following holds: a[d] < b[d].
Definition: ArrayMath.h:79
bool notInBox(const std::array< T, 3 > &position, const std::array< T, 3 > &low, const std::array< T, 3 > &high)
Checks if position is not inside of a box defined by low and high.
Definition: inBox.h:50
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.
int autopas_get_num_threads()
Dummy for omp_get_num_threads() when no OpenMP is available.
Definition: WrapOpenMP.h:138
@ owned
Owned state, a particle with this state is an actual particle and owned by the current AutoPas object...
int autopas_get_thread_num()
Dummy for omp_set_lock() when no OpenMP is available.
Definition: WrapOpenMP.h:132