chombo-discharge
Loading...
Searching...
No Matches
CD_KDParticleMerge.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
13#ifndef CD_KDPARTICLEMERGE_H
14#define CD_KDPARTICLEMERGE_H
15
16// Std includes
17#include <cstdint>
18#include <functional>
19#include <vector>
20
21// Chombo includes
22#include <Box.H>
23#include <FArrayBox.H>
24#include <RealVect.H>
25
26// Our includes
27#include <CD_ParticleSoA.H>
30#include <CD_AmrMesh.H>
31#include <CD_NamespaceHeader.H>
32
34
52template <typename Packed>
53using KDPayloadCombine = std::function<
54 Packed(const Packed* a_payloads, const Real* a_weights, const std::size_t a_count)>;
55
56namespace detail {
57
67struct KDLeaf
68{
72 std::size_t lo;
73
77 std::size_t hi;
78
82 RealVect boxLo;
83
87 RealVect boxHi;
88};
89
134template <typename Packed>
135inline void
136buildKDQuotaLeaves(std::vector<MergeParticle<Packed>>& a_particles,
137 FArrayBox& a_used,
138 std::vector<KDLeaf>& a_leaves,
139 const int a_ppc,
140 const Real a_splitWeightLeafDx,
141 const RealVect& a_dx,
142 const RealVect& a_probLo,
143 const FArrayBox& a_cellCounts) noexcept;
144
159template <typename T>
160inline std::vector<T>
161kdExchangeByRank(const std::vector<std::vector<T>>& a_sendByRank);
162
163} // namespace detail
164
204template <typename P,
205 typename Packed,
206 typename Traits = ParticleTraits<P>,
207 typename Gather,
208 typename Combine,
209 typename Scatter,
210 typename Allocator,
211 typename PosValid>
212inline void
214 EBAMRFAB& a_cellHistogram,
215 EBAMRFAB& a_leafQuota,
216 const AmrMesh& a_amr,
217 const int a_ppc,
218 const Real a_splitWeightLeafDx,
219 const Gather& a_gather,
220 const Combine& a_combine,
221 const Scatter& a_scatter,
222 const Allocator& a_allocateID,
223 const PosValid& a_isPositionValid);
224
263template <typename P,
264 typename Packed,
265 typename Traits = ParticleTraits<P>,
266 typename Gather,
267 typename Combine,
268 typename Scatter,
269 typename Allocator,
270 typename PosValid>
271inline void
273 EBAMRFAB& a_cellHistogram,
274 EBAMRFAB& a_leafQuota,
275 const AmrMesh& a_amr,
276 const int a_ppc,
277 const Real a_splitWeightLeafDx,
278 const Gather& a_gather,
279 const Combine& a_combine,
280 const Scatter& a_scatter,
281 const Allocator& a_allocateID,
282 const PosValid& a_isPositionValid);
283
330template <typename P,
331 typename Packed,
332 typename Traits = ParticleTraits<P>,
333 typename Gather,
334 typename Combine,
335 typename Scatter,
336 typename Allocator,
337 typename PosValid>
338inline void
341 EBAMRFAB& a_cellHistogram,
342 EBAMRFAB& a_leafQuota,
343 const AmrMesh& a_amr,
344 const int a_ppc,
345 const Real a_splitWeightLeafDx,
346 const Gather& a_gather,
347 const Combine& a_combine,
348 const Scatter& a_scatter,
349 const Allocator& a_allocateID,
350 const PosValid& a_isPositionValid);
351
352} // namespace ParticleManagement
353
354#include <CD_NamespaceFooter.H>
355
357
358#endif
Declaration of core class for handling AMR-related operations (with embedded boundaries)
Implementation of CD_KDParticleMerge.H.
Declaration of an AMR-hierarchy container that owns per-patch ParticleSoA leaves.
Namespace containing various particle management utilities.
Declaration of ParticleSoA, an arena-backed Struct-of-Arrays particle container.
Class for handling spatial operations.
Definition CD_AmrMesh.H:45
AMR-hierarchy container of computational particles, stored per patch in Struct-of-Arrays form.
Definition CD_ParticleContainer.H:123
std::vector< T > kdExchangeByRank(const std::vector< std::vector< T > > &a_sendByRank)
Generic Alltoallv-style exchange for a trivially-copyable record type: send a per-destination-rank bu...
Definition CD_KDParticleMergeImplem.H:42
void buildKDQuotaLeaves(std::vector< MergeParticle< Packed > > &a_particles, FArrayBox &a_used, std::vector< KDLeaf > &a_leaves, const int a_ppc, const Real a_splitWeightLeafDx, const RealVect &a_dx, const RealVect &a_probLo, const FArrayBox &a_cellCounts) noexcept
Build one whole-patch kd tree: partition a_particles by position into leaves, each of which becomes e...
Definition CD_KDParticleMergeImplem.H:368
Namespace for various particle management tools.
Definition CD_KDParticleMerge.H:33
std::function< Packed(const Packed *a_payloads, const Real *a_weights, const std::size_t a_count)> KDPayloadCombine
Illustrative signature of the N-ary combine callback: produce a merged particle's opaque payload from...
Definition CD_KDParticleMerge.H:54
void mergeKDInterior(ParticleContainer< P, Traits > &a_particles, ParticleContainer< P, Traits > &a_interior, EBAMRFAB &a_cellHistogram, EBAMRFAB &a_leafQuota, const AmrMesh &a_amr, const int a_ppc, const Real a_splitWeightLeafDx, const Gather &a_gather, const Combine &a_combine, const Scatter &a_scatter, const Allocator &a_allocateID, const PosValid &a_isPositionValid)
Run the uncontested tier of the kd merge, splitting the input into merged and leftover.
Definition CD_KDParticleMergeImplem.H:1606
void mergeKDPatch(ParticleContainer< P, Traits > &a_particles, EBAMRFAB &a_cellHistogram, EBAMRFAB &a_leafQuota, const AmrMesh &a_amr, const int a_ppc, const Real a_splitWeightLeafDx, const Gather &a_gather, const Combine &a_combine, const Scatter &a_scatter, const Allocator &a_allocateID, const PosValid &a_isPositionValid)
Run one patch-local kd-tree merge over every patch this rank owns.
Definition CD_KDParticleMergeImplem.H:1563
void mergeKDCarve(ParticleContainer< P, Traits > &a_particles, EBAMRFAB &a_cellHistogram, EBAMRFAB &a_leafQuota, const AmrMesh &a_amr, const int a_ppc, const Real a_splitWeightLeafDx, const Gather &a_gather, const Combine &a_combine, const Scatter &a_scatter, const Allocator &a_allocateID, const PosValid &a_isPositionValid)
Run one non-iterative pass of the kd-tree carve merge over every patch this rank owns.
Definition CD_KDParticleMergeImplem.H:651
Minimal, payload-agnostic description of one particle as input to a distributed merge.
Definition CD_ParticleManagement.H:430
One leaf of a kd tree: a contiguous index range into the (in-place reordered) particle buffer,...
Definition CD_KDParticleMerge.H:68
RealVect boxHi
High corner of this leaf's axis-aligned bounding box.
Definition CD_KDParticleMerge.H:87
std::size_t hi
End of this leaf's member range (exclusive) in the reordered particle buffer.
Definition CD_KDParticleMerge.H:77
RealVect boxLo
Low corner of this leaf's axis-aligned bounding box.
Definition CD_KDParticleMerge.H:82
std::size_t lo
Start of this leaf's member range (inclusive) in the reordered particle buffer.
Definition CD_KDParticleMerge.H:72
Traits class that a user specializes to describe the PAYLOAD columns of a particle type....
Definition CD_ParticleSoA.H:192