Skip to content

Commit f264290

Browse files
authored
AddRealComp/AddIntComp: Resize SoA (#3615)
## 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
1 parent 1be7257 commit f264290

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Src/Particle/AMReX_ParticleContainer.H

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,18 @@ public:
12441244
m_num_runtime_real++;
12451245
h_redistribute_real_comp.push_back(communicate);
12461246
SetParticleSize();
1247+
1248+
// resize runtime SoA
1249+
for (int lev = 0; lev < numLevels(); ++lev) {
1250+
for (ParIterType pti(*this,lev); pti.isValid(); ++pti) {
1251+
auto& tile = DefineAndReturnParticleTile(lev, pti);
1252+
auto np = tile.numParticles();
1253+
if (np > 0) {
1254+
auto& soa = tile.GetStructOfArrays();
1255+
soa.resize(np);
1256+
}
1257+
}
1258+
}
12471259
}
12481260

12491261
template <typename T,
@@ -1254,6 +1266,18 @@ public:
12541266
m_num_runtime_int++;
12551267
h_redistribute_int_comp.push_back(communicate);
12561268
SetParticleSize();
1269+
1270+
// resize runtime SoA
1271+
for (int lev = 0; lev < numLevels(); ++lev) {
1272+
for (ParIterType pti(*this,lev); pti.isValid(); ++pti) {
1273+
auto& tile = DefineAndReturnParticleTile(lev, pti);
1274+
auto np = tile.numParticles();
1275+
if (np > 0) {
1276+
auto& soa = tile.GetStructOfArrays();
1277+
soa.resize(np);
1278+
}
1279+
}
1280+
}
12571281
}
12581282

12591283
int NumRuntimeRealComps () const { return m_num_runtime_real; }
@@ -1262,7 +1286,18 @@ public:
12621286
int NumRealComps () const { return NArrayReal + NumRuntimeRealComps(); }
12631287
int NumIntComps () const { return NArrayInt + NumRuntimeIntComps() ; }
12641288

1289+
/** Resize the Real runtime components (SoA)
1290+
*
1291+
* @param new_size new number of Real runtime components
1292+
* @param communicate participate this component in redistribute
1293+
*/
12651294
void ResizeRuntimeRealComp (int new_size, bool communicate);
1295+
1296+
/** Resize the Int runtime components (SoA)
1297+
*
1298+
* @param new_size new number of integer runtime components
1299+
* @param communicate participate this component in redistribute
1300+
*/
12661301
void ResizeRuntimeIntComp (int new_size, bool communicate);
12671302

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

0 commit comments

Comments
 (0)