Skip to content

Commit 603bc57

Browse files
FlushFormat int comp writing (BLAST-WarpX#6130)
This PR fixes an indexing bug related to writing integer components of particles in WarpX. This PR fixes a bug in PR BLAST-WarpX#5969, where an integer value is added to the particle container at runtime and an error occurs on restarts.
1 parent f35dbba commit 603bc57

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,12 @@ FlushFormatCheckpoint::CheckpointParticles (
235235
// and the int comps
236236
int_names.resize(pc->NumIntComps());
237237
write_int_comps.resize(pc->NumIntComps());
238+
// note: inames and h_redistribute_int_comp are not the same size
238239
auto inames = pc->GetIntSoANames();
240+
std::size_t const i0_redist = pc->h_redistribute_int_comp.size() - inames.size();
239241
for (std::size_t index = 0; index < inames.size(); ++index) {
240242
int_names[index] = inames[index];
241-
write_int_comps[index] = pc->h_redistribute_int_comp[index];
243+
write_int_comps[index] = pc->h_redistribute_int_comp[i0_redist + index];
242244
}
243245

244246
pc->Checkpoint(dir, part_diag.getSpeciesName(),

Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,12 @@ FlushFormatPlotfile::WriteParticles(const std::string& dir,
409409
// and the int comps
410410
int_names.resize(tmp.NumIntComps());
411411
int_flags.resize(tmp.NumIntComps());
412+
// note: inames and h_redistribute_int_comp are not the same size
412413
auto inames = tmp.GetIntSoANames();
414+
std::size_t const i0_redist = tmp.h_redistribute_int_comp.size() - inames.size();
413415
for (std::size_t index = 0; index < inames.size(); ++index) {
414416
int_names[index] = inames[index];
415-
int_flags[index] = tmp.h_redistribute_int_comp[index];
417+
int_flags[index] = tmp.h_redistribute_int_comp[i0_redist + index];
416418
}
417419

418420
const auto mass = pc->AmIA<PhysicalSpecies::photon>() ? PhysConst::m_e : pc->getMass();

0 commit comments

Comments
 (0)