Skip to content

Commit

Permalink
fix how we fillpatch relative to regridding (erf-model#1923)
Browse files Browse the repository at this point in the history
  • Loading branch information
asalmgren authored Nov 3, 2024
1 parent 1412c99 commit 84efdc3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
56 changes: 29 additions & 27 deletions Source/TimeIntegration/ERF_Advance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,35 @@ ERF::Advance (int lev, Real time, Real dt_lev, int iteration, int /*ncycle*/)
MultiFab& V_new = vars_new[lev][Vars::yvel];
MultiFab& W_new = vars_new[lev][Vars::zvel];

// We need to set these because otherwise in the first call to erf_advance we may
// read uninitialized data on ghost values in setting the bc's on the velocities
U_new.setVal(1.e34,U_new.nGrowVect());
V_new.setVal(1.e34,V_new.nGrowVect());
W_new.setVal(1.e34,W_new.nGrowVect());

//
// NOTE: the momenta here are not fillpatched (they are only used as scratch space)
// If lev == 0 we have already FillPatched this in ERF::TimeStep
//
// if (lev == 0) {
// FillPatch(lev, time, {&S_old, &U_old, &V_old, &W_old});
// } else {
if (lev > 0) {
FillPatch(lev, time, {&S_old, &U_old, &V_old, &W_old},
{&S_old, &rU_old[lev], &rV_old[lev], &rW_old[lev]},
base_state[lev], base_state[lev]);
}

//
// So we must convert the fillpatched to momenta, including the ghost values
//
VelocityToMomentum(U_old, rU_old[lev].nGrowVect(),
V_old, rV_old[lev].nGrowVect(),
W_old, rW_old[lev].nGrowVect(),
S_old, rU_old[lev], rV_old[lev], rW_old[lev],
Geom(lev).Domain(),
domain_bcs_type);

// TODO: Can test on multiple levels later
// Update the inflow perturbation update time and amplitude
if (lev == 0) {
Expand Down Expand Up @@ -86,33 +115,6 @@ ERF::Advance (int lev, Real time, Real dt_lev, int iteration, int /*ncycle*/)
}
}

// We need to set these because otherwise in the first call to erf_advance we may
// read uninitialized data on ghost values in setting the bc's on the velocities
U_new.setVal(1.e34,U_new.nGrowVect());
V_new.setVal(1.e34,V_new.nGrowVect());
W_new.setVal(1.e34,W_new.nGrowVect());

//
// NOTE: the momenta here are not fillpatched (they are only used as scratch space)
//
if (lev == 0) {
FillPatch(lev, time, {&S_old, &U_old, &V_old, &W_old});
} else {
FillPatch(lev, time, {&S_old, &U_old, &V_old, &W_old},
{&S_old, &rU_old[lev], &rV_old[lev], &rW_old[lev]},
base_state[lev], base_state[lev]);
}

//
// So we must convert the fillpatched to momenta, including the ghost values
//
VelocityToMomentum(U_old, rU_old[lev].nGrowVect(),
V_old, rV_old[lev].nGrowVect(),
W_old, rW_old[lev].nGrowVect(),
S_old, rU_old[lev], rV_old[lev], rW_old[lev],
Geom(lev).Domain(),
domain_bcs_type);

#if defined(ERF_USE_WINDFARM)
if (solverChoice.windfarm_type != WindFarmType::None) {
advance_windfarm(Geom(lev), dt_lev, S_old,
Expand Down
20 changes: 20 additions & 0 deletions Source/TimeIntegration/ERF_TimeStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ using namespace amrex;
void
ERF::timeStep (int lev, Real time, int /*iteration*/)
{
//
// We need to FillPatch the coarse level before assessing whether to regrid
// We have not done the swap yet so we fill the "new" which will become the "old"
//
MultiFab& S_new = vars_new[lev][Vars::cons];
MultiFab& U_new = vars_new[lev][Vars::xvel];
MultiFab& V_new = vars_new[lev][Vars::yvel];
MultiFab& W_new = vars_new[lev][Vars::zvel];

//
// NOTE: the momenta here are not fillpatched (they are only used as scratch space)
//
if (lev == 0) {
FillPatch(lev, time, {&S_new, &U_new, &V_new, &W_new});
} else if (lev < finest_level) {
FillPatch(lev, time, {&S_new, &U_new, &V_new, &W_new},
{&S_new, &rU_new[lev], &rV_new[lev], &rW_new[lev]},
base_state[lev], base_state[lev]);
}

if (regrid_int > 0) // We may need to regrid
{
// help keep track of whether a level was already regridded
Expand Down

0 comments on commit 84efdc3

Please sign in to comment.