AutoPas  3.0.0
Loading...
Searching...
No Matches
LinkedCellsReferences.h
1
7#pragma once
8
25#include "autopas/utils/inBox.h"
27
28namespace autopas {
29
38template <class Particle_T>
39class LinkedCellsReferences : public CellBasedParticleContainer<ReferenceParticleCell<Particle_T>> {
40 public:
44 using ParticleType = Particle_T;
49
64 LinkedCellsReferences(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax, const double cutoff,
65 const double skin, const double cellSizeFactor = 1.0, const size_t aosSortingThreshold = 8,
66 const size_t soaSortingThreshold = 50,
68 : CellBasedParticleContainer<ParticleCellType>(boxMin, boxMax, cutoff, skin, aosSortingThreshold,
69 soaSortingThreshold),
70 _cellBlock(this->_cells, boxMin, boxMax, cutoff + skin, cellSizeFactor),
71 _loadEstimator(loadEstimator) {}
72
76 [[nodiscard]] ContainerOption getContainerType() const override { return ContainerOption::linkedCellsReferences; }
77
78 void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override {
79 _cellBlock.reserve(numParticles + numParticlesHaloEstimate);
80 }
81
85 void addParticleImpl(const Particle_T &p) override {
87 _particleList.push_back(p);
90 }
91
95 void addHaloParticleImpl(const Particle_T &haloParticle) override {
97 _particleList.push_back(haloParticle);
100 }
101
105 bool updateHaloParticle(const Particle_T &haloParticle) override {
106 auto cells = _cellBlock.getNearbyHaloCells(haloParticle.getR(), this->getVerletSkin());
107 for (auto cellptr : cells) {
108 bool updated = internal::checkParticleInCellAndUpdateByID(*cellptr, haloParticle);
109 if (updated) {
110 return true;
111 }
112 }
113 AutoPasLog(TRACE, "UpdateHaloParticle was not able to update particle: {}", haloParticle.toString());
114 return false;
115 }
116
120 void deleteAllParticles() override {
121 _particleList.clearAllParticles();
123 }
124
128 void deleteHaloParticles() override {
129 _particleList.clearHaloParticles();
130 _cellBlock.clearHaloCells();
131 }
132
138 // (Explicit) static cast required for Apple Clang (last tested version: 17.0.0)
139 switch (static_cast<LoadEstimatorOption::Value>(this->_loadEstimator)) {
141 return [&](const std::array<unsigned long, 3> &cellsPerDimension,
142 const std::array<unsigned long, 3> &lowerCorner, const std::array<unsigned long, 3> &upperCorner) {
143 return loadEstimators::squaredParticlesPerCell(this->_cells, cellsPerDimension, lowerCorner, upperCorner);
144 };
145 }
147 [[fallthrough]];
148 default: {
149 return
150 [&](const std::array<unsigned long, 3> &cellsPerDimension, const std::array<unsigned long, 3> &lowerCorner,
151 const std::array<unsigned long, 3> &upperCorner) { return 1; };
152 }
153 }
154 }
155
157
163 if (_particleList.isDirty()) {
164 if (_particleList.needsRebuild()) {
165 for (auto &cell : this->_cells) {
166 cell.clear();
167 }
168 }
169
170 for (auto it = _particleList.beginDirty(); it < _particleList.endDirty(); it++) {
171 if (it->isDummy()) {
172 continue;
173 }
174 ParticleCellType &cell = _cellBlock.getContainingCell(it->getR());
175 auto address = &(*it);
176 cell.addParticleReference(address);
177 }
178 _particleList.markAsClean();
179 }
180 }
181
182 void computeInteractions(TraversalInterface *traversal) override {
183 // Check if traversal is allowed for this container and give it the data it needs.
184 auto *traversalInterface = dynamic_cast<LCTraversalInterface *>(traversal);
185 auto *cellPairTraversal = dynamic_cast<CellTraversal<ParticleCellType> *>(traversal);
186 if (auto *balancedTraversal = dynamic_cast<BalancedTraversal *>(traversal)) {
187 balancedTraversal->setLoadEstimator(getLoadEstimatorFunction());
188 }
189 if (traversalInterface && cellPairTraversal) {
190 cellPairTraversal->setAoSSortingThreshold(this->_aosSortingThreshold);
191 cellPairTraversal->setSoASortingThreshold(this->_soaSortingThreshold);
192 cellPairTraversal->setCellsToTraverse(this->_cells);
193 } else {
195 "Trying to use a traversal of wrong type in LinkedCellsReferences::computeInteractions. TraversalID: {}",
196 traversal->getTraversalType());
197 }
198
199 traversal->initTraversal();
200 traversal->traverseParticles();
201 traversal->endTraversal();
202 }
203
204 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
205 IteratorBehavior iteratorBehavior,
206 const std::array<double, 3> &boxMin,
207 const std::array<double, 3> &boxMax) const override {
208 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
209 }
210 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
211 IteratorBehavior iteratorBehavior) const override {
212 // this is not a region iter hence we stretch the bounding box to the numeric max
213 constexpr std::array<double, 3> boxMin{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
214 std::numeric_limits<double>::lowest()};
215
216 constexpr std::array<double, 3> boxMax{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
217 std::numeric_limits<double>::max()};
218 return getParticleImpl<false>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
219 }
220
232 template <bool regionIter>
233 std::tuple<const Particle_T *, size_t, size_t> getParticleImpl(size_t cellIndex, size_t particleIndex,
234 IteratorBehavior iteratorBehavior,
235 const std::array<double, 3> &boxMin,
236 const std::array<double, 3> &boxMax) const {
237 using namespace autopas::utils::ArrayMath::literals;
238
239 std::array<double, 3> boxMinWithSafetyMargin = boxMin;
240 std::array<double, 3> boxMaxWithSafetyMargin = boxMax;
241 if constexpr (regionIter) {
242 // We extend the search box for cells here since particles might have moved
243 boxMinWithSafetyMargin -= this->getVerletSkin();
244 boxMaxWithSafetyMargin += this->getVerletSkin();
245 }
246
247 // first and last relevant cell index
248 const auto [startCellIndex, endCellIndex] = [&]() -> std::tuple<size_t, size_t> {
249 if constexpr (regionIter) {
250 // We extend the search box for cells here since particles might have moved
251 return {_cellBlock.get1DIndexOfPosition(boxMinWithSafetyMargin),
252 _cellBlock.get1DIndexOfPosition(boxMaxWithSafetyMargin)};
253 } else {
254 if (not(iteratorBehavior & IteratorBehavior::halo)) {
255 // only potentially owned region
256 return {_cellBlock.getFirstOwnedCellIndex(), _cellBlock.getLastOwnedCellIndex()};
257 } else {
258 // whole range of cells
259 return {0, this->_cells.size() - 1};
260 }
261 }
262 }();
263
264 // if we are at the start of an iteration ...
265 if (cellIndex == 0 and particleIndex == 0) {
266 cellIndex =
267 startCellIndex + ((iteratorBehavior & IteratorBehavior::forceSequential) ? 0 : autopas_get_thread_num());
268 }
269 // abort if the start index is already out of bounds
270 if (cellIndex >= this->_cells.size()) {
271 return {nullptr, 0, 0};
272 }
273 // check the data behind the indices
274 if (particleIndex >= this->_cells[cellIndex].size() or
275 not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
276 this->_cells[cellIndex][particleIndex], iteratorBehavior, boxMin, boxMax)) {
277 // either advance them to something interesting or invalidate them.
278 std::tie(cellIndex, particleIndex) =
279 advanceIteratorIndices<regionIter>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax,
280 boxMinWithSafetyMargin, boxMaxWithSafetyMargin, endCellIndex);
281 }
282
283 // shortcut if the given index doesn't exist
284 if (cellIndex > endCellIndex) {
285 return {nullptr, 0, 0};
286 }
287 const Particle_T *retPtr = &this->_cells[cellIndex][particleIndex];
288
289 return {retPtr, cellIndex, particleIndex};
290 }
291
295 bool deleteParticle(Particle_T &particle) override {
296 // This function doesn't actually delete anything as it would mess up the reference structure.
298 return false;
299 }
300
304 bool deleteParticle(size_t cellIndex, size_t particleIndex) override {
305 // This function doesn't actually delete anything as it would mess up the reference structure.
306 internal::markParticleAsDeleted(this->_cells[cellIndex][particleIndex]);
307 return false;
308 }
309
310 std::vector<Particle_T> updateContainer(bool keepNeighborListsValid) override {
311 if (keepNeighborListsValid) {
313 }
314
315 std::vector<Particle_T> invalidParticles;
316
317 // for exception handling in parallel region
318 bool exceptionCaught{false};
319 std::string exceptionMsg{""};
320
321 AUTOPAS_OPENMP(parallel) {
322 // private for each thread!
323 std::vector<Particle_T> myInvalidParticles, myInvalidNotOwnedParticles;
324 AUTOPAS_OPENMP(for)
325 for (size_t cellId = 0; cellId < this->getCells().size(); ++cellId) {
326 // Delete dummy particles of each cell.
327 this->getCells()[cellId].deleteDummyParticles();
328
329 // if empty
330 if (this->getCells()[cellId].isEmpty()) continue;
331
332 auto [cellLowerCorner, cellUpperCorner] = this->getCellBlock().getCellBoundingBox(cellId);
333
334 auto &particleVec = this->getCells()[cellId]._particles;
335 for (auto pIter = particleVec.begin(); pIter != particleVec.end();) {
336 if ((*pIter)->isOwned() and utils::notInBox((*pIter)->getR(), cellLowerCorner, cellUpperCorner)) {
337 myInvalidParticles.push_back(**pIter);
338
339 // multi layer swap-delete
340 // we copy the particle behind the last pointer in the cell over the particle we want to delete
341 **pIter = *particleVec.back();
342 // since we will not actually delete the particle we just copied mark it as dummy.
343 particleVec.back()->setOwnershipState(OwnershipState::dummy);
344 // then we pop the last pointer from the cell.
345 particleVec.pop_back();
346
347 } else {
348 ++pIter;
349 }
350 }
351 }
352 // implicit barrier here
353 // the barrier is needed because iterators are not thread safe w.r.t. addParticle()
354
355 // this loop is executed for every thread and thus parallel. Don't use #pragma omp for here!
356 // addParticle might throw. Set exceptionCaught to true, so we can handle that after the OpenMP region
357 try {
358 for (auto &&p : myInvalidParticles) {
359 // if not in halo
360 if (utils::inBox(p.getR(), this->getBoxMin(), this->getBoxMax())) {
361 this->template addParticle<false>(p);
362 } else {
363 myInvalidNotOwnedParticles.push_back(p);
364 }
365 }
366 } catch (const std::exception &e) {
367 exceptionCaught = true;
368 AUTOPAS_OPENMP(critical)
369 exceptionMsg.append(e.what());
370 }
371 AUTOPAS_OPENMP(critical) {
372 // merge private vectors to global one.
373 invalidParticles.insert(invalidParticles.end(), myInvalidNotOwnedParticles.begin(),
374 myInvalidNotOwnedParticles.end());
375 }
376 }
377
378 if (exceptionCaught) {
380 }
381
382 // we have to remove halo particles after the above for-loop since removing halo particles changes the underlying
383 // datastructure (_particleList) which invalidates the references in the cells.
384 // Note: removing halo particles before the loop and do a call to updateDirtyParticleReferences() right after won't
385 // work since there are owned particles in _particleList which fall into the halo area (they are not yet filtered
386 // out by the above loop) and can therefore not added to halo cells during particle insert in
387 // updateDirtyParticleReferences()
388 this->deleteHaloParticles();
389
390 _particleList.deleteDummyParticles();
392 return invalidParticles;
393 }
394
398 [[nodiscard]] TraversalSelectorInfo getTraversalSelectorInfo() const override {
399 return TraversalSelectorInfo(this->getCellBlock().getCellsPerDimensionWithHalo(), this->getInteractionLength(),
400 this->getCellBlock().getCellLength(), 0);
401 }
402
407 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
409 std::nullopt) override {
410 return ContainerIterator<Particle_T, true, false>(*this, behavior, additionalVectors);
411 }
412
417 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
419 std::nullopt) const override {
420 return ContainerIterator<Particle_T, false, false>(*this, behavior, additionalVectors);
421 }
422
426 template <typename Lambda>
427 void forEach(Lambda forEachLambda, IteratorBehavior behavior = IteratorBehavior::ownedOrHaloOrDummy) {
428 if (behavior == IteratorBehavior::ownedOrHaloOrDummy) {
429 // iterate over all particles, so execute directly on particle vector
430 _particleList.forEach(forEachLambda);
431 } else {
432 for (size_t index = 0; index < getCells().size(); index++) {
433 if (!_cellBlock.ignoreCellForIteration(index, behavior)) {
434 getCells()[index].forEach(forEachLambda, behavior);
435 }
436 }
437 }
438 }
439
443 template <typename Lambda, typename A>
444 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior = IteratorBehavior::ownedOrHaloOrDummy) {
445 if (behavior == IteratorBehavior::ownedOrHaloOrDummy) {
446 // iterate over all particles, so execute directly on particle vector
447 _particleList.reduce(reduceLambda, result);
448 } else {
449 for (size_t index = 0; index < getCells().size(); index++) {
450 if (!_cellBlock.ignoreCellForIteration(index, behavior)) {
451 getCells()[index].reduce(reduceLambda, result, behavior);
452 }
453 }
454 }
455 }
456
461 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
463 std::nullopt) override {
464 return ContainerIterator<Particle_T, true, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
465 }
466
471 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
473 std::nullopt) const override {
474 return ContainerIterator<Particle_T, false, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
475 }
476
480 template <typename Lambda>
481 void forEachInRegion(Lambda forEachLambda, const std::array<double, 3> &lowerCorner,
482 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
483 using namespace autopas::utils::ArrayMath::literals;
484
485 // We increase the search region by skin, as particles can move over cell borders.
486 const auto startIndex3D = this->_cellBlock.get3DIndexOfPosition(lowerCorner - this->getVerletSkin());
487 const auto stopIndex3D = this->_cellBlock.get3DIndexOfPosition(higherCorner + this->getVerletSkin());
488
489 size_t numCellsOfInterest = (stopIndex3D[0] - startIndex3D[0] + 1) * (stopIndex3D[1] - startIndex3D[1] + 1) *
490 (stopIndex3D[2] - startIndex3D[2] + 1);
491 std::vector<size_t> cellsOfInterest(numCellsOfInterest);
492
493 int i = 0;
494 for (size_t z = startIndex3D[2]; z <= stopIndex3D[2]; ++z) {
495 for (size_t y = startIndex3D[1]; y <= stopIndex3D[1]; ++y) {
496 for (size_t x = startIndex3D[0]; x <= stopIndex3D[0]; ++x) {
497 cellsOfInterest[i++] =
498 utils::ThreeDimensionalMapping::threeToOneD({x, y, z}, this->_cellBlock.getCellsPerDimensionWithHalo());
499 }
500 }
501 }
502
503 for (size_t index : cellsOfInterest) {
504 if (!_cellBlock.ignoreCellForIteration(index, behavior)) {
505 getCells()[index].forEach(forEachLambda, lowerCorner, higherCorner, behavior);
506 }
507 }
508 }
509
513 template <typename Lambda, typename A>
514 void reduceInRegion(Lambda reduceLambda, A &result, const std::array<double, 3> &lowerCorner,
515 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
516 using namespace autopas::utils::ArrayMath::literals;
517
518 // We increase the search region by skin, as particles can move over cell borders.
519 const auto startIndex3D = this->_cellBlock.get3DIndexOfPosition(lowerCorner - this->getVerletSkin());
520 const auto stopIndex3D = this->_cellBlock.get3DIndexOfPosition(higherCorner + this->getVerletSkin());
521
522 size_t numCellsOfInterest = (stopIndex3D[0] - startIndex3D[0] + 1) * (stopIndex3D[1] - startIndex3D[1] + 1) *
523 (stopIndex3D[2] - startIndex3D[2] + 1);
524 std::vector<size_t> cellsOfInterest(numCellsOfInterest);
525
526 int i = 0;
527 for (size_t z = startIndex3D[2]; z <= stopIndex3D[2]; ++z) {
528 for (size_t y = startIndex3D[1]; y <= stopIndex3D[1]; ++y) {
529 for (size_t x = startIndex3D[0]; x <= stopIndex3D[0]; ++x) {
530 cellsOfInterest[i++] =
531 utils::ThreeDimensionalMapping::threeToOneD({x, y, z}, this->_cellBlock.getCellsPerDimensionWithHalo());
532 }
533 }
534 }
535
536 for (size_t index : cellsOfInterest) {
537 if (!_cellBlock.ignoreCellForIteration(index, behavior)) {
538 getCells()[index].reduce(reduceLambda, result, lowerCorner, higherCorner, behavior);
539 }
540 }
541 }
542
548
554
559 std::vector<ParticleCellType> &getCells() { return this->_cells; }
560
561 protected:
576 template <bool regionIter>
577 std::tuple<size_t, size_t> advanceIteratorIndices(
578 size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior, const std::array<double, 3> &boxMin,
579 const std::array<double, 3> &boxMax, const std::array<double, 3> &boxMinWithSafetyMargin,
580 const std::array<double, 3> &boxMaxWithSafetyMargin, size_t endCellIndex) const {
581 // Finding the indices for the next particle
582 const size_t stride = (iteratorBehavior & IteratorBehavior::forceSequential) ? 1 : autopas_get_num_threads();
583
584 // helper function to determine if the cell can even contain particles of interest to the iterator
585 auto cellIsRelevant = [&]() -> bool {
586 bool isRelevant =
587 // behavior matches possible particle ownership
588 (iteratorBehavior & IteratorBehavior::owned and _cellBlock.cellCanContainOwnedParticles(cellIndex)) or
589 (iteratorBehavior & IteratorBehavior::halo and _cellBlock.cellCanContainHaloParticles(cellIndex));
590 if constexpr (regionIter) {
591 // short circuit if already false
592 if (isRelevant) {
593 // is the cell in the region?
594 const auto [cellLowCorner, cellHighCorner] = _cellBlock.getCellBoundingBox(cellIndex);
595 isRelevant =
596 utils::boxesOverlap(cellLowCorner, cellHighCorner, boxMinWithSafetyMargin, boxMaxWithSafetyMargin);
597 }
598 }
599 return isRelevant;
600 };
601
602 do {
603 // advance to the next particle
604 ++particleIndex;
605 // If this breaches the end of a cell, find the next non-empty cell and reset particleIndex.
606
607 // If cell has wrong type, or there are no more particles in this cell jump to the next
608 while (not cellIsRelevant() or particleIndex >= this->_cells[cellIndex].size()) {
609 // TODO: can this jump be done more efficient if behavior is only halo or owned?
610 // TODO: can this jump be done more efficient for region iters if the cell is outside the region?
611 cellIndex += stride;
612 particleIndex = 0;
613
614 // If we notice that there is nothing else to look at set invalid values, so we get a nullptr next time and
615 // break.
616 if (cellIndex > endCellIndex) {
617 return {std::numeric_limits<decltype(cellIndex)>::max(), std::numeric_limits<decltype(particleIndex)>::max()};
618 }
619 }
620 } while (not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
621 this->_cells[cellIndex][particleIndex], iteratorBehavior, boxMin, boxMax));
622
623 // the indices returned at this point should always be valid
624 return {cellIndex, particleIndex};
625 }
626
643};
644
645} // 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
ParticleVector class.
Definition: ParticleVector.h:22
AutoPasLock for the sequential case.
Definition: WrapOpenMP.h:155
void unlock()
Release the lock.
Definition: WrapOpenMP.h:200
void lock()
Acquire the lock.
Definition: WrapOpenMP.h:190
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 size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: CellBasedParticleContainer.h:136
double getVerletSkin() const final
Returns the verlet Skin length.
Definition: CellBasedParticleContainer.h:99
void deleteAllParticles() override
Deletes all particles from the container.
Definition: CellBasedParticleContainer.h:104
size_t _aosSortingThreshold
If the number of particles in a cell or cell pair exceeds this threshold, the particles will be sorte...
Definition: CellBasedParticleContainer.h:167
size_t _soaSortingThreshold
If the sum of the SoA buffer sizes of two cells exceeds this threshold, SoAFunctorPairSorted is used.
Definition: CellBasedParticleContainer.h:171
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: CellBasedParticleContainer.h:94
std::vector< ParticleCellType > _cells
Vector of particle cells.
Definition: CellBasedParticleContainer.h:162
A cell pair traversal.
Definition: CellTraversal.h:23
virtual void setAoSSortingThreshold(size_t aosSortingThreshold)=0
Set the aos-sorting-threshold for traversals that use the CellFunctor If the sum of the number of par...
Public iterator class that iterates over a particle container and additional vectors (which are typic...
Definition: ContainerIterator.h:95
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:108
Interface for traversals used by the LinkedCell class.
Definition: LCTraversalInterface.h:18
LinkedCells class.
Definition: LinkedCellsReferences.h:39
LinkedCellsReferences(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 aosSortingThreshold=8, const size_t soaSortingThreshold=50, LoadEstimatorOption loadEstimator=LoadEstimatorOption::squaredParticlesPerCell)
Constructor of the LinkedCells class.
Definition: LinkedCellsReferences.h:64
void forEach(Lambda forEachLambda, IteratorBehavior behavior=IteratorBehavior::ownedOrHaloOrDummy)
Execute code on all particles in this container as defined by a lambda function.
Definition: LinkedCellsReferences.h:427
LoadEstimatorOption _loadEstimator
load estimation algorithm for balanced traversals.
Definition: LinkedCellsReferences.h:638
void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override
Reserve memory for a given number of particles in the container and logic layers.
Definition: LinkedCellsReferences.h:78
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: LinkedCellsReferences.h:514
ContainerIterator< Particle_T, true, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, utils::optRef< typename ContainerIterator< Particle_T, true, true >::ParticleVecType > additionalVectors=std::nullopt) override
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
Definition: LinkedCellsReferences.h:460
AutoPasLock addParticleLock
Workaround for adding particles in parallel -> https://github.com/AutoPas/AutoPas/issues/555.
Definition: LinkedCellsReferences.h:642
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: LinkedCellsReferences.h:204
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: LinkedCellsReferences.h:233
void updateDirtyParticleReferences()
Updates all the References in the cells that are out of date.
Definition: LinkedCellsReferences.h:162
void addParticleImpl(const Particle_T &p) override
Adds a particle to the container.
Definition: LinkedCellsReferences.h:85
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: LinkedCellsReferences.h:304
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: LinkedCellsReferences.h:210
ContainerOption getContainerType() const override
Get the ContainerType.
Definition: LinkedCellsReferences.h:76
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, const std::array< double, 3 > &boxMinWithSafetyMargin, const 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: LinkedCellsReferences.h:577
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: LinkedCellsReferences.h:398
ParticleVector< Particle_T > _particleList
object that stores the actual Particles and keeps track of the references.
Definition: LinkedCellsReferences.h:630
internal::CellBlock3D< ParticleCellType > _cellBlock
object to manage the block of cells.
Definition: LinkedCellsReferences.h:634
BalancedTraversal::EstimatorFunction getLoadEstimatorFunction()
Generates the load estimation function depending on _loadEstimator.
Definition: LinkedCellsReferences.h:137
void rebuildNeighborLists(TraversalInterface *traversal) override
Rebuilds the neighbor lists for the next traversals.
Definition: LinkedCellsReferences.h:156
bool deleteParticle(Particle_T &particle) override
Deletes the given particle as long as this does not compromise the validity of the container.
Definition: LinkedCellsReferences.h:295
internal::CellBlock3D< ParticleCellType > & getCellBlock()
Get the cell block, not supposed to be used except by verlet lists.
Definition: LinkedCellsReferences.h:547
ContainerIterator< Particle_T, false, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, utils::optRef< typename ContainerIterator< Particle_T, false, true >::ParticleVecType > additionalVectors=std::nullopt) const override
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
Definition: LinkedCellsReferences.h:470
Particle_T ParticleType
Type of the Particle.
Definition: LinkedCellsReferences.h:44
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: LinkedCellsReferences.h:481
void computeInteractions(TraversalInterface *traversal) override
Iterates over all particle multiples (e.g.
Definition: LinkedCellsReferences.h:182
std::vector< Particle_T > updateContainer(bool keepNeighborListsValid) override
Updates the container.
Definition: LinkedCellsReferences.h:310
void deleteAllParticles() override
Deletes all particles from the container.
Definition: LinkedCellsReferences.h:120
ContainerIterator< Particle_T, false, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, utils::optRef< typename ContainerIterator< Particle_T, false, false >::ParticleVecType > additionalVectors=std::nullopt) const override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: LinkedCellsReferences.h:416
ContainerIterator< Particle_T, true, false > begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo, utils::optRef< typename ContainerIterator< Particle_T, true, false >::ParticleVecType > additionalVectors=std::nullopt) override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: LinkedCellsReferences.h:406
void deleteHaloParticles() override
Deletes all halo particles.
Definition: LinkedCellsReferences.h:128
void addHaloParticleImpl(const Particle_T &haloParticle) override
Adds a particle to the container that lies in the halo region of the container.
Definition: LinkedCellsReferences.h:95
std::vector< ParticleCellType > & getCells()
Returns reference to the data of LinkedCellsReferences.
Definition: LinkedCellsReferences.h:559
const internal::CellBlock3D< ParticleCellType > & getCellBlock() const
Get the cell block, not supposed to be used except by verlet lists.
Definition: LinkedCellsReferences.h:553
bool updateHaloParticle(const Particle_T &haloParticle) override
Update a halo particle of the container with the given haloParticle.
Definition: LinkedCellsReferences.h:105
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior=IteratorBehavior::ownedOrHaloOrDummy)
Reduce properties of particles as defined by a lambda function.
Definition: LinkedCellsReferences.h:444
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 class handles the storage of particles in their full form.
Definition: ReferenceParticleCell.h:24
void addParticleReference(Particle_T *p)
Adds a Particle to the cell.
Definition: ReferenceParticleCell.h:55
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
virtual void endTraversal()=0
Finalizes the traversal.
virtual TraversalOption getTraversalType() const =0
Return a enum representing the name of the traversal class.
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:64
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
void markParticleAsDeleted(Particle_T &p)
Marks a particle as deleted.
Definition: markParticleAsDeleted.h:23
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
std::optional< std::reference_wrapper< T > > optRef
Short alias for std::optional<std::reference_wrapper<T>>
Definition: optRef.h:16
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34
int autopas_get_num_threads()
Dummy for omp_get_num_threads() when no OpenMP is available.
Definition: WrapOpenMP.h:138
@ dummy
Dummy or deleted state, a particle with this state is not an actual particle!
int autopas_get_thread_num()
Dummy for omp_set_lock() when no OpenMP is available.
Definition: WrapOpenMP.h:132