AutoPas  3.0.0
Loading...
Searching...
No Matches
LinkedCells.h
Go to the documentation of this file.
1
8#pragma once
9
27#include "autopas/utils/inBox.h"
28
29namespace autopas {
30
39template <class Particle_T>
40class LinkedCells : public CellBasedParticleContainer<FullParticleCell<Particle_T>> {
41 public:
46
50 using ParticleType = Particle_T;
51
63 LinkedCells(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax, const double cutoff,
64 const double skin, const double cellSizeFactor = 1.0, const size_t sortingThreshold = 8,
66 : CellBasedParticleContainer<ParticleCellType>(boxMin, boxMax, cutoff, skin, sortingThreshold),
67 _cellBlock(this->_cells, boxMin, boxMax, cutoff + skin, cellSizeFactor),
68 _loadEstimator(loadEstimator) {}
69
70 [[nodiscard]] ContainerOption getContainerType() const override { return ContainerOption::linkedCells; }
71
72 void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override {
73 _cellBlock.reserve(numParticles + numParticlesHaloEstimate);
74 }
75
79 void addParticleImpl(const Particle_T &p) override {
80 ParticleCellType &cell = _cellBlock.getContainingCell(p.getR());
81 cell.addParticle(p);
82 }
83
87 void addHaloParticleImpl(const Particle_T &haloParticle) override {
88 ParticleCellType &cell = _cellBlock.getContainingCell(haloParticle.getR());
89 cell.addParticle(haloParticle);
90 }
91
95 bool updateHaloParticle(const Particle_T &haloParticle) override {
96 auto cells = _cellBlock.getNearbyHaloCells(haloParticle.getR(), this->getVerletSkin());
97 for (auto cellptr : cells) {
98 bool updated = internal::checkParticleInCellAndUpdateByID(*cellptr, haloParticle);
99 if (updated) {
100 return true;
101 }
102 }
103 AutoPasLog(TRACE, "UpdateHaloParticle was not able to update particle: {}", haloParticle.toString());
104 return false;
105 }
106
110 void deleteHaloParticles() override { _cellBlock.clearHaloCells(); }
111
112 void rebuildNeighborLists(TraversalInterface *traversal) override {
113 // nothing to do.
114 }
115
121 // (Explicit) static cast required for Apple Clang (last tested version: 17.0.0)
122 switch (static_cast<LoadEstimatorOption::Value>(this->_loadEstimator)) {
124 return [&](const std::array<unsigned long, 3> &cellsPerDimension,
125 const std::array<unsigned long, 3> &lowerCorner, const std::array<unsigned long, 3> &upperCorner) {
126 return loadEstimators::squaredParticlesPerCell(this->_cells, cellsPerDimension, lowerCorner, upperCorner);
127 };
128 }
130 [[fallthrough]];
131 default: {
132 return
133 [&](const std::array<unsigned long, 3> &cellsPerDimension, const std::array<unsigned long, 3> &lowerCorner,
134 const std::array<unsigned long, 3> &upperCorner) { return 1; };
135 }
136 }
137 }
138
139 void computeInteractions(TraversalInterface *traversal) override {
140 prepareTraversal(traversal);
141
142 traversal->initTraversal();
143 traversal->traverseParticles();
144 traversal->endTraversal();
145 }
146
147 [[nodiscard]] std::vector<Particle_T> updateContainer(bool keepNeighborListsValid) override {
148 if (keepNeighborListsValid) {
150 }
151
152 this->deleteHaloParticles();
153
154 std::vector<Particle_T> invalidParticles;
155 AUTOPAS_OPENMP(parallel) {
156 // private for each thread!
157 std::vector<Particle_T> myInvalidParticles{}, myInvalidNotOwnedParticles{};
158 // TODO: needs smarter heuristic than this.
159 myInvalidParticles.reserve(128);
160 myInvalidNotOwnedParticles.reserve(128);
161 AUTOPAS_OPENMP(for)
162 for (size_t cellId = 0; cellId < this->getCells().size(); ++cellId) {
163 // Delete dummy particles of each cell.
164 this->getCells()[cellId].deleteDummyParticles();
165
166 // if empty
167 if (this->getCells()[cellId].isEmpty()) continue;
168
169 const auto [cellLowerCorner, cellUpperCorner] = this->getCellBlock().getCellBoundingBox(cellId);
170
171 auto &particleVec = this->getCells()[cellId]._particles;
172 for (auto pIter = particleVec.begin(); pIter < particleVec.end();) {
173 // if not in cell
174 if (utils::notInBox(pIter->getR(), cellLowerCorner, cellUpperCorner)) {
175 myInvalidParticles.push_back(*pIter);
176 // swap-delete
177 *pIter = particleVec.back();
178 particleVec.pop_back();
179 } else {
180 ++pIter;
181 }
182 }
183 }
184 // implicit barrier here
185 // the barrier is needed because iterators are not threadsafe w.r.t. addParticle()
186
187 // this loop is executed for every thread and thus parallel. Don't use #pragma omp for here!
188 for (auto &&p : myInvalidParticles) {
189 // if not in halo
190 if (utils::inBox(p.getR(), this->getBoxMin(), this->getBoxMax())) {
191 this->template addParticle<false>(p);
192 } else {
193 myInvalidNotOwnedParticles.push_back(p);
194 }
195 }
196 AUTOPAS_OPENMP(critical) {
197 // merge private vectors to global one.
198 invalidParticles.insert(invalidParticles.end(), myInvalidNotOwnedParticles.begin(),
199 myInvalidNotOwnedParticles.end());
200 }
201 }
202 return invalidParticles;
203 }
204
205 [[nodiscard]] TraversalSelectorInfo getTraversalSelectorInfo() const override {
206 return TraversalSelectorInfo(this->getCellBlock().getCellsPerDimensionWithHalo(), this->getInteractionLength(),
207 this->getCellBlock().getCellLength(), 0);
208 }
209
210 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
211 IteratorBehavior iteratorBehavior,
212 const std::array<double, 3> &boxMin,
213 const std::array<double, 3> &boxMax) const override {
214 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
215 }
216
217 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
218 IteratorBehavior iteratorBehavior) const override {
219 // this is not a region iter hence we stretch the bounding box to the numeric max
220 constexpr std::array<double, 3> boxMin{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
221 std::numeric_limits<double>::lowest()};
222
223 constexpr std::array<double, 3> boxMax{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
224 std::numeric_limits<double>::max()};
225 return getParticleImpl<false>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
226 }
227
239 template <bool regionIter>
240 std::tuple<const Particle_T *, size_t, size_t> getParticleImpl(size_t cellIndex, size_t particleIndex,
241 IteratorBehavior iteratorBehavior,
242 const std::array<double, 3> &boxMin,
243 const std::array<double, 3> &boxMax) const {
244 using namespace autopas::utils::ArrayMath::literals;
245
246 std::array<double, 3> boxMinWithSafetyMargin = boxMin;
247 std::array<double, 3> boxMaxWithSafetyMargin = boxMax;
248 if constexpr (regionIter) {
249 // We extend the search box for cells here since particles might have moved
250 boxMinWithSafetyMargin -= this->getVerletSkin();
251 boxMaxWithSafetyMargin += this->getVerletSkin();
252 }
253
254 // first and last relevant cell index
255 const auto [startCellIndex, endCellIndex] = [&]() -> std::tuple<size_t, size_t> {
256 if constexpr (regionIter) {
257 // We extend the search box for cells here since particles might have moved
258 return {_cellBlock.get1DIndexOfPosition(boxMinWithSafetyMargin),
259 _cellBlock.get1DIndexOfPosition(boxMaxWithSafetyMargin)};
260 } else {
261 if (not(iteratorBehavior & IteratorBehavior::halo)) {
262 // only potentially owned region
263 return {_cellBlock.getFirstOwnedCellIndex(), _cellBlock.getLastOwnedCellIndex()};
264 } else {
265 // whole range of cells
266 return {0, this->_cells.size() - 1};
267 }
268 }
269 }();
270
271 // if we are at the start of an iteration ...
272 if (cellIndex == 0 and particleIndex == 0) {
273 cellIndex =
274 startCellIndex + ((iteratorBehavior & IteratorBehavior::forceSequential) ? 0 : autopas_get_thread_num());
275 }
276 // abort if the start index is already out of bounds
277 if (cellIndex >= this->_cells.size()) {
278 return {nullptr, 0, 0};
279 }
280 // check the data behind the indices
281 if (particleIndex >= this->_cells[cellIndex].size() or
282 not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
283 this->_cells[cellIndex][particleIndex], iteratorBehavior, boxMin, boxMax)) {
284 // either advance them to something interesting or invalidate them.
285 std::tie(cellIndex, particleIndex) =
286 advanceIteratorIndices<regionIter>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax,
287 boxMinWithSafetyMargin, boxMaxWithSafetyMargin, endCellIndex);
288 }
289
290 // shortcut if the given index doesn't exist
291 if (cellIndex > endCellIndex) {
292 return {nullptr, 0, 0};
293 }
294 const Particle_T *retPtr = &this->_cells[cellIndex][particleIndex];
295
296 return {retPtr, cellIndex, particleIndex};
297 }
298
302 bool deleteParticle(Particle_T &particle) override {
303 // deduce into which vector the reference points
304 auto &particleVec = _cellBlock.getContainingCell(particle.getR())._particles;
305 const bool isRearParticle = &particle == &particleVec.back();
306 // swap-delete
307 particle = particleVec.back();
308 particleVec.pop_back();
309 return not isRearParticle;
310 }
311
315 bool deleteParticle(size_t cellIndex, size_t particleIndex) override {
316 auto &particleVec = this->_cells[cellIndex]._particles;
317 auto &particle = particleVec[particleIndex];
318 // swap-delete
319 particle = particleVec.back();
320 particleVec.pop_back();
321 return particleIndex < particleVec.size();
322 }
323
328 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
329 typename ContainerIterator<Particle_T, true, false>::ParticleVecType *additionalVectors = nullptr) override {
330 return ContainerIterator<Particle_T, true, false>(*this, behavior, additionalVectors);
331 }
332
337 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
339 nullptr) const override {
340 return ContainerIterator<Particle_T, false, false>(*this, behavior, additionalVectors);
341 }
342
349 template <typename Lambda>
350 void forEach(Lambda forEachLambda, IteratorBehavior behavior = IteratorBehavior::ownedOrHalo) {
351 if (behavior == IteratorBehavior::ownedOrHaloOrDummy) {
352 for (auto &cell : getCells()) {
353 cell.forEach(forEachLambda);
354 }
355 } else {
356 for (size_t index = 0; index < getCells().size(); index++) {
357 if (not _cellBlock.ignoreCellForIteration(index, behavior)) {
358 getCells()[index].forEach(forEachLambda, behavior);
359 }
360 }
361 }
362 }
363
372 template <typename Lambda, typename A>
373 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior = IteratorBehavior::ownedOrHalo) {
374 if (behavior == IteratorBehavior::ownedOrHaloOrDummy) {
375 for (auto &cell : getCells()) {
376 cell.reduce(reduceLambda, result);
377 }
378 } else {
379 for (size_t index = 0; index < getCells().size(); index++) {
380 if (not _cellBlock.ignoreCellForIteration(index, behavior)) {
381 getCells()[index].reduce(reduceLambda, result, behavior);
382 }
383 }
384 }
385 }
386
391 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
392 typename ContainerIterator<Particle_T, true, true>::ParticleVecType *additionalVectors = nullptr) override {
393 return ContainerIterator<Particle_T, true, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
394 }
395
400 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
402 nullptr) const override {
403 return ContainerIterator<Particle_T, false, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
404 }
405
414 template <typename Lambda>
415 void forEachInRegion(Lambda forEachLambda, const std::array<double, 3> &lowerCorner,
416 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
417 using namespace autopas::utils::ArrayMath::literals;
418
419 const auto startIndex3D = this->_cellBlock.get3DIndexOfPosition(lowerCorner - this->getVerletSkin());
420 const auto stopIndex3D = this->_cellBlock.get3DIndexOfPosition(higherCorner + this->getVerletSkin());
421
422 const size_t numCellsOfInterest = (stopIndex3D[0] - startIndex3D[0] + 1) * (stopIndex3D[1] - startIndex3D[1] + 1) *
423 (stopIndex3D[2] - startIndex3D[2] + 1);
424 std::vector<size_t> cellsOfInterest;
425 cellsOfInterest.reserve(numCellsOfInterest);
426
427 const auto &cellsPerDimensionWithHalo = this->_cellBlock.getCellsPerDimensionWithHalo();
428
429 for (size_t z = startIndex3D[2]; z <= stopIndex3D[2]; ++z) {
430 for (size_t y = startIndex3D[1]; y <= stopIndex3D[1]; ++y) {
431 for (size_t x = startIndex3D[0]; x <= stopIndex3D[0]; ++x) {
432 cellsOfInterest.push_back(utils::ThreeDimensionalMapping::threeToOneD({x, y, z}, cellsPerDimensionWithHalo));
433 }
434 }
435 }
436
437 for (auto cellIndex : cellsOfInterest) {
438 if (not _cellBlock.ignoreCellForIteration(cellIndex, behavior)) {
439 getCells()[cellIndex].forEach(forEachLambda, lowerCorner, higherCorner, behavior);
440 }
441 }
442 }
443
454 template <typename Lambda, typename A>
455 void reduceInRegion(Lambda reduceLambda, A &result, const std::array<double, 3> &lowerCorner,
456 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
457 using namespace autopas::utils::ArrayMath::literals;
458 const auto startIndex3D = this->_cellBlock.get3DIndexOfPosition(lowerCorner - this->getVerletSkin());
459 const auto stopIndex3D = this->_cellBlock.get3DIndexOfPosition(higherCorner + this->getVerletSkin());
460
461 const size_t numCellsOfInterest = (stopIndex3D[0] - startIndex3D[0] + 1) * (stopIndex3D[1] - startIndex3D[1] + 1) *
462 (stopIndex3D[2] - startIndex3D[2] + 1);
463 std::vector<size_t> cellsOfInterest;
464 cellsOfInterest.reserve(numCellsOfInterest);
465
466 const auto &cellsPerDimensionWithHalo = this->_cellBlock.getCellsPerDimensionWithHalo();
467
468 for (size_t z = startIndex3D[2]; z <= stopIndex3D[2]; ++z) {
469 for (size_t y = startIndex3D[1]; y <= stopIndex3D[1]; ++y) {
470 for (size_t x = startIndex3D[0]; x <= stopIndex3D[0]; ++x) {
471 cellsOfInterest.push_back(utils::ThreeDimensionalMapping::threeToOneD({x, y, z}, cellsPerDimensionWithHalo));
472 }
473 }
474 }
475
476 for (auto cellIndex : cellsOfInterest) {
477 if (not _cellBlock.ignoreCellForIteration(cellIndex, behavior)) {
478 getCells()[cellIndex].reduce(reduceLambda, result, lowerCorner, higherCorner, behavior);
479 }
480 }
481 }
482
488
494
499 std::vector<ParticleCellType> &getCells() { return this->_cells; }
500
501 protected:
516 template <bool regionIter>
517 std::tuple<size_t, size_t> advanceIteratorIndices(
518 size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior, const std::array<double, 3> &boxMin,
519 const std::array<double, 3> &boxMax, std::array<double, 3> boxMinWithSafetyMargin,
520 std::array<double, 3> boxMaxWithSafetyMargin, size_t endCellIndex) const {
521 // Finding the indices for the next particle
522 const size_t stride = (iteratorBehavior & IteratorBehavior::forceSequential) ? 1 : autopas_get_num_threads();
523
524 // helper function to determine if the cell can even contain particles of interest to the iterator
525 auto cellIsRelevant = [&]() -> bool {
526 bool isRelevant =
527 // behavior matches possible particle ownership
528 (iteratorBehavior & IteratorBehavior::owned and _cellBlock.cellCanContainOwnedParticles(cellIndex)) or
529 (iteratorBehavior & IteratorBehavior::halo and _cellBlock.cellCanContainHaloParticles(cellIndex));
530 if constexpr (regionIter) {
531 // short circuit if already false
532 if (isRelevant) {
533 // is the cell in the region?
534 const auto [cellLowCorner, cellHighCorner] = _cellBlock.getCellBoundingBox(cellIndex);
535 isRelevant =
536 utils::boxesOverlap(cellLowCorner, cellHighCorner, boxMinWithSafetyMargin, boxMaxWithSafetyMargin);
537 }
538 }
539 return isRelevant;
540 };
541
542 do {
543 // advance to the next particle
544 ++particleIndex;
545 // If this breaches the end of a cell, find the next non-empty cell and reset particleIndex.
546
547 // If cell has wrong type, or there are no more particles in this cell jump to the next
548 while (not cellIsRelevant() or particleIndex >= this->_cells[cellIndex].size()) {
549 // TODO: can this jump be done more efficient if behavior is only halo or owned?
550 // TODO: can this jump be done more efficient for region iters if the cell is outside the region?
551 cellIndex += stride;
552 particleIndex = 0;
553
554 // If we notice that there is nothing else to look at set invalid values, so we get a nullptr next time and
555 // break.
556 if (cellIndex > endCellIndex) {
557 return {std::numeric_limits<decltype(cellIndex)>::max(), std::numeric_limits<decltype(particleIndex)>::max()};
558 }
559 }
560 } while (not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
561 this->_cells[cellIndex][particleIndex], iteratorBehavior, boxMin, boxMax));
562
563 // the indices returned at this point should always be valid
564 return {cellIndex, particleIndex};
565 }
566
572 template <typename Traversal>
573 void prepareTraversal(Traversal &traversal) {
574 auto *traversalInterface = dynamic_cast<LCTraversalInterface *>(traversal);
575 auto *cellTraversal = dynamic_cast<CellTraversal<ParticleCellType> *>(traversal);
576 if (auto *balancedTraversal = dynamic_cast<BalancedTraversal *>(traversal)) {
577 balancedTraversal->setLoadEstimator(getLoadEstimatorFunction());
578 }
579 if (traversalInterface && cellTraversal) {
580 cellTraversal->setSortingThreshold(this->_sortingThreshold);
581 cellTraversal->setCellsToTraverse(this->_cells);
582 } else {
584 "The selected traversal is not compatible with the LinkedCells container. TraversalID: {}",
585 traversal->getTraversalType());
586 }
587 }
588
593
598};
599
600} // namespace autopas
#define AutoPasLog(lvl, fmt,...)
Macro for logging providing common meta information without filename.
Definition: Logger.h:24
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
Base class for traversals utilising load balancing.
Definition: BalancedTraversal.h:19
std::function< unsigned long(const std::array< unsigned long, 3 > &, const std::array< unsigned long, 3 > &, const std::array< unsigned long, 3 > &)> EstimatorFunction
Type signature for load estimators.
Definition: BalancedTraversal.h:26
The CellBasedParticleContainer class stores particles in some object and provides methods to iterate ...
Definition: CellBasedParticleContainer.h:25
size_t _sortingThreshold
If the number of particles in a cell or cell pair exceeds this threshold, the particles will be sorte...
Definition: CellBasedParticleContainer.h:164
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: CellBasedParticleContainer.h:133
double getVerletSkin() const final
Returns the verlet Skin length.
Definition: CellBasedParticleContainer.h:96
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: CellBasedParticleContainer.h:91
std::vector< ParticleCellType > _cells
Vector of particle cells.
Definition: CellBasedParticleContainer.h:159
A cell pair traversal.
Definition: CellTraversal.h:23
virtual void setSortingThreshold(size_t sortingThreshold)=0
Set the sorting-threshold for traversals that use the CellFunctor If the sum of the number of particl...
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
This class handles the storage of particles in their full form.
Definition: FullParticleCell.h:26
void addParticle(const Particle_T &p) override
Adds a Particle to the cell.
Definition: FullParticleCell.h:51
Interface for traversals used by the LinkedCell class.
Definition: LCTraversalInterface.h:18
LinkedCells class.
Definition: LinkedCells.h:40
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: LinkedCells.h:315
std::tuple< const Particle_T *, size_t, size_t > getParticleImpl(size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior, const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax) const
Container specific implementation for getParticle.
Definition: LinkedCells.h:240
internal::CellBlock3D< ParticleCellType > & getCellBlock()
Get the cell block, not supposed to be used except by verlet lists.
Definition: LinkedCells.h:487
BalancedTraversal::EstimatorFunction getLoadEstimatorFunction()
Generates the load estimation function depending on _loadEstimator.
Definition: LinkedCells.h:120
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: LinkedCells.h:415
void addParticleImpl(const Particle_T &p) override
Adds a particle to the container.
Definition: LinkedCells.h:79
void deleteHaloParticles() override
Deletes all halo particles.
Definition: LinkedCells.h:110
bool updateHaloParticle(const Particle_T &haloParticle) override
Update a halo particle of the container with the given haloParticle.
Definition: LinkedCells.h:95
void addHaloParticleImpl(const Particle_T &haloParticle) override
Adds a particle to the container that lies in the halo region of the container.
Definition: LinkedCells.h:87
LoadEstimatorOption _loadEstimator
load estimation algorithm for balanced traversals.
Definition: LinkedCells.h:597
void prepareTraversal(Traversal &traversal)
Checks if a given traversal is allowed for LinkedCells and sets it up for the force interactions.
Definition: LinkedCells.h:573
std::vector< Particle_T > updateContainer(bool keepNeighborListsValid) override
Updates the container.
Definition: LinkedCells.h:147
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: LinkedCells.h:455
ContainerIterator< Particle_T, false, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, typename ContainerIterator< Particle_T, false, false >::ParticleVecType *additionalVectors=nullptr) const override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: LinkedCells.h:336
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior=IteratorBehavior::ownedOrHalo)
Reduce properties of particles as defined by a lambda function.
Definition: LinkedCells.h:373
std::vector< ParticleCellType > & getCells()
Returns a non-const reference to the cell data structure.
Definition: LinkedCells.h:499
const internal::CellBlock3D< ParticleCellType > & getCellBlock() const
Get the cell block, not supposed to be used except by verlet lists.
Definition: LinkedCells.h:493
ContainerIterator< Particle_T, true, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, typename ContainerIterator< Particle_T, true, true >::ParticleVecType *additionalVectors=nullptr) override
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
Definition: LinkedCells.h:390
Particle_T ParticleType
Type of the Particle.
Definition: LinkedCells.h:50
bool deleteParticle(Particle_T &particle) override
Deletes the given particle as long as this does not compromise the validity of the container.
Definition: LinkedCells.h:302
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: LinkedCells.h:205
void computeInteractions(TraversalInterface *traversal) override
Iterates over all particle multiples (e.g.
Definition: LinkedCells.h:139
void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override
Reserve memory for a given number of particles in the container and logic layers.
Definition: LinkedCells.h:72
void rebuildNeighborLists(TraversalInterface *traversal) override
Rebuilds the neighbor lists for the next traversals.
Definition: LinkedCells.h:112
ContainerIterator< Particle_T, false, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, typename ContainerIterator< Particle_T, false, true >::ParticleVecType *additionalVectors=nullptr) const override
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
Definition: LinkedCells.h:399
std::tuple< size_t, size_t > advanceIteratorIndices(size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior, const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, std::array< double, 3 > boxMinWithSafetyMargin, std::array< double, 3 > boxMaxWithSafetyMargin, size_t endCellIndex) const
Given a pair of cell-/particleIndex and iterator restrictions either returns the next indices that ma...
Definition: LinkedCells.h:517
void forEach(Lambda forEachLambda, IteratorBehavior behavior=IteratorBehavior::ownedOrHalo)
Execute code on all particles in this container as defined by a lambda function.
Definition: LinkedCells.h:350
LinkedCells(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, const double cutoff, const double skin, const double cellSizeFactor=1.0, const size_t sortingThreshold=8, LoadEstimatorOption loadEstimator=LoadEstimatorOption::squaredParticlesPerCell)
Constructor of the LinkedCells class.
Definition: LinkedCells.h:63
ContainerIterator< Particle_T, true, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, typename ContainerIterator< Particle_T, true, false >::ParticleVecType *additionalVectors=nullptr) override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: LinkedCells.h:327
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: LinkedCells.h:210
ContainerOption getContainerType() const override
Get the ContainerType.
Definition: LinkedCells.h:70
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: LinkedCells.h:217
internal::CellBlock3D< ParticleCellType > _cellBlock
object to manage the block of cells.
Definition: LinkedCells.h:592
Class representing the load estimator choices.
Definition: LoadEstimatorOption.h:18
Value
Possible choices for the load estimation algorithm.
Definition: LoadEstimatorOption.h:23
@ squaredParticlesPerCell
Number of particles per cell squared.
Definition: LoadEstimatorOption.h:31
@ none
No load estimator.
Definition: LoadEstimatorOption.h:27
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
Class that manages a block of ParticleCells.
Definition: CellBlock3D.h:30
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 checkParticleInCellAndUpdateByID(CellType &cell, const typename CellType::ParticleType &particle)
Updates a found particle within cellI to the values of particleI.
Definition: ParticleCellHelpers.h:21
unsigned long squaredParticlesPerCell(const std::vector< ParticleCell > &cells, const std::array< unsigned long, 3 > &cellsPerDimension, const std::array< unsigned long, 3 > &lowerCorner, const std::array< unsigned long, 3 > &upperCorner)
Sums up the squared number of particles for all cells within region.
Definition: LoadEstimators.h:31
constexpr T threeToOneD(T x, T y, T z, const std::array< T, 3 > &dims)
Convert a 3d index to a 1d index.
Definition: ThreeDimensionalMapping.h:29
bool boxesOverlap(const std::array< T, 3 > &boxALow, const std::array< T, 3 > &boxAHigh, const std::array< T, 3 > &boxBLow, const std::array< T, 3 > &boxBHigh)
Checks if two boxes have overlap.
Definition: inBox.h:67
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
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
int autopas_get_num_threads()
Dummy for omp_get_num_threads() when no OpenMP is available.
Definition: WrapOpenMP.h:138
int autopas_get_thread_num()
Dummy for omp_set_lock() when no OpenMP is available.
Definition: WrapOpenMP.h:132