Skip to content

Commit

Permalink
AddRealComp/AddIntComp: Resize
Browse files Browse the repository at this point in the history
When adding new `Real`/`Int` runtime components, they
could be made available without additional calls.

The cost should be the same as calling it explicitly later,
but clarifies the usage.
  • Loading branch information
ax3l committed Nov 6, 2023
1 parent a7afcba commit d0d1132
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Src/Particle/AMReX_ParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,18 @@ public:
m_num_runtime_real++;
h_redistribute_real_comp.push_back(communicate);
SetParticleSize();

// resize runtime SoA
for (int lev = 0; lev < numLevels(); ++lev) {
for (ParIterType pti(*this,lev); pti.isValid(); ++pti) {
auto& tile = DefineAndReturnParticleTile(lev, pti);
auto np = tile.numParticles();
if (np > 0) {
auto& soa = tile.GetStructOfArrays();
soa.resize(np);
}
}
}
}

template <typename T,
Expand All @@ -1259,6 +1271,18 @@ public:
m_num_runtime_int++;
h_redistribute_int_comp.push_back(communicate);
SetParticleSize();

// resize runtime SoA
for (int lev = 0; lev < numLevels(); ++lev) {
for (ParIterType pti(*this,lev); pti.isValid(); ++pti) {
auto& tile = DefineAndReturnParticleTile(lev, pti);
auto np = tile.numParticles();
if (np > 0) {
auto& soa = tile.GetStructOfArrays();
soa.resize(np);
}
}
}
}

int NumRuntimeRealComps () const { return m_num_runtime_real; }
Expand All @@ -1267,7 +1291,18 @@ public:
int NumRealComps () const { return NArrayReal + NumRuntimeRealComps(); }
int NumIntComps () const { return NArrayInt + NumRuntimeIntComps() ; }

/** Resize the Real runtime components (SoA)
*
* @param new_size new number of Real runtime components
* @param communicate participate this component in redistribute
*/
void ResizeRuntimeRealComp (int new_size, bool communicate);

/** Resize the Int runtime components (SoA)
*
* @param new_size new number of integer runtime components
* @param communicate participate this component in redistribute
*/
void ResizeRuntimeIntComp (int new_size, bool communicate);

/** type trait to translate one particle container to another, with changed allocator */
Expand Down

0 comments on commit d0d1132

Please sign in to comment.