13#ifndef CD_PARTICLEMANAGEMENT_H
14#define CD_PARTICLEMANAGEMENT_H
29#include <CD_NamespaceHeader.H>
195template <
class P,
class Traits = ParticleTraits<P>>
259template <
class P, Real P::*weight, RealVect P::*position>
262 const int a_maxLeaves,
263 const Real a_weightMedianLength,
264 const bool a_capWeights,
265 const std::function<RealVect(
const RealVect&)>& a_splitPosition,
267 std::vector<std::pair<const P*, const P*>>& a_leaves)
noexcept;
310template <
class Packed,
311 Real Packed::*packWeight,
312 RealVect Packed::*packPosition,
315inline ParticleMerger<P, Traits>
317 const Real a_weightMedianCellWidths,
318 const bool a_capWeights,
320 std::function<RealVect()> a_probLo,
322 BinaryParticleReconcile<Packed> a_reconcile,
355template <
class Context,
class P,
class Traits = ParticleTraits<P>>
356inline ParticleMerger<P, Traits>
359 std::function<RealVect()> a_probLo)
noexcept;
370template <typename P, typename Traits, typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
381template <
typename P,
typename Traits>
396template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
398partitionParticleWeights(std::vector<T>& a_weights,
399 const T a_numPhysicalParticles,
400 const T a_maxCompParticles)
noexcept;
408template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
409static inline std::vector<T>
410partitionParticleWeights(
const T a_numPhysicalParticles,
const T a_maxCompParticles)
noexcept;
425template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
427partitionParticles(
const T a_numParticles);
445template <typename P, typename Traits, typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
448 const T a_numParticles,
449 const std::function<RealVect()>& a_distribution);
463template <typename P, typename Traits, typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
466 const T a_numParticles,
467 const RealVect& a_center,
468 const Real a_radius)
noexcept;
482template <typename P, typename Traits, typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
485 const T a_numParticles,
486 const RealVect& a_loCorner,
487 const RealVect& a_hiCorner)
noexcept;
501template <typename P, typename Traits, typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
504 const T a_numParticles,
505 const RealVect& a_center,
506 const Real a_radius)
noexcept;
517template <
typename Packed>
568#include <CD_NamespaceFooter.H>
Simple class for holding some quantities relevant in a grid cell.
Implementation of CD_ParticleManagement.H.
Declaration of ParticleSoA, an arena-backed Struct-of-Arrays particle container.
std::int32_t RankID
Owning-rank identifier type (container-owned metadata column; fixed-width for I/O).
Definition CD_ParticleSoA.H:166
std::int64_t ParticleID
Global particle identifier type (container-owned metadata column; fixed-width for I/O).
Definition CD_ParticleSoA.H:161
Class for the cell-information that is often queried when merging particles inside a cell.
Definition CD_CellInfo.H:26
Arena-backed Struct-of-Arrays particle container for a single grid patch.
Definition CD_ParticleSoA.H:655
Class for encapsulating random number generation. This class is MPI and OpenMP safe.
Definition CD_Random.H:39
void buildKDCellLeaves(const std::vector< P > &a_particles, const int a_maxLeaves, const Real a_weightMedianLength, const bool a_capWeights, const std::function< RealVect(const RealVect &)> &a_splitPosition, const BinaryParticleReconcile< P > &a_particleReconcile, std::vector< std::pair< const P *, const P * > > &a_leaves) noexcept
Build a KD partition of a list of particles and return the leaf particle ranges.
Definition CD_ParticleManagementImplem.H:275
Namespace for various particle management tools.
Definition CD_KDParticleMerge.H:33
std::function< void(ParticleSoA< P, Traits > &a_particles, const CellInfo &a_cellInfo, const int a_numTargetParticles)> ParticleMerger
Concept for splitting/merging particles.
Definition CD_ParticleManagement.H:197
KDAmrBoundary kdAmrBoundaryFromString(const std::string &a_str) noexcept
Turn an input string into a kd AMR boundary rule.
Definition CD_ParticleManagementImplem.H:183
KDSplitPlacement kdSplitPlacementFromString(const std::string &a_str) noexcept
Turn an input string into a split placement rule.
Definition CD_ParticleManagementImplem.H:162
void drawBoxParticles(ParticleSoA< P, Traits > &a_particles, const T a_numParticles, const RealVect &a_loCorner, const RealVect &a_hiCorner) noexcept
Draw box-distributed particles into an SoA container (unit weight; positions only).
Definition CD_ParticleManagementImplem.H:910
KDSplitPlacement
Where the pieces of a split particle go.
Definition CD_ParticleManagement.H:65
@ Cell
Each piece drawn uniformly in the owning cell.
@ Jitter
Each piece drawn from the local mean interparticle spacing around the parent, truncated to the cell.
@ Center
Every piece at the parent's position. No spatial perturbation, duplicate positions.
std::function< void(P &p1, P &p2, const P &p0)> BinaryParticleReconcile
Declaration of a reconciliation function when splitting particles.
Definition CD_ParticleManagement.H:207
ParticleMerger< P, Traits > makeKDCellMerger(const Real a_weightMedianCellWidths, const bool a_capWeights, const KDSplitPlacement a_splitPlacement, std::function< RealVect()> a_probLo, std::function< Packed(const ParticleSoA< P, Traits > &, std::size_t)> a_gather, BinaryParticleReconcile< Packed > a_reconcile, std::function< void(ParticleSoA< P, Traits > &, const Packed *, const Packed *, const CellInfo &)> a_scatterLeaf) noexcept
Create a per-cell KD-tree super-particle merger as a reusable ParticleMerger.
Definition CD_ParticleManagementImplem.H:595
void drawSphereParticles(ParticleSoA< P, Traits > &a_particles, const T a_numParticles, const RealVect &a_center, const Real a_radius) noexcept
Draw sphere-distributed particles into an SoA container (unit weight; positions only).
Definition CD_ParticleManagementImplem.H:930
KDPartition
How a kd merge divides a node into two children.
Definition CD_ParticleManagement.H:48
@ WeightCapped
PROTOTYPE. Cap every particle at the target leaf weight, then split at the weight median.
@ Weight
Split at the weight median at every node; halves carry near-equal weight.
@ Count
Split at the count median at every node; halves hold near-equal particle counts.
@ Hybrid
Count median while the node is wider than the crossover length, weight median below it.
KDAmrBoundary
How the AMR-scope kd merge resolves the leaves that touch a patch or rank boundary.
Definition CD_ParticleManagement.H:94
@ Nn
Merge the interior with the kd tree and the boundary skin with nearest-neighbour pairs.
@ Carve
Arbitrate contested particles between patches (z-buffer carve).
KDPartition kdPartitionFromString(const std::string &a_str) noexcept
Turn an input string into a kd partition rule.
Definition CD_ParticleManagementImplem.H:117
ParticleMerger< P, Traits > makeReinitializeMerger(std::function< std::pair< long long, Context >(const ParticleSoA< P, Traits > &)> a_aggregate, std::function< void(ParticleSoA< P, Traits > &, const RealVect &, long long, const Context &)> a_emit, std::function< RealVect()> a_probLo) noexcept
Create a reinitialize super-particle merger as a reusable ParticleMerger.
Definition CD_ParticleManagementImplem.H:671
void drawGaussianParticles(ParticleSoA< P, Traits > &a_particles, const T a_numParticles, const RealVect &a_center, const Real a_radius) noexcept
Draw Gaussian-distributed particles into an SoA container (unit weight; positions only).
Definition CD_ParticleManagementImplem.H:892
NNSearch nnSearchFromString(const std::string &a_str) noexcept
Turn an input string into a nearest-neighbour search backend.
Definition CD_ParticleManagementImplem.H:201
NNSearch
How the AMR-scope nearest-neighbour merge finds a particle's merge candidates.
Definition CD_ParticleManagement.H:105
@ Tree
One whole-patch PointCloudBVH per patch.
@ OneCell
One PointCloudBVH per occupied cell; merge distance structurally fixed at 1 cell.
@ Hash
One whole-patch PointCloudHashGrid per patch.
KDPlacement
Where a kd merge puts the particle a leaf reduces to.
Definition CD_ParticleManagement.H:80
@ Centroid
The leaf's weighted centroid.
@ Sample
One of the leaf's own particles, drawn with probability proportional to weight.
ParticleMergeMethod
The super-particle merge methods, named by the scope they group particles over.
Definition CD_ParticleManagement.H:118
@ KdPatch
Patch: mergeKDPatch, one kd tree per patch, patch-local (no ghosts).
@ NnAmr
AMR: nearest-neighbour pair merge over the hierarchy – see NNSearch.
@ KdCell
Cell: makeKDCellMerger, one kd tree per cell.
@ KdAmr
AMR: one kd tree per patch, resolved across patches – see KDAmrBoundary.
@ External
Cell: caller-supplied per-cell merger.
@ Reinitialize
Cell: makeReinitializeMerger; positions discarded and redrawn.
void drawRandomParticles(ParticleSoA< P, Traits > &a_particles, const T a_numParticles, const std::function< RealVect()> &a_distribution)
Draw random SoA particles into a free buffer, distributed according to a predefined distribution.
Definition CD_ParticleManagementImplem.H:875
ParticleMergeMethod mergeMethodFromString(const std::string &a_str) noexcept
Map a merge-method selector string to a ParticleMergeMethod.
Definition CD_ParticleManagementImplem.H:37
KDPlacement kdPlacementFromString(const std::string &a_str) noexcept
Turn an input string into a kd placement rule.
Definition CD_ParticleManagementImplem.H:141
Minimal, payload-agnostic description of one particle as input to a distributed merge.
Definition CD_ParticleManagement.H:519
bool isGhost
True iff this is a ghost copy in the patch currently holding it, i.e. not physically stored there....
Definition CD_ParticleManagement.H:551
RealVect position
Particle position.
Definition CD_ParticleManagement.H:523
Packed payload
Opaque, caller-defined payload. Never inspected by the merge logic – only carried through to the comb...
Definition CD_ParticleManagement.H:563
Real weight
Particle weight. Not required to be an integer.
Definition CD_ParticleManagement.H:528
int level
The AMR level this particle lives on. Used by the nearest-neighbor mergers, whose cell keys are level...
Definition CD_ParticleManagement.H:557
ParticleID globalID
Globally unique particle id, unique within one merge round across every rank.
Definition CD_ParticleManagement.H:537
RankID ownerRank
The rank owning this particle. Always read from the particle's own data, never inferred from MPI tran...
Definition CD_ParticleManagement.H:543
Traits class that a user specializes to describe the PAYLOAD columns of a particle type....
Definition CD_ParticleSoA.H:192