Skip to content

Commit 83de032

Browse files
authored
Fix bug in the dual grid PC restart in the case where there are no particles on some levels. (#2276)
1 parent bc3ad83 commit 83de032

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Src/Particle/AMReX_ParticleIO.H

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,8 @@ ParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt, Allocator>
730730
AMREX_ASSERT(finest_level_in_file >= 0);
731731

732732
// Determine whether this is a dual-grid restart or not.
733+
Vector<DistributionMapping> old_dms(finest_level_in_file + 1);
734+
Vector<BoxArray> old_bas(finest_level_in_file + 1);
733735
Vector<BoxArray> particle_box_arrays(finest_level_in_file + 1);
734736
bool dual_grid = false;
735737

@@ -750,6 +752,8 @@ ParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt, Allocator>
750752
{
751753
for (int lev = 0; lev <= finest_level_in_file; lev++)
752754
{
755+
old_dms[lev] = ParticleDistributionMap(lev);
756+
old_bas[lev] = ParticleBoxArray(lev);
753757
std::string phdr_name = fullname;
754758
phdr_name = amrex::Concatenate(phdr_name + "/Level_", lev, 1);
755759
phdr_name += "/Particle_H";
@@ -777,6 +781,10 @@ ParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt, Allocator>
777781

778782
if (dual_grid) {
779783
for (int lev = 0; lev <= finestLevel(); lev++) {
784+
// this can happen if there are no particles at a given level in the checkpoint
785+
if (particle_box_arrays[lev].size() == 0) {
786+
particle_box_arrays[lev] = BoxArray(Geom(lev).Domain());
787+
}
780788
SetParticleBoxArray(lev, particle_box_arrays[lev]);
781789
DistributionMapping pdm(particle_box_arrays[lev]);
782790
SetParticleDistributionMap(lev, pdm);
@@ -883,6 +891,13 @@ ParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt, Allocator>
883891
}
884892
}
885893

894+
if (dual_grid) {
895+
for (int lev = 0; lev <= finest_level_in_file; lev++) {
896+
SetParticleBoxArray(lev, old_bas[lev]);
897+
SetParticleDistributionMap(lev, old_dms[lev]);
898+
}
899+
}
900+
886901
Redistribute();
887902

888903
AMREX_ASSERT(OK());

0 commit comments

Comments
 (0)