AutoPas  3.0.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
autopas::OctreeNodeWrapper< Particle_T > Class Template Reference

This class wraps the functionality provided by the octree leaves and inner nodes in a structure that adheres to the ParticleCell concept. More...

#include <OctreeNodeWrapper.h>

Inheritance diagram for autopas::OctreeNodeWrapper< Particle_T >:
Inheritance graph
[legend]
Collaboration diagram for autopas::OctreeNodeWrapper< Particle_T >:
Collaboration graph
[legend]

Public Types

using ParticleCell = OctreeNodeWrapper< Particle_T >
 The contained particle cell.
 
using ParticleType = typename ParticleCell::ParticleType
 The contained particle type.
 
using StorageType = std::vector< Particle_T * >
 Type that holds or refers to the actual particles.
 
- Public Types inherited from autopas::ParticleCell< Particle_T >
using ParticleType = Particle_T
 The particle type for this cell.
 

Public Member Functions

 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.
 
void collectAllParticles (StorageType &ps)
 Append all particles in the octree to a list using DFS.
 
void appendAllLeaves (std::vector< OctreeLeafNode< Particle_T > * > &leaves)
 Append all leaves in the octree to a list.
 
void addParticle (const Particle_T &p) override
 Adds a Particle to the cell.
 
CellIterator< StorageType, true > begin ()
 Get an iterator to the start of a ParticleCell.
 
CellIterator< StorageType, false > begin () const
 Get an iterator to the start of a ParticleCell.
 
CellIterator< StorageType, true > end ()
 Get an iterator to the end of a ParticleCell.
 
CellIterator< StorageType, false > end () const
 Get an iterator to the end of a ParticleCell.
 
size_t size () const override
 Get the number of all particles stored in this cell (owned, halo and dummy).
 
size_t getNumberOfParticles (IteratorBehavior behavior) const override
 Get the number of particles with respect to the specified IteratorBehavior.
 
bool isEmpty () const override
 Check if the cell is not empty.
 
void clear () override
 Deletes all particles in this cell.
 
void deleteDummyParticles () override
 Deletes all dummy particles in this cell.
 
CellType getParticleCellTypeAsEnum () override
 Get the ParticleCell type as an ParticleCellTypeEnum.
 
bool deleteParticle (Particle_T &particle)
 Delete the given particle from the data structure.
 
void deleteByIndex (size_t index) override
 Deletes the index-th particle.
 
void setCellLength (std::array< double, 3 > &cellLength) override
 Set the side lengths of this cell.
 
std::array< double, 3 > getCellLength () const override
 Get the side lengths of this cell.
 
Particle_T & at (size_t index)
 Get a particle from the iterator.
 
const Particle_T & at (size_t index) const
 Get a particle from the iterator.
 
Particle_T & operator[] (size_t index)
 Get a particle from the iterator.
 
const Particle_T & operator[] (size_t index) const
 Get a particle from the iterator.
 
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.
 
OctreeNodeInterface< Particle_T > * getRaw () const
 Get a raw pointer to the enclosed cell.
 
template<typename Lambda >
void forEach (Lambda forEachLambda)
 Apply the forEach lambda to each particle.
 
template<typename Lambda , typename A >
void reduce (Lambda reduceLambda, A &result)
 Apply the reduce lambda to each particle.
 
template<typename Lambda >
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.
 
template<typename Lambda , typename A >
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.
 
- Public Member Functions inherited from autopas::ParticleCell< Particle_T >
virtual ~ParticleCell ()=default
 Default destructor.
 
 ParticleCell ()=default
 Default default constructor.
 
 ParticleCell (ParticleCell &&other) noexcept=default
 Default move constructor.
 
 ParticleCell (const ParticleCell &other)
 Copy constructor that creates a new default constructed lock for the new cell.
 
virtual void addParticle (const Particle_T &p)=0
 Adds a Particle to the cell.
 
virtual size_t size () const =0
 Get the number of all particles stored in this cell (owned, halo and dummy).
 
virtual size_t getNumberOfParticles (IteratorBehavior behavior=IteratorBehavior::owned) const =0
 Get the number of particles with respect to the specified IteratorBehavior.
 
virtual bool isEmpty () const =0
 Check if the cell is empty.
 
virtual void clear ()=0
 Deletes all particles in this cell.
 
virtual void deleteDummyParticles ()=0
 Deletes all dummy particles in this cell.
 
virtual CellType getParticleCellTypeAsEnum ()=0
 Get the ParticleCell type as an ParticleCellTypeEnum.
 
virtual void deleteByIndex (size_t index)=0
 Deletes the index-th particle.
 
virtual void setCellLength (std::array< double, 3 > &cellLength)=0
 Set the side lengths of this cell.
 
virtual std::array< double, 3 > getCellLength () const =0
 Get the side lengths of this cell.
 
OwnershipState getPossibleParticleOwnerships () const
 Get the type of particles contained in this cell.
 
void setPossibleParticleOwnerships (OwnershipState state)
 Set the type of particles contained in this cell.
 
AutoPasLockgetCellLock () const
 Get a reference to the lock object for exclusive access to this cell.
 

Additional Inherited Members

- Protected Attributes inherited from autopas::ParticleCell< Particle_T >
AutoPasLock _cellLock {}
 Lock object for exclusive access to this cell.
 
OwnershipState _ownershipState {autopas::OwnershipState::owned | autopas::OwnershipState::halo}
 The particles which can be contained in this cell are determined by the OwnershipState.
 
bool _ownershipStateDefined {false}
 Flag that is set to true once OwnershipState has been set to avoid resetting the OwnershipState.
 

Detailed Description

template<typename Particle_T>
class autopas::OctreeNodeWrapper< Particle_T >

This class wraps the functionality provided by the octree leaves and inner nodes in a structure that adheres to the ParticleCell concept.

What this wrapper does is the following: It hides implementation details of the octree nodes that should not be exposed to the outside. (For instance, the OctreeNodeInterface::insert() method has a very specific method signature that requires the caller to change the pointer to a subtree if necessary. Since the user should not care about this, it is wrapped in this class inside of the addParticle() method. This method does not have to be treated special like insert().)

This class includes some proxy methods: appendAllParticles(), appendAllLeaves() and some more. Those methods only invoke similar functions on the pointer to an octree. This indirection could be removed by implementing the OctreeNodeInterface<Particle_T>. However, if this class inherited directly from OctreeNodeInterface<Particle_T>, it would have to implement the entire interface provided by OctreeNodeInterface<Particle_T>. This does not increase the code quality, since one would have to implement other interface methods (like insert()) that should not be exposed to the outside. Having proxy calls inside this class keeps the interface clean.

Template Parameters
Particle_TThe particle class that should be used in the octree cell.

Constructor & Destructor Documentation

◆ OctreeNodeWrapper()

template<typename Particle_T >
autopas::OctreeNodeWrapper< Particle_T >::OctreeNodeWrapper ( const std::array< double, 3 > &  boxMin,
const std::array< double, 3 > &  boxMax,
int unsigned const  treeSplitThreshold,
double const  interactionLength,
double const  cellSizeFactor 
)
inline

Constructs a new, empty octree and stores the root.

Parameters
boxMinThe min coordinate of the box containing the octree
boxMaxThe max coordinate of the box containing the octree
treeSplitThresholdMaximum number of particles inside a leaf before it tries to split itself
interactionLengthThe minimum distance at which a force is considered nonzero, cutoff+skin.
cellSizeFactorThe cell size factor

Member Function Documentation

◆ addParticle()

template<typename Particle_T >
void autopas::OctreeNodeWrapper< Particle_T >::addParticle ( const Particle_T &  p)
inlineoverridevirtual

Adds a Particle to the cell.

Parameters
pthe particle to be added

Implements autopas::ParticleCell< Particle_T >.

◆ appendAllLeaves()

template<typename Particle_T >
void autopas::OctreeNodeWrapper< Particle_T >::appendAllLeaves ( std::vector< OctreeLeafNode< Particle_T > * > &  leaves)
inline

Append all leaves in the octree to a list.

Parameters
leavesThe list to which the leaves should be appended to

◆ at() [1/2]

template<typename Particle_T >
Particle_T & autopas::OctreeNodeWrapper< Particle_T >::at ( size_t  index)
inline

Get a particle from the iterator.

Parameters
indexThe index of the particle
Returns
A ref to a particle

◆ at() [2/2]

template<typename Particle_T >
const Particle_T & autopas::OctreeNodeWrapper< Particle_T >::at ( size_t  index) const
inline

Get a particle from the iterator.

Parameters
indexThe index of the particle
Returns
A const ref to a particle

◆ begin() [1/2]

template<typename Particle_T >
CellIterator< StorageType, true > autopas::OctreeNodeWrapper< Particle_T >::begin ( )
inline

Get an iterator to the start of a ParticleCell.

normal use: for(auto iter = cell.begin(); iter.isValid; ++iter){...}

Returns
the iterator

◆ begin() [2/2]

template<typename Particle_T >
CellIterator< StorageType, false > autopas::OctreeNodeWrapper< Particle_T >::begin ( ) const
inline

Get an iterator to the start of a ParticleCell.

normal use: for(auto iter = cell.begin(); iter.isValid; ++iter){...}

Returns
the iterator
Note
const version

◆ clear()

template<typename Particle_T >
void autopas::OctreeNodeWrapper< Particle_T >::clear ( )
inlineoverridevirtual

Deletes all particles in this cell.

Implements autopas::ParticleCell< Particle_T >.

◆ collectAllParticles()

template<typename Particle_T >
void autopas::OctreeNodeWrapper< Particle_T >::collectAllParticles ( StorageType ps)
inline

Append all particles in the octree to a list using DFS.

Parameters
psThe list to which the particles should be appended to

◆ deleteByIndex()

template<typename Particle_T >
void autopas::OctreeNodeWrapper< Particle_T >::deleteByIndex ( size_t  index)
inlineoverridevirtual

Deletes the index-th particle.

Parameters
indexthe index of the particle that shall be deleted

Implements autopas::ParticleCell< Particle_T >.

◆ deleteDummyParticles()

template<typename Particle_T >
void autopas::OctreeNodeWrapper< Particle_T >::deleteDummyParticles ( )
inlineoverridevirtual

Deletes all dummy particles in this cell.

Implements autopas::ParticleCell< Particle_T >.

◆ deleteParticle()

template<typename Particle_T >
bool autopas::OctreeNodeWrapper< Particle_T >::deleteParticle ( Particle_T &  particle)
inline

Delete the given particle from the data structure.

This function does not change the tree layout if the node is empty after the operation.

Parameters
particle
Returns
True if the given pointer still points to a new, valid particle.

◆ end() [1/2]

template<typename Particle_T >
CellIterator< StorageType, true > autopas::OctreeNodeWrapper< Particle_T >::end ( )
inline

Get an iterator to the end of a ParticleCell.

normal use: for(auto &p : cell){...}

Returns
the iterator

◆ end() [2/2]

template<typename Particle_T >
CellIterator< StorageType, false > autopas::OctreeNodeWrapper< Particle_T >::end ( ) const
inline

Get an iterator to the end of a ParticleCell.

normal use: for(auto &p : cell){...}

Returns
the iterator
Note
const version

◆ forEach()

template<typename Particle_T >
template<typename Lambda >
void autopas::OctreeNodeWrapper< Particle_T >::forEach ( Lambda  forEachLambda)
inline

Apply the forEach lambda to each particle.

Template Parameters
LambdaFunction type
Parameters
forEachLambdaFunction to apply

◆ forEachInRegion()

template<typename Particle_T >
template<typename Lambda >
void autopas::OctreeNodeWrapper< Particle_T >::forEachInRegion ( Lambda  forEachLambda,
const std::array< double, 3 > &  lowerCorner,
const std::array< double, 3 > &  higherCorner 
)
inline

Apply the forEach lambda to each particle in the region.

Template Parameters
LambdaFunction type
Parameters
forEachLambdaFunction to apply
lowerCornerLower corner of region
higherCornerHigher corner of region

◆ getCellLength()

template<typename Particle_T >
std::array< double, 3 > autopas::OctreeNodeWrapper< Particle_T >::getCellLength ( ) const
inlineoverridevirtual

Get the side lengths of this cell.

Returns
cell side length

Implements autopas::ParticleCell< Particle_T >.

◆ getLeavesInRange()

template<typename Particle_T >
std::set< OctreeLeafNode< Particle_T > * > autopas::OctreeNodeWrapper< Particle_T >::getLeavesInRange ( const std::array< double, 3 > &  min,
const std::array< double, 3 > &  max 
)
inline

Find all leaves below this subtree that are in the given range.

Parameters
minThe minimum coordinate in 3D space of the query area
maxThe maximum coordinate in 3D space of the query area
Returns
A set of all leaf nodes that are in the query region

◆ getNumberOfParticles()

template<typename Particle_T >
size_t autopas::OctreeNodeWrapper< Particle_T >::getNumberOfParticles ( IteratorBehavior  behavior) const
inlineoverridevirtual

Get the number of particles with respect to the specified IteratorBehavior.

Warning
: Since this function counts the number of the respective particles in the internal particle storage, this is in O(n) + lock is required. Only use it when it is absolutely necessary to have the exact number of different particle types like owned or halo. If it is enough to have the whole number of particles (owned + halo + dummy), the function size() can be used.
Parameters
behaviorBehavior of the iterator, see IteratorBehavior.
Returns
The number of particles with respect to the specified IteratorBehavior.

Implements autopas::ParticleCell< Particle_T >.

◆ getParticleCellTypeAsEnum()

template<typename Particle_T >
CellType autopas::OctreeNodeWrapper< Particle_T >::getParticleCellTypeAsEnum ( )
inlineoverridevirtual

Get the ParticleCell type as an ParticleCellTypeEnum.

Returns
The Cell type as an Enum

Implements autopas::ParticleCell< Particle_T >.

◆ getRaw()

template<typename Particle_T >
OctreeNodeInterface< Particle_T > * autopas::OctreeNodeWrapper< Particle_T >::getRaw ( ) const
inline

Get a raw pointer to the enclosed cell.

Note
This should only be used for debugging and insight into the internal structure fo the octree.
Returns
A raw C pointer to the enclosed node

◆ isEmpty()

template<typename Particle_T >
bool autopas::OctreeNodeWrapper< Particle_T >::isEmpty ( ) const
inlineoverridevirtual

Check if the cell is not empty.

Returns
true if at least one particle is stored in this cell

Implements autopas::ParticleCell< Particle_T >.

◆ operator[]() [1/2]

template<typename Particle_T >
Particle_T & autopas::OctreeNodeWrapper< Particle_T >::operator[] ( size_t  index)
inline

Get a particle from the iterator.

Parameters
indexThe index of the particle
Returns
A ref to a particle

◆ operator[]() [2/2]

template<typename Particle_T >
const Particle_T & autopas::OctreeNodeWrapper< Particle_T >::operator[] ( size_t  index) const
inline

Get a particle from the iterator.

Parameters
indexThe index of the particle
Returns
A ref to a particle

◆ reduce()

template<typename Particle_T >
template<typename Lambda , typename A >
void autopas::OctreeNodeWrapper< Particle_T >::reduce ( Lambda  reduceLambda,
A &  result 
)
inline

Apply the reduce lambda to each particle.

Template Parameters
LambdaFunction type
AInitial value type
Parameters
reduceLambdaFunction to apply
resultInitial value

◆ reduceInRegion()

template<typename Particle_T >
template<typename Lambda , typename A >
void autopas::OctreeNodeWrapper< Particle_T >::reduceInRegion ( Lambda  reduceLambda,
A &  result,
const std::array< double, 3 > &  lowerCorner,
const std::array< double, 3 > &  higherCorner 
)
inline

Apply the reduce lambda to each particle in the region.

Template Parameters
LambdaFunction type
AInitial value type
Parameters
reduceLambdaFunction to apply
resultInitial value
lowerCornerLower corner of region
higherCornerHigher corner of region

◆ setCellLength()

template<typename Particle_T >
void autopas::OctreeNodeWrapper< Particle_T >::setCellLength ( std::array< double, 3 > &  cellLength)
inlineoverridevirtual

Set the side lengths of this cell.

Parameters
cellLengthcell side length

Implements autopas::ParticleCell< Particle_T >.

◆ size()

template<typename Particle_T >
size_t autopas::OctreeNodeWrapper< Particle_T >::size ( ) const
inlineoverridevirtual

Get the number of all particles stored in this cell (owned, halo and dummy).

Returns
number of particles stored in this cell (owned, halo and dummy).

Implements autopas::ParticleCell< Particle_T >.


The documentation for this class was generated from the following file: