13#ifndef CD_PARTICLECONTAINERIMPLEM_H
14#define CD_PARTICLECONTAINERIMPLEM_H
24#include <unordered_map>
32#include <BoxIterator.H>
38#include <CD_NamespaceHeader.H>
40template <
typename P,
typename Traits>
47template <
typename P,
typename Traits>
50 const Vector<DisjointBoxLayout>& a_sourceGrids)
52 CH_TIME(
"ParticleContainer::gatherToPool");
60 auto binLeaf = [
this](
MoverPool& a_target,
const Leaf& a_leaf) ->
unsigned long long {
61 unsigned long long outcast = 0;
63 for (std::size_t i = 0; i < a_leaf.size(); i++) {
64 RealVect pos = a_leaf.position(i);
67 if (!dst.valid && this->moveInsideDomain(pos)) {
76 Leaf& bin = a_target[dst.rank][
PoolKey(dst.level, dst.gridIndex)];
78 bin.
append(pos, a_leaf.weight(i), a_leaf.gather(i));
80 const std::size_t k = bin.
size() - 1;
89 unsigned long long numOutcast = 0;
91 for (
int lvl = 0; lvl < a_source.size(); lvl++) {
93 const DataIterator& dit = a_sourceGrids[lvl].dataIterator();
94 const int nbox = dit.size();
97#pragma omp parallel reduction(+ : numOutcast)
101#pragma omp for schedule(runtime)
102 for (
int mybox = 0; mybox < nbox; mybox++) {
103 Leaf& leaf = level[dit[mybox]];
105 numOutcast += binLeaf(threadPool, leaf);
118#pragma omp critical(ParticleContainer_gatherMerge)
120 for (
int r = 0; r < numProc(); r++) {
121 for (
auto& kv : threadPool[r]) {
122 pool[r][kv.first].catenate(kv.second);
128 for (
int mybox = 0; mybox < nbox; mybox++) {
129 Leaf& leaf = level[dit[mybox]];
131 numOutcast += binLeaf(pool, leaf);
145template <
typename P,
typename Traits>
149 CH_TIME(
"ParticleContainer::gatherMoversToPool");
154 unsigned long long numOutcast = 0;
158 const LevelData<BaseFab<bool>>* maskLevel = (*m_validCells)[lvl].isNull() ? nullptr : &(*(*m_validCells)[lvl]);
159 const DataIterator& dit =
m_grids[lvl].dataIterator();
160 const int nbox = dit.size();
167 auto partitionLeaf = [
this, lvl](
MoverPool& a_target,
168 [[maybe_unused]]
const DataIndex& a_din,
170 const BaseFab<bool>* a_mask) ->
unsigned long long {
171 unsigned long long outcast = 0;
173 const Box maskBox = (a_mask !=
nullptr) ? a_mask->box() : Box();
177 while (i < a_leaf.size()) {
178 RealVect pos = a_leaf.position(i);
179 if (a_mask !=
nullptr) {
180 const IntVect iv = this->
cellIndex(lvl, pos);
182 if (maskBox.contains(iv) && (*a_mask)(iv, 0)) {
188 CH_assert(chk.valid && chk.level == lvl && chk.rank == procID() &&
189 m_levelTiles[lvl]->getMyGrids().at(chk.gridIndex) == a_din);
199 if (!dst.valid && this->moveInsideDomain(pos)) {
204 Leaf& bin = a_target[dst.rank][
PoolKey(dst.level, dst.gridIndex)];
206 bin.
append(pos, a_leaf.weight(i), a_leaf.gather(i));
208 const std::size_t k = bin.
size() - 1;
224#pragma omp parallel reduction(+ : numOutcast)
228#pragma omp for schedule(runtime)
229 for (
int mybox = 0; mybox < nbox; mybox++) {
230 const DataIndex& din = dit[mybox];
231 const BaseFab<bool>* mask = (maskLevel !=
nullptr) ? &(*maskLevel)[din] :
nullptr;
233 if (mask !=
nullptr && !mask->isUsable()) {
237 numOutcast += partitionLeaf(threadPool, din, level[din], mask);
240#pragma omp critical(ParticleContainer_gatherMerge)
242 for (
int r = 0; r < numProc(); r++) {
243 for (
auto& kv : threadPool[r]) {
244 pool[r][kv.first].catenate(kv.second);
250 for (
int mybox = 0; mybox < nbox; mybox++) {
251 const DataIndex& din = dit[mybox];
252 const BaseFab<bool>* mask = (maskLevel !=
nullptr) ? &(*maskLevel)[din] :
nullptr;
254 if (mask !=
nullptr && !mask->isUsable()) {
258 numOutcast += partitionLeaf(pool, din, level[din], mask);
268template <
typename P,
typename Traits>
272 CH_TIME(
"ParticleContainer::distributeFromPool");
274 const int myRank = procID();
275 const int numRanks = numProc();
282 for (
auto& kv : a_pool[myRank]) {
283 const int lvl = kv.first.first;
284 const unsigned int gidx = kv.first.second;
285 const DataIndex din =
m_levelTiles[lvl]->getMyGrids().at(gidx);
293 constexpr std::size_t headerLen = 2 *
sizeof(std::uint32_t) +
sizeof(std::uint64_t);
300 std::vector<int> sendCounts(numRanks, 0);
301 std::vector<int> recvCounts(numRanks, 0);
302 std::vector<std::int64_t> sendBytes(numRanks, 0);
304 std::int64_t stot = 0;
306 for (
int r = 0; r < numRanks; r++) {
311 std::int64_t bytes = 0;
313 for (
const auto& kv : a_pool[r]) {
314 bytes +=
static_cast<std::int64_t
>(headerLen + kv.second.size() * pp);
317 sendBytes[r] = bytes;
326 if (stot >
static_cast<std::int64_t
>(std::numeric_limits<int>::max())) {
327 MayDay::Abort(
"ParticleContainer::distributeFromPool - outbound particle bytes exceed MPI's int limit");
330 for (
int r = 0; r < numRanks; r++) {
331 sendCounts[r] =
static_cast<int>(sendBytes[r]);
334 MPI_Alltoall(sendCounts.data(), 1, MPI_INT, recvCounts.data(), 1, MPI_INT, Chombo_MPI::comm);
336 std::vector<int> sdispl(numRanks, 0);
337 std::vector<int> rdispl(numRanks, 0);
339 std::int64_t sacc = 0;
340 std::int64_t rtot = 0;
342 for (
int r = 0; r < numRanks; r++) {
343 sdispl[r] =
static_cast<int>(sacc);
344 sacc += sendCounts[r];
346 rdispl[r] =
static_cast<int>(rtot);
347 rtot += recvCounts[r];
350 if (rtot >
static_cast<std::int64_t
>(std::numeric_limits<int>::max())) {
351 MayDay::Abort(
"ParticleContainer::distributeFromPool - inbound particle bytes exceed MPI's int limit");
354 std::vector<char> sflat(stot);
355 std::vector<char> rflat(rtot);
361 const std::size_t flatBytes =
static_cast<std::size_t
>(stot) +
static_cast<std::size_t
>(rtot);
371#pragma omp parallel for schedule(runtime)
373 for (
int r = 0; r < numRanks; r++) {
378 char* p = sflat.data() + sdispl[r];
380 for (
auto& kv : a_pool[r]) {
381 Leaf& src = kv.second;
383 const std::uint32_t lvl =
static_cast<std::uint32_t
>(kv.first.first);
384 const std::uint32_t gidx =
static_cast<std::uint32_t
>(kv.first.second);
385 const std::uint64_t count =
static_cast<std::uint64_t
>(src.
size());
387 std::memcpy(p, &lvl,
sizeof(std::uint32_t));
388 p +=
sizeof(std::uint32_t);
390 std::memcpy(p, &gidx,
sizeof(std::uint32_t));
391 p +=
sizeof(std::uint32_t);
393 std::memcpy(p, &count,
sizeof(std::uint64_t));
394 p +=
sizeof(std::uint64_t);
396 for (std::size_t i = 0; i < count; i++) {
406 MPI_Alltoallv(sflat.data(),
428 unsigned int gridIndex;
430 std::vector<RecvChunk> chunks;
433 std::vector<DestGroup> groups;
434 std::map<PoolKey, std::size_t> keyToGroup;
436 const char* p = rflat.data();
437 const char* end = p + rtot;
444 std::memcpy(&lvl, p,
sizeof(std::uint32_t));
445 p +=
sizeof(std::uint32_t);
447 std::memcpy(&gidx, p,
sizeof(std::uint32_t));
448 p +=
sizeof(std::uint32_t);
450 std::memcpy(&count, p,
sizeof(std::uint64_t));
451 p +=
sizeof(std::uint64_t);
453 const PoolKey key(
static_cast<int>(lvl), gidx);
454 const auto it = keyToGroup.find(key);
456 if (it == keyToGroup.end()) {
457 keyToGroup.emplace(key, groups.size());
458 groups.push_back(DestGroup{
static_cast<int>(lvl), gidx, count, {RecvChunk{p, count}}});
461 DestGroup& g = groups[it->second];
463 g.chunks.push_back(RecvChunk{p, count});
470 const int numGroups =
static_cast<int>(groups.size());
473#pragma omp parallel for schedule(runtime)
475 for (
int d = 0; d < numGroups; d++) {
476 const DestGroup& g = groups[d];
477 const DataIndex din =
m_levelTiles[g.level]->getMyGrids().at(g.gridIndex);
482 for (
const RecvChunk& chunk : g.chunks) {
483 const char* q = chunk.payload;
485 for (std::uint64_t c = 0; c < chunk.count; c++) {
488 if (a_setOwnerToReceiver) {
500template <
typename P,
typename Traits>
504 CH_TIME(
"ParticleContainer::remap");
531template <
typename P,
typename Traits>
535 CH_TIME(
"ParticleContainer::preRegrid");
546template <
typename P,
typename Traits>
549 const Vector<ProblemDomain>& a_domains,
550 const Vector<Real>& a_dx,
551 const Vector<int>& a_refRat,
552 const int a_minBlockSize,
553 const Vector<RefCountedPtr<LevelTiles>>& a_levelTiles,
554 const int a_newFinestLevel)
556 CH_TIME(
"ParticleContainer::regrid");
559 CH_assert(a_levelTiles.size() > a_newFinestLevel);
571 m_dx.resize(a_newFinestLevel + 1);
572 for (
int lvl = 0; lvl <= a_newFinestLevel; lvl++) {
573 m_dx[lvl] = a_dx[lvl] * RealVect::Unit;
580 for (
int lvl = 0; lvl <= a_newFinestLevel; lvl++) {
589 for (
int lvl = 0; lvl <= a_newFinestLevel; lvl++) {
604template <
typename P,
typename Traits>
608 CH_TIME(
"ParticleContainer::clearGhostParticles");
614 const DisjointBoxLayout& dbl =
m_grids[lvl];
615 const DataIterator& dit = dbl.dataIterator();
617 const int nbox = dit.size();
619#pragma omp parallel for schedule(runtime)
620 for (
int mybox = 0; mybox < nbox; mybox++) {
621 const DataIndex& din = dit[mybox];
626 while (i < leaf.
size()) {
637 m_isOrganizedByCell =
false;
640template <
typename P,
typename Traits>
644 CH_TIME(
"ParticleContainer::claimOwnership");
655 const DisjointBoxLayout& dbl =
m_grids[lvl];
656 const DataIterator& dit = dbl.dataIterator();
657 const int nbox = dit.size();
659#pragma omp parallel for schedule(runtime)
660 for (
int mybox = 0; mybox < nbox; mybox++) {
661 const DataIndex& din = dit[mybox];
662 const Box box = dbl[din];
663 Leaf& leaf = level[din];
665 for (std::size_t i = 0; i < leaf.
size(); i++) {
669 if (!a_onlyValidRegion || this->inValidBox(lvl, box, leaf.
position(i))) {
677template <
typename P,
typename Traits>
681 CH_TIME(
"ParticleContainer::resetParticleIDs");
690 std::vector<std::pair<int, DataIndex>> boxes;
692 const DataIterator& dit =
m_grids[lvl].dataIterator();
693 const int nbox = dit.size();
694 for (
int mybox = 0; mybox < nbox; mybox++) {
695 boxes.emplace_back(lvl, dit[mybox]);
698 const int numBoxes =
static_cast<int>(boxes.size());
701 std::vector<long long> boxCount(numBoxes, 0);
702#pragma omp parallel for schedule(runtime)
703 for (
int b = 0; b < numBoxes; b++) {
704 const int lvl = boxes[b].first;
705 const DataIndex& din = boxes[b].second;
706 const Box box = m_grids[lvl][din];
707 const Leaf& leaf = (*m_particles[lvl])[din];
710 for (std::size_t i = 0; i < leaf.size(); i++) {
711 if (!leaf.isGhost(i) && (!a_onlyValidRegion || this->inValidBox(lvl, box, leaf.position(i)))) {
719 std::vector<long long> boxLocalOffset(numBoxes, 0);
720 long long localTotal = 0;
721 for (
int b = 0; b < numBoxes; b++) {
722 boxLocalOffset[b] = localTotal;
723 localTotal += boxCount[b];
730 for (
int r = 0; r < procID(); r++) {
731 rankOffset += perRankCount[r];
736#pragma omp parallel for schedule(runtime)
737 for (
int b = 0; b < numBoxes; b++) {
738 const int lvl = boxes[b].first;
739 const DataIndex& din = boxes[b].second;
740 const Box box = m_grids[lvl][din];
741 Leaf& leaf = (*m_particles[lvl])[din];
744 for (std::size_t i = 0; i < leaf.size(); i++) {
745 if (leaf.isGhost(i)) {
748 if (!a_onlyValidRegion || this->inValidBox(lvl, box, leaf.position(i))) {
749 leaf.particleID(i) =
id++;
760template <
typename P,
typename Traits>
766 CH_TIME(
"ParticleContainer::gatherGhostsFromMasks");
774 auto binLeaf = [&](
MoverPool& a_target,
const Leaf& a_leaf,
const int a_srcLvl,
const DataIndex& a_din) {
775 const bool haveSame = (a_srcLvl < a_maskSame.size()) && !a_maskSame[a_srcLvl].isNull();
776 const bool haveC2F = (a_srcLvl <
m_finestLevel) && (a_srcLvl < a_maskCoarToFine.size()) &&
777 !a_maskCoarToFine[a_srcLvl].isNull();
778 const bool haveF2C = (a_srcLvl >= 1) && (a_srcLvl < a_maskFineToCoar.size()) &&
779 !a_maskFineToCoar[a_srcLvl].isNull();
781 const ParticleGhostMask* same = haveSame ? &((*a_maskSame[a_srcLvl])[a_din]) :
nullptr;
782 const ParticleGhostMask* c2f = haveC2F ? &((*a_maskCoarToFine[a_srcLvl])[a_din]) :
nullptr;
783 const ParticleGhostMask* f2c = haveF2C ? &((*a_maskFineToCoar[a_srcLvl])[a_din]) :
nullptr;
785 if (same ==
nullptr && c2f ==
nullptr && f2c ==
nullptr) {
789 for (std::size_t i = 0; i < a_leaf.size(); i++) {
790 const RealVect pos = a_leaf.position(i);
791 const IntVect iv = this->
cellIndex(a_srcLvl, pos);
795 if (a_mask ==
nullptr || !a_mask->
box().contains(iv)) {
803 const IntVect dstCell = a_pruneByTargetBox ? this->
cellIndex(a_dstLvl, pos) : IntVect::Zero;
805 for (
int k = 0; k < nt; k++) {
806 if (a_pruneByTargetBox && !a_mask->
targetBox(iv, k).contains(dstCell)) {
812 bin.
append(pos, a_leaf.weight(i), a_leaf.gather(i));
814 const std::size_t j = bin.
size() - 1;
830 const DataIterator& dit =
m_grids[lvl].dataIterator();
831 const int nbox = dit.size();
838#pragma omp for schedule(runtime)
839 for (
int mybox = 0; mybox < nbox; mybox++) {
840 binLeaf(threadPool, level[dit[mybox]], lvl, dit[mybox]);
843#pragma omp critical(ParticleContainer_gatherGhostsFromMasksMerge)
845 for (
int r = 0; r < numProc(); r++) {
846 for (
auto& kv : threadPool[r]) {
847 pool[r][kv.first].catenate(kv.second);
853 for (
int mybox = 0; mybox < nbox; mybox++) {
854 binLeaf(pool, level[dit[mybox]], lvl, dit[mybox]);
862template <
typename P,
typename Traits>
868 CH_TIME(
"ParticleContainer::fillGhostParticles");
883template <
typename P,
typename Traits>
887 CH_TIME(
"ParticleContainer::setupGrownGrids");
891 const DisjointBoxLayout& dbl =
m_grids[lvl];
893 Vector<Box> boxes = dbl.boxArray();
896 const Box domainBox =
m_domains[lvl].domainBox();
897 for (
int i = 0; i < boxes.size(); i++) {
899 boxes[i] &= domainBox;
903 m_grownGrids[lvl] = BoxLayout(boxes, dbl.procIDs());
907template <
typename P,
typename Traits>
911 CH_TIME(
"ParticleContainer::copyMaskParticles(amr)");
916 if (!a_mask[lvl].isNull()) {
922template <
typename P,
typename Traits>
926 CH_TIME(
"ParticleContainer::copyMaskParticles(level)");
933 const DisjointBoxLayout& dbl =
m_grids[a_level];
934 const DataIterator& dit = dbl.dataIterator();
936 const int nbox = dit.size();
938#pragma omp parallel for schedule(runtime)
939 for (
int mybox = 0; mybox < nbox; mybox++) {
940 const DataIndex& din = dit[mybox];
942 maskLevel[din].clear();
944 const BaseFab<bool>& mask = a_mask[din];
945 if (!mask.isUsable()) {
948 const Box maskBox = mask.box();
950 const Leaf& src = srcLevel[din];
951 Leaf& dst = maskLevel[din];
953 for (std::size_t i = 0; i < src.size(); i++) {
954 const IntVect iv = this->cellIndex(a_level, src.position(i));
956 if (maskBox.contains(iv) && mask(iv, 0)) {
957 dst.append(src.position(i), src.weight(i), src.gather(i));
959 const std::size_t k = dst.size() - 1;
961 dst.particleID(k) = src.particleID(i);
962 dst.rankID(k) = src.rankID(i);
968template <
typename P,
typename Traits>
972 CH_TIME(
"ParticleContainer::transferMaskParticles(amr)");
977 if (!a_mask[lvl].isNull()) {
983template <
typename P,
typename Traits>
987 CH_TIME(
"ParticleContainer::transferMaskParticles(level)");
994 const DisjointBoxLayout& dbl =
m_grids[a_level];
995 const DataIterator& dit = dbl.dataIterator();
997 const int nbox = dit.size();
999#pragma omp parallel for schedule(runtime)
1000 for (
int mybox = 0; mybox < nbox; mybox++) {
1001 const DataIndex& din = dit[mybox];
1003 const BaseFab<bool>& mask = a_mask[din];
1004 if (!mask.isUsable()) {
1007 const Box maskBox = mask.box();
1009 Leaf& src = srcLevel[din];
1010 Leaf& dst = maskLevel[din];
1013 while (i < src.
size()) {
1016 if (maskBox.contains(iv) && mask(iv, 0)) {
1019 const std::size_t k = dst.
size() - 1;
1033#include <CD_NamespaceFooter.H>
Declaration of an AMR-hierarchy container that owns per-patch ParticleSoA leaves.
Vector< RefCountedPtr< LayoutData< ParticleSoA< P, Traits > > > > AMRParticlesSoA
Per-level holder vector: one ParticleSoA leaf container per box, per level.
Definition CD_ParticleContainer.H:56
Vector< RefCountedPtr< LayoutData< ParticleGhostMask > > > AMRParticleGhostMask
AMR-wide particle ghost-target lookup: one per-box CSR table per level, indexed by SOURCE level.
Definition CD_ParticleGhostMask.H:210
Process-wide accounting of the memory held by particle data.
std::int32_t RankID
Owning-rank identifier type (container-owned metadata column; fixed-width for I/O).
Definition CD_ParticleSoA.H:166
GhostType
Ghost designation of a particle (container-owned metadata column).
Definition CD_ParticleSoA.H:177
@ SameLevel
Ghost from an adjacent patch on the same level.
Definition CD_ParticleSoA.H:179
@ Coarse
Ghost from the next-coarser level (level l-1).
Definition CD_ParticleSoA.H:180
@ Fine
Ghost from the next-finer level (level l+1).
Definition CD_ParticleSoA.H:181
std::int64_t ParticleID
Global particle identifier type (container-owned metadata column; fixed-width for I/O).
Definition CD_ParticleSoA.H:161
static LevelAndBox findDestination(const RealVect &a_pos, const RealVect &a_probLo, const Vector< RealVect > &a_dx, const int a_minBlockSize, const Vector< RefCountedPtr< LevelTiles > > &a_levelTiles, const int a_finestLevel) noexcept
Map a physical position to its owning (level, grid index, rank) via the finest containing tile.
Definition CD_LevelTiles.H:161
void fillGhostParticles(const AMRParticleGhostMask &a_maskSame, const AMRParticleGhostMask &a_maskCoarToFine, const AMRParticleGhostMask &a_maskFineToCoar)
Fill each patch's ghost halo from prebuilt Realm particle ghost masks.
Definition CD_ParticleContainerImplem.H:864
std::vector< std::map< PoolKey, Leaf > > MoverPool
Per-rank pool of movers: pool[rank] maps a destination patch to a small SoA of particles.
Definition CD_ParticleContainer.H:917
void regrid(const Vector< DisjointBoxLayout > &a_grids, const Vector< ProblemDomain > &a_domains, const Vector< Real > &a_dx, const Vector< int > &a_refRat, const int a_minBlockSize, const Vector< RefCountedPtr< LevelTiles > > &a_levelTiles, const int a_newFinestLevel)
Rebuild over a new AMR layout and redistribute the preRegrid()-cached particles onto it.
Definition CD_ParticleContainerImplem.H:548
void clearParticles()
Drop all valid particles on every level (keeps each leaf's arena capacity).
Definition CD_ParticleContainer.H:447
AMRParticlesSoA< P, Traits > m_maskParticles
Halo/mask particles per level.
Definition CD_ParticleContainer.H:1063
IntVect cellIndex(const int a_lvl, const RealVect &a_pos) const
Cell index containing a position on a given level (floor((x - probLo)/dx)).
Definition CD_ParticleContainer.H:1082
void transferMaskParticles(const Vector< RefCountedPtr< LevelData< BaseFab< bool > > > > &a_mask)
Move the valid particles selected by a per-cell mask into the mask holder, all levels.
Definition CD_ParticleContainerImplem.H:970
AMRParticlesSoA< P, Traits > m_cacheParticles
Regrid cache: the pre-regrid valid holders, kept alive over the old layout by preRegrid().
Definition CD_ParticleContainer.H:1053
int m_finestLevel
Finest AMR level index.
Definition CD_ParticleContainer.H:1014
void setupGrownGrids()
Build the grown grids (buffer-particle layout): boxes grown by the refinement factor.
Definition CD_ParticleContainerImplem.H:885
MoverPool gatherMoversToPool()
Mask fast path for remap(): pool ONLY the movers, leaving stayers in place.
Definition CD_ParticleContainerImplem.H:147
void clearGhostParticles()
Remove every ghost particle (any non-Valid GhostType) from all levels and patches.
Definition CD_ParticleContainerImplem.H:606
Vector< BoxLayout > m_grownGrids
Per-level grown grids (boxes grown by the refinement factor on finer levels) for the buffer.
Definition CD_ParticleContainer.H:1073
void preRegrid()
Cache the current valid particles ahead of a regrid.
Definition CD_ParticleContainerImplem.H:533
AMRParticlesSoA< P, Traits > m_bufferParticles
Grown-grid buffer particles per level (on m_grownGrids; filled during halo deposition).
Definition CD_ParticleContainer.H:1068
Vector< int > m_refRat
Per-level refinement ratios (entry l is the ratio between level l and l+1).
Definition CD_ParticleContainer.H:989
AMRParticlesSoA< P, Traits > m_particles
Valid particles: one ParticleSoA leaf per box, per level.
Definition CD_ParticleContainer.H:1048
void claimOwnership(const bool a_onlyValidRegion)
Claim ownership of this rank's particles by stamping their owner rank (rankID = procID()).
Definition CD_ParticleContainerImplem.H:642
const Vector< RefCountedPtr< LevelData< BaseFab< bool > > > > * m_validCells
Optional alias to the realm's valid-cell mask (true = cell not covered by a finer level).
Definition CD_ParticleContainer.H:1033
bool m_isOrganizedByCell
Whether the valid leaves are currently cell-sorted.
Definition CD_ParticleContainer.H:1043
void distributeFromPool(MoverPool &a_pool, const bool a_setOwnerToReceiver)
Assign a pool into the valid holders: local appends + MPI scatter.
Definition CD_ParticleContainerImplem.H:270
ParticleSoA< P, Traits > Leaf
The per-patch leaf type owned at every (level, box).
Definition CD_ParticleContainer.H:128
unsigned long long m_numOutcastLocal
Particles dropped off-domain by the most recent remap() (local count).
Definition CD_ParticleContainer.H:1019
int m_minBlockSize
Grid blocking factor (tile size).
Definition CD_ParticleContainer.H:1009
RealVect m_probLo
Lower-left corner of the physical domain.
Definition CD_ParticleContainer.H:999
long long resetParticleIDs(const bool a_onlyValidRegion, const ParticleID a_startID)
Assign globally-unique, contiguous particle IDs to the owned particles.
Definition CD_ParticleContainerImplem.H:679
void remap()
Redistribute every valid particle to the patch/level/rank that owns its cell.
Definition CD_ParticleContainerImplem.H:502
Vector< RefCountedPtr< LevelTiles > > m_levelTiles
Per-level tile-ownership maps (cell tile -> owning grid index / rank), used by remap().
Definition CD_ParticleContainer.H:994
MoverPool gatherToPool(AMRParticlesSoA< P, Traits > &a_source, const Vector< DisjointBoxLayout > &a_sourceGrids)
Gather every particle of a source holder into a per-rank, per-destination-patch pool.
Definition CD_ParticleContainerImplem.H:49
LayoutData< Leaf > LevelParticles
The per-level holder type (one Leaf per box on the level's DisjointBoxLayout).
Definition CD_ParticleContainer.H:133
Vector< ProblemDomain > m_domains
Per-level problem domains.
Definition CD_ParticleContainer.H:979
LevelTiles::LevelAndBox findDestination(const RealVect &a_pos) const
Map a position to its owning (level, grid index, rank) via the finest containing tile.
Definition CD_ParticleContainerImplem.H:42
void copyMaskParticles(const Vector< RefCountedPtr< LevelData< BaseFab< bool > > > > &a_mask)
Copy the valid particles selected by a per-cell mask into the mask holder, all levels.
Definition CD_ParticleContainerImplem.H:909
Vector< RealVect > m_dx
Per-level grid spacing (isotropic, stored as RealVect).
Definition CD_ParticleContainer.H:984
Vector< DisjointBoxLayout > m_grids
Per-level AMR grids.
Definition CD_ParticleContainer.H:974
std::pair< int, unsigned int > PoolKey
Pool key identifying a destination patch: (level, grid index within the level).
Definition CD_ParticleContainer.H:912
bool m_isDefined
Whether define() has been called.
Definition CD_ParticleContainer.H:1038
MoverPool gatherGhostsFromMasks(const AMRParticleGhostMask &a_maskSame, const AMRParticleGhostMask &a_maskCoarToFine, const AMRParticleGhostMask &a_maskFineToCoar)
Gather ghost copies into a per-rank pool using prebuilt particle ghost masks.
Definition CD_ParticleContainerImplem.H:762
Vector< DisjointBoxLayout > m_cacheGrids
The old (pre-regrid) grids the cache holders are defined on (for iterating the cache).
Definition CD_ParticleContainer.H:1058
Per-box CSR lookup from a source cell to the destination boxes whose ghosted region covers it.
Definition CD_ParticleGhostMask.H:53
const Box & box() const noexcept
Get the box that the source cells live on.
Definition CD_ParticleGhostMaskImplem.H:90
unsigned int targetGridIndex(const IntVect &a_iv, const int a_i) const noexcept
Get the destination grid index of the i-th target for a cell.
Definition CD_ParticleGhostMaskImplem.H:116
const Box & targetBox(const IntVect &a_iv, const int a_i) const noexcept
Get the acceptance box of the i-th target for a cell.
Definition CD_ParticleGhostMaskImplem.H:128
int numTargets(const IntVect &a_iv) const noexcept
Get the number of scatter targets for a cell.
Definition CD_ParticleGhostMaskImplem.H:100
unsigned int targetRank(const IntVect &a_iv, const int a_i) const noexcept
Get the receiving rank of the i-th target for a cell.
Definition CD_ParticleGhostMaskImplem.H:122
RankID & rankID(const std::size_t a_index) noexcept
Owning rank of particle i (container-owned metadata).
Definition CD_ParticleSoA.H:1286
void append(const RealVect &a_position, const double a_weight)
Append one particle with a default-constructed payload.
Definition CD_ParticleSoA.H:962
void shrinkToFit()
Reclaim unused capacity by reallocating the arena down to the current size.
Definition CD_ParticleSoAImplem.H:187
bool isGhost(const std::size_t a_index) const noexcept
Whether particle i is a ghost particle (any non-Valid designation).
Definition CD_ParticleSoA.H:1338
void delinearizeAndAppend(const void *a_buffer)
Append a particle delinearized from a byte buffer (all columns, for MPI receive).
Definition CD_ParticleSoAImplem.H:243
void linearizeParticle(void *a_buffer, const std::size_t a_index) const noexcept
Linearize particle i into a byte buffer (all columns, for MPI send).
Definition CD_ParticleSoAImplem.H:232
RealVect position(const std::size_t a_index) const noexcept
Position of particle i as a RealVect (by value, assembled from the scalar columns).
Definition CD_ParticleSoA.H:1195
GhostType & ghost(const std::size_t a_index) noexcept
Ghost designation of particle i (container-owned metadata).
Definition CD_ParticleSoA.H:1312
double & weight(const std::size_t a_index) noexcept
Weight of particle i.
Definition CD_ParticleSoA.H:1229
static constexpr std::size_t bytesPerParticle() noexcept
Definition CD_ParticleSoA.H:1355
std::size_t size() const noexcept
Number of particles currently stored.
Definition CD_ParticleSoA.H:882
P gather(const std::size_t a_index) const
Gather particle i's payload back into the AoS payload view.
Definition CD_ParticleSoA.H:1028
ParticleID & particleID(const std::size_t a_index) noexcept
Global id of particle i (container-owned metadata).
Definition CD_ParticleSoA.H:1260
void remove(const std::size_t a_index) noexcept
Remove particle i using swap-and-pop (O(1), does NOT preserve order).
Definition CD_ParticleSoA.H:1040
static constexpr ParticleID s_invalidID
Sentinel for an unassigned/invalid global particle id.
Definition CD_ParticleSoA.H:1252
void clear() noexcept
Drop all particles (keeps the arena; invalidates the cell sort unless there was nothing to drop).
Definition CD_ParticleSoA.H:915
void reserve(const std::size_t a_capacity)
Ensure capacity for at least a_capacity particles (reallocates + moves on growth).
Definition CD_ParticleSoAImplem.H:88
Vector< int > gather(const int &a_localValue) noexcept
Gather local values – return a vector of local values.
Definition CD_ParallelOpsImplem.H:560
Real sum(const Real &a_value) noexcept
Compute the sum across all MPI ranks.
Definition CD_ParallelOpsImplem.H:354
void removeBytes(const Kind a_kind, const std::size_t a_bytes) noexcept
Record a release.
Definition CD_ParticleMemory.H:140
void addBytes(const Kind a_kind, const std::size_t a_bytes) noexcept
Record an allocation.
Definition CD_ParticleMemory.H:124
@ Buffer
Flat exchange buffers: payload in flight.
Definition CD_ParticleMemory.H:63
Result of a point->block query. See findDestination.
Definition CD_LevelTiles.H:123