|
chombo-discharge
|
Implementation of CD_NearestNeighborParticleMerge.H. More...
#include <algorithm>#include <cmath>#include <CH_Timer.H>#include <MayDay.H>#include <SPMD.H>#include <DataIterator.H>#include <BoxIterator.H>#include <CD_NearestNeighborParticleMerge.H>#include <CD_AmrMesh.H>#include <CD_NamespaceHeader.H>#include <CD_NamespaceFooter.H>

Go to the source code of this file.
Namespaces | |
| namespace | ParticleManagement |
| Namespace for various particle management tools. | |
| namespace | ParticleManagement::detail |
| Internal-only implementation details of the ParticleManagement API. | |
Functions | |
| Real | ParticleManagement::detail::nnMergeDistSquared (const RealVect &a_a, const RealVect &a_b) noexcept |
| Squared Euclidean distance between two physical positions. | |
| int | ParticleManagement::detail::nnMergeChebyshevCellDistance (const IntVect &a_a, const IntVect &a_b) noexcept |
| Chebyshev (max-per-axis) distance between two cell-index vectors – see CD_NearestNeighborParticleMerge.H's a_maxCellDistance docs. | |
| bool | ParticleManagement::detail::nnMergeCrossLevelTooFar (const RealVect &a_posA, const int a_levelA, const RealVect &a_posB, const int a_levelB, const RealVect &a_probLo, const std::vector< RealVect > &a_dxByLevel, const int a_maxCellDistance) noexcept |
| a_maxCellDistance check for two positions that may be on DIFFERENT AMR levels. | |
| void | ParticleManagement::detail::nnMergeWeightedCentroid (RealVect &a_mergedPos, Real &a_mergedWeight, const RealVect &a_posA, const Real a_weightA, const RealVect &a_posB, const Real a_weightB) noexcept |
| Weighted-centroid merge of two positions/weights – shared by resolveTrivialTier() and judgeProposals() so the formula is written exactly once. | |
| Real | ParticleManagement::detail::nnMergePointToCellDistSquared (const RealVect &a_point, const IntVect &a_cell, const RealVect &a_probLo, const RealVect &a_dx) noexcept |
| Squared distance from a physical point to a cell's axis-aligned bounding box (0 if the point is inside). | |
| template<typename T> | |
| std::vector< T > | ParticleManagement::detail::nnMergeExchangeByRank (const std::vector< std::vector< T > > &a_sendByRank) |
| Generic alltoallv-style exchange: send a per-destination-rank bucket of trivially- copyable records, return the flat concatenation of everything received. | |
| IntVect | ParticleManagement::detail::cellKeyOf (const RealVect &a_position, const RealVect &a_probLo, const RealVect &a_dx) noexcept |
| The unclamped, position-derived cell index a given physical position falls in. | |
| template<typename Packed> | |
| bool | ParticleManagement::detail::nnMergeAnyCellCrowded (const std::vector< MergeParticle< Packed > > &a_localValid, const std::vector< MergeParticle< Packed > > &a_ghosts, const RealVect &a_probLo, const RealVect &a_dx, const NNCellBudget &a_cellBudget) noexcept |
| Exact per-cell crowding pre-filter shared by buildNNSpatialIndex()/buildNNCellSpatialIndex(): is any cell in this patch's local+ghost particle set over its a_cellBudget? | |
| template<typename Packed, typename Cloud = EBGeometry::PointCloudBVH<Real, ParticleID>> | |
| void | ParticleManagement::detail::buildNNSpatialIndex (NNSpatialIndex< Packed, Cloud > &a_index, const std::vector< MergeParticle< Packed > > &a_localValid, const std::vector< MergeParticle< Packed > > &a_ghosts, const RealVect &a_probLo, const RealVect &a_dx, const NNCellBudget &a_cellBudget, const int a_kNearest) noexcept |
Build a patch's spatial index for one round: an EBGeometry point-cloud index (see Cloud) over the whole patch (every local valid particle then every ghost) plus its precomputed k-nearest-neighbor graph – UNLESS no cell in this patch could possibly be crowded, in which case nothing is built. | |
| template<typename Packed, typename Cloud = EBGeometry::PointCloudBVH<Real, ParticleID>> | |
| void | ParticleManagement::detail::findNearestNeighborCandidates (std::vector< NNMergeEdge< Packed > > &a_edges, const std::vector< MergeParticle< Packed > > &a_localValid, const std::vector< MergeParticle< Packed > > &a_ghosts, const std::unordered_set< ParticleID > &a_consumedIDs, const NNSpatialIndex< Packed, Cloud > &a_spatialIndex, const std::unordered_map< NNCellKey, int, NNCellKeyHasher > &a_liveCellCount, const RealVect &a_probLo, const RealVect &a_dx, const NNCellBudget &a_cellBudget, const int a_maxFallbackCandidates=0, const std::optional< int > a_maxCellDistance=std::nullopt) noexcept |
| For every over-threshold, currently-alive valid particle in a patch, find its single TRUE nearest neighbor among {this patch's own other valid particles} union {every ghost shipped to this patch}. | |
| template<typename Packed> | |
| void | ParticleManagement::detail::buildNNCellSpatialIndex (NNCellSpatialIndex &a_index, const std::vector< MergeParticle< Packed > > &a_localValid, const std::vector< MergeParticle< Packed > > &a_ghosts, const RealVect &a_probLo, const RealVect &a_dx, const NNCellBudget &a_cellBudget) noexcept |
| Build a patch's one-cell spatial index for the one-cell nearest-neighbor merge: one PointCloudBVH per occupied cell – UNLESS no cell in this patch could possibly be crowded, in which case nothing is built. | |
| template<typename Packed> | |
| void | ParticleManagement::detail::findNearestNeighborCandidatesOneCell (std::vector< NNMergeEdge< Packed > > &a_edges, const std::vector< MergeParticle< Packed > > &a_localValid, const std::unordered_set< ParticleID > &a_consumedIDs, const NNCellSpatialIndex &a_cellIndex, const std::unordered_map< NNCellKey, int, NNCellKeyHasher > &a_liveCellCount, const RealVect &a_probLo, const RealVect &a_dx, const std::vector< RealVect > &a_dxByLevel, const NNCellBudget &a_cellBudget, const int a_maxFallbackCandidates=0) noexcept |
| For every over-threshold, currently-alive valid particle in a patch, find its single TRUE nearest neighbor restricted to its own cell and its Moore-adjacent neighbor cells (Chebyshev cell distance <= 1) – the one-cell counterpart of findNearestNeighborCandidates(). | |
| template<typename Packed, typename Combine, typename PosValid, typename Allocator, typename OnMerge> | |
| void | ParticleManagement::detail::resolveTrivialTier (std::unordered_map< NNCellKey, int, NNCellKeyHasher > &a_liveCellCount, std::unordered_set< ParticleID > &a_consumedIDs, std::unordered_set< ParticleID > &a_hasOutgoingCommitment, std::vector< NNMergeResult< Packed > > &a_results, const std::vector< NNMergeEdge< Packed > > &a_edges, const std::unordered_map< ParticleID, NNPooledParticle< Packed > > &a_particlesByID, const Combine &a_combine, const NNCellBudget &a_cellBudget, const RealVect &a_probLo, const std::vector< RealVect > &a_dxByLevel, const PosValid &a_isPositionValid, const Allocator &a_allocateID, const int a_maxFallbackCandidates=0, const std::optional< int > a_maxCellDistance=std::nullopt, unsigned long long *a_crossLevelMergeCount=nullptr, const OnMerge &a_onMergeCommitted=[](const MergeParticle< Packed > &, const MergeParticle< Packed > &, const MergeParticle< Packed > &) { }) noexcept |
| Resolve every candidate edge that is safely mergeable with zero cross-rank coordination, and mark which remaining particles have committed to a non-trivial outgoing proposal. | |
| template<typename Packed> | |
| void | ParticleManagement::detail::generateProposals (std::vector< std::vector< NNMergeProposal< Packed > > > &a_proposalsByDestRank, const std::vector< NNMergeEdge< Packed > > &a_edges, const std::unordered_set< ParticleID > &a_hasOutgoingCommitment, const std::unordered_map< ParticleID, NNPooledParticle< Packed > > &a_particlesByID, const int a_numRanks) noexcept |
| Package one outgoing proposal for every edge that resolveTrivialTier() could not resolve locally, bucketed by destination rank. | |
| template<typename Packed, typename Combine, typename PosValid, typename Allocator, typename OnMerge> | |
| void | ParticleManagement::detail::judgeProposals (std::unordered_map< NNCellKey, int, NNCellKeyHasher > &a_liveCellCount, std::vector< NNMergeResult< Packed > > &a_results, std::vector< std::vector< NNMergeVerdict > > &a_verdictsByDestRank, const std::vector< NNMergeProposal< Packed > > &a_incomingProposals, const std::unordered_map< ParticleID, NNPooledParticle< Packed > > &a_particlesByID, const std::unordered_set< ParticleID > &a_consumedIDs, const std::unordered_set< ParticleID > &a_hasOutgoingCommitment, const std::map< ParticleID, ParticleID > &a_outgoingTargetOf, const Combine &a_combine, const NNCellBudget &a_cellBudget, const RealVect &a_probLo, const std::vector< RealVect > &a_dxByLevel, const PosValid &a_isPositionValid, const Allocator &a_allocateID, const std::optional< int > a_maxCellDistance=std::nullopt, unsigned long long *a_crossLevelMergeCount=nullptr, const OnMerge &a_onMergeCommitted=[](const MergeParticle< Packed > &, const MergeParticle< Packed > &, const MergeParticle< Packed > &) { }) noexcept |
| Judge every incoming proposal that targets a particle this rank owns, and produce the verdicts to send back. | |
| void | ParticleManagement::detail::applyVerdicts (std::unordered_set< ParticleID > &a_consumedIDs, const std::vector< NNMergeVerdict > &a_incomingVerdicts) noexcept |
| Apply every verdict addressed to one of this rank's own outgoing proposals: remove the source particle for every accepted proposal, do nothing for rejected ones. | |
| template<typename Packed> | |
| void | ParticleManagement::detail::placeMergedParticles (std::map< std::pair< int, unsigned int >, std::vector< MergeParticle< Packed > > > &a_localByPatch, std::vector< std::vector< MergeParticle< Packed > > > &a_scatterByDestRank, const std::vector< NNMergeResult< Packed > > &a_results, const PositionLocator &a_locate, const int a_thisRank) noexcept |
| Point-locate a newly created merged particle against the AMR grid, and bucket it for a scatter exchange if it belongs to someone else. | |
| template<typename P, typename Packed, typename Traits, typename Gather> | |
| void | ParticleManagement::detail::gatherMergeParticles (ParticleContainer< P, Traits > &a_particles, std::vector< NNPatchWork > &a_patchWork, std::vector< std::vector< MergeParticle< Packed > > > &a_patchLocalValid, std::vector< std::vector< MergeParticle< Packed > > > &a_patchGhosts, std::unordered_map< ParticleID, NNPooledParticle< Packed > > &a_particlesByID, std::unordered_map< NNCellKey, int, NNCellKeyHasher > &a_liveCellCount, const AmrMesh &a_amr, const std::string &a_realm, const int a_finestLevel, const RealVect &a_probLo, const std::vector< RealVect > &a_dxByLevel, const int a_ghostWidth, const Gather &a_gather) noexcept |
| Gather every patch this rank owns into the backend-agnostic per-patch particle sets and pooled bookkeeping a merge round needs, shared by every search backend. | |
| template<typename P, typename Packed, typename Traits, typename Combine, typename Scatter, typename PosValid, typename Allocator, typename OnMerge> | |
| void | ParticleManagement::detail::finishMergeRound (ParticleContainer< P, Traits > &a_particles, std::unordered_map< ParticleID, NNPooledParticle< Packed > > &a_particlesByID, std::unordered_set< ParticleID > &a_consumedIDs, std::unordered_map< NNCellKey, int, NNCellKeyHasher > &a_liveCellCount, std::vector< NNMergeResult< Packed > > &a_allResults, unsigned long long *a_crossLevelMergeCount, const AmrMesh &a_amr, const std::string &a_realm, const NNCellBudget &a_cellBudget, const Combine &a_combine, const Scatter &a_scatter, const Allocator &a_allocateID, const std::optional< int > a_maxCellDistance, const PosValid &a_isPositionValid, const RealVect &a_probLo, const std::vector< RealVect > &a_dxByLevel, const std::vector< NNPatchWork > &a_patchWork, const std::vector< NNMergeEdge< Packed > > &a_pooledEdges, const std::unordered_set< ParticleID > &a_hasOutgoingCommitment, const OnMerge &a_onMergeCommitted) noexcept |
| Finish a merge round: propose/judge/verdict the edges the local tier could not resolve, place every merge result, and apply everything to the real particle containers – the backend-agnostic tail shared by mergeNearestNeighborsTree() and mergeNearestNeighborsOneCell(). | |
| template<typename P, typename Packed, typename Traits, typename Cloud, typename Gather, typename Combine, typename Scatter, typename Allocator, typename PosValid, typename OnMerge> | |
| void | ParticleManagement::detail::mergeNearestNeighborsRoundImpl (ParticleContainer< P, Traits > &a_particles, unsigned long long *a_crossLevelMergeCount, const AmrMesh &a_amr, const NNCellBudget &a_cellBudget, const Gather &a_gather, const Combine &a_combine, const Scatter &a_scatter, const Allocator &a_allocateID, const bool a_iterateLocalTierToConvergence, const int a_maxFallbackCandidates, const std::optional< int > a_maxCellDistance, const int a_ghostWidth, const PosValid &a_isPositionValid, const OnMerge &a_onMergeCommitted) |
| Shared implementation behind mergeNearestNeighborsTree() and mergeNearestNeighborsHash(): one full round of the whole-patch-tree nearest-neighbor merge, generic over which EBGeometry point-cloud index backs the per-patch spatial search. | |
| template<typename P, typename Packed, typename Traits = ParticleTraits<P>, typename Gather, typename Combine, typename Scatter, typename Allocator, typename PosValid = std::function<bool(const RealVect&)>, typename OnMerge = std::function< void(const MergeParticle<Packed>&, const MergeParticle<Packed>&, const MergeParticle<Packed>&)>> | |
| void | ParticleManagement::mergeNearestNeighborsTree (ParticleContainer< P, Traits > &a_particles, const AmrMesh &a_amr, const NNCellBudget &a_cellBudget, const Gather &a_gather, const Combine &a_combine, const Scatter &a_scatter, const Allocator &a_allocateID, const bool a_iterateLocalTierToConvergence=false, const int a_maxFallbackCandidates=0, const std::optional< int > a_maxCellDistance=std::nullopt, const int a_ghostWidth=1, const PosValid &a_isPositionValid=[](const RealVect &) { return true;}, unsigned long long *a_crossLevelMergeCount=nullptr, const OnMerge &a_onMergeCommitted=[](const MergeParticle< Packed > &, const MergeParticle< Packed > &, const MergeParticle< Packed > &) { }) |
| Run one full round (one timestep's worth) of the nearest-neighbor merge algorithm. | |
| template<typename P, typename Packed, typename Traits = ParticleTraits<P>, typename Gather, typename Combine, typename Scatter, typename Allocator, typename PosValid = std::function<bool(const RealVect&)>, typename OnMerge = std::function< void(const MergeParticle<Packed>&, const MergeParticle<Packed>&, const MergeParticle<Packed>&)>> | |
| void | ParticleManagement::mergeNearestNeighborsHash (ParticleContainer< P, Traits > &a_particles, const AmrMesh &a_amr, const NNCellBudget &a_cellBudget, const Gather &a_gather, const Combine &a_combine, const Scatter &a_scatter, const Allocator &a_allocateID, const bool a_iterateLocalTierToConvergence=false, const int a_maxFallbackCandidates=0, const std::optional< int > a_maxCellDistance=std::nullopt, const int a_ghostWidth=1, const PosValid &a_isPositionValid=[](const RealVect &) { return true;}, unsigned long long *a_crossLevelMergeCount=nullptr, const OnMerge &a_onMergeCommitted=[](const MergeParticle< Packed > &, const MergeParticle< Packed > &, const MergeParticle< Packed > &) { }) |
| Run one full round of the nearest-neighbor merge algorithm, identical in every respect to mergeNearestNeighborsTree() except that the per-patch spatial search is backed by an EBGeometry::PointCloudHashGrid (a uniform-grid index) instead of an EBGeometry::PointCloudBVH. | |
| template<typename P, typename Packed, typename Traits = ParticleTraits<P>, typename Gather, typename Combine, typename Scatter, typename Allocator, typename PosValid = std::function<bool(const RealVect&)>, typename OnMerge = std::function< void(const MergeParticle<Packed>&, const MergeParticle<Packed>&, const MergeParticle<Packed>&)>> | |
| void | ParticleManagement::mergeNearestNeighborsOneCell (ParticleContainer< P, Traits > &a_particles, const AmrMesh &a_amr, const NNCellBudget &a_cellBudget, const Gather &a_gather, const Combine &a_combine, const Scatter &a_scatter, const Allocator &a_allocateID, const bool a_iterateLocalTierToConvergence=false, const int a_maxFallbackCandidates=0, const PosValid &a_isPositionValid=[](const RealVect &) { return true;}, unsigned long long *a_crossLevelMergeCount=nullptr, const OnMerge &a_onMergeCommitted=[](const MergeParticle< Packed > &, const MergeParticle< Packed > &, const MergeParticle< Packed > &) { }) |
| Run one full round of the one-cell nearest-neighbor merge: the same distributed propose/judge/verdict protocol as mergeNearestNeighborsTree(), but with candidates found via a per-cell PointCloudBVH spatial index (see NNCellSpatialIndex) instead of one whole-patch tree. | |
Implementation of CD_NearestNeighborParticleMerge.H.