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,
66 const size_t aosSortingThresholdFallback = 8, const size_t soaSortingThresholdFallback = 100,
68 : CellBasedParticleContainer<ParticleCellType>(boxMin, boxMax, cutoff, skin, aosSortingThresholdFallback,
69 soaSortingThresholdFallback),
70 _cellBlock(this->_cells, boxMin, boxMax, cutoff + skin, cellSizeFactor),
71 _loadEstimator(loadEstimator) {
72 // The cells refer to the particles by their index in _particleList.
73 for (auto &cell : this->_cells) {
74 cell.setParticleStorage(&_particleList.getParticleStorage());
75 }
76 }
77
81 [[nodiscard]] ContainerOption getContainerType() const override { return ContainerOption::linkedCellsReferences; }
82
83 void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override {
84 _cellBlock.reserve(numParticles + numParticlesHaloEstimate);
85 }
86
90 void addParticleImpl(const Particle_T &p) override {
92 _particleList.push_back(p);
95 }
96
100 void addHaloParticleImpl(const Particle_T &haloParticle) override {
102 _particleList.push_back(haloParticle);
105 }
106
110 bool updateHaloParticle(const Particle_T &haloParticle) override {
111 const auto skinHalf = 0.5 * this->getVerletSkin();
112 auto cells = _cellBlock.getNearbyHaloCells(haloParticle.getR(), skinHalf);
113 for (auto cellptr : cells) {
114 bool updated = internal::checkParticleInCellAndUpdateByIDAndPosition(*cellptr, haloParticle, skinHalf);
115 if (updated) {
116 return true;
117 }
118 }
119 AutoPasLog(TRACE, "UpdateHaloParticle was not able to update particle: {}", haloParticle.toString());
120 return false;
121 }
122
126 void deleteAllParticles() override {
127 _particleList.clearAllParticles();
129 }
130
134 void deleteHaloParticles() override {
135 _particleList.clearHaloParticles();
136 _cellBlock.clearHaloCells();
137 }
138
144 // (Explicit) static cast required for Apple Clang (last tested version: 17.0.0)
145 switch (static_cast<LoadEstimatorOption::Value>(this->_loadEstimator)) {
147 return [&](const std::array<unsigned long, 3> &cellsPerDimension,
148 const std::array<unsigned long, 3> &lowerCorner, const std::array<unsigned long, 3> &upperCorner) {
149 return loadEstimators::squaredParticlesPerCell(this->_cells, cellsPerDimension, lowerCorner, upperCorner);
150 };
151 }
153 [[fallthrough]];
154 default: {
155 return
156 [&](const std::array<unsigned long, 3> &cellsPerDimension, const std::array<unsigned long, 3> &lowerCorner,
157 const std::array<unsigned long, 3> &upperCorner) { return 1; };
158 }
159 }
160 }
161
163
170 if (_particleList.isDirty()) {
171 if (_particleList.needsRebuild()) {
172 for (auto &cell : this->_cells) {
173 cell.clear();
174 }
175 }
176
177 auto &particles = _particleList.getParticleStorage();
178 for (size_t index = _particleList.getDirtyIndex(); index < particles.size(); ++index) {
179 if (particles[index].isDummy()) {
180 continue;
181 }
182 ParticleCellType &cell = _cellBlock.getContainingCell(particles[index].getR());
183 cell.addParticleReference(index);
184 }
185 _particleList.markAsClean();
186 }
187 }
188
189 void computeInteractions(TraversalInterface *traversal) override {
190 // Check if traversal is allowed for this container and give it the data it needs.
191 auto *traversalInterface = dynamic_cast<LCTraversalInterface *>(traversal);
192 auto *cellPairTraversal = dynamic_cast<CellTraversal<ParticleCellType> *>(traversal);
193 if (auto *balancedTraversal = dynamic_cast<BalancedTraversal *>(traversal)) {
194 balancedTraversal->setLoadEstimator(getLoadEstimatorFunction());
195 }
196 if (traversalInterface && cellPairTraversal) {
197 cellPairTraversal->setAoSSortingThresholds(*this->_aosSortingThresholds);
198 cellPairTraversal->setSoASortingThresholds(*this->_soaSortingThresholds);
199 cellPairTraversal->setCellsToTraverse(this->_cells);
200 } else {
202 "Trying to use a traversal of wrong type in LinkedCellsReferences::computeInteractions. TraversalID: {}",
203 traversal->getTraversalType());
204 }
205
206 traversal->initTraversal();
207 traversal->traverseParticles();
208 traversal->endTraversal();
209 }
210
211 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
212 IteratorBehavior iteratorBehavior,
213 const std::array<double, 3> &boxMin,
214 const std::array<double, 3> &boxMax) const override {
215 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
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 void deleteParticle(Particle_T &particle) override {
303 // This function doesn't actually delete anything as it would mess up the reference structure.
305 }
306
310 void deleteParticle(size_t cellIndex, size_t particleIndex) override {
311 // This function doesn't actually delete anything as it would mess up the reference structure.
312 internal::markParticleAsDeleted(this->_cells[cellIndex][particleIndex]);
313 }
314
315 std::vector<Particle_T> updateContainer(bool keepNeighborListsValid) override {
316 if (keepNeighborListsValid) {
318 }
319
320 std::vector<Particle_T> invalidParticles;
321 auto &particles = _particleList.getParticleStorage();
322
323 // for exception handling in parallel region
324 bool exceptionCaught{false};
325 std::string exceptionMsg{""};
326
327 AUTOPAS_OPENMP(parallel) {
328 // private for each thread!
329 std::vector<Particle_T> myInvalidParticles, myInvalidNotOwnedParticles;
330 AUTOPAS_OPENMP(for)
331 for (size_t cellId = 0; cellId < this->getCells().size(); ++cellId) {
332 // Delete dummy particles of each cell.
333 this->getCells()[cellId].deleteDummyParticles();
334
335 // if empty
336 if (this->getCells()[cellId].isEmpty()) continue;
337
338 auto [cellLowerCorner, cellUpperCorner] = this->getCellBlock().getCellBoundingBox(cellId);
339
340 auto &particleVec = this->getCells()[cellId]._particles;
341 for (auto pIter = particleVec.begin(); pIter != particleVec.end();) {
342 if (particles[*pIter].isOwned() and
343 utils::notInBox(particles[*pIter].getR(), cellLowerCorner, cellUpperCorner)) {
344 myInvalidParticles.push_back(particles[*pIter]);
345
346 // multi layer swap-delete
347 // we copy the particle behind the last index in the cell over the particle we want to delete
348 particles[*pIter] = particles[particleVec.back()];
349 // since we will not actually delete the particle we just copied mark it as dummy.
350 particles[particleVec.back()].setOwnershipState(OwnershipState::dummy);
351 // then we pop the last index from the cell.
352 particleVec.pop_back();
353
354 } else {
355 ++pIter;
356 }
357 }
358 }
359 // implicit barrier here
360 // the barrier is needed because iterators are not thread safe w.r.t. addParticle()
361
362 // this loop is executed for every thread and thus parallel. Don't use #pragma omp for here!
363 // addParticle might throw. Set exceptionCaught to true, so we can handle that after the OpenMP region
364 try {
365 for (auto &&p : myInvalidParticles) {
366 // if not in halo
367 if (utils::inBox(p.getR(), this->getBoxMin(), this->getBoxMax())) {
368 this->template addParticle<false>(p);
369 } else {
370 myInvalidNotOwnedParticles.push_back(p);
371 }
372 }
373 } catch (const std::exception &e) {
374 exceptionCaught = true;
375 AUTOPAS_OPENMP(critical)
376 exceptionMsg.append(e.what());
377 }
378 AUTOPAS_OPENMP(critical) {
379 // merge private vectors to global one.
380 invalidParticles.insert(invalidParticles.end(), myInvalidNotOwnedParticles.begin(),
381 myInvalidNotOwnedParticles.end());
382 }
383 }
384
385 if (exceptionCaught) {
387 }
388
389 // we have to remove halo particles after the above for-loop since removing halo particles changes the underlying
390 // datastructure (_particleList) which invalidates the references in the cells.
391 // Note: removing halo particles before the loop and do a call to updateDirtyParticleReferences() right after won't
392 // work since there are owned particles in _particleList which fall into the halo area (they are not yet filtered
393 // out by the above loop) and can therefore not added to halo cells during particle insert in
394 // updateDirtyParticleReferences()
395 this->deleteHaloParticles();
396
397 _particleList.deleteDummyParticles();
399 return invalidParticles;
400 }
401
405 [[nodiscard]] TraversalSelectorInfo getTraversalSelectorInfo() const override {
406 return TraversalSelectorInfo(this->getCellBlock().getCellsPerDimensionWithHalo(), this->getInteractionLength(),
407 this->getCellBlock().getCellLength(), 0);
408 }
409
414 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
416 std::nullopt) override {
417 return ContainerIterator<Particle_T, true, false>(*this, behavior, additionalVectors);
418 }
419
424 IteratorBehavior behavior = IteratorBehavior::ownedOrHalo,
426 std::nullopt) const override {
427 return ContainerIterator<Particle_T, false, false>(*this, behavior, additionalVectors);
428 }
429
433 template <typename Lambda>
434 void forEach(Lambda forEachLambda, IteratorBehavior behavior = IteratorBehavior::ownedOrHaloOrDummy) {
435 if (behavior == IteratorBehavior::ownedOrHaloOrDummy) {
436 // iterate over all particles, so execute directly on particle vector
437 _particleList.forEach(forEachLambda);
438 } else {
439 for (size_t index = 0; index < getCells().size(); index++) {
440 if (!_cellBlock.ignoreCellForIteration(index, behavior)) {
441 getCells()[index].forEach(forEachLambda, behavior);
442 }
443 }
444 }
445 }
446
450 template <typename Lambda, typename A>
451 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior = IteratorBehavior::ownedOrHaloOrDummy) {
452 if (behavior == IteratorBehavior::ownedOrHaloOrDummy) {
453 // iterate over all particles, so execute directly on particle vector
454 _particleList.reduce(reduceLambda, result);
455 } else {
456 for (size_t index = 0; index < getCells().size(); index++) {
457 if (!_cellBlock.ignoreCellForIteration(index, behavior)) {
458 getCells()[index].reduce(reduceLambda, result, behavior);
459 }
460 }
461 }
462 }
463
468 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
470 std::nullopt) override {
471 return ContainerIterator<Particle_T, true, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
472 }
473
478 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
480 std::nullopt) const override {
481 return ContainerIterator<Particle_T, false, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
482 }
483
487 template <typename Lambda>
488 void forEachInRegion(Lambda forEachLambda, const std::array<double, 3> &lowerCorner,
489 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
490 using namespace autopas::utils::ArrayMath::literals;
491
492 // We increase the search region by skin, as particles can move over cell borders.
493 const auto startIndex3D = this->_cellBlock.get3DIndexOfPosition(lowerCorner - this->getVerletSkin());
494 const auto stopIndex3D = this->_cellBlock.get3DIndexOfPosition(higherCorner + this->getVerletSkin());
495
496 size_t numCellsOfInterest = (stopIndex3D[0] - startIndex3D[0] + 1) * (stopIndex3D[1] - startIndex3D[1] + 1) *
497 (stopIndex3D[2] - startIndex3D[2] + 1);
498 std::vector<size_t> cellsOfInterest(numCellsOfInterest);
499
500 int i = 0;
501 for (size_t z = startIndex3D[2]; z <= stopIndex3D[2]; ++z) {
502 for (size_t y = startIndex3D[1]; y <= stopIndex3D[1]; ++y) {
503 for (size_t x = startIndex3D[0]; x <= stopIndex3D[0]; ++x) {
504 cellsOfInterest[i++] =
505 utils::ThreeDimensionalMapping::threeToOneD({x, y, z}, this->_cellBlock.getCellsPerDimensionWithHalo());
506 }
507 }
508 }
509
510 for (size_t index : cellsOfInterest) {
511 if (!_cellBlock.ignoreCellForIteration(index, behavior)) {
512 getCells()[index].forEach(forEachLambda, lowerCorner, higherCorner, behavior);
513 }
514 }
515 }
516
520 template <typename Lambda, typename A>
521 void reduceInRegion(Lambda reduceLambda, A &result, const std::array<double, 3> &lowerCorner,
522 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
523 using namespace autopas::utils::ArrayMath::literals;
524
525 // We increase the search region by skin, as particles can move over cell borders.
526 const auto startIndex3D = this->_cellBlock.get3DIndexOfPosition(lowerCorner - this->getVerletSkin());
527 const auto stopIndex3D = this->_cellBlock.get3DIndexOfPosition(higherCorner + this->getVerletSkin());
528
529 size_t numCellsOfInterest = (stopIndex3D[0] - startIndex3D[0] + 1) * (stopIndex3D[1] - startIndex3D[1] + 1) *
530 (stopIndex3D[2] - startIndex3D[2] + 1);
531 std::vector<size_t> cellsOfInterest(numCellsOfInterest);
532
533 int i = 0;
534 for (size_t z = startIndex3D[2]; z <= stopIndex3D[2]; ++z) {
535 for (size_t y = startIndex3D[1]; y <= stopIndex3D[1]; ++y) {
536 for (size_t x = startIndex3D[0]; x <= stopIndex3D[0]; ++x) {
537 cellsOfInterest[i++] =
538 utils::ThreeDimensionalMapping::threeToOneD({x, y, z}, this->_cellBlock.getCellsPerDimensionWithHalo());
539 }
540 }
541 }
542
543 for (size_t index : cellsOfInterest) {
544 if (!_cellBlock.ignoreCellForIteration(index, behavior)) {
545 getCells()[index].reduce(reduceLambda, result, lowerCorner, higherCorner, behavior);
546 }
547 }
548 }
549
555
561
566 std::vector<ParticleCellType> &getCells() { return this->_cells; }
567
568 protected:
583 template <bool regionIter>
584 std::tuple<size_t, size_t> advanceIteratorIndices(
585 size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior, const std::array<double, 3> &boxMin,
586 const std::array<double, 3> &boxMax, const std::array<double, 3> &boxMinWithSafetyMargin,
587 const std::array<double, 3> &boxMaxWithSafetyMargin, size_t endCellIndex) const {
588 // Finding the indices for the next particle
589 const size_t stride = (iteratorBehavior & IteratorBehavior::forceSequential) ? 1 : autopas_get_num_threads();
590
591 // helper function to determine if the cell can even contain particles of interest to the iterator
592 auto cellIsRelevant = [&]() -> bool {
593 bool isRelevant =
594 // behavior matches possible particle ownership
595 (iteratorBehavior & IteratorBehavior::owned and _cellBlock.cellCanContainOwnedParticles(cellIndex)) or
596 (iteratorBehavior & IteratorBehavior::halo and _cellBlock.cellCanContainHaloParticles(cellIndex));
597 if constexpr (regionIter) {
598 // short circuit if already false
599 if (isRelevant) {
600 // is the cell in the region?
601 const auto [cellLowCorner, cellHighCorner] = _cellBlock.getCellBoundingBox(cellIndex);
602 isRelevant =
603 utils::boxesOverlap(cellLowCorner, cellHighCorner, boxMinWithSafetyMargin, boxMaxWithSafetyMargin);
604 }
605 }
606 return isRelevant;
607 };
608
609 do {
610 // advance to the next particle
611 ++particleIndex;
612 // If this breaches the end of a cell, find the next non-empty cell and reset particleIndex.
613
614 // If cell has wrong type, or there are no more particles in this cell jump to the next
615 while (not cellIsRelevant() or particleIndex >= this->_cells[cellIndex].size()) {
616 // TODO: can this jump be done more efficient if behavior is only halo or owned?
617 // TODO: can this jump be done more efficient for region iters if the cell is outside the region?
618 cellIndex += stride;
619 particleIndex = 0;
620
621 // If we notice that there is nothing else to look at set invalid values, so we get a nullptr next time and
622 // break.
623 if (cellIndex > endCellIndex) {
624 return {std::numeric_limits<decltype(cellIndex)>::max(), std::numeric_limits<decltype(particleIndex)>::max()};
625 }
626 }
627 } while (not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
628 this->_cells[cellIndex][particleIndex], iteratorBehavior, boxMin, boxMax));
629
630 // the indices returned at this point should always be valid
631 return {cellIndex, particleIndex};
632 }
633
650};
651
652} // namespace autopas
#define AutoPasLog(lvl, fmt,...)
Macro for logging providing common meta information without filename.
Definition: Logger.h:74
#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:28
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: CellBasedParticleContainer.h:141
double getVerletSkin() const final
Returns the verlet Skin length.
Definition: CellBasedParticleContainer.h:104
std::shared_ptr< const SortingThresholdInfoInterface > _soaSortingThresholds
Current AoS pair-sorting threshold, forwarded to freshly generated traversals in prepareTraversal().
Definition: CellBasedParticleContainer.h:192
void deleteAllParticles() override
Deletes all particles from the container.
Definition: CellBasedParticleContainer.h:109
std::shared_ptr< const SortingThresholdInfoInterface > _aosSortingThresholds
Current AoS pair-sorting threshold, forwarded to freshly generated traversals in prepareTraversal().
Definition: CellBasedParticleContainer.h:188
double getInteractionLength() const final
Return the interaction length (cutoff+skin) of the container.
Definition: CellBasedParticleContainer.h:99
std::vector< ParticleCellType > _cells
Vector of particle cells.
Definition: CellBasedParticleContainer.h:181
A cell pair traversal.
Definition: CellTraversal.h:25
virtual void setAoSSortingThresholds(const SortingThresholdInfoInterface &aosSortingThreshold)=0
Set the aos-sorting-threshold for traversals that use the CellFunctor.
Public iterator class that iterates over a particle container and additional vectors (which are typic...
Definition: ContainerIterator.h:96
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:109
Interface for traversals used by the LinkedCell class.
Definition: LCTraversalInterface.h:18
LinkedCells class.
Definition: LinkedCellsReferences.h:39
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:434
LoadEstimatorOption _loadEstimator
load estimation algorithm for balanced traversals.
Definition: LinkedCellsReferences.h:645
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:83
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:521
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:467
AutoPasLock addParticleLock
Workaround for adding particles in parallel -> https://github.com/AutoPas/AutoPas/issues/555.
Definition: LinkedCellsReferences.h:649
void deleteParticle(Particle_T &particle) override
Marks the given particle as deleted.
Definition: LinkedCellsReferences.h:302
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:211
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:240
void updateDirtyParticleReferences()
Updates all the References in the cells that are out of date.
Definition: LinkedCellsReferences.h:169
void deleteParticle(size_t cellIndex, size_t particleIndex) override
Marks the particle at the given index positions as deleted.
Definition: LinkedCellsReferences.h:310
void addParticleImpl(const Particle_T &p) override
Adds a particle to the container.
Definition: LinkedCellsReferences.h:90
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:217
ContainerOption getContainerType() const override
Get the ContainerType.
Definition: LinkedCellsReferences.h:81
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:584
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: LinkedCellsReferences.h:405
ParticleVector< Particle_T > _particleList
object that stores the actual Particles and keeps track of the references.
Definition: LinkedCellsReferences.h:637
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 aosSortingThresholdFallback=8, const size_t soaSortingThresholdFallback=100, LoadEstimatorOption loadEstimator=LoadEstimatorOption::squaredParticlesPerCell)
Constructor of the LinkedCells class.
Definition: LinkedCellsReferences.h:64
internal::CellBlock3D< ParticleCellType > _cellBlock
object to manage the block of cells.
Definition: LinkedCellsReferences.h:641
BalancedTraversal::EstimatorFunction getLoadEstimatorFunction()
Generates the load estimation function depending on _loadEstimator.
Definition: LinkedCellsReferences.h:143
void rebuildNeighborLists(TraversalInterface *traversal) override
Rebuilds the neighbor lists for the next traversals.
Definition: LinkedCellsReferences.h:162
internal::CellBlock3D< ParticleCellType > & getCellBlock()
Get the cell block, not supposed to be used except by verlet lists.
Definition: LinkedCellsReferences.h:554
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:477
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:488
void computeInteractions(TraversalInterface *traversal) override
Iterates over all particle multiples (e.g.
Definition: LinkedCellsReferences.h:189
std::vector< Particle_T > updateContainer(bool keepNeighborListsValid) override
Updates the container.
Definition: LinkedCellsReferences.h:315
void deleteAllParticles() override
Deletes all particles from the container.
Definition: LinkedCellsReferences.h:126
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:423
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:413
void deleteHaloParticles() override
Deletes all halo particles.
Definition: LinkedCellsReferences.h:134
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:100
std::vector< ParticleCellType > & getCells()
Returns reference to the data of LinkedCellsReferences.
Definition: LinkedCellsReferences.h:566
const internal::CellBlock3D< ParticleCellType > & getCellBlock() const
Get the cell block, not supposed to be used except by verlet lists.
Definition: LinkedCellsReferences.h:560
bool updateHaloParticle(const Particle_T &haloParticle) override
Update a halo particle of the container with the given haloParticle.
Definition: LinkedCellsReferences.h:110
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior=IteratorBehavior::ownedOrHaloOrDummy)
Reduce properties of particles as defined by a lambda function.
Definition: LinkedCellsReferences.h:451
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 refers to particles that are stored in a vector outside of the cell by their indices in th...
Definition: ReferenceParticleCell.h:26
void addParticleReference(size_t index)
Adds the particle at the given index of the particle storage to this cell.
Definition: ReferenceParticleCell.h:60
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
void markParticleAsDeleted(Particle_T &p)
Marks a particle as deleted.
Definition: markParticleAsDeleted.h:23
static bool checkParticleInCellAndUpdateByIDAndPosition(CellType &cell, const typename CellType::ParticleType &particle, double absError)
Updates a found particle within cellI to the values of particleI.
Definition: ParticleCellHelpers.h:25
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