Skip to content

Commit

Permalink
AddRealComp/AddIntComp: Resize SoA (#3615)
Browse files Browse the repository at this point in the history
## Summary

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. Alternatively, we should add API contract details
to the `AddRealComp`/`AddIntComp` doc strings to make sure people use it
right.

## Additional background

- AMReX-Codes/pyamrex#220
- AMReX-Codes/pyamrex#222

## Checklist

The proposed changes:
- [ ] fix a bug or incorrect behavior in AMReX
- [x] add new capabilities to AMReX
- [ ] changes answers in the test suite to more than roundoff level
- [ ] are likely to significantly affect the results of downstream AMReX
users
- [ ] include documentation in the code and/or rst files, if appropriate
  • Loading branch information
ax3l authored Mar 29, 2024
1 parent 1be7257 commit f264290
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 @@ -1244,6 +1244,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 @@ -1254,6 +1266,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 @@ -1262,7 +1286,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 f264290

Please sign in to comment.