36template <
typename Particle_T>
62 int unsigned const treeSplitThreshold,
double const interactionLength,
63 double const cellSizeFactor) {
64 _pointer = std::make_unique<OctreeLeafNode<Particle_T>>(boxMin, boxMax,
nullptr, treeSplitThreshold,
65 interactionLength, cellSizeFactor);
73 std::lock_guard<AutoPasLock> lock(_lock);
74 _pointer->collectAllParticles(ps);
88 std::lock_guard<AutoPasLock> lock(_lock);
90 auto ret = _pointer->insert(p);
91 if (ret) _pointer = std::move(ret);
93 ++_enclosedParticleCount;
103 std::lock_guard<AutoPasLock> lock(_lock);
105 _pointer->collectAllParticles(_ps);
114 std::lock_guard<AutoPasLock> lock(_lock);
116 _pointer->collectAllParticles(_ps);
134 [[nodiscard]]
size_t size()
const override {
135 std::lock_guard<AutoPasLock> lock(_lock);
136 return _enclosedParticleCount;
143 std::lock_guard<AutoPasLock> lock(_lock);
144 return _pointer->getNumberOfParticles(behavior);
152 std::lock_guard<AutoPasLock> lock(_lock);
153 return _enclosedParticleCount == 0;
160 std::lock_guard<AutoPasLock> lock(_lock);
161 _pointer->clearChildren(_pointer);
162 _enclosedParticleCount = 0;
183 --_enclosedParticleCount;
185 return _pointer->deleteParticle(particle);
193 throw std::runtime_error(
"[OctreeNodeWrapper::deleteByIndex()] Operation not supported");
201 throw std::runtime_error(
"[OctreeNodeWrapper::setCellLength()] Operation not supported");
209 using namespace autopas::utils::ArrayMath::literals;
210 return _pointer->getBoxMin() - _pointer->getBoxMax();
219 Particle_T &
at(
size_t index) {
220 std::lock_guard<AutoPasLock> lock(_lock);
221 return _ps.at(index);
230 const Particle_T &
at(
size_t index)
const {
231 std::lock_guard<AutoPasLock> lock(_lock);
232 return _ps.at(index);
242 std::lock_guard<AutoPasLock> lock(_lock);
253 std::lock_guard<AutoPasLock> lock(_lock);
264 const std::array<double, 3> &max) {
265 return _pointer->getLeavesInRange(min, max);
281 template <
typename Lambda>
294 template <
typename Lambda,
typename A>
295 void reduce(Lambda reduceLambda, A &result) {
296 withStaticNodeType(_pointer, [&](
auto nodePtr) { nodePtr->reduce(reduceLambda, result); });
307 template <
typename Lambda>
309 const std::array<double, 3> &higherCorner) {
313 nodePtr->forEach(forEachLambda, lowerCorner, higherCorner, IteratorBehavior::ownedOrHalo);
327 template <
typename Lambda,
typename A>
328 void reduceInRegion(Lambda reduceLambda, A &result,
const std::array<double, 3> &lowerCorner,
329 const std::array<double, 3> &higherCorner) {
333 nodePtr->reduce(reduceLambda, result, lowerCorner, higherCorner, IteratorBehavior::ownedOrHalo);
341 std::unique_ptr<OctreeNodeInterface<Particle_T>> _pointer;
361 long _enclosedParticleCount{0L};
Wraps the iterator of arbitrary cells to provide a common interface.
Definition: CellIterator.h:19
AutoPasLock for the sequential case.
Definition: WrapOpenMP.h:155
An octree leaf node.
Definition: OctreeLeafNode.h:27
The base class that provides the necessary function definitions that can be applied to an octree.
Definition: OctreeNodeInterface.h:32
This class wraps the functionality provided by the octree leaves and inner nodes in a structure that ...
Definition: OctreeNodeWrapper.h:37
void appendAllLeaves(std::vector< OctreeLeafNode< Particle_T > * > &leaves)
Append all leaves in the octree to a list.
Definition: OctreeNodeWrapper.h:81
std::array< double, 3 > getCellLength() const override
Get the side lengths of this cell.
Definition: OctreeNodeWrapper.h:208
Particle_T & operator[](size_t index)
Get a particle from the iterator.
Definition: OctreeNodeWrapper.h:241
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: OctreeNodeWrapper.h:142
void clear() override
Deletes all particles in this cell.
Definition: OctreeNodeWrapper.h:159
void reduceInRegion(Lambda reduceLambda, A &result, const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner)
Apply the reduce lambda to each particle in the region.
Definition: OctreeNodeWrapper.h:328
CellType getParticleCellTypeAsEnum() override
Get the ParticleCell type as an ParticleCellTypeEnum.
Definition: OctreeNodeWrapper.h:174
bool isEmpty() const override
Check if the cell is not empty.
Definition: OctreeNodeWrapper.h:151
const Particle_T & operator[](size_t index) const
Get a particle from the iterator.
Definition: OctreeNodeWrapper.h:252
std::set< OctreeLeafNode< Particle_T > * > getLeavesInRange(const std::array< double, 3 > &min, const std::array< double, 3 > &max)
Find all leaves below this subtree that are in the given range.
Definition: OctreeNodeWrapper.h:263
void reduce(Lambda reduceLambda, A &result)
Apply the reduce lambda to each particle.
Definition: OctreeNodeWrapper.h:295
bool deleteParticle(Particle_T &particle)
Delete the given particle from the data structure.
Definition: OctreeNodeWrapper.h:182
CellIterator< StorageType, false > begin() const
Get an iterator to the start of a ParticleCell.
Definition: OctreeNodeWrapper.h:113
void setCellLength(std::array< double, 3 > &cellLength) override
Set the side lengths of this cell.
Definition: OctreeNodeWrapper.h:200
void collectAllParticles(StorageType &ps)
Append all particles in the octree to a list using DFS.
Definition: OctreeNodeWrapper.h:72
CellIterator< StorageType, false > end() const
Get an iterator to the end of a ParticleCell.
Definition: OctreeNodeWrapper.h:128
OctreeNodeWrapper(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, int unsigned const treeSplitThreshold, double const interactionLength, double const cellSizeFactor)
Constructs a new, empty octree and stores the root.
Definition: OctreeNodeWrapper.h:61
size_t size() const override
Get the number of all particles stored in this cell (owned, halo and dummy).
Definition: OctreeNodeWrapper.h:134
void forEach(Lambda forEachLambda)
Apply the forEach lambda to each particle.
Definition: OctreeNodeWrapper.h:282
const Particle_T & at(size_t index) const
Get a particle from the iterator.
Definition: OctreeNodeWrapper.h:230
void deleteDummyParticles() override
Deletes all dummy particles in this cell.
Definition: OctreeNodeWrapper.h:168
CellIterator< StorageType, true > end()
Get an iterator to the end of a ParticleCell.
Definition: OctreeNodeWrapper.h:123
CellIterator< StorageType, true > begin()
Get an iterator to the start of a ParticleCell.
Definition: OctreeNodeWrapper.h:102
void deleteByIndex(size_t index) override
Deletes the index-th particle.
Definition: OctreeNodeWrapper.h:192
Particle_T & at(size_t index)
Get a particle from the iterator.
Definition: OctreeNodeWrapper.h:219
std::vector< Particle_T * > StorageType
Type that holds or refers to the actual particles.
Definition: OctreeNodeWrapper.h:50
OctreeNodeInterface< Particle_T > * getRaw() const
Get a raw pointer to the enclosed cell.
Definition: OctreeNodeWrapper.h:273
void addParticle(const Particle_T &p) override
Adds a Particle to the cell.
Definition: OctreeNodeWrapper.h:87
void forEachInRegion(Lambda forEachLambda, const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner)
Apply the forEach lambda to each particle in the region.
Definition: OctreeNodeWrapper.h:308
typename ParticleCell::ParticleType ParticleType
The contained particle type.
Definition: OctreeNodeWrapper.h:46
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.
decltype(auto) withStaticNodeType(const std::unique_ptr< OctreeNodeInterface< Particle_T > > &root, FunctionType &&function)
Will execute the passed function on the given root node.
Definition: OctreeStaticNodeSelector.h:29