chombo-discharge
Typedefs | Functions
ParticleManagement Namespace Reference

Namespace for various particle management tools. More...

Typedefs

template<class P >
using ParticleMerger = std::function< void(List< P > &a_particles, const CellInfo &a_cellInfo, const int a_numTargetParticles)>
 Concept for splitting/merging particles. More...
 
template<class P >
using BinaryParticleReconcile = std::function< void(P &p1, P &p2, const P &p0)>
 Declaration of a reconciliation function when splitting particles. More...
 

Functions

template<class P , Real &(P::*)() weight, const RealVect &(P::*)() const position>
std::vector< std::shared_ptr< KDNode< P > > > recursivePartitionAndSplitEqualWeightKD (typename KDNode< P >::ParticleList &a_inputParticles, const int a_maxLeaves, const BinaryParticleReconcile< P > a_particleReconcile) noexcept
 Recursively build a KD-tree following the "equal weight" principle when partitioning nodes. More...
 
template<typename P , typename T , typename >
void removePhysicalParticles (List< P > &a_particles, const T a_numPhysPartToRemove) noexcept
 Remove physical particles from the input particles. More...
 
template<typename P >
void deleteParticles (List< P > &a_particles, const Real a_weightThresh) noexcept
 Remove particles if their weight is below the input weight. More...
 
template<typename T , typename >
std::vector< T > partitionParticleWeights (const T a_numPhysicalParticles, const T a_maxCompParticles) noexcept
 Partition particle weights among a number of computational particles. More...
 
template<typename T , typename >
partitionParticles (const T a_numParticles)
 Partition particles so that all MPI rank draw a cumulative number of particles equal to a_numParticles. More...
 
template<typename P , typename T , typename >
void drawRandomParticles (List< P > &a_particles, const T a_numParticles, const std::function< RealVect()> &a_distribution)
 Draw a specified number of random particles distributed according to a predefined distribution. More...
 
template<typename P , typename T , typename >
void drawSphereParticles (List< P > &a_particles, const T a_numParticles, const RealVect a_center, const Real a_radius) noexcept
 Draw particles in a sphere. More...
 
template<typename P , typename T , typename >
void drawBoxParticles (List< P > &a_particles, const T a_numParticles, const RealVect a_loCorner, const RealVect a_hiCorner) noexcept
 Draw particles in a box. More...
 
template<typename P , typename T , typename >
void drawGaussianParticles (List< P > &a_particles, const T a_numParticles, const RealVect a_center, const Real a_radius) noexcept
 Draw particles from a Gaussian distribution. More...
 

Detailed Description

Namespace for various particle management tools.

Typedef Documentation

◆ BinaryParticleReconcile

template<class P >
using ParticleManagement::BinaryParticleReconcile = typedef std::function<void(P& p1, P& p2, const P& p0)>

Declaration of a reconciliation function when splitting particles.

This is, for example, passed into the KD-tree equal-weight partioning structure, which may split a particle such that the weight of the two nodes differ by at most one physical particle. By default, that method will call the particle copy constructor, but this function permits the user to input a reconciliation function that manipulates other class members in the split particles.

◆ ParticleMerger

template<class P >
using ParticleManagement::ParticleMerger = typedef std::function< void(List<P>& a_particles, const CellInfo& a_cellInfo, const int a_numTargetParticles)>

Concept for splitting/merging particles.

Parameters
[in,out]a_particlesParticles to be merged/split
[in]a_numTargetParticlesNumber of target particles

Function Documentation

◆ deleteParticles()

template<typename P >
void ParticleManagement::deleteParticles ( List< P > &  a_particles,
const Real  a_weightThresh 
)
inlinenoexcept

Remove particles if their weight is below the input weight.

Parameters
[in,out]a_particlesInput list of particles. Must have a weight function.
[in]a_weightThreshWeight threshold for removal

◆ drawBoxParticles()

template<typename P , typename T , typename >
void ParticleManagement::drawBoxParticles ( List< P > &  a_particles,
const T  a_numParticles,
const RealVect  a_loCorner,
const RealVect  a_hiCorner 
)
inlinenoexcept

Draw particles in a box.

The implementation will partition a_numParticles among the ranks so the total number of particles drawn is a_numParticles. P is the particle type (must have a RealVect& position() function) and T is an integer type.

Parameters
[out]a_particlesOutput particles (different for each rank)
[in]a_numParticlesNumber of particles
[in]a_loCornerLow corner of box
[in]a_hiCornerHigh corner of box

◆ drawGaussianParticles()

template<typename P , typename T , typename >
void ParticleManagement::drawGaussianParticles ( List< P > &  a_particles,
const T  a_numParticles,
const RealVect  a_center,
const Real  a_radius 
)
inlinenoexcept

Draw particles from a Gaussian distribution.

The implementation will partition a_numParticles among the ranks so the total number of particles drawn is a_numParticles. P is the particle type (must have a RealVect& position() function) and T is an integer type.

Parameters
[out]a_particlesOutput particles (different for each rank)
[in]a_numParticlesNumber of particles
[in]a_centerGaussian blob Center
[in]a_radiusGaussian blob radius

◆ drawRandomParticles()

template<typename P , typename T , typename >
void ParticleManagement::drawRandomParticles ( List< P > &  a_particles,
const T  a_numParticles,
const std::function< RealVect()> &  a_distribution 
)
inline

Draw a specified number of random particles distributed according to a predefined distribution.

The implementation will partition a_numParticles among the ranks so the total number of particles drawn is a_numParticles. P is the particle type (must derived from BinItem) and T is an integer type.

Parameters
[out]a_particlesOutput particles (different for each rank)
[in]a_numParticlesNumber of particles
[in]a_distributionParticle distribution. Must return a random position when calling the function.

◆ drawSphereParticles()

template<typename P , typename T , typename >
void ParticleManagement::drawSphereParticles ( List< P > &  a_particles,
const T  a_numParticles,
const RealVect  a_center,
const Real  a_radius 
)
inlinenoexcept

Draw particles in a sphere.

The implementation will partition a_numParticles among the ranks so the total number of particles drawn is a_numParticles. P is the particle type (must have a RealVect& position() function) and T is an integer type.

Parameters
[out]a_particlesOutput particles (different for each rank)
[in]a_numParticlesNumber of particles
[in]a_centerSphere center
[in]a_radiusSphere radius

◆ partitionParticles()

template<typename T , typename >
T ParticleManagement::partitionParticles ( const T  a_numParticles)
inline

Partition particles so that all MPI rank draw a cumulative number of particles equal to a_numParticles.

Parameters
[in]a_numParticlesTotal number of particles to be drawn.
Returns
Returns the number of particles drawn by each rank.

◆ partitionParticleWeights()

template<typename T , typename >
std::vector<T> ParticleManagement::partitionParticleWeights ( const T  a_numPhysicalParticles,
const T  a_maxCompParticles 
)
inlinenoexcept

Partition particle weights among a number of computational particles.

Parameters
[in]a_numPhysicalParticlesNumber of physical particles.
[in]a_maxCompParticlesMaximum number of computational particles

◆ recursivePartitionAndSplitEqualWeightKD()

template<class P , Real &(P::*)() weight, const RealVect &(P::*)() const position>
std::vector<std::shared_ptr<KDNode<P> > > ParticleManagement::recursivePartitionAndSplitEqualWeightKD ( typename KDNode< P >::ParticleList &  a_inputParticles,
const int  a_maxLeaves,
const BinaryParticleReconcile< P >  a_particleReconcile = [](P &p1, P &p2, const P &p0) -> void { } 
)
inlinenoexcept

Recursively build a KD-tree following the "equal weight" principle when partitioning nodes.

Parameters
[in,out]a_inputParticlesInput particles. These are destroyed on output.
[in]a_maxLeavesMaximum number of leaves in the tree.
Returns
Returns leaf nodes containing the particles

If the number of leaves is a factor of two, leaves exist on the same level and the weight in each node will differ by at most one physical particle. The template parameters are

P -> Particle type P::*weight -> Function pointer to particle weight P::*position -> Function pointer to particle position.

A possible call signature is e.g. recursivePartitionAndSplitEqualWeightKD<P, &P::weight, &P::position>.

The user can input a particle reconciliation function that manipulates the particle properties of the split particles. By default, the split particles will use the copy constructor and thus inherit class members from p0, with the exception of the particle weights. The reconcile function lets the user manipulate other particle properties, e.g. ones that are not properly captured by the particle copy constructor, or that need some other form of reconciliation.

◆ removePhysicalParticles()

template<typename P , typename T , typename >
void ParticleManagement::removePhysicalParticles ( List< P > &  a_particles,
const T  a_numPhysPartToRemove 
)
inlinenoexcept

Remove physical particles from the input particles.

Parameters
[in,out]a_particlesInput list of particles. Must have a weight function.
[in]a_numPhysPartToRemoveNumber of physical particles to remove
Note
May fail if particle weights are not (close to) integers.