Skip to content

Commit

Permalink
Amr Class: Synchronization of StateData's Time (#3375)
Browse files Browse the repository at this point in the history
The synchronization of StateData's time is done in a virtual function,
AmrLevel::postCoarseTime. However, the issue is the override version of
the virtual function often forget to do it. In this PR, the job is
instead done in the Amr class directly. This should make the code more
robust.

Close #3374
  • Loading branch information
WeiqunZhang committed Jun 20, 2023
1 parent d28b9ab commit 239d4d8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
9 changes: 8 additions & 1 deletion Src/Amr/AMReX_Amr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2108,8 +2108,15 @@ Amr::coarseTimeStep (Real stop_time)

cumtime += dt_level[0];

amr_level[0]->postCoarseTimeStep(cumtime);
// sync up statedata time
for (int lev = 0; lev <= finestLevel(); ++lev) {
AmrLevel& amrlevel = getLevel(lev);
for (auto& statedata : amrlevel.state) {
statedata.syncNewTimeLevel(cumtime);
}
}

amr_level[0]->postCoarseTimeStep(cumtime);

if (verbose > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion Src/Amr/AMReX_AmrLevel.H
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ void AmrLevel::RK (int order, int state_type, Real time, Real dt, int iteration,
MultiFab& S_new = get_new_data(state_type);
const Real t_old = state[state_type].prevTime();
const Real t_new = state[state_type].curTime();
AMREX_ALWAYS_ASSERT(amrex::almostEqual(time,t_old) && amrex::almostEqual(time+dt,t_new));
AMREX_ALWAYS_ASSERT(amrex::almostEqual(time,t_old,10) && amrex::almostEqual(time+dt,t_new,10));

if (order == 2) {
RungeKutta::RK2(S_old, S_new, time, dt, std::forward<F>(f),
Expand Down
10 changes: 1 addition & 9 deletions Src/Amr/AMReX_AmrLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,8 @@ AmrLevel::post_timestep (int /*iteration*/)
}

void
AmrLevel::postCoarseTimeStep (Real time)
AmrLevel::postCoarseTimeStep (Real /*time*/)
{
BL_ASSERT(level == 0);
// sync up statedata time
for (int lev = 0; lev <= parent->finestLevel(); ++lev) {
AmrLevel& amrlevel = parent->getLevel(lev);
for (int i = 0; i < amrlevel.state.size(); ++i) {
amrlevel.state[i].syncNewTimeLevel(time);
}
}
}

void
Expand Down

0 comments on commit 239d4d8

Please sign in to comment.