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;
60 LinkedCellsReferences(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax, const double cutoff,
61 const double skin, const unsigned int rebuildFrequency, const double cellSizeFactor = 1.0,
63 : CellBasedParticleContainer<ReferenceCell>(boxMin, boxMax, cutoff, skin, rebuildFrequency),
64 _cellBlock(this->_cells, boxMin, boxMax, cutoff + skin, cellSizeFactor),
65 _loadEstimator(loadEstimator) {}
66
70 [[nodiscard]] ContainerOption getContainerType() const override { return ContainerOption::linkedCellsReferences; }
71
75 [[nodiscard]] CellType getParticleCellTypeEnum() const override { return CellType::ReferenceParticleCell; }
76
77 void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override {
78 _cellBlock.reserve(numParticles + numParticlesHaloEstimate);
79 }
80
84 void addParticleImpl(const ParticleType &p) override {
89 }
90
94 void addHaloParticleImpl(const ParticleType &haloParticle) override {
96 _particleList.push_back(haloParticle);
99 }
100
104 bool updateHaloParticle(const ParticleType &haloParticle) override {
105 auto cells = _cellBlock.getNearbyHaloCells(haloParticle.getR(), this->getVerletSkin());
106 for (auto cellptr : cells) {
107 bool updated = internal::checkParticleInCellAndUpdateByID(*cellptr, haloParticle);
108 if (updated) {
109 return true;
110 }
111 }
112 AutoPasLog(TRACE, "UpdateHaloParticle was not able to update particle: {}", haloParticle.toString());
113 return false;
114 }
115
119 void deleteHaloParticles() override {
121 _cellBlock.clearHaloCells();
122 }
123
129 // (Explicit) static cast required for Apple Clang (last tested version: 17.0.0)
130 switch (static_cast<LoadEstimatorOption::Value>(this->_loadEstimator)) {
132 return [&](const std::array<unsigned long, 3> &cellsPerDimension,
133 const std::array<unsigned long, 3> &lowerCorner, const std::array<unsigned long, 3> &upperCorner) {
134 return loadEstimators::squaredParticlesPerCell(this->_cells, cellsPerDimension, lowerCorner, upperCorner);
135 };
136 }
138 [[fallthrough]];
139 default: {
140 return
141 [&](const std::array<unsigned long, 3> &cellsPerDimension, const std::array<unsigned long, 3> &lowerCorner,
142 const std::array<unsigned long, 3> &upperCorner) { return 1; };
143 }
144 }
145 }
146
148
154 if (_particleList.isDirty()) {
156 for (auto &cell : this->_cells) {
157 cell.clear();
158 }
159 }
160
161 for (auto it = _particleList.beginDirty(); it < _particleList.endDirty(); it++) {
162 if (it->isDummy()) {
163 continue;
164 }
165 ReferenceCell &cell = _cellBlock.getContainingCell(it->getR());
166 auto address = &(*it);
167 cell.addParticleReference(address);
168 }
170 }
171 }
172
173 void computeInteractions(TraversalInterface *traversal) override {
174 // Check if traversal is allowed for this container and give it the data it needs.
175 auto *traversalInterface = dynamic_cast<LCTraversalInterface *>(traversal);
176 auto *cellPairTraversal = dynamic_cast<CellTraversal<ReferenceCell> *>(traversal);
177 if (auto *balancedTraversal = dynamic_cast<BalancedTraversal *>(traversal)) {
178 balancedTraversal->setLoadEstimator(getLoadEstimatorFunction());
179 }
180 if (traversalInterface && cellPairTraversal) {
181 cellPairTraversal->setCellsToTraverse(this->_cells);
182 } else {
184 "Trying to use a traversal of wrong type in LinkedCellsReferences::computeInteractions. TraversalID: {}",
185 traversal->getTraversalType());
186 }
187
188 traversal->initTraversal();
189 traversal->traverseParticles();
190 traversal->endTraversal();
191 }
192
193 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
194 IteratorBehavior iteratorBehavior,
195 const std::array<double, 3> &boxMin,
196 const std::array<double, 3> &boxMax) const override {
197 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
198 }
199 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
200 IteratorBehavior iteratorBehavior) const override {
201 // this is not a region iter hence we stretch the bounding box to the numeric max
202 constexpr std::array<double, 3> boxMin{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
203 std::numeric_limits<double>::lowest()};
204
205 constexpr std::array<double, 3> boxMax{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
206 std::numeric_limits<double>::max()};
207 return getParticleImpl<false>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
208 }
209
221 template <bool regionIter>
222 std::tuple<const Particle_T *, size_t, size_t> getParticleImpl(size_t cellIndex, size_t particleIndex,
223 IteratorBehavior iteratorBehavior,
224 const std::array<double, 3> &boxMin,
225 const std::array<double, 3> &boxMax) const {
226 using namespace autopas::utils::ArrayMath::literals;
227
228 std::array<double, 3> boxMinWithSafetyMargin = boxMin;
229 std::array<double, 3> boxMaxWithSafetyMargin = boxMax;
230 if constexpr (regionIter) {
231 // We extend the search box for cells here since particles might have moved
232 boxMinWithSafetyMargin -= this->getVerletSkin();
233 boxMaxWithSafetyMargin += this->getVerletSkin();
234 }
235
236 // first and last relevant cell index
237 const auto [startCellIndex, endCellIndex] = [&]() -> std::tuple<size_t, size_t> {
238 if constexpr (regionIter) {
239 // We extend the search box for cells here since particles might have moved
240 return {_cellBlock.get1DIndexOfPosition(boxMinWithSafetyMargin),
241 _cellBlock.get1DIndexOfPosition(boxMaxWithSafetyMargin)};
242 } else {
243 if (not(iteratorBehavior & IteratorBehavior::halo)) {
244 // only potentially owned region
245 return {_cellBlock.getFirstOwnedCellIndex(), _cellBlock.getLastOwnedCellIndex()};
246 } else {
247 // whole range of cells
248 return {0, this->_cells.size() - 1};
249 }
250 }
251 }();
252
253 // if we are at the start of an iteration ...
254 if (cellIndex == 0 and particleIndex == 0) {
255 cellIndex =
256 startCellIndex + ((iteratorBehavior & IteratorBehavior::forceSequential) ? 0 : autopas_get_thread_num());
257 }
258 // abort if the start index is already out of bounds
259 if (cellIndex >= this->_cells.size()) {
260 return {nullptr, 0, 0};
261 }
262 // check the data behind the indices
263 if (particleIndex >= this->_cells[cellIndex].size() or
264 not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
265 this->_cells[cellIndex][particleIndex], iteratorBehavior, boxMin, boxMax)) {
266 // either advance them to something interesting or invalidate them.
267 std::tie(cellIndex, particleIndex) =
268 advanceIteratorIndices<regionIter>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax,
269 boxMinWithSafetyMargin, boxMaxWithSafetyMargin, endCellIndex);
270 }
271
272 // shortcut if the given index doesn't exist
273 if (cellIndex > endCellIndex) {
274 return {nullptr, 0, 0};
275 }
276 const Particle_T *retPtr = &this->_cells[cellIndex][particleIndex];
277
278 return {retPtr, cellIndex, particleIndex};
279 }
280
281 bool deleteParticle(Particle_T &particle) override {
282 // This function doesn't actually delete anything as it would mess up the reference structure.
284 return false;
285 }
286
287 bool deleteParticle(size_t cellIndex, size_t particleIndex) override {
288 // This function doesn't actually delete anything as it would mess up the reference structure.
289 internal::markParticleAsDeleted(this->_cells[cellIndex][particleIndex]);
290 return false;
291 }
292
293 std::vector<ParticleType> updateContainer(bool keepNeighborListsValid) override {
294 if (keepNeighborListsValid) {
296 }
297
298 std::vector<ParticleType> invalidParticles;
299
300 // for exception handling in parallel region
301 bool exceptionCaught{false};
302 std::string exceptionMsg{""};
303
304 AUTOPAS_OPENMP(parallel) {
305 // private for each thread!
306 std::vector<ParticleType> myInvalidParticles, myInvalidNotOwnedParticles;
307 AUTOPAS_OPENMP(for)
308 for (size_t cellId = 0; cellId < this->getCells().size(); ++cellId) {
309 // Delete dummy particles of each cell.
310 this->getCells()[cellId].deleteDummyParticles();
311
312 // if empty
313 if (this->getCells()[cellId].isEmpty()) continue;
314
315 auto [cellLowerCorner, cellUpperCorner] = this->getCellBlock().getCellBoundingBox(cellId);
316
317 auto &particleVec = this->getCells()[cellId]._particles;
318 for (auto pIter = particleVec.begin(); pIter != particleVec.end();) {
319 if ((*pIter)->isOwned() and utils::notInBox((*pIter)->getR(), cellLowerCorner, cellUpperCorner)) {
320 myInvalidParticles.push_back(**pIter);
321
322 // multi layer swap-delete
323 // we copy the particle behind the last pointer in the cell over the particle we want to delete
324 **pIter = *particleVec.back();
325 // since we will not actually delete the particle we just copied mark it as dummy.
326 particleVec.back()->setOwnershipState(OwnershipState::dummy);
327 // then we pop the last pointer from the cell.
328 particleVec.pop_back();
329
330 } else {
331 ++pIter;
332 }
333 }
334 }
335 // implicit barrier here
336 // the barrier is needed because iterators are not thread safe w.r.t. addParticle()
337
338 // this loop is executed for every thread and thus parallel. Don't use #pragma omp for here!
339 // addParticle might throw. Set exceptionCaught to true, so we can handle that after the OpenMP region
340 try {
341 for (auto &&p : myInvalidParticles) {
342 // if not in halo
343 if (utils::inBox(p.getR(), this->getBoxMin(), this->getBoxMax())) {
344 this->template addParticle<false>(p);
345 } else {
346 myInvalidNotOwnedParticles.push_back(p);
347 }
348 }
349 } catch (const std::exception &e) {
350 exceptionCaught = true;
351 AUTOPAS_OPENMP(critical)
352 exceptionMsg.append(e.what());
353 }
354 AUTOPAS_OPENMP(critical) {
355 // merge private vectors to global one.
356 invalidParticles.insert(invalidParticles.end(), myInvalidNotOwnedParticles.begin(),
357 myInvalidNotOwnedParticles.end());
358 }
359 }
360
361 if (exceptionCaught) {
363 }
364
365 // we have to remove halo particles after the above for-loop since removing halo particles changes the underlying
366 // datastructure (_particleList) which invalidates the references in the cells.
367 // Note: removing halo particles before the loop and do a call to updateDirtyParticleReferences() right after won't
368 // work since there are owned particles in _particleList which fall into the halo area (they are not yet filtered
369 // out by the above loop) and can therefore not added to halo cells during particle insert in
370 // updateDirtyParticleReferences()
371 this->deleteHaloParticles();
372
375 return invalidParticles;
376 }
377
381 [[nodiscard]] TraversalSelectorInfo getTraversalSelectorInfo() const override {
382 return TraversalSelectorInfo(this->getCellBlock().getCellsPerDimensionWithHalo(), this->getInteractionLength(),
383 this->getCellBlock().getCellLength(), 0);
384 }
385
387 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHalo,
388 typename ContainerIterator<ParticleType, true, false>::ParticleVecType *additionalVectors = nullptr) override {
389 return ContainerIterator<ParticleType, true, false>(*this, behavior, additionalVectors);
390 }
391
393 IteratorBehavior behavior = autopas::IteratorBehavior::ownedOrHalo,
395 nullptr) const override {
396 return ContainerIterator<ParticleType, false, false>(*this, behavior, additionalVectors);
397 }
398
402 template <typename Lambda>
403 void forEach(Lambda forEachLambda, IteratorBehavior behavior = IteratorBehavior::ownedOrHaloOrDummy) {
404 if (behavior == IteratorBehavior::ownedOrHaloOrDummy) {
405 // iterate over all particles, so execute directly on particle vector
406 _particleList.forEach(forEachLambda);
407 } else {
408 for (size_t index = 0; index < getCells().size(); index++) {
409 if (!_cellBlock.ignoreCellForIteration(index, behavior)) {
410 getCells()[index].forEach(forEachLambda, behavior);
411 }
412 }
413 }
414 }
415
419 template <typename Lambda, typename A>
420 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior = IteratorBehavior::ownedOrHaloOrDummy) {
421 if (behavior == IteratorBehavior::ownedOrHaloOrDummy) {
422 // iterate over all particles, so execute directly on particle vector
423 _particleList.reduce(reduceLambda, result);
424 } else {
425 for (size_t index = 0; index < getCells().size(); index++) {
426 if (!_cellBlock.ignoreCellForIteration(index, behavior)) {
427 getCells()[index].reduce(reduceLambda, result, behavior);
428 }
429 }
430 }
431 }
432
434 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
435 typename ContainerIterator<ParticleType, true, true>::ParticleVecType *additionalVectors = nullptr) override {
436 return ContainerIterator<ParticleType, true, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
437 }
438
440 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
442 nullptr) const override {
443 return ContainerIterator<ParticleType, false, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
444 }
445
449 template <typename Lambda>
450 void forEachInRegion(Lambda forEachLambda, const std::array<double, 3> &lowerCorner,
451 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
452 using namespace autopas::utils::ArrayMath::literals;
453
454 // We increase the search region by skin, as particles can move over cell borders.
455 const auto startIndex3D = this->_cellBlock.get3DIndexOfPosition(lowerCorner - this->getVerletSkin());
456 const auto stopIndex3D = this->_cellBlock.get3DIndexOfPosition(higherCorner + this->getVerletSkin());
457
458 size_t numCellsOfInterest = (stopIndex3D[0] - startIndex3D[0] + 1) * (stopIndex3D[1] - startIndex3D[1] + 1) *
459 (stopIndex3D[2] - startIndex3D[2] + 1);
460 std::vector<size_t> cellsOfInterest(numCellsOfInterest);
461
462 int i = 0;
463 for (size_t z = startIndex3D[2]; z <= stopIndex3D[2]; ++z) {
464 for (size_t y = startIndex3D[1]; y <= stopIndex3D[1]; ++y) {
465 for (size_t x = startIndex3D[0]; x <= stopIndex3D[0]; ++x) {
466 cellsOfInterest[i++] =
467 utils::ThreeDimensionalMapping::threeToOneD({x, y, z}, this->_cellBlock.getCellsPerDimensionWithHalo());
468 }
469 }
470 }
471
472 for (size_t index : cellsOfInterest) {
473 if (!_cellBlock.ignoreCellForIteration(index, behavior)) {
474 getCells()[index].forEach(forEachLambda, lowerCorner, higherCorner, behavior);
475 }
476 }
477 }
478
482 template <typename Lambda, typename A>
483 void reduceInRegion(Lambda reduceLambda, A &result, const std::array<double, 3> &lowerCorner,
484 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
485 using namespace autopas::utils::ArrayMath::literals;
486
487 // We increase the search region by skin, as particles can move over cell borders.
488 const auto startIndex3D = this->_cellBlock.get3DIndexOfPosition(lowerCorner - this->getVerletSkin());
489 const auto stopIndex3D = this->_cellBlock.get3DIndexOfPosition(higherCorner + this->getVerletSkin());
490
491 size_t numCellsOfInterest = (stopIndex3D[0] - startIndex3D[0] + 1) * (stopIndex3D[1] - startIndex3D[1] + 1) *
492 (stopIndex3D[2] - startIndex3D[2] + 1);
493 std::vector<size_t> cellsOfInterest(numCellsOfInterest);
494
495 int i = 0;
496 for (size_t z = startIndex3D[2]; z <= stopIndex3D[2]; ++z) {
497 for (size_t y = startIndex3D[1]; y <= stopIndex3D[1]; ++y) {
498 for (size_t x = startIndex3D[0]; x <= stopIndex3D[0]; ++x) {
499 cellsOfInterest[i++] =
500 utils::ThreeDimensionalMapping::threeToOneD({x, y, z}, this->_cellBlock.getCellsPerDimensionWithHalo());
501 }
502 }
503 }
504
505 for (size_t index : cellsOfInterest) {
506 if (!_cellBlock.ignoreCellForIteration(index, behavior)) {
507 getCells()[index].reduce(reduceLambda, result, lowerCorner, higherCorner, behavior);
508 }
509 }
510 }
511
517
523
528 std::vector<ReferenceCell> &getCells() { return this->_cells; }
529
530 protected:
545 template <bool regionIter>
546 std::tuple<size_t, size_t> advanceIteratorIndices(
547 size_t cellIndex, size_t particleIndex, IteratorBehavior iteratorBehavior, const std::array<double, 3> &boxMin,
548 const std::array<double, 3> &boxMax, const std::array<double, 3> &boxMinWithSafetyMargin,
549 const std::array<double, 3> &boxMaxWithSafetyMargin, size_t endCellIndex) const {
550 // Finding the indices for the next particle
551 const size_t stride = (iteratorBehavior & IteratorBehavior::forceSequential) ? 1 : autopas_get_num_threads();
552
553 // helper function to determine if the cell can even contain particles of interest to the iterator
554 auto cellIsRelevant = [&]() -> bool {
555 bool isRelevant =
556 // behavior matches possible particle ownership
557 (iteratorBehavior & IteratorBehavior::owned and _cellBlock.cellCanContainOwnedParticles(cellIndex)) or
558 (iteratorBehavior & IteratorBehavior::halo and _cellBlock.cellCanContainHaloParticles(cellIndex));
559 if constexpr (regionIter) {
560 // short circuit if already false
561 if (isRelevant) {
562 // is the cell in the region?
563 const auto [cellLowCorner, cellHighCorner] = _cellBlock.getCellBoundingBox(cellIndex);
564 isRelevant =
565 utils::boxesOverlap(cellLowCorner, cellHighCorner, boxMinWithSafetyMargin, boxMaxWithSafetyMargin);
566 }
567 }
568 return isRelevant;
569 };
570
571 do {
572 // advance to the next particle
573 ++particleIndex;
574 // If this breaches the end of a cell, find the next non-empty cell and reset particleIndex.
575
576 // If cell has wrong type, or there are no more particles in this cell jump to the next
577 while (not cellIsRelevant() or particleIndex >= this->_cells[cellIndex].size()) {
578 // TODO: can this jump be done more efficient if behavior is only halo or owned?
579 // TODO: can this jump be done more efficient for region iters if the cell is outside the region?
580 cellIndex += stride;
581 particleIndex = 0;
582
583 // If we notice that there is nothing else to look at set invalid values, so we get a nullptr next time and
584 // break.
585 if (cellIndex > endCellIndex) {
586 return {std::numeric_limits<decltype(cellIndex)>::max(), std::numeric_limits<decltype(particleIndex)>::max()};
587 }
588 }
589 } while (not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
590 this->_cells[cellIndex][particleIndex], iteratorBehavior, boxMin, boxMax));
591
592 // the indices returned at this point should always be valid
593 return {cellIndex, particleIndex};
594 }
595
612};
613
614} // 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
bool needsRebuild()
Indicates, whether References already stored in cells need to be updated.
Definition: ParticleVector.h:92
void push_back(const Particle_T &particle)
Add a Particle to the data structure.
Definition: ParticleVector.h:66
auto endDirty()
End of the iterator over dirty Particles.
Definition: ParticleVector.h:103
void clearHaloParticles()
Remove all halo particles from the container and mark it as dirty.
Definition: ParticleVector.h:43
void reduce(Lambda reduceLambda, A &result)
Iterate over all particles and execute lambda function on them.
Definition: ParticleVector.h:122
void markAsClean()
Marks the ParticleVector as clean.
Definition: ParticleVector.h:35
auto beginDirty()
Begin of the iterator over dirty Particles.
Definition: ParticleVector.h:98
void forEach(Lambda forEachLambda)
Iterate over all particles and execute lambda function on them.
Definition: ParticleVector.h:110
bool isDirty()
Returns the dirty flag, indicating whether Particles exist in the vector that are not stored in a cel...
Definition: ParticleVector.h:30
void deleteDummyParticles()
Remove all dummy particles from the container and mark it as dirty.
Definition: ParticleVector.h:54
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
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< ReferenceParticleCell< 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
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:403
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:77
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:483
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: LinkedCellsReferences.h:392
AutoPasLock addParticleLock
Workaround for adding particles in parallel -> https://github.com/AutoPas/AutoPas/issues/555.
Definition: LinkedCellsReferences.h:611
internal::CellBlock3D< ReferenceCell > _cellBlock
object to manage the block of cells.
Definition: LinkedCellsReferences.h:603
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:193
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: LinkedCellsReferences.h:386
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:222
void updateDirtyParticleReferences()
Updates all the References in the cells that are out of date.
Definition: LinkedCellsReferences.h:153
void addHaloParticleImpl(const ParticleType &haloParticle) override
Adds a particle to the container that lies in the halo region of the container.
Definition: LinkedCellsReferences.h:94
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:287
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:199
ContainerOption getContainerType() const override
Get the ContainerType.
Definition: LinkedCellsReferences.h:70
std::vector< ParticleType > updateContainer(bool keepNeighborListsValid) override
Updates the container.
Definition: LinkedCellsReferences.h:293
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:546
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: LinkedCellsReferences.h:381
const internal::CellBlock3D< ReferenceCell > & getCellBlock() const
Get the cell block, not supposed to be used except by verlet lists.
Definition: LinkedCellsReferences.h:522
std::vector< ReferenceCell > & getCells()
Returns reference to the data of LinkedCellsReferences.
Definition: LinkedCellsReferences.h:528
BalancedTraversal::EstimatorFunction getLoadEstimatorFunction()
Generates the load estimation function depending on _loadEstimator.
Definition: LinkedCellsReferences.h:128
void rebuildNeighborLists(TraversalInterface *traversal) override
Rebuilds the neighbor lists for the next traversals.
Definition: LinkedCellsReferences.h:147
internal::CellBlock3D< ReferenceCell > & getCellBlock()
Get the cell block, not supposed to be used except by verlet lists.
Definition: LinkedCellsReferences.h:516
void addParticleImpl(const ParticleType &p) override
Adds a particle to the container.
Definition: LinkedCellsReferences.h:84
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: LinkedCellsReferences.h:439
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:281
autopas::LoadEstimatorOption _loadEstimator
load estimation algorithm for balanced traversals.
Definition: LinkedCellsReferences.h:607
bool updateHaloParticle(const ParticleType &haloParticle) override
Update a halo particle of the container with the given haloParticle.
Definition: LinkedCellsReferences.h:104
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:450
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: LinkedCellsReferences.h:433
void computeInteractions(TraversalInterface *traversal) override
Iterates over all particle multiples (e.g.
Definition: LinkedCellsReferences.h:173
CellType getParticleCellTypeEnum() const override
Get the ParticleCell type as an Enum.
Definition: LinkedCellsReferences.h:75
ParticleVector< ParticleType > _particleList
object that stores the actual Particles and keeps track of the references.
Definition: LinkedCellsReferences.h:599
LinkedCellsReferences(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: LinkedCellsReferences.h:60
void deleteHaloParticles() override
Deletes all halo particles.
Definition: LinkedCellsReferences.h:119
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior=IteratorBehavior::ownedOrHaloOrDummy)
Reduce properties of particles as defined by a lambda function.
Definition: LinkedCellsReferences.h:420
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: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
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
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
CellType
The ParticleCell Type as an Enum.
Definition: ParticleCell.h:19
@ ReferenceParticleCell
ReferenceParticleCell : Cell holding only references instead of actual particle objects.
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