diff --git a/Source/gravity/Gravity.cpp b/Source/gravity/Gravity.cpp index c5f7bac162..edeb7359d2 100644 --- a/Source/gravity/Gravity.cpp +++ b/Source/gravity/Gravity.cpp @@ -881,11 +881,17 @@ Gravity::get_old_grav_vector(int level, MultiFab& grav_vector, Real time) MultiFab grav(grids[level], dmap[level], AMREX_SPACEDIM, ng); grav.setVal(0.0,ng); - if (gravity::gravity_type == "ConstantGrav") { + const Geometry& geom = parent->Geom(level); - // Set to constant value in the AMREX_SPACEDIM direction and zero in all others. + if (gravity::gravity_type == "ConstantGrav") { - grav.setVal(gravity::const_grav,AMREX_SPACEDIM-1,1,ng); + if (AMREX_SPACEDIM == 2 && geom.Coord() == 2) { + // 2D spherical r-theta, we want g in the radial direction + grav.setVal(gravity::const_grav, 0, 1, ng); + } else { + // Set to constant value in the AMREX_SPACEDIM direction and zero in all others. + grav.setVal(gravity::const_grav, AMREX_SPACEDIM-1, 1, ng); + } } else if (gravity::gravity_type == "MonopoleGrav") { @@ -895,7 +901,6 @@ Gravity::get_old_grav_vector(int level, MultiFab& grav_vector, Real time) } else if (gravity::gravity_type == "PoissonGrav") { - const Geometry& geom = parent->Geom(level); amrex::average_face_to_cellcenter(grav, amrex::GetVecOfConstPtrs(grad_phi_prev[level]), geom); grav.mult(-1.0, ng); // g = - grad(phi) @@ -952,11 +957,17 @@ Gravity::get_new_grav_vector(int level, MultiFab& grav_vector, Real time) MultiFab grav(grids[level],dmap[level],AMREX_SPACEDIM,ng); grav.setVal(0.0,ng); + const Geometry& geom = parent->Geom(level); if (gravity::gravity_type == "ConstantGrav") { - // Set to constant value in the AMREX_SPACEDIM direction - grav.setVal(gravity::const_grav,AMREX_SPACEDIM-1,1,ng); + if (AMREX_SPACEDIM == 2 && geom.Coord() == 2) { + // 2D spherical r-theta, we want g in the radial direction + grav.setVal(gravity::const_grav, 0, 1, ng); + } else { + // Set to constant value in the AMREX_SPACEDIM direction + grav.setVal(gravity::const_grav, AMREX_SPACEDIM-1, 1, ng); + } } else if (gravity::gravity_type == "MonopoleGrav") { @@ -967,7 +978,6 @@ Gravity::get_new_grav_vector(int level, MultiFab& grav_vector, Real time) } else if (gravity::gravity_type == "PoissonGrav") { - const Geometry& geom = parent->Geom(level); amrex::average_face_to_cellcenter(grav, amrex::GetVecOfConstPtrs(grad_phi_curr[level]), geom); grav.mult(-1.0, ng); // g = - grad(phi)