18template <
typename Particle_T>
26template <
typename Particle_T>
38 OctreeLeafNode(
const std::array<double, 3> &boxMin,
const std::array<double, 3> &boxMax,
40 const double interactionLength,
const double cellSizeFactor)
41 :
OctreeNodeInterface<Particle_T>(boxMin, boxMax, parent, treeSplitThreshold, interactionLength, cellSizeFactor),
62 std::unique_ptr<OctreeNodeInterface<Particle_T>>
insert(
const Particle_T &p)
override {
63 using namespace autopas::utils::ArrayMath::literals;
67 splitLeafDimensions *= 0.5;
68 bool anyNewDimSmallerThanMinSize =
false;
69 for (
auto d = 0; d < 3; ++d) {
76 anyNewDimSmallerThanMinSize =
true;
81 if ((this->
_particles.size() < this->_treeSplitThreshold) or anyNewDimSmallerThanMinSize) {
84 if ((not
toInt64(p.getOwnershipState() & this->_ownershipState)) and
87 "OctreeLeafNode::insert() can not add a particle with OwnershipState {} to a cell with "
89 p.getOwnershipState(), this->_ownershipState);
96 std::unique_ptr<OctreeNodeInterface<Particle_T>> newInner = std::make_unique<OctreeInnerNode<Particle_T>>(
99 auto ret = newInner->insert(p);
100 if (ret) newInner = std::move(ret);
101 for (
auto cachedParticle : this->
_particles) {
102 ret = newInner->insert(cachedParticle);
103 if (ret) newInner = std::move(ret);
111 const bool isRearParticle = &particle == &this->
_particles.back();
116 return not isRearParticle;
123 ps.reserve(ps.size() + this->_particles.size());
127 ps.push_back((Particle_T *)&particle);
134 void appendAllLeafBoxes(std::vector<std::pair<std::array<double, 3>, std::array<double, 3>>> &boxes)
const override {
136 boxes.push_back(minMax);
153 return std::count_if(this->
_particles.begin(), this->_particles.end(),
154 [&behavior](
auto p) { return behavior.contains(p); });
166 throw std::runtime_error(
"[OctreeLeafNode::getChild()] Unable to return child by index in leaf");
170 const std::vector<octree::Vertex> &directions)
override {
175 throw std::runtime_error(
"Unable to get SON of leaf node");
183 const std::array<double, 3> &max)
override {
201 void setID(
int id) { this->_id = id; }
This class handles the storage of particles in their full form.
Definition: FullParticleCell.h:26
StorageType _particles
Storage of the molecules of the cell.
Definition: FullParticleCell.h:274
An octree leaf node.
Definition: OctreeLeafNode.h:27
OctreeLeafNode(OctreeLeafNode< Particle_T > const &other)
Copy a leaf by copying all particles from the other leaf to this leaf.
Definition: OctreeLeafNode.h:48
void setID(int id)
Set the ID of this node.
Definition: OctreeLeafNode.h:201
size_t getNumberOfParticles(IteratorBehavior behavior) const override
Get the number of particles with respect to the specified IteratorBehavior.
Definition: OctreeLeafNode.h:152
void collectAllParticles(std::vector< Particle_T * > &ps) const override
Put all particles that are below this node into the vector.
Definition: OctreeLeafNode.h:122
bool deleteParticle(Particle_T &particle) override
Delete the given particle from the data structure.
Definition: OctreeLeafNode.h:110
int getID()
Get the assigned id of this leaf node.
Definition: OctreeLeafNode.h:195
void appendAllLeafBoxes(std::vector< std::pair< std::array< double, 3 >, std::array< double, 3 > > > &boxes) const override
Put the min/max corner coordinates of every leaf into the vector.
Definition: OctreeLeafNode.h:134
void appendAllLeaves(std::vector< OctreeLeafNode< Particle_T > * > &leaves) const override
Put all leaves below this subtree into a given list.
Definition: OctreeLeafNode.h:178
OctreeNodeInterface< Particle_T > * SON(octree::Octant O) override
Get a child node of this node (if there are children) given a specific octant using the spacial struc...
Definition: OctreeLeafNode.h:174
std::unique_ptr< OctreeNodeInterface< Particle_T > > insert(const Particle_T &p) override
Insert a particle into the octree.
Definition: OctreeLeafNode.h:62
std::set< OctreeLeafNode< Particle_T > * > getLeavesInRange(const std::array< double, 3 > &min, const std::array< double, 3 > &max) override
Find all leaves below this subtree that are in the given range.
Definition: OctreeLeafNode.h:182
std::vector< OctreeLeafNode< Particle_T > * > getLeavesFromDirections(const std::vector< octree::Vertex > &directions) override
Find all leaf nodes along a list of given directions.
Definition: OctreeLeafNode.h:169
void clearChildren(std::unique_ptr< OctreeNodeInterface< Particle_T > > &ref) override
Delete the entire tree below this node.
Definition: OctreeLeafNode.h:142
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: OctreeLeafNode.h:147
OctreeLeafNode(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, OctreeNodeInterface< Particle_T > *parent, const int unsigned treeSplitThreshold, const double interactionLength, const double cellSizeFactor)
Create an empty octree leaf node.
Definition: OctreeLeafNode.h:38
bool hasChildren() override
Check if the node is a leaf or an inner node.
Definition: OctreeLeafNode.h:160
OctreeNodeInterface< Particle_T > * getChild(int index) override
Get a child by its index from the node.
Definition: OctreeLeafNode.h:165
The base class that provides the necessary function definitions that can be applied to an octree.
Definition: OctreeNodeInterface.h:32
static double getEnclosedVolumeWith(const std::array< double, 3 > &aMin, const std::array< double, 3 > &aMax, const std::array< double, 3 > &bMin, const std::array< double, 3 > &bMax)
Get the enclosed volume between two boxes a and b.
Definition: OctreeNodeInterface.h:196
std::array< double, 3 > _boxMin
The min coordinate of the enclosed volume.
Definition: OctreeNodeInterface.h:393
const std::array< double, 3 > & getBoxMax() const
Get the maximum coordinate of the enclosing box.
Definition: OctreeNodeInterface.h:370
std::array< double, 3 > _boxMax
The max coordinate of the enclosed volume.
Definition: OctreeNodeInterface.h:398
const std::array< double, 3 > & getBoxMin() const
Get the minimum coordinate of the enclosing box.
Definition: OctreeNodeInterface.h:364
double _interactionLength
The minimum distance at which a force is considered nonzero, cutoff+skin.
Definition: OctreeNodeInterface.h:408
int unsigned _treeSplitThreshold
Maximum number of particles inside a leaf node before the leaf tries to split itself.
Definition: OctreeNodeInterface.h:403
OctreeNodeInterface< Particle_T > * _parent
A pointer to the parent node.
Definition: OctreeNodeInterface.h:388
double _cellSizeFactor
The cell size factor for this node.
Definition: OctreeNodeInterface.h:413
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
Vertex
This enum can be used to index all vertices of a cube including an "invalid" vertex.
Definition: OctreeDirection.h:79
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
constexpr int64_t toInt64(const OwnershipState a)
Returns the int64_t value of a given OwnershipState.
Definition: OwnershipState.h:56
@ dummy
Dummy or deleted state, a particle with this state is not an actual particle!