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_weightMedianCellWidths,
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
218template <typename P,
219 typename Packed,
220 typename Traits = ParticleTraits<P>,
221 typename Gather,
222 typename Combine,
223 typename Scatter,
224 typename Allocator,
225 typename PosValid,
226 typename PatchRegular>
227inline void
229 EBAMRFAB& a_cellHistogram,
230 EBAMRFAB& a_leafQuota,
231 const AmrMesh& a_amr,
232 const int a_ppc,
233 const Real a_weightMedianCellWidths,
234 const KDPlacement a_placement,
235 const bool a_capWeights,
236 const KDSplitPlacement a_splitPlacement,
237 const Gather& a_gather,
238 const Combine& a_combine,
239 const Scatter& a_scatter,
240 const Allocator& a_allocateID,
241 const PosValid& a_isPositionValid,
242 const PatchRegular& a_isPatchRegular);
243
296template <typename P,
297 typename Packed,
298 typename Traits = ParticleTraits<P>,
299 typename Gather,
300 typename Combine,
301 typename Scatter,
302 typename Allocator,
303 typename PosValid,
304 typename PatchRegular>
305inline void
307 EBAMRFAB& a_cellHistogram,
308 EBAMRFAB& a_leafQuota,
309 const AmrMesh& a_amr,
310 const int a_ppc,
311 const Real a_weightMedianCellWidths,
312 const KDPlacement a_placement,
313 const bool a_capWeights,
314 const KDSplitPlacement a_splitPlacement,
315 const Gather& a_gather,
316 const Combine& a_combine,
317 const Scatter& a_scatter,
318 const Allocator& a_allocateID,
319 const PosValid& a_isPositionValid,
320 const PatchRegular& a_isPatchRegular);
321
382template <typename P,
383 typename Packed,
384 typename Traits = ParticleTraits<P>,
385 typename Gather,
386 typename Combine,
387 typename Scatter,
388 typename Allocator,
389 typename PosValid,
390 typename PatchRegular>
391inline void
394 EBAMRFAB& a_cellHistogram,
395 EBAMRFAB& a_leafQuota,
396 const AmrMesh& a_amr,
397 const int a_ppc,
398 const Real a_weightMedianCellWidths,
399 const KDPlacement a_placement,
400 const bool a_capWeights,
401 const KDSplitPlacement a_splitPlacement,
402 const Gather& a_gather,
403 const Combine& a_combine,
404 const Scatter& a_scatter,
405 const Allocator& a_allocateID,
406 const PosValid& a_isPositionValid,
407 const PatchRegular& a_isPatchRegular);
408
409} // namespace ParticleManagement
410
411#include <CD_NamespaceFooter.H>
412
414
415#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:46
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:43
void buildKDQuotaLeaves(std::vector< MergeParticle< Packed > > &a_particles, FArrayBox &a_used, std::vector< KDLeaf > &a_leaves, const int a_ppc, const Real a_weightMedianCellWidths, 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:474
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
KDSplitPlacement
Where the pieces of a split particle go.
Definition CD_ParticleManagement.H:65
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_weightMedianCellWidths, const KDPlacement a_placement, const bool a_capWeights, const KDSplitPlacement a_splitPlacement, const Gather &a_gather, const Combine &a_combine, const Scatter &a_scatter, const Allocator &a_allocateID, const PosValid &a_isPositionValid, const PatchRegular &a_isPatchRegular)
Run the uncontested tier of the kd merge, splitting the input into merged and leftover.
Definition CD_KDParticleMergeImplem.H:1900
void mergeKDCarve(ParticleContainer< P, Traits > &a_particles, EBAMRFAB &a_cellHistogram, EBAMRFAB &a_leafQuota, const AmrMesh &a_amr, const int a_ppc, const Real a_weightMedianCellWidths, const KDPlacement a_placement, const bool a_capWeights, const KDSplitPlacement a_splitPlacement, const Gather &a_gather, const Combine &a_combine, const Scatter &a_scatter, const Allocator &a_allocateID, const PosValid &a_isPositionValid, const PatchRegular &a_isPatchRegular)
Run one non-iterative pass of the kd-tree carve merge over every patch this rank owns.
Definition CD_KDParticleMergeImplem.H:832
KDPlacement
Where a kd merge puts the particle a leaf reduces to.
Definition CD_ParticleManagement.H:80
void mergeKDPatch(ParticleContainer< P, Traits > &a_particles, EBAMRFAB &a_cellHistogram, EBAMRFAB &a_leafQuota, const AmrMesh &a_amr, const int a_ppc, const Real a_weightMedianCellWidths, const KDPlacement a_placement, const bool a_capWeights, const KDSplitPlacement a_splitPlacement, const Gather &a_gather, const Combine &a_combine, const Scatter &a_scatter, const Allocator &a_allocateID, const PosValid &a_isPositionValid, const PatchRegular &a_isPatchRegular)
Run one patch-local kd-tree merge over every patch this rank owns.
Definition CD_KDParticleMergeImplem.H:1848
Minimal, payload-agnostic description of one particle as input to a distributed merge.
Definition CD_ParticleManagement.H:519
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