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
74 Octree(const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax, const double cutoff,
75 const double skin, const unsigned int rebuildFrequency, const double cellSizeFactor)
76 : CellBasedParticleContainer<ParticleCell>(boxMin, boxMax, cutoff, skin, rebuildFrequency) {
77 using namespace autopas::utils::ArrayMath::literals;
78
79 // @todo Obtain this from a configuration, reported in https://github.com/AutoPas/AutoPas/issues/624
80 int unsigned treeSplitThreshold = 16;
81
82 double interactionLength = this->getInteractionLength();
83
84 // Create the octree for the owned particles
85 this->_cells.push_back(
86 OctreeNodeWrapper<Particle_T>(boxMin, boxMax, treeSplitThreshold, interactionLength, cellSizeFactor));
87
88 // Extend the halo region with cutoff + skin in all dimensions
89 auto haloBoxMin = boxMin - interactionLength;
90 auto haloBoxMax = boxMax + interactionLength;
91 // Create the octree for the halo particles
92 this->_cells.push_back(
93 OctreeNodeWrapper<Particle_T>(haloBoxMin, haloBoxMax, treeSplitThreshold, interactionLength, cellSizeFactor));
94
95 // set type of particles in the two cells
96 this->_cells[CellTypes::OWNED].setPossibleParticleOwnerships(OwnershipState::owned);
97 this->_cells[CellTypes::HALO].setPossibleParticleOwnerships(OwnershipState::halo);
98 }
99
100 [[nodiscard]] std::vector<ParticleType> updateContainer(bool keepNeighborListValid) override {
101 // invalidParticles: all outside boxMin/Max
102 std::vector<Particle_T> invalidParticles{};
103
104 if (keepNeighborListValid) {
106 } else {
107 // This is a very primitive and inefficient way to rebuild the container:
108
109 // @todo Make this less indirect. (Find a better way to iterate all particles inside the octree to change
110 // this function back to a function that actually copies all particles out of the octree.)
111 // The problem is captured by https://github.com/AutoPas/AutoPas/issues/622
112
113 // 1. Copy all particles out of the container
114 std::vector<Particle_T *> particleRefs;
115 this->_cells[CellTypes::OWNED].collectAllParticles(particleRefs);
116 std::vector<Particle_T> particles{};
117 particles.reserve(particleRefs.size());
118
119 for (auto *p : particleRefs) {
120 if (p->isDummy()) {
121 // don't do anything with dummies. They will just be dropped when the container is rebuilt.
122 continue;
123 } else if (utils::inBox(p->getR(), this->getBoxMin(), this->getBoxMax())) {
124 particles.push_back(*p);
125 } else {
126 invalidParticles.push_back(*p);
127 }
128 }
129
130 // 2. Clear the container
131 this->deleteAllParticles();
132
133 // 3. Insert the particles back into the container
134 for (auto &particle : particles) {
135 addParticleImpl(particle);
136 }
137 }
138
139 return invalidParticles;
140 }
141
142 void computeInteractions(TraversalInterface *traversal) override {
143 if (auto *traversalInterface = dynamic_cast<OTTraversalInterface<ParticleCell> *>(traversal)) {
144 traversalInterface->setCells(&this->_cells);
145 }
146
147 traversal->initTraversal();
148 traversal->traverseParticles();
149 traversal->endTraversal();
150 }
151
155 [[nodiscard]] ContainerOption getContainerType() const override { return ContainerOption::octree; }
156
163 [[nodiscard]] CellType getParticleCellTypeEnum() const override { return CellType::FullParticleCell; }
164
165 void reserve(size_t numParticles, size_t numParticlesHaloEstimate) override {
166 // TODO create a balanced tree and reserve space in the leaves.
167 }
168
172 void addParticleImpl(const ParticleType &p) override { this->_cells[CellTypes::OWNED].addParticle(p); }
173
177 void addHaloParticleImpl(const ParticleType &haloParticle) override {
178 this->_cells[CellTypes::HALO].addParticle(haloParticle);
179 }
180
184 bool updateHaloParticle(const ParticleType &haloParticle) override {
185 return internal::checkParticleInCellAndUpdateByIDAndPosition(this->_cells[CellTypes::HALO], haloParticle,
186 this->getVerletSkin());
187 }
188
189 void rebuildNeighborLists(TraversalInterface *traversal) override {}
190
191 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
192 IteratorBehavior iteratorBehavior,
193 const std::array<double, 3> &boxMin,
194 const std::array<double, 3> &boxMax) const override {
195 return getParticleImpl<true>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
196 }
197 std::tuple<const Particle_T *, size_t, size_t> getParticle(size_t cellIndex, size_t particleIndex,
198 IteratorBehavior iteratorBehavior) const override {
199 // this is not a region iter hence we stretch the bounding box to the numeric max
200 constexpr std::array<double, 3> boxMin{std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(),
201 std::numeric_limits<double>::lowest()};
202
203 constexpr std::array<double, 3> boxMax{std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
204 std::numeric_limits<double>::max()};
205 return getParticleImpl<false>(cellIndex, particleIndex, iteratorBehavior, boxMin, boxMax);
206 }
207
225 template <bool regionIter>
226 std::tuple<const ParticleType *, size_t, size_t> getParticleImpl(size_t cellIndex, size_t particleIndex,
227 IteratorBehavior iteratorBehavior,
228 const std::array<double, 3> &boxMin,
229 const std::array<double, 3> &boxMax) const {
230 using namespace autopas::utils::ArrayMath::literals;
231 // FIXME think about parallelism.
232 // This `if` currently disables it but should be replaced with logic that determines the start index.
233 if (autopas_get_thread_num() > 0 and not(iteratorBehavior & IteratorBehavior::forceSequential)) {
234 return {nullptr, 0, 0};
235 }
236 // if owned particles are not interesting jump directly to the halo tree
237 // FIXME: with num threads > 1 the start cell IDs will have to be set to more complicated values here
238 if (cellIndex == 0 and not(iteratorBehavior & IteratorBehavior::owned)) {
239 cellIndex = HALO;
240 }
241
242 // shortcut if the given index doesn't exist
243 if (cellIndex < 10 and cellIndex > HALO) {
244 return {nullptr, 0, 0};
245 }
246
247 std::array<double, 3> boxMinWithSafetyMargin = boxMin;
248 std::array<double, 3> boxMaxWithSafetyMargin = boxMax;
249 if constexpr (regionIter) {
250 // We extend the search box for cells here since particles might have moved
251 boxMinWithSafetyMargin -= 0.5 * this->getVerletSkin();
252 boxMaxWithSafetyMargin += 0.5 * this->getVerletSkin();
253 }
254
255 std::vector<size_t> currentCellIndex{};
256 OctreeLeafNode<Particle_T> *currentCellPtr = nullptr;
257
258 std::tie(currentCellIndex, currentCellPtr) = getLeafCellByIndex(cellIndex);
259 // check the data behind the indices
260 if (particleIndex >= currentCellPtr->size() or
261 not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
262 (*currentCellPtr)[particleIndex], iteratorBehavior, boxMin, boxMax)) {
263 // either advance them to something interesting or invalidate them.
264 std::tie(currentCellPtr, particleIndex) =
265 advanceIteratorIndices<regionIter>(currentCellIndex, currentCellPtr, particleIndex, iteratorBehavior, boxMin,
266 boxMax, boxMinWithSafetyMargin, boxMaxWithSafetyMargin);
267 }
268
269 // shortcut if the given index doesn't exist
270 if (currentCellPtr == nullptr) {
271 return {nullptr, 0, 0};
272 }
273 // parse cellIndex and get referenced cell and particle
274 const Particle_T *retPtr = &((*currentCellPtr)[particleIndex]);
275
276 // if no err value was set, convert cell index from vec to integer
277 if (currentCellIndex.empty()) {
278 cellIndex = invalidCellIndex;
279 } else {
280 cellIndex = 0;
281 // needs signed int to prevent underflow
282 for (int i = static_cast<int>(currentCellIndex.size()) - 1; i >= 0; --i) {
283 cellIndex *= 10;
284 cellIndex += currentCellIndex[i];
285 }
286 }
287
288 return {retPtr, cellIndex, particleIndex};
289 }
290
300 std::tuple<std::vector<size_t>, OctreeLeafNode<Particle_T> *> getLeafCellByIndex(size_t cellIndex) const {
301 // parse cellIndex and get referenced cell and particle
302 std::vector<size_t> currentCellIndex;
303 // constant heuristic for the tree depth
304 currentCellIndex.reserve(10);
305 currentCellIndex.push_back(cellIndex % 10);
306 cellIndex /= 10;
307 OctreeNodeInterface<Particle_T> *currentCell = this->_cells[currentCellIndex.back()].getRaw();
308 // don't restrict loop via cellIndex because it might have "hidden" leading 0
309 while (currentCell->hasChildren()) {
310 currentCellIndex.push_back(cellIndex % 10);
311 cellIndex /= 10;
312 currentCell = currentCell->getChild(currentCellIndex.back());
313 }
314 return {currentCellIndex, dynamic_cast<OctreeLeafNode<Particle_T> *>(currentCell)};
315 }
316
320 bool deleteParticle(Particle_T &particle) override {
321 if (particle.isOwned()) {
322 return this->_cells[CellTypes::OWNED].deleteParticle(particle);
323 } else if (particle.isHalo()) {
324 return this->_cells[CellTypes::HALO].deleteParticle(particle);
325 } else {
326 utils::ExceptionHandler::exception("Particle to be deleted is neither owned nor halo!\n" + particle.toString());
327 return false;
328 }
329 }
330
331 bool deleteParticle(size_t cellIndex, size_t particleIndex) override {
332 auto [cellIndexVector, cell] = getLeafCellByIndex(cellIndex);
333 auto &particleVec = cell->_particles;
334 auto &particle = particleVec[particleIndex];
335 // swap-delete
336 particle = particleVec.back();
337 particleVec.pop_back();
338 return particleIndex < particleVec.size();
339 }
340
345 IteratorBehavior behavior,
346 typename ContainerIterator<Particle_T, true, false>::ParticleVecType *additionalVectors = nullptr) override {
347 return ContainerIterator<Particle_T, true, false>(*this, behavior, additionalVectors);
348 }
349
354 IteratorBehavior behavior,
356 nullptr) const override {
357 return ContainerIterator<Particle_T, false, false>(*this, behavior, additionalVectors);
358 }
359
364 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
365 typename ContainerIterator<Particle_T, true, true>::ParticleVecType *additionalVectors = nullptr) override {
366 return ContainerIterator<Particle_T, true, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
367 }
368
373 const std::array<double, 3> &lowerCorner, const std::array<double, 3> &higherCorner, IteratorBehavior behavior,
375 nullptr) const override {
376 return ContainerIterator<Particle_T, false, true>(*this, behavior, additionalVectors, lowerCorner, higherCorner);
377 }
378
382 [[nodiscard]] TraversalSelectorInfo getTraversalSelectorInfo() const override {
383 using namespace autopas::utils::ArrayMath::literals;
384
385 // this is a dummy since it is not actually used
386 const std::array<unsigned long, 3> dims = {1, 1, 1};
387 const std::array<double, 3> cellLength = this->getBoxMax() - this->getBoxMin();
388 return TraversalSelectorInfo(dims, this->getInteractionLength(), cellLength, 0);
389 }
390
395 [[nodiscard]] size_t size() const override {
396 return this->_cells[CellTypes::OWNED].size() + this->_cells[CellTypes::HALO].size();
397 }
398
402 [[nodiscard]] size_t getNumberOfParticles(IteratorBehavior behavior) const override {
403 return this->_cells[CellTypes::OWNED].getNumberOfParticles(behavior) +
404 this->_cells[CellTypes::HALO].getNumberOfParticles(behavior);
405 }
406
407 void deleteHaloParticles() override { this->_cells[CellTypes::HALO].clear(); }
408
409 [[nodiscard]] bool cellCanContainHaloParticles(std::size_t i) const override {
410 if (i > 1) {
411 throw std::runtime_error("[Octree.h]: This cell container (octree) contains only two cells");
412 }
413 return i == CellTypes::HALO;
414 }
415
416 [[nodiscard]] bool cellCanContainOwnedParticles(std::size_t i) const override {
417 if (i > 1) {
418 throw std::runtime_error("[Octree.h]: This cell container (octree) contains only two cells");
419 }
420 return i == CellTypes::OWNED;
421 }
422
429 template <typename Lambda>
430 void forEach(Lambda forEachLambda, IteratorBehavior behavior = IteratorBehavior::ownedOrHalo) {
431 if (behavior & IteratorBehavior::owned) this->_cells[OWNED].forEach(forEachLambda);
432 if (behavior & IteratorBehavior::halo) this->_cells[HALO].forEach(forEachLambda);
433 if (not(behavior & IteratorBehavior::ownedOrHalo))
434 utils::ExceptionHandler::exception("Encountered invalid iterator behavior!");
435 }
436
445 template <typename Lambda, typename A>
446 void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior = IteratorBehavior::ownedOrHalo) {
447 if (behavior & IteratorBehavior::owned) this->_cells[OWNED].reduce(reduceLambda, result);
448 if (behavior & IteratorBehavior::halo) this->_cells[HALO].reduce(reduceLambda, result);
449 if (not(behavior & IteratorBehavior::ownedOrHalo))
450 utils::ExceptionHandler::exception("Encountered invalid iterator behavior!");
451 }
452
456 template <typename Lambda>
457 void forEachInRegion(Lambda forEachLambda, const std::array<double, 3> &lowerCorner,
458 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
459 if (behavior & IteratorBehavior::owned)
460 this->_cells[OWNED].forEachInRegion(forEachLambda, lowerCorner, higherCorner);
461 if (behavior & IteratorBehavior::halo) this->_cells[HALO].forEachInRegion(forEachLambda, lowerCorner, higherCorner);
462 if (not(behavior & IteratorBehavior::ownedOrHalo))
463 utils::ExceptionHandler::exception("Encountered invalid iterator behavior!");
464 }
465
469 template <typename Lambda, typename A>
470 void reduceInRegion(Lambda reduceLambda, A &result, const std::array<double, 3> &lowerCorner,
471 const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
472 if (behavior & IteratorBehavior::owned)
473 this->_cells[OWNED].reduceInRegion(reduceLambda, result, lowerCorner, higherCorner);
474 if (behavior & IteratorBehavior::halo)
475 this->_cells[HALO].reduceInRegion(reduceLambda, result, lowerCorner, higherCorner);
476 if (not(behavior & IteratorBehavior::ownedOrHalo))
477 utils::ExceptionHandler::exception("Encountered invalid iterator behavior!");
478 }
479
480 private:
496 template <bool regionIter>
497 std::tuple<OctreeLeafNode<Particle_T> *, size_t> advanceIteratorIndices(
498 std::vector<size_t> &currentCellIndex, OctreeNodeInterface<Particle_T> *const currentCellPtr,
499 size_t particleIndex, IteratorBehavior iteratorBehavior, const std::array<double, 3> &boxMin,
500 const std::array<double, 3> &boxMax, const std::array<double, 3> &boxMinWithSafetyMargin,
501 const std::array<double, 3> &boxMaxWithSafetyMargin) const {
502 // TODO: parallelize at the higher tree levels. Choose tree level to parallelize via log_8(numThreads)
503 const size_t minLevel = 0;
504 // (iteratorBehavior & IteratorBehavior::forceSequential) or autopas_get_num_threads() == 1
505 // ? 0
506 // : static_cast<size_t>(std::ceil(std::log(static_cast<double>(autopas_get_num_threads())) /
507 // std::log(8.)));
508 OctreeNodeInterface<Particle_T> *currentCellInterfacePtr = currentCellPtr;
509 OctreeLeafNode<Particle_T> *currentLeafCellPtr = nullptr;
510
511 // helper function:
512 auto cellIsRelevant = [&](const OctreeNodeInterface<Particle_T> *const cellPtr) {
513 bool isRelevant = cellPtr->size() > 0;
514 if constexpr (regionIter) {
515 isRelevant = utils::boxesOverlap(cellPtr->getBoxMin(), cellPtr->getBoxMax(), boxMinWithSafetyMargin,
516 boxMaxWithSafetyMargin);
517 }
518 return isRelevant;
519 };
520
521 // find the next particle of interest which might be in a different cell
522 do {
523 // advance to the next particle
524 ++particleIndex;
525
526 // this loop finds the next relevant leaf cell or triggers a return
527 // flag for weird corner cases. See further down.
528 bool forceJumpToNextCell = false;
529 // If this breaches the end of a cell, find the next non-empty cell and reset particleIndex.
530 while (particleIndex >= currentCellInterfacePtr->size() or forceJumpToNextCell) {
531 // CASE: we are at the end of a branch
532 // => Move up until there are siblings that were not touched yet
533 while (currentCellIndex.back() == 7) {
534 currentCellInterfacePtr = currentCellInterfacePtr->getParent();
535 currentCellIndex.pop_back();
536 // If there are no more cells in the branch that we are responsible for set invalid parameters and return.
537 if (currentCellIndex.size() < minLevel or currentCellIndex.empty()) {
538 currentCellIndex.clear();
539 return {nullptr, std::numeric_limits<decltype(particleIndex)>::max()};
540 }
541 }
542
543 // Switch to the next child of the same parent
544 ++currentCellIndex.back();
545 // Identify the next (inner) cell pointer
546 if (currentCellIndex.size() == 1) {
547 // if we are already beyond everything
548 if (currentCellIndex.back() > HALO) {
549 return {nullptr, std::numeric_limits<decltype(particleIndex)>::max()};
550 }
551 // special case: the current thread should ALSO iterate halo particles
552 if ((iteratorBehavior & IteratorBehavior::halo)
553 /* FIXME: for parallelization: and ((iteratorBehavior & IteratorBehavior::forceSequential) or autopas_get_num_threads() == 1) */) {
554 currentCellInterfacePtr = this->_cells[HALO].getRaw();
555 } else {
556 // don't jump to the halo tree -> set invalid parameters and return
557 currentCellIndex.clear();
558 return {nullptr, std::numeric_limits<decltype(particleIndex)>::max()};
559 }
560 } else {
561 currentCellInterfacePtr = currentCellInterfacePtr->getParent()->getChild(currentCellIndex.back());
562 }
563 // check that the inner cell is actually interesting, otherwise skip it.
564 if (not cellIsRelevant(currentCellInterfacePtr)) {
565 forceJumpToNextCell = true;
566 continue;
567 }
568 // The inner cell is relevant so descend to its first relevant leaf
569 forceJumpToNextCell = false;
570 while (currentCellInterfacePtr->hasChildren() and not forceJumpToNextCell) {
571 // find the first child in the relevant region
572 size_t firstRelevantChild = 0;
573 // if the child is irrelevant (empty or outside the region) skip it
574 const auto *childToCheck = currentCellInterfacePtr->getChild(firstRelevantChild);
575 while (not cellIsRelevant(childToCheck)) {
576 ++firstRelevantChild;
577 childToCheck = currentCellInterfacePtr->getChild(firstRelevantChild);
578 if (firstRelevantChild > 7) {
579 // weird corner case: we descended into this branch because it overlaps with the region and has particles
580 // BUT the particles are not inside the children which are in the region,
581 // hence no child fulfills both requirements and all are irrelevant.
582 forceJumpToNextCell = true;
583 break;
584 }
585 }
586 currentCellIndex.push_back(firstRelevantChild);
587 currentCellInterfacePtr = currentCellInterfacePtr->getChild(firstRelevantChild);
588 }
589 particleIndex = 0;
590 }
591
592 // at this point we should point to a leaf. All other cases should have hit a return earlier.
593 currentLeafCellPtr = dynamic_cast<OctreeLeafNode<Particle_T> *>(currentCellInterfacePtr);
594 // sanity check
595 if (currentLeafCellPtr == nullptr) {
596 utils::ExceptionHandler::exception("Expected a leaf node but didn't get one!");
597 }
598
599 } while (not containerIteratorUtils::particleFulfillsIteratorRequirements<regionIter>(
600 (*currentLeafCellPtr)[particleIndex], iteratorBehavior, boxMin, boxMax));
601 return {currentLeafCellPtr, particleIndex};
602 }
603
608
609 double skin;
610};
611
612} // namespace autopas
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< OctreeNodeWrapper< Particle_T > > _cells
Vector of particle cells.
Definition: CellBasedParticleContainer.h:157
const std::array< double, 3 > & getBoxMin() const final
Get the lower corner of the container without halo.
Definition: CellBasedParticleContainer.h:74
const std::array< double, 3 > & getBoxMax() const final
Get the upper corner of the container without halo.
Definition: CellBasedParticleContainer.h:69
void deleteAllParticles() override
Deletes all particles from the container.
Definition: CellBasedParticleContainer.h:99
Public iterator class that iterates over a particle container and additional vectors (which are typic...
Definition: ContainerIterator.h:93
std::conditional_t< modifiable, std::vector< std::vector< Particle_T > * >, std::vector< std::vector< Particle_T > const * > > ParticleVecType
Type of the additional vector collection.
Definition: ContainerIterator.h:106
This 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:457
CellType getParticleCellTypeEnum() const override
Get the ParticleCell type as an Enum.
Definition: Octree.h:163
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:300
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:416
Octree(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)
Construct a new octree with two sub-octrees: One for the owned particles and one for the halo particl...
Definition: Octree.h:74
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:165
void rebuildNeighborLists(TraversalInterface *traversal) override
Rebuilds the neighbor lists for the next traversals.
Definition: Octree.h:189
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:409
void reduce(Lambda reduceLambda, A &result, IteratorBehavior behavior=IteratorBehavior::ownedOrHalo)
Reduce properties of particles as defined by a lambda function.
Definition: Octree.h:446
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:142
void addHaloParticleImpl(const ParticleType &haloParticle) override
Adds a particle to the container that lies in the halo region of the container.
Definition: Octree.h:177
ContainerIterator< Particle_T, true, false > begin(IteratorBehavior behavior, typename ContainerIterator< Particle_T, true, false >::ParticleVecType *additionalVectors=nullptr) override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: Octree.h:344
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: Octree.h:402
bool updateHaloParticle(const ParticleType &haloParticle) override
Update a halo particle of the container with the given haloParticle.
Definition: Octree.h:184
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:430
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:191
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: Octree.h:395
void deleteHaloParticles() override
Deletes all halo particles.
Definition: Octree.h:407
void addParticleImpl(const ParticleType &p) override
Adds a particle to the container.
Definition: Octree.h:172
std::vector< ParticleType > updateContainer(bool keepNeighborListValid) override
Updates the container.
Definition: Octree.h:100
TraversalSelectorInfo getTraversalSelectorInfo() const override
Generates a traversal selector info for this container.
Definition: Octree.h:382
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:226
ContainerIterator< Particle_T, false, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, typename ContainerIterator< Particle_T, false, true >::ParticleVecType *additionalVectors=nullptr) const override
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
Definition: Octree.h:372
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:320
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:197
typename ParticleCell::ParticleType ParticleType
The particle type used in this container.
Definition: Octree.h:51
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:470
ContainerIterator< Particle_T, false, false > begin(IteratorBehavior behavior, typename ContainerIterator< Particle_T, false, false >::ParticleVecType *additionalVectors=nullptr) const override
Iterate over all particles using for(auto iter = container.begin(); iter.isValid(); ++iter) .
Definition: Octree.h:353
ContainerOption getContainerType() const override
Get the ContainerType.
Definition: Octree.h:155
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:331
ContainerIterator< Particle_T, true, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior, typename ContainerIterator< Particle_T, true, true >::ParticleVecType *additionalVectors=nullptr) override
Iterate over all particles in a specified region for(auto iter = container.getRegionIterator(lowCorne...
Definition: Octree.h:363
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:63
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
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
CellType
The ParticleCell Type as an Enum.
Definition: ParticleCell.h:19
@ FullParticleCell
FullParticleCell : Default cell type for almost everything.
@ 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