From d074b48c1dd536e9646fbbf7a167311047aec7cb Mon Sep 17 00:00:00 2001 From: Cheng Li <69489965+chengcli@users.noreply.github.com> Date: Sun, 13 Aug 2023 10:18:19 -0400 Subject: [PATCH] Fix restart problem (#78) Initialize IndexMap and Thermodynamics before Mesh. Place global variables in InitUserMeshData --- examples/2019-Li-snap/bryan_pgen.cpp | 11 ++++++----- src/mesh_setup.cpp | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/examples/2019-Li-snap/bryan_pgen.cpp b/examples/2019-Li-snap/bryan_pgen.cpp index 0a446272..a95a298a 100644 --- a/examples/2019-Li-snap/bryan_pgen.cpp +++ b/examples/2019-Li-snap/bryan_pgen.cpp @@ -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.; diff --git a/src/mesh_setup.cpp b/src/mesh_setup.cpp index 186232d9..ea7f0917 100644 --- a/src/mesh_setup.cpp +++ b/src/mesh_setup.cpp @@ -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);