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
51
63 LinkedCells(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax, const double cutoff,
64 const double skin, const unsigned int rebuildFrequency, const double cellSizeFactor = 1.0,
66 : CellBasedParticleContainer<ParticleCell>(boxMin, boxMax, cutoff, skin, rebuildFrequency),
67 _cellBlock(this->_cells, boxMin, boxMax, cutoff + skin, cellSizeFactor),
68 _loadEstimator(loadEstimator) {}
69
70 [[nodiscard]] ContainerOption getContainerType() const override { return ContainerOption::linkedCells; }
71
72 [[nodiscard]] CellType getParticleCellTypeEnum() const override { return CellType::FullParticleCell; }
73
74 void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override {
75 _cellBlock.reserve(numParticles + numParticlesHaloEstimate);
76 }
77
78 void addParticleImpl(const ParticleType &p) override {
79 ParticleCell &cell = _cellBlock.getContainingCell(p.getR());
80 cell.addParticle(p);
81 }
82
83 void addHaloParticleImpl(const ParticleType &haloParticle) override {
84 ParticleCell &cell = _cellBlock.getContainingCell(haloParticle.getR());
85 cell.addParticle(haloParticle);
86 }
87
88 bool updateHaloParticle(const ParticleType &haloParticle) override {
89 auto cells = _cellBlock.getNearbyHaloCells(haloParticle.getR(), this->getVerletSkin());
90 for (auto cellptr : cells) {
91 bool updated = internal::checkParticleInCellAndUpdateByID(*cellptr, haloParticle);
92 if (updated) {
93 return true;
94 }
95 }
96 AutoPasLog(TRACE, "UpdateHaloParticle was not able to update particle: {}", haloParticle.toString());
97 return false;
98 }
99
100 void deleteHaloParticles() override { _cellBlock.clearHaloCells(); }
101
102 void rebuildNeighborLists(TraversalInterface *traversal) override {
103 // nothing to do.
104 }
105
111 // (Explicit) static cast required for Apple Clang (last tested version: 17.0.0)
112 switch (static_cast<LoadEstimatorOption::Value>(this->_loadEstimator)) {
114 return [&](const std::array<unsigned long, 3> &cellsPerDimension,
115 const std::array<unsigned long, 3> &lowerCorner, const std::array<unsigned long, 3> &upperCorner) {
116 return loadEstimators::squaredParticlesPerCell(this->_cells, cellsPerDimension, lowerCorner, upperCorner);
117 };
118 }
120 [[fallthrough]];
121 default: {
122 return
123 [&](const std::array<unsigned long, 3> &cellsPerDimension, const std::array<unsigned long, 3> &lowerCorner,
124 const std::array<unsigned long, 3> &upperCorner) { return 1; };
125 }
126 }
127 }
128
129 void computeInteractions(TraversalInterface *traversal) override {
130 prepareTraversal(traversal);
131
132 traversal->initTraversal();
133 traversal->traverseParticles();
134 traversal->endTraversal();
135 }
136
137 [[nodiscard]] std::vector<ParticleType> updateContainer(bool keepNeighborListsValid) override {
138 if (keepNeighborListsValid) {
140 }
141
142 this->deleteHaloParticles();
143
144 std::vector<ParticleType> invalidParticles;
145 AUTOPAS_OPENMP(parallel) {
146 // private for each thread!
147 std::vector<ParticleType> myInvalidParticles{}, myInvalidNotOwnedParticles{};
148 // TODO: needs smarter heuristic than this.
149 myInvalidParticles.reserve(128);
150 myInvalidNotOwnedParticles.reserve(128);
151 AUTOPAS_OPENMP(for)
152 for (size_t cellId = 0; cellId < this->getCells().size(); ++cellId) {
153 // Delete dummy particles of each cell.
154 this->getCells()[cellId].deleteDummyParticles();
155
156 // if empty
157 if (this->getCells()[cellId].isEmpty()) continue;
158
159 const auto [cellLowerCorner, cellUpperCorner] = this->getCellBlock().getCellBoundingBox(cellId);
160
161 auto &particleVec = this->getCells()[cellId]._particles;
162 for (auto pIter = particleVec.begin(); pIter < particleVec.end();) {
163 // if not in cell
164 if (utils::notInBox(pIter->getR(), cellLowerCorner, cellUpperCorner)) {
165 myInvalidParticles.push_back(*pIter);
166 // swap-delete
167 *pIter = particleVec.back();
168 particleVec.pop_back();
169 } else {
170 ++pIter;
171 }
172 }
173 }
174 // implicit barrier here
175 // the barrier is needed because iterators are not threadsafe w.r.t. addParticle()
176
177 // this loop is executed for every thread and thus parallel. Don't use #pragma omp for here!
178 for (auto &&p : myInvalidParticles) {
179 // if not in halo
180 if (utils::inBox(p.getR(), this->getBoxMin(), this->getBoxMax())) {
181 this->template addParticle<false>(p);
182 } else {
183 myInvalidNotOwnedParticles.push_back(p);
184 }
185 }
186 AUTOPAS_OPENMP(critical) {
187 // merge private vectors to global one.
188 invalidParticles.insert(invalidParticles.end(), myInvalidNotOwnedParticles.begin(),
189 myInvalidNotOwnedParticles.end());
190 }
191 }
192 return invalidParticles;
193 }
194
195 [[nodiscard]] TraversalSelectorInfo getTraversalSelectorInfo() const override {
196 return TraversalSelectorInfo(this->getCellBlock().getCellsPerDimensionWithHalo(), this->getInteractionLength(),
197 this->getCellBlock().getCellLength(), 0);
198 }
199
200 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
201 IteratorBehavior iteratorBehavior,
202 const std::array<double, 3> &boxMin,
203 const std::array<double, 3> &boxMax) const override {
204 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
205 }
206 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
207 IteratorBehavior iteratorBehavior) const override {
208 // this is not a region iter hence we stretch the bounding box to the numeric max
209 constexpr std::array<double, 3> boxMin{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
210 std::numeric_limits<double>::lowest()};
211
212 constexpr std::array<double, 3> boxMax{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
213 std::numeric_limits<double>::max()};
214 return getParticleImpl<false>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
215 }
216
228 template <bool regionIter>
229 std::tuple<const Particle_T *, size_t, size_t> getParticleImpl(size_t cellIndex, size_t particleIndex,
230 IteratorBehavior iteratorBehavior,
231 const std::array<double, 3> &boxMin,
232 const std::array<double, 3> &boxMax) const {
233 using namespace autopas::utils::ArrayMath::literals;
234
235 std::array<double, 3> boxMinWithSafetyMargin = boxMin;
236 std::array<double, 3> boxMaxWithSafetyMargin = boxMax;
237 if constexpr (regionIter) {
238 // We extend the search box for cells here since particles might have moved
239 boxMinWithSafetyMargin -= this->getVerletSkin();
240 boxMaxWithSafetyMargin += this->getVerletSkin();
241 }
242
243 // first and last relevant cell index
244 const auto [startCellIndex, endCellIndex] = [&]() -> std::tuple<size_t, size_t> {
245 if constexpr (regionIter) {
246 // We extend the search box for cells here since particles might have moved
247 return {_cellBlock.get1DIndexOfPosition(boxMinWithSafetyMargin),
248 _cellBlock.get1DIndexOfPosition(boxMaxWithSafetyMargin)};
249 } else {
250 if (not(iteratorBehavior & IteratorBehavior::halo)) {
251 // only potentially owned region
252 return {_cellBlock.getFirstOwnedCellIndex(), _cellBlock.getLastOwnedCellIndex()};
253 } else {
254 // whole range of cells
255 return {0, this->_cells.size() - 1};
256 }
257 }
258 }();
259
260 // if we are at the start of an iteration ...
261 if (cellIndex == 0 and particleIndex == 0) {
262 cellIndex =
263 startCellIndex + ((iteratorBehavior & IteratorBehavior::forceSequential) ? 0 : autopas_get_thread_num());
264 }
265 // abort if the start index is already out of bounds
266 if (cellIndex >= this->_cells.size()) {
267 return {nullptr, 0, 0};
268 }
269 // check the data behind the indices
270 if (particleIndex >= this->_cells[cellIndex].size() or
271 not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
272 this->_cells[cellIndex][particleIndex], iteratorBehavior, boxMin, boxMax)) {
273 // either advance them to something interesting or invalidate them.
274 std::tie(cellIndex, particleIndex) =
275 advanceIteratorIndices<regionIter>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax,
276 boxMinWithSafetyMargin, boxMaxWithSafetyMargin, endCellIndex);
277 }
278
279 // shortcut if the given index doesn't exist
280 if (cellIndex > endCellIndex) {
281 return {nullptr, 0, 0};
282 }
283 const Particle_T *retPtr = &this->_cells[cellIndex][particleIndex];
284
285 return {retPtr, cellIndex, particleIndex};
286 }
287
288 bool deleteParticle(Particle_T &particle) override {
289 // deduce into which vector the reference points
290 auto &particleVec = _cellBlock.getContainingCell(particle.getR())._particles;
291 const bool isRearParticle = &particle == &particleVec.back();
292 // swap-delete
293 particle = particleVec.back();
294 particleVec.pop_back();
295 return not isRearParticle;
296 }
297
298 bool deleteParticle(size_t cellIndex, size_t particleIndex) override {
299 auto &particleVec = this->_cells[cellIndex]._particles;
300 auto &particle = particleVec[particleIndex];
301 // swap-delete
302 particle = particleVec.back();
303 particleVec.pop_back();
304 return particleIndex < particleVec.size();
305 }
306
308 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHalo,
309 typename ContainerIterator<ParticleType, true, false>::ParticleVecType *additionalVectors = nullptr) override {
310 return ContainerIterator<ParticleType, true, false>(*this, behavior, additionalVectors);
311 }
312
314 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHalo,
316 nullptr) const override {
317 return ContainerIterator<ParticleType, false, false>(*this, behavior, additionalVectors);
318 }
319
326 template <typename Lambda>
327 void forEach(Lambda forEachLambda, IteratorBehavior behavior = IteratorBehavior::ownedOrHalo) {
328 if (behavior == IteratorBehavior::ownedOrHaloOrDummy) {
329 for (auto &cell : getCells()) {
330 cell.forEach(forEachLambda);
331 }
332 } else {
333 for (size_t index = 0; index < getCells().size(); index++) {
334 if (not _cellBlock.ignoreCellForIteration(index, behavior)) {
335 getCells()[index].forEach(forEachLambda, behavior);
336 }
337 }
338 }
339 }
340
349 template <typename Lambda, typename A>
350 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior = IteratorBehavior::ownedOrHalo) {
351 if (behavior == IteratorBehavior::ownedOrHaloOrDummy) {
352 for (auto &cell : getCells()) {
353 cell.reduce(reduceLambda, result);
354 }
355 } else {
356 for (size_t index = 0; index < getCells().size(); index++) {
357 if (not _cellBlock.ignoreCellForIteration(index, behavior)) {
358 getCells()[index].reduce(reduceLambda, result, behavior);
359 }
360 }
361 }
362 }
363
365 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
366 typename ContainerIterator<ParticleType, true, true>::ParticleVecType *additionalVectors = nullptr) override {
367 return ContainerIterator<ParticleType, true, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
368 }
369
371 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
373 nullptr) const override {
374 return ContainerIterator<ParticleType, false, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
375 }
376
385 template <typename Lambda>
386 void forEachInRegion(Lambda forEachLambda, const std::array<double, 3> &lowerCorner,
387 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
388 using namespace autopas::utils::ArrayMath::literals;
389
390 const auto startIndex3D = this->_cellBlock.get3DIndexOfPosition(lowerCorner - this->getVerletSkin());
391 const auto stopIndex3D = this->_cellBlock.get3DIndexOfPosition(higherCorner + this->getVerletSkin());
392
393 const size_t numCellsOfInterest = (stopIndex3D[0] - startIndex3D[0] + 1) * (stopIndex3D[1] - startIndex3D[1] + 1) *
394 (stopIndex3D[2] - startIndex3D[2] + 1);
395 std::vector<size_t> cellsOfInterest;
396 cellsOfInterest.reserve(numCellsOfInterest);
397
398 const auto &cellsPerDimensionWithHalo = this->_cellBlock.getCellsPerDimensionWithHalo();
399
400 for (size_t z = startIndex3D[2]; z <= stopIndex3D[2]; ++z) {
401 for (size_t y = startIndex3D[1]; y <= stopIndex3D[1]; ++y) {
402 for (size_t x = startIndex3D[0]; x <= stopIndex3D[0]; ++x) {
403 cellsOfInterest.push_back(utils::ThreeDimensionalMapping::threeToOneD({x, y, z}, cellsPerDimensionWithHalo));
404 }
405 }
406 }
407
408 for (auto cellIndex : cellsOfInterest) {
409 if (not _cellBlock.ignoreCellForIteration(cellIndex, behavior)) {
410 getCells()[cellIndex].forEach(forEachLambda, lowerCorner, higherCorner, behavior);
411 }
412 }
413 }
414
425 template <typename Lambda, typename A>
426 void reduceInRegion(Lambda reduceLambda, A &result, const std::array<double, 3> &lowerCorner,
427 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
428 using namespace autopas::utils::ArrayMath::literals;
429 const auto startIndex3D = this->_cellBlock.get3DIndexOfPosition(lowerCorner - this->getVerletSkin());
430 const auto stopIndex3D = this->_cellBlock.get3DIndexOfPosition(higherCorner + this->getVerletSkin());
431
432 const size_t numCellsOfInterest = (stopIndex3D[0] - startIndex3D[0] + 1) * (stopIndex3D[1] - startIndex3D[1] + 1) *
433 (stopIndex3D[2] - startIndex3D[2] + 1);
434 std::vector<size_t> cellsOfInterest;
435 cellsOfInterest.reserve(numCellsOfInterest);
436
437 const auto &cellsPerDimensionWithHalo = this->_cellBlock.getCellsPerDimensionWithHalo();
438
439 for (size_t z = startIndex3D[2]; z <= stopIndex3D[2]; ++z) {
440 for (size_t y = startIndex3D[1]; y <= stopIndex3D[1]; ++y) {
441 for (size_t x = startIndex3D[0]; x <= stopIndex3D[0]; ++x) {
442 cellsOfInterest.push_back(utils::ThreeDimensionalMapping::threeToOneD({x, y, z}, cellsPerDimensionWithHalo));
443 }
444 }
445 }
446
447 for (auto cellIndex : cellsOfInterest) {
448 if (not _cellBlock.ignoreCellForIteration(cellIndex, behavior)) {
449 getCells()[cellIndex].reduce(reduceLambda, result, lowerCorner, higherCorner, behavior);
450 }
451 }
452 }
453
459
465
470 std::vector<ParticleCell> &getCells() { return this->_cells; }
471
472 protected:
487 template <bool regionIter>
488 std::tuple<size_t, size_t> advanceIteratorIndices(
489 size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior, const std::array<double, 3> &boxMin,
490 const std::array<double, 3> &boxMax, std::array<double, 3> boxMinWithSafetyMargin,
491 std::array<double, 3> boxMaxWithSafetyMargin, size_t endCellIndex) const {
492 // Finding the indices for the next particle
493 const size_t stride = (iteratorBehavior & IteratorBehavior::forceSequential) ? 1 : autopas_get_num_threads();
494
495 // helper function to determine if the cell can even contain particles of interest to the iterator
496 auto cellIsRelevant = [&]() -> bool {
497 bool isRelevant =
498 // behavior matches possible particle ownership
499 (iteratorBehavior & IteratorBehavior::owned and _cellBlock.cellCanContainOwnedParticles(cellIndex)) or
500 (iteratorBehavior & IteratorBehavior::halo and _cellBlock.cellCanContainHaloParticles(cellIndex));
501 if constexpr (regionIter) {
502 // short circuit if already false
503 if (isRelevant) {
504 // is the cell in the region?
505 const auto [cellLowCorner, cellHighCorner] = _cellBlock.getCellBoundingBox(cellIndex);
506 isRelevant =
507 utils::boxesOverlap(cellLowCorner, cellHighCorner, boxMinWithSafetyMargin, boxMaxWithSafetyMargin);
508 }
509 }
510 return isRelevant;
511 };
512
513 do {
514 // advance to the next particle
515 ++particleIndex;
516 // If this breaches the end of a cell, find the next non-empty cell and reset particleIndex.
517
518 // If cell has wrong type, or there are no more particles in this cell jump to the next
519 while (not cellIsRelevant() or particleIndex >= this->_cells[cellIndex].size()) {
520 // TODO: can this jump be done more efficient if behavior is only halo or owned?
521 // TODO: can this jump be done more efficient for region iters if the cell is outside the region?
522 cellIndex += stride;
523 particleIndex = 0;
524
525 // If we notice that there is nothing else to look at set invalid values, so we get a nullptr next time and
526 // break.
527 if (cellIndex > endCellIndex) {
528 return {std::numeric_limits<decltype(cellIndex)>::max(), std::numeric_limits<decltype(particleIndex)>::max()};
529 }
530 }
531 } while (not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
532 this->_cells[cellIndex][particleIndex], iteratorBehavior, boxMin, boxMax));
533
534 // the indices returned at this point should always be valid
535 return {cellIndex, particleIndex};
536 }
537
543 template <typename Traversal>
544 void prepareTraversal(Traversal &traversal) {
545 auto *traversalInterface = dynamic_cast<LCTraversalInterface *>(traversal);
546 auto *cellTraversal = dynamic_cast<CellTraversal<ParticleCell> *>(traversal);
547 if (auto *balancedTraversal = dynamic_cast<BalancedTraversal *>(traversal)) {
548 balancedTraversal->setLoadEstimator(getLoadEstimatorFunction());
549 }
550 if (traversalInterface && cellTraversal) {
551 cellTraversal->setCellsToTraverse(this->_cells);
552 } else {
554 "The selected traversal is not compatible with the LinkedCells container. TraversalID: {}",
555 traversal->getTraversalType());
556 }
557 }
558
563
568};
569
570} // 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
double getVerletSkin() const final
Returns the verlet Skin length.
Definition: CellBasedParticleContainer.h:94
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: CellBasedParticleContainer.h:89
std::vector< FullParticleCell< Particle_T > > _cells
Vector of particle cells.
Definition: CellBasedParticleContainer.h:157
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: CellBasedParticleContainer.h:131
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
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
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: LinkedCells.h:370
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:298
autopas::LoadEstimatorOption _loadEstimator
load estimation algorithm for balanced traversals.
Definition: LinkedCells.h:567
const internal::CellBlock3D< ParticleCell > & getCellBlock() const
Get the cell block, not supposed to be used except by verlet lists.
Definition: LinkedCells.h:464
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:229
LinkedCells(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, const double cutoff, const double skin, const unsigned int rebuildFrequency, const double cellSizeFactor=1.0, LoadEstimatorOption loadEstimator=LoadEstimatorOption::squaredParticlesPerCell)
Constructor of the LinkedCells class.
Definition: LinkedCells.h:63
BalancedTraversal::EstimatorFunction getLoadEstimatorFunction()
Generates the load estimation function depending on _loadEstimator.
Definition: LinkedCells.h:110
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:386
void deleteHaloParticles() override
Deletes all halo particles.
Definition: LinkedCells.h:100
void addHaloParticleImpl(const ParticleType &haloParticle) override
Adds a particle to the container that lies in the halo region of the container.
Definition: LinkedCells.h:83
internal::CellBlock3D< ParticleCell > & getCellBlock()
Get the cell block, not supposed to be used except by verlet lists.
Definition: LinkedCells.h:458
typename ParticleCell::ParticleType ParticleType
Type of the Particle.
Definition: LinkedCells.h:50
void prepareTraversal(Traversal &traversal)
Checks if a given traversal is allowed for LinkedCells and sets it up for the force interactions.
Definition: LinkedCells.h:544
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:426
CellType getParticleCellTypeEnum() const override
Get the ParticleCell type as an Enum.
Definition: LinkedCells.h:72
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: LinkedCells.h:307
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior=IteratorBehavior::ownedOrHalo)
Reduce properties of particles as defined by a lambda function.
Definition: LinkedCells.h:350
std::vector< ParticleType > updateContainer(bool keepNeighborListsValid) override
Updates the container.
Definition: LinkedCells.h:137
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: LinkedCells.h:364
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:288
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: LinkedCells.h:195
internal::CellBlock3D< ParticleCell > _cellBlock
object to manage the block of cells.
Definition: LinkedCells.h:562
void computeInteractions(TraversalInterface *traversal) override
Iterates over all particle multiples (e.g.
Definition: LinkedCells.h:129
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:74
void rebuildNeighborLists(TraversalInterface *traversal) override
Rebuilds the neighbor lists for the next traversals.
Definition: LinkedCells.h:102
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: LinkedCells.h:313
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:488
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:327
bool updateHaloParticle(const ParticleType &haloParticle) override
Update a halo particle of the container with the given haloParticle.
Definition: LinkedCells.h:88
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:200
std::vector< ParticleCell > & getCells()
Returns a non-const reference to the cell data structure.
Definition: LinkedCells.h:470
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:206
void addParticleImpl(const ParticleType &p) override
Adds a particle to the container.
Definition: LinkedCells.h:78
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
Particle_T ParticleType
The particle type for this cell.
Definition: ParticleCell.h:56
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
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
int autopas_get_thread_num()
Dummy for omp_set_lock() when no OpenMP is available.
Definition: WrapOpenMP.h:132