AutoPas  3.0.0
Loading...
Searching...
No Matches
Octree.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <cstdio>
11#include <list>
12#include <stack>
13
24#include "autopas/utils/inBox.h"
26
27namespace autopas {
28
39template <class Particle_T>
40class Octree : public CellBasedParticleContainer<OctreeNodeWrapper<Particle_T>>,
42 public:
47
52
58 enum CellTypes : int { OWNED = 0, HALO = 1 };
59
63 constexpr static size_t invalidCellIndex = 9;
64
75 Octree(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax, const double cutoff,
76 const double skin, const double cellSizeFactor, const size_t aosSortingThreshold,
77 const size_t soaSortingThreshold)
78 : CellBasedParticleContainer<ParticleCellType>(boxMin, boxMax, cutoff, skin, aosSortingThreshold,
79 soaSortingThreshold) {
80 using namespace autopas::utils::ArrayMath::literals;
81
82 if (cellSizeFactor != 1.0) {
83 // Throw exception - this config should have been caught by LogicHandler. Note: This is not a fundamental issue
84 // with the algorithm but simply has not been implemented.
86 "Trying to construct an Octree with CSF != 1.0! This should never occur as the LogicHandler "
87 "should reject this (as Configuration::hasCompatibleValues should return false).");
88 }
89
90 // @todo Obtain this from a configuration, reported in https://github.com/AutoPas/AutoPas/issues/624
91 int unsigned treeSplitThreshold = 16;
92
93 double interactionLength = this->getInteractionLength();
94
95 // Create the octree for the owned particles
96 this->_cells.push_back(
97 OctreeNodeWrapper<Particle_T>(boxMin, boxMax, treeSplitThreshold, interactionLength, cellSizeFactor));
98
99 // Extend the halo region with cutoff + skin in all dimensions
100 auto haloBoxMin = boxMin - interactionLength;
101 auto haloBoxMax = boxMax + interactionLength;
102 // Create the octree for the halo particles
103 this->_cells.push_back(
104 OctreeNodeWrapper<Particle_T>(haloBoxMin, haloBoxMax, treeSplitThreshold, interactionLength, cellSizeFactor));
105
106 // set type of particles in the two cells
107 this->_cells[CellTypes::OWNED].setPossibleParticleOwnerships(OwnershipState::owned);
108 this->_cells[CellTypes::HALO].setPossibleParticleOwnerships(OwnershipState::halo);
109 }
110
111 [[nodiscard]] std::vector<ParticleType> updateContainer(bool keepNeighborListValid) override {
112 // invalidParticles: all outside boxMin/Max
113 std::vector<Particle_T> invalidParticles{};
114
115 if (keepNeighborListValid) {
117 } else {
118 // This is a very primitive and inefficient way to rebuild the container:
119
120 // @todo Make this less indirect. (Find a better way to iterate all particles inside the octree to change
121 // this function back to a function that actually copies all particles out of the octree.)
122 // The problem is captured by https://github.com/AutoPas/AutoPas/issues/622
123
124 // 1. Copy all particles out of the container
125 std::vector<Particle_T *> particleRefs;
126 this->_cells[CellTypes::OWNED].collectAllParticles(particleRefs);
127 std::vector<Particle_T> particles{};
128 particles.reserve(particleRefs.size());
129
130 for (auto *p : particleRefs) {
131 if (p->isDummy()) {
132 // don't do anything with dummies. They will just be dropped when the container is rebuilt.
133 continue;
134 } else if (utils::inBox(p->getR(), this->getBoxMin(), this->getBoxMax())) {
135 particles.push_back(*p);
136 } else {
137 invalidParticles.push_back(*p);
138 }
139 }
140
141 // 2. Clear the container
142 this->deleteAllParticles();
143
144 // 3. Insert the particles back into the container
145 for (auto &particle : particles) {
146 addParticleImpl(particle);
147 }
148 }
149
150 return invalidParticles;
151 }
152
153 void computeInteractions(TraversalInterface *traversal) override {
154 if (auto *traversalInterface = dynamic_cast<OTTraversalInterface<ParticleCellType> *>(traversal)) {
155 traversalInterface->setCells(&this->_cells);
156 }
157
158 traversal->initTraversal();
159 traversal->traverseParticles();
160 traversal->endTraversal();
161 }
162
166 [[nodiscard]] ContainerOption getContainerType() const override { return ContainerOption::octree; }
167
168 void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override {
169 // TODO create a balanced tree and reserve space in the leaves.
170 }
171
175 void addParticleImpl(const ParticleType &p) override { this->_cells[CellTypes::OWNED].addParticle(p); }
176
180 void addHaloParticleImpl(const ParticleType &haloParticle) override {
181 this->_cells[CellTypes::HALO].addParticle(haloParticle);
182 }
183
187 bool updateHaloParticle(const ParticleType &haloParticle) override {
188 return internal::checkParticleInCellAndUpdateByIDAndPosition(this->_cells[CellTypes::HALO], haloParticle,
189 this->getVerletSkin());
190 }
191
192 void rebuildNeighborLists(TraversalInterface *traversal) override {}
193
194 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
195 IteratorBehavior iteratorBehavior,
196 const std::array<double, 3> &boxMin,
197 const std::array<double, 3> &boxMax) const override {
198 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
199 }
200 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
201 IteratorBehavior iteratorBehavior) const override {
202 // this is not a region iter hence we stretch the bounding box to the numeric max
203 constexpr std::array<double, 3> boxMin{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
204 std::numeric_limits<double>::lowest()};
205
206 constexpr std::array<double, 3> boxMax{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
207 std::numeric_limits<double>::max()};
208 return getParticleImpl<false>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
209 }
210
228 template <bool regionIter>
229 std::tuple<const ParticleType *, size_t, size_t> getParticleImpl(size_t cellIndex, size_t particleIndex,
230 IteratorBehavior iteratorBehavior,
231 const std::array<double, 3> &boxMin,
232 const std::array<double, 3> &boxMax) const {
233 using namespace autopas::utils::ArrayMath::literals;
234 // FIXME think about parallelism.
235 // This `if` currently disables it but should be replaced with logic that determines the start index.
236 if (autopas_get_thread_num() > 0 and not(iteratorBehavior & IteratorBehavior::forceSequential)) {
237 return {nullptr, 0, 0};
238 }
239 // if owned particles are not interesting jump directly to the halo tree
240 // FIXME: with num threads > 1 the start cell IDs will have to be set to more complicated values here
241 if (cellIndex == 0 and not(iteratorBehavior & IteratorBehavior::owned)) {
242 cellIndex = HALO;
243 }
244
245 // shortcut if the given index doesn't exist
246 if (cellIndex < 10 and cellIndex > HALO) {
247 return {nullptr, 0, 0};
248 }
249
250 std::array<double, 3> boxMinWithSafetyMargin = boxMin;
251 std::array<double, 3> boxMaxWithSafetyMargin = boxMax;
252 if constexpr (regionIter) {
253 // We extend the search box for cells here since particles might have moved
254 boxMinWithSafetyMargin -= 0.5 * this->getVerletSkin();
255 boxMaxWithSafetyMargin += 0.5 * this->getVerletSkin();
256 }
257
258 std::vector<size_t> currentCellIndex{};
259 OctreeLeafNode<Particle_T> *currentCellPtr = nullptr;
260
261 std::tie(currentCellIndex, currentCellPtr) = getLeafCellByIndex(cellIndex);
262 // check the data behind the indices
263 if (particleIndex >= currentCellPtr->size() or
264 not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
265 (*currentCellPtr)[particleIndex], iteratorBehavior, boxMin, boxMax)) {
266 // either advance them to something interesting or invalidate them.
267 std::tie(currentCellPtr, particleIndex) =
268 advanceIteratorIndices<regionIter>(currentCellIndex, currentCellPtr, particleIndex, iteratorBehavior, boxMin,
269 boxMax, boxMinWithSafetyMargin, boxMaxWithSafetyMargin);
270 }
271
272 // shortcut if the given index doesn't exist
273 if (currentCellPtr == nullptr) {
274 return {nullptr, 0, 0};
275 }
276 // parse cellIndex and get referenced cell and particle
277 const Particle_T *retPtr = &((*currentCellPtr)[particleIndex]);
278
279 // if no err value was set, convert cell index from vec to integer
280 if (currentCellIndex.empty()) {
281 cellIndex = invalidCellIndex;
282 } else {
283 cellIndex = 0;
284 // needs signed int to prevent underflow
285 for (int i = static_cast<int>(currentCellIndex.size()) - 1; i >= 0; --i) {
286 cellIndex *= 10;
287 cellIndex += currentCellIndex[i];
288 }
289 }
290
291 return {retPtr, cellIndex, particleIndex};
292 }
293
303 std::tuple<std::vector<size_t>, OctreeLeafNode<Particle_T> *> getLeafCellByIndex(size_t cellIndex) const {
304 // parse cellIndex and get referenced cell and particle
305 std::vector<size_t> currentCellIndex;
306 // constant heuristic for the tree depth
307 currentCellIndex.reserve(10);
308 currentCellIndex.push_back(cellIndex % 10);
309 cellIndex /= 10;
310 OctreeNodeInterface<Particle_T> *currentCell = this->_cells[currentCellIndex.back()].getRaw();
311 // don't restrict loop via cellIndex because it might have "hidden" leading 0
312 while (currentCell->hasChildren()) {
313 currentCellIndex.push_back(cellIndex % 10);
314 cellIndex /= 10;
315 currentCell = currentCell->getChild(currentCellIndex.back());
316 }
317 return {currentCellIndex, dynamic_cast<OctreeLeafNode<Particle_T> *>(currentCell)};
318 }
319
323 bool deleteParticle(Particle_T &particle) override {
324 if (particle.isOwned()) {
325 return this->_cells[CellTypes::OWNED].deleteParticle(particle);
326 } else if (particle.isHalo()) {
327 return this->_cells[CellTypes::HALO].deleteParticle(particle);
328 } else {
329 utils::ExceptionHandler::exception("Particle to be deleted is neither owned nor halo!\n" + particle.toString());
330 return false;
331 }
332 }
333
334 bool deleteParticle(size_t cellIndex, size_t particleIndex) override {
335 auto [cellIndexVector, cell] = getLeafCellByIndex(cellIndex);
336 auto &particleVec = cell->_particles;
337 auto &particle = particleVec[particleIndex];
338 // swap-delete
339 particle = particleVec.back();
340 particleVec.pop_back();
341 return particleIndex < particleVec.size();
342 }
343
348 IteratorBehavior behavior,
350 return ContainerIterator<Particle_T, true, false>(*this, behavior, additionalVectors);
351 }
352
357 IteratorBehavior behavior,
359 std::nullopt) const override {
360 return ContainerIterator<Particle_T, false, false>(*this, behavior, additionalVectors);
361 }
362
367 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
369 std::nullopt) override {
370 return ContainerIterator<Particle_T, true, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
371 }
372
377 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
379 std::nullopt) const override {
380 return ContainerIterator<Particle_T, false, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
381 }
382
386 [[nodiscard]] TraversalSelectorInfo getTraversalSelectorInfo() const override {
387 using namespace autopas::utils::ArrayMath::literals;
388
389 // this is a dummy since it is not actually used
390 const std::array<unsigned long, 3> dims = {1, 1, 1};
391 const std::array<double, 3> cellLength = this->getBoxMax() - this->getBoxMin();
392 return TraversalSelectorInfo(dims, this->getInteractionLength(), cellLength, 0);
393 }
394
399 [[nodiscard]] size_t size() const override {
400 return this->_cells[CellTypes::OWNED].size() + this->_cells[CellTypes::HALO].size();
401 }
402
406 [[nodiscard]] size_t getNumberOfParticles(IteratorBehavior behavior) const override {
407 return this->_cells[CellTypes::OWNED].getNumberOfParticles(behavior) +
408 this->_cells[CellTypes::HALO].getNumberOfParticles(behavior);
409 }
410
411 void deleteHaloParticles() override { this->_cells[CellTypes::HALO].clear(); }
412
413 [[nodiscard]] bool cellCanContainHaloParticles(std::size_t i) const override {
414 if (i > 1) {
415 throw std::runtime_error("[Octree.h]: This cell container (octree) contains only two cells");
416 }
417 return i == CellTypes::HALO;
418 }
419
420 [[nodiscard]] bool cellCanContainOwnedParticles(std::size_t i) const override {
421 if (i > 1) {
422 throw std::runtime_error("[Octree.h]: This cell container (octree) contains only two cells");
423 }
424 return i == CellTypes::OWNED;
425 }
426
433 template <typename Lambda>
434 void forEach(Lambda forEachLambda, IteratorBehavior behavior = IteratorBehavior::ownedOrHalo) {
435 if (behavior & IteratorBehavior::owned) this->_cells[OWNED].forEach(forEachLambda);
436 if (behavior & IteratorBehavior::halo) this->_cells[HALO].forEach(forEachLambda);
437 if (not(behavior & IteratorBehavior::ownedOrHalo))
438 utils::ExceptionHandler::exception("Encountered invalid iterator behavior!");
439 }
440
449 template <typename Lambda, typename A>
450 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior = IteratorBehavior::ownedOrHalo) {
451 if (behavior & IteratorBehavior::owned) this->_cells[OWNED].reduce(reduceLambda, result);
452 if (behavior & IteratorBehavior::halo) this->_cells[HALO].reduce(reduceLambda, result);
453 if (not(behavior & IteratorBehavior::ownedOrHalo))
454 utils::ExceptionHandler::exception("Encountered invalid iterator behavior!");
455 }
456
460 template <typename Lambda>
461 void forEachInRegion(Lambda forEachLambda, const std::array<double, 3> &lowerCorner,
462 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
463 if (behavior & IteratorBehavior::owned)
464 this->_cells[OWNED].forEachInRegion(forEachLambda, lowerCorner, higherCorner);
465 if (behavior & IteratorBehavior::halo) this->_cells[HALO].forEachInRegion(forEachLambda, lowerCorner, higherCorner);
466 if (not(behavior & IteratorBehavior::ownedOrHalo))
467 utils::ExceptionHandler::exception("Encountered invalid iterator behavior!");
468 }
469
473 template <typename Lambda, typename A>
474 void reduceInRegion(Lambda reduceLambda, A &result, const std::array<double, 3> &lowerCorner,
475 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
476 if (behavior & IteratorBehavior::owned)
477 this->_cells[OWNED].reduceInRegion(reduceLambda, result, lowerCorner, higherCorner);
478 if (behavior & IteratorBehavior::halo)
479 this->_cells[HALO].reduceInRegion(reduceLambda, result, lowerCorner, higherCorner);
480 if (not(behavior & IteratorBehavior::ownedOrHalo))
481 utils::ExceptionHandler::exception("Encountered invalid iterator behavior!");
482 }
483
484 private:
500 template <bool regionIter>
501 std::tuple<OctreeLeafNode<Particle_T> *, size_t> advanceIteratorIndices(
502 std::vector<size_t> &currentCellIndex, OctreeNodeInterface<Particle_T> *const currentCellPtr,
503 size_t particleIndex, IteratorBehavior iteratorBehavior, const std::array<double, 3> &boxMin,
504 const std::array<double, 3> &boxMax, const std::array<double, 3> &boxMinWithSafetyMargin,
505 const std::array<double, 3> &boxMaxWithSafetyMargin) const {
506 // TODO: parallelize at the higher tree levels. Choose tree level to parallelize via log_8(numThreads)
507 const size_t minLevel = 0;
508 // (iteratorBehavior & IteratorBehavior::forceSequential) or autopas_get_num_threads() == 1
509 // ? 0
510 // : static_cast<size_t>(std::ceil(std::log(static_cast<double>(autopas_get_num_threads())) /
511 // std::log(8.)));
512 OctreeNodeInterface<Particle_T> *currentCellInterfacePtr = currentCellPtr;
513 OctreeLeafNode<Particle_T> *currentLeafCellPtr = nullptr;
514
515 // helper function:
516 auto cellIsRelevant = [&](const OctreeNodeInterface<Particle_T> *const cellPtr) {
517 bool isRelevant = cellPtr->size() > 0;
518 if constexpr (regionIter) {
519 isRelevant = utils::boxesOverlap(cellPtr->getBoxMin(), cellPtr->getBoxMax(), boxMinWithSafetyMargin,
520 boxMaxWithSafetyMargin);
521 }
522 return isRelevant;
523 };
524
525 // find the next particle of interest which might be in a different cell
526 do {
527 // advance to the next particle
528 ++particleIndex;
529
530 // this loop finds the next relevant leaf cell or triggers a return
531 // flag for weird corner cases. See further down.
532 bool forceJumpToNextCell = false;
533 // If this breaches the end of a cell, find the next non-empty cell and reset particleIndex.
534 while (particleIndex >= currentCellInterfacePtr->size() or forceJumpToNextCell) {
535 // CASE: we are at the end of a branch
536 // => Move up until there are siblings that were not touched yet
537 while (currentCellIndex.back() == 7) {
538 currentCellInterfacePtr = currentCellInterfacePtr->getParent();
539 currentCellIndex.pop_back();
540 // If there are no more cells in the branch that we are responsible for set invalid parameters and return.
541 if (currentCellIndex.size() < minLevel or currentCellIndex.empty()) {
542 currentCellIndex.clear();
543 return {nullptr, std::numeric_limits<decltype(particleIndex)>::max()};
544 }
545 }
546
547 // Switch to the next child of the same parent
548 ++currentCellIndex.back();
549 // Identify the next (inner) cell pointer
550 if (currentCellIndex.size() == 1) {
551 // if we are already beyond everything
552 if (currentCellIndex.back() > HALO) {
553 return {nullptr, std::numeric_limits<decltype(particleIndex)>::max()};
554 }
555 // special case: the current thread should ALSO iterate halo particles
556 if ((iteratorBehavior & IteratorBehavior::halo)
557 /* FIXME: for parallelization: and ((iteratorBehavior & IteratorBehavior::forceSequential) or autopas_get_num_threads() == 1) */) {
558 currentCellInterfacePtr = this->_cells[HALO].getRaw();
559 } else {
560 // don't jump to the halo tree -> set invalid parameters and return
561 currentCellIndex.clear();
562 return {nullptr, std::numeric_limits<decltype(particleIndex)>::max()};
563 }
564 } else {
565 currentCellInterfacePtr = currentCellInterfacePtr->getParent()->getChild(currentCellIndex.back());
566 }
567 // check that the inner cell is actually interesting, otherwise skip it.
568 if (not cellIsRelevant(currentCellInterfacePtr)) {
569 forceJumpToNextCell = true;
570 continue;
571 }
572 // The inner cell is relevant so descend to its first relevant leaf
573 forceJumpToNextCell = false;
574 while (currentCellInterfacePtr->hasChildren() and not forceJumpToNextCell) {
575 // find the first child in the relevant region
576 size_t firstRelevantChild = 0;
577 // if the child is irrelevant (empty or outside the region) skip it
578 const auto *childToCheck = currentCellInterfacePtr->getChild(firstRelevantChild);
579 while (not cellIsRelevant(childToCheck)) {
580 ++firstRelevantChild;
581 childToCheck = currentCellInterfacePtr->getChild(firstRelevantChild);
582 if (firstRelevantChild > 7) {
583 // weird corner case: we descended into this branch because it overlaps with the region and has particles
584 // BUT the particles are not inside the children which are in the region,
585 // hence no child fulfills both requirements and all are irrelevant.
586 forceJumpToNextCell = true;
587 break;
588 }
589 }
590 currentCellIndex.push_back(firstRelevantChild);
591 currentCellInterfacePtr = currentCellInterfacePtr->getChild(firstRelevantChild);
592 }
593 particleIndex = 0;
594 }
595
596 // at this point we should point to a leaf. All other cases should have hit a return earlier.
597 currentLeafCellPtr = dynamic_cast<OctreeLeafNode<Particle_T> *>(currentCellInterfacePtr);
598 // sanity check
599 if (currentLeafCellPtr == nullptr) {
600 utils::ExceptionHandler::exception("Expected a leaf node but didn't get one!");
601 }
602
603 } while (not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
604 (*currentLeafCellPtr)[particleIndex], iteratorBehavior, boxMin, boxMax));
605 return {currentLeafCellPtr, particleIndex};
606 }
607
612};
613
614} // namespace autopas
The CellBasedParticleContainer class stores particles in some object and provides methods to iterate ...
Definition: CellBasedParticleContainer.h:25
const std::array< double, 3 > & getBoxMax() const final
Get the upper corner of the container without halo.
Definition: CellBasedParticleContainer.h:74
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
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: CellBasedParticleContainer.h:79
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
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
This interface exists to provide a row interface for octree to add its cells.
Definition: OTTraversalInterface.h:22
An octree leaf node.
Definition: OctreeLeafNode.h:27
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: OctreeLeafNode.h:147
Log an octree to a .vtk file.
Definition: OctreeLogger.h:25
The base class that provides the necessary function definitions that can be applied to an octree.
Definition: OctreeNodeInterface.h:32
virtual OctreeNodeInterface< Particle_T > * getChild(int index)=0
Get a child by its index from the node.
OctreeNodeInterface< Particle_T > * getParent() const
Get the parent node of this node.
Definition: OctreeNodeInterface.h:376
virtual size_t size() const =0
Get the total number of particles saved in the container (owned + halo + dummy).
virtual bool hasChildren()=0
Check if the node is a leaf or an inner node.
This class wraps the functionality provided by the octree leaves and inner nodes in a structure that ...
Definition: OctreeNodeWrapper.h:37
typename ParticleCell::ParticleType ParticleType
The contained particle type.
Definition: OctreeNodeWrapper.h:46
The octree is a CellBasedParticleContainer that consists internally of two octrees.
Definition: Octree.h:41
static constexpr size_t invalidCellIndex
A cell index that is definitely always invalid.
Definition: Octree.h:63
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: Octree.h:461
std::tuple< std::vector< size_t >, OctreeLeafNode< Particle_T > * > getLeafCellByIndex(size_t cellIndex) const
Helper function to retrieve the pointer to a leaf cell as well as properly parse the cell index.
Definition: Octree.h:303
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: Octree.h:376
bool cellCanContainOwnedParticles(std::size_t i) const override
Checks if the cell with the one-dimensional index index1d can contain owned particles.
Definition: Octree.h:420
ContainerIterator< Particle_T, false, false > begin(IteratorBehavior behavior, 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: Octree.h:356
void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override
Reserve memory for a given number of particles in the container and logic layers.
Definition: Octree.h:168
void rebuildNeighborLists(TraversalInterface *traversal) override
Rebuilds the neighbor lists for the next traversals.
Definition: Octree.h:192
bool cellCanContainHaloParticles(std::size_t i) const override
Checks if the cell with the one-dimensional index index1d can contain halo particles.
Definition: Octree.h:413
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior=IteratorBehavior::ownedOrHalo)
Reduce properties of particles as defined by a lambda function.
Definition: Octree.h:450
CellTypes
This particle container contains two cells.
Definition: Octree.h:58
void computeInteractions(TraversalInterface *traversal) override
Iterates over all particle multiples (e.g.
Definition: Octree.h:153
Octree(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, const double cutoff, const double skin, const double cellSizeFactor, const size_t aosSortingThreshold, const size_t soaSortingThreshold)
Construct a new octree with two sub-octrees: One for the owned particles and one for the halo particl...
Definition: Octree.h:75
void addHaloParticleImpl(const ParticleType &haloParticle) override
Adds a particle to the container that lies in the halo region of the container.
Definition: Octree.h:180
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: Octree.h:406
bool updateHaloParticle(const ParticleType &haloParticle) override
Update a halo particle of the container with the given haloParticle.
Definition: Octree.h:187
typename ParticleCellType::ParticleType ParticleType
The particle type used in this container.
Definition: Octree.h:51
void forEach(Lambda forEachLambda, IteratorBehavior behavior=IteratorBehavior::ownedOrHalo)
Execute code on all particles in this container as defined by a lambda function.
Definition: Octree.h:434
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: Octree.h:194
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: Octree.h:399
void deleteHaloParticles() override
Deletes all halo particles.
Definition: Octree.h:411
void addParticleImpl(const ParticleType &p) override
Adds a particle to the container.
Definition: Octree.h:175
std::vector< ParticleType > updateContainer(bool keepNeighborListValid) override
Updates the container.
Definition: Octree.h:111
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: Octree.h:386
std::tuple< const ParticleType *, 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: Octree.h:229
ContainerIterator< Particle_T, true, false > begin(IteratorBehavior behavior, utils::optRef< typename ContainerIterator< Particle_T, true, false >::ParticleVecType > additionalVectors) override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: Octree.h:347
bool deleteParticle(Particle_T &particle) override
Deletes the given particle as long as this does not compromise the validity of the container.
Definition: Octree.h:323
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: Octree.h:366
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: Octree.h:200
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: Octree.h:474
ContainerOption getContainerType() const override
Get the ContainerType.
Definition: Octree.h:166
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: Octree.h:334
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
virtual void endTraversal()=0
Finalizes the traversal.
virtual void traverseParticles()=0
Traverse the particles by pairs, triplets etc.
virtual void initTraversal()=0
Initializes the traversal.
Info for traversals of a specific container.
Definition: TraversalSelectorInfo.h:14
Interface class to handle cell borders and cell types of cells.
Definition: CellBorderAndFlagManager.h:17
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 checkParticleInCellAndUpdateByIDAndPosition(CellType &cell, const typename CellType::ParticleType &particle, double absError)
Same as checkParticleInCellAndUpdateByID(CellType, ParticleType), but additionally checks whether the...
Definition: ParticleCellHelpers.h:39
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 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
@ halo
Halo state, a particle with this state is an actual particle, but not owned by the current AutoPas ob...
@ owned
Owned state, a particle with this state is an actual particle and owned by the current AutoPas object...
int autopas_get_thread_num()
Dummy for omp_set_lock() when no OpenMP is available.
Definition: WrapOpenMP.h:132