SPH
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BarnesHut Class Reference

Multipole approximation of distance particle. More...

#include <BarnesHut.h>

Inheritance diagram for BarnesHut:
IGravity Polymorphic

Classes

class  NodeTask
 
struct  TreeWalkResult
 
struct  TreeWalkState
 Data passed into each node during treewalk. More...
 

Public Member Functions

 BarnesHut (const Float theta, const MultipoleOrder order, const Size leafSize=25, const Size maxDepth=50, const Float gravityConstant=Constants::gravity)
 Constructs the Barnes-Hut gravity assuming point-like particles (with zero radius). More...
 
 BarnesHut (const Float theta, const MultipoleOrder order, GravityLutKernel &&kernel, const Size leafSize=25, const Size maxDepth=50, const Float gravityConstant=Constants::gravity)
 Constructs the Barnes-Hut gravity with given smoothing kernel. More...
 
virtual void build (IScheduler &pool, const Storage &storage) override
 Masses of particles must be strictly positive, otherwise center of mass would be undefined. More...
 
virtual void evalAll (IScheduler &pool, ArrayView< Vector > dv, Statistics &stats) const override
 Evaluates the gravitational acceleration concurrently. More...
 
virtual Vector eval (const Vector &r0) const override
 Evaluates the gravitational acceleration at given point. More...
 
virtual Float evalEnergy (IScheduler &scheduler, Statistics &stats) const override
 Computes the total potential energy of the particles. More...
 
virtual RawPtr< const IBasicFindergetFinder () const override
 Optionally returns a finder used by the gravity implementation. More...
 
MultipoleExpansion< 3 > getMoments () const
 Returns the multipole moments computed from root node. More...
 
- Public Member Functions inherited from Polymorphic
virtual ~Polymorphic ()
 

Protected Member Functions

Vector evalImpl (const Vector &r0, const Size idx) const
 Evaluates the gravity at a single point in space. More...
 
void evalNode (IScheduler &scheduler, ArrayView< Vector > dv, const Size nodeIdx, TreeWalkState data, TreeWalkResult &result) const
 Performs a recursive treewalk evaluating gravity for all particles. More...
 
void evalParticleList (const LeafNode< BarnesHutNode > &leaf, ArrayView< Size > particleList, ArrayView< Vector > dv) const
 
void evalNodeList (const LeafNode< BarnesHutNode > &leaf, ArrayView< Size > nodeList, ArrayView< Vector > dv) const
 
Vector evalExact (const LeafNode< BarnesHutNode > &node, const Vector &r0, const Size idx) const
 
void buildLeaf (BarnesHutNode &node)
 
void buildInner (BarnesHutNode &node, BarnesHutNode &left, BarnesHutNode &right)
 

Protected Attributes

ArrayView< const Vectorr
 View of a position buffer in the storage. More...
 
Array< Floatm
 Particle masses multiplied by gravitational constant. More...
 
KdTree< BarnesHutNodekdTree
 K-d tree storing gravitational moments. More...
 
GravityLutKernel kernel
 Kernel used to evaluate gravity of close particles. More...
 
Float thetaInv
 Inverted value of the opening angle for multipole approximation (in radians) More...
 
MultipoleOrder order
 Order of multipole approximation. More...
 
Size maxDepth
 Maximum depth at which the nodes evaluation is parallelized. More...
 
Float gravityConstant = Constants::gravity
 Gravitational constant in the selected unit system. More...
 

Detailed Description

Multipole approximation of distance particle.

Definition at line 43 of file BarnesHut.h.

Constructor & Destructor Documentation

◆ BarnesHut() [1/2]

BarnesHut::BarnesHut ( const Float  theta,
const MultipoleOrder  order,
const Size  leafSize = 25,
const Size  maxDepth = 50,
const Float  gravityConstant = Constants::gravity 
)

Constructs the Barnes-Hut gravity assuming point-like particles (with zero radius).

Parameters
thetaOpening angle; lower value means higher precision, but slower computation
orderOrder of multipole approximation
leafSizeMaximum number of particles in a leaf
maxDepthMaximum parallel depth for tree contruction and evaluation

Definition at line 17 of file BarnesHut.cpp.

◆ BarnesHut() [2/2]

BarnesHut::BarnesHut ( const Float  theta,
const MultipoleOrder  order,
GravityLutKernel &&  kernel,
const Size  leafSize = 25,
const Size  maxDepth = 50,
const Float  gravityConstant = Constants::gravity 
)

Constructs the Barnes-Hut gravity with given smoothing kernel.

Parameters
thetaOpening angle; lower value means higher precision, but slower computation
orderOrder of multipole approximation
kernelPrecomputed gravity smoothing kernel
leafSizeMaximum number of particles in a leaf
maxDepthMaximum parallel depth for tree contruction and evaluation

Definition at line 34 of file BarnesHut.cpp.

Member Function Documentation

◆ build()

void BarnesHut::build ( IScheduler pool,
const Storage storage 
)
overridevirtual

Masses of particles must be strictly positive, otherwise center of mass would be undefined.

Todo:
sequential needed because TBB cannot wait on child tasks yet

Implements IGravity.

Definition at line 49 of file BarnesHut.cpp.

◆ buildInner()

void BarnesHut::buildInner ( BarnesHutNode node,
BarnesHutNode left,
BarnesHutNode right 
)
protected

Definition at line 413 of file BarnesHut.cpp.

◆ buildLeaf()

void BarnesHut::buildLeaf ( BarnesHutNode node)
protected

Definition at line 351 of file BarnesHut.cpp.

◆ eval()

Vector BarnesHut::eval ( const Vector r0) const
overridevirtual

Evaluates the gravitational acceleration at given point.

The point must NOT correspond to any particle, as this case could formally lead to infinite acceleration if no smoothing kernel is used.

Parameters
r0Point where the gravity is evaluated.

Implements IGravity.

Definition at line 99 of file BarnesHut.cpp.

◆ evalAll()

void BarnesHut::evalAll ( IScheduler scheduler,
ArrayView< Vector dv,
Statistics stats 
) const
overridevirtual

Evaluates the gravitational acceleration concurrently.

The function is blocking, it must exit after the gravity is evaluated.

Parameters
schedulerScheduler used for parallelization.
dvAcceleration values; it may already contain some accelerations computed by other code components, gravity should add acceleration instead of replacing the current values.
statsOutput statistics of the gravitational solver.

Implements IGravity.

Definition at line 83 of file BarnesHut.cpp.

◆ evalEnergy()

Float BarnesHut::evalEnergy ( IScheduler scheduler,
Statistics stats 
) const
overridevirtual

Computes the total potential energy of the particles.

The zero point is implementation-specific; it is not required that the energy is strictly negative.

Parameters
schedulerScheduler used for parallelization.
statsOutput statistics of the gravitational solver.

Implements IGravity.

Definition at line 103 of file BarnesHut.cpp.

◆ evalExact()

Vector BarnesHut::evalExact ( const LeafNode< BarnesHutNode > &  node,
const Vector r0,
const Size  idx 
) const
protected

Definition at line 339 of file BarnesHut.cpp.

◆ evalImpl()

Vector BarnesHut::evalImpl ( const Vector r0,
const Size  idx 
) const
protected

Evaluates the gravity at a single point in space.

Definition at line 107 of file BarnesHut.cpp.

◆ evalNode()

void BarnesHut::evalNode ( IScheduler scheduler,
ArrayView< Vector dv,
const Size  evaluatedNodeIdx,
TreeWalkState  data,
TreeWalkResult result 
) const
protected

Performs a recursive treewalk evaluating gravity for all particles.

Treewalk starts at given node and subsequently calls evalNode for children nodes. Function moves nodes from checkList into interaction lists and in case the node is a leaf, gravity is computed using constructed interaction lists.

Parameters
schedulerScheduler used for (potential) parallelization
dvOutput thread-local buffer where computed accelerations are stored
nodeIdxIndex of the first node evaluated by the function
dataChecklist nad interaction lists of he node
resultStatistics incremented by the node. Cannot be return value, the type is not moveable.
Todo:
try different containers; we need fast inserting & deletion
Todo:
ASSERT FIRED !

Definition at line 185 of file BarnesHut.cpp.

◆ evalNodeList()

void BarnesHut::evalNodeList ( const LeafNode< BarnesHutNode > &  leaf,
ArrayView< Size nodeList,
ArrayView< Vector dv 
) const
protected

Definition at line 325 of file BarnesHut.cpp.

◆ evalParticleList()

void BarnesHut::evalParticleList ( const LeafNode< BarnesHutNode > &  leaf,
ArrayView< Size particleList,
ArrayView< Vector dv 
) const
protected

Definition at line 288 of file BarnesHut.cpp.

◆ getFinder()

RawPtr< const IBasicFinder > BarnesHut::getFinder ( ) const
overridevirtual

Optionally returns a finder used by the gravity implementation.

If the gravity uses an acceleration structure that implements the IBasicFinder interface, this function allows the user to obtain the object and re-use in other parts of the code. Finder is assumed to be initialized after build is called.

If the gravity does not use any such structure or it simply does not implement the IBasicFinder interface, the function returns nullptr.

Implements IGravity.

Definition at line 470 of file BarnesHut.cpp.

◆ getMoments()

MultipoleExpansion< 3 > BarnesHut::getMoments ( ) const

Returns the multipole moments computed from root node.

Mostly for testing purposes.

Definition at line 465 of file BarnesHut.cpp.

Member Data Documentation

◆ gravityConstant

Float BarnesHut::gravityConstant = Constants::gravity
protected

Gravitational constant in the selected unit system.

In SI, this is simply Constants::gravity.

Todo:
generalize

Definition at line 72 of file BarnesHut.h.

◆ kdTree

KdTree<BarnesHutNode> BarnesHut::kdTree
protected

K-d tree storing gravitational moments.

Definition at line 52 of file BarnesHut.h.

◆ kernel

GravityLutKernel BarnesHut::kernel
protected

Kernel used to evaluate gravity of close particles.

Definition at line 55 of file BarnesHut.h.

◆ m

Array<Float> BarnesHut::m
protected

Particle masses multiplied by gravitational constant.

Definition at line 49 of file BarnesHut.h.

◆ maxDepth

Size BarnesHut::maxDepth
protected

Maximum depth at which the nodes evaluation is parallelized.

Child nodes are then evaluated serially on the same thread.

Definition at line 66 of file BarnesHut.h.

◆ order

MultipoleOrder BarnesHut::order
protected

Order of multipole approximation.

Definition at line 61 of file BarnesHut.h.

◆ r

ArrayView<const Vector> BarnesHut::r
protected

View of a position buffer in the storage.

Definition at line 46 of file BarnesHut.h.

◆ thetaInv

Float BarnesHut::thetaInv
protected

Inverted value of the opening angle for multipole approximation (in radians)

Definition at line 58 of file BarnesHut.h.


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