Skip to content

Commit

Permalink
Fix restart problem (#78)
Browse files Browse the repository at this point in the history
Initialize IndexMap and Thermodynamics before Mesh. Place global variables in InitUserMeshData
  • Loading branch information
chengcli authored Aug 13, 2023
1 parent 73ea256 commit d074b48
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions examples/2019-Li-snap/bryan_pgen.cpp
Original file line number Diff line number Diff line change
@@ -79,13 +79,18 @@ void MeshBlock::UserWorkBeforeOutput(ParameterInput *pin) {
}

void Mesh::InitUserMeshData(ParameterInput *pin) {
auto pindex = IndexMap::GetInstance();

grav = -pin->GetReal("hydro", "grav_acc1");
p0 = pin->GetReal("problem", "p0");

// index
iH2O = pindex->GetVaporId("H2O");
iH2Oc = pindex->GetCloudId("H2O(c)");
}

void MeshBlock::ProblemGenerator(ParameterInput *pin) {
auto pthermo = Thermodynamics::GetInstance();
auto pindex = IndexMap::GetInstance();

Real Ps = p0;
Real Ts = pin->GetReal("problem", "Ts");
@@ -97,10 +102,6 @@ void MeshBlock::ProblemGenerator(ParameterInput *pin) {
Real dT = pin->GetReal("problem", "dT");
Real qt = pin->GetReal("problem", "qt");

// index
iH2O = pindex->GetVaporId("H2O");
iH2Oc = pindex->GetCloudId("H2O(c)");

AirParcel air(AirParcel::Type::MassFrac);
air.w[iH2O] = qt;
air.c[iH2Oc] = 0.;
12 changes: 6 additions & 6 deletions src/mesh_setup.cpp
Original file line number Diff line number Diff line change
@@ -55,6 +55,12 @@ void mesh_setup(ParameterInput*& pinput, Mesh*& pmesh) {
throw RuntimeError("main", ex.what());
}

// index map
IndexMap::InitFromAthenaInput(pinput);

// thermodynamics
Thermodynamics::InitFromAthenaInput(pinput);

try {
if (cli->res_flag == 0) {
pmesh = new Mesh(pinput, cli->mesh_flag);
@@ -98,12 +104,6 @@ void mesh_setup(ParameterInput*& pinput, Mesh*& pmesh) {
exit(0);
}

// index map
IndexMap::InitFromAthenaInput(pinput);

// thermodynamics
Thermodynamics::InitFromAthenaInput(pinput);

// set up additional components
for (int b = 0; b < pmesh->nblocal; ++b) {
MeshBlock* pmb = pmesh->my_blocks(b);

0 comments on commit d074b48

Please sign in to comment.