From 6870ece4ba5322b6723ccaade83f9c36136f0012 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Thu, 14 Mar 2024 10:35:06 -0400 Subject: [PATCH] fix a bounds issue in sources in true SDC --- Source/driver/Castro_advance_sdc.cpp | 74 ++++++++++++++-------------- Source/hydro/Castro_mol_hydro.cpp | 3 +- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/Source/driver/Castro_advance_sdc.cpp b/Source/driver/Castro_advance_sdc.cpp index 2d0463aa1f..83b226c7bc 100644 --- a/Source/driver/Castro_advance_sdc.cpp +++ b/Source/driver/Castro_advance_sdc.cpp @@ -94,54 +94,54 @@ Castro::do_advance_sdc (Real time, #endif if (apply_sources()) { - if (sdc_order == 4) { - // if we are 4th order, convert to cell-center Sborder -> Sborder_cc - // we'll use Sburn for this memory buffer at the moment + if (sdc_order == 4) { + // if we are 4th order, convert to cell-center Sborder -> Sborder_cc + // we'll use Sburn for this memory buffer at the moment - for (MFIter mfi(S_new); mfi.isValid(); ++mfi) { - const Box& gbx = mfi.growntilebox(1); + for (MFIter mfi(S_new); mfi.isValid(); ++mfi) { + const Box& gbx = mfi.growntilebox(1); - make_cell_center(gbx, Sborder.array(mfi), Sburn.array(mfi), domain_lo, domain_hi); + make_cell_center(gbx, Sborder.array(mfi), Sburn.array(mfi), domain_lo, domain_hi); - } + } + + // we pass in the stage time here + do_old_sources(old_source, Sburn, Sburn, node_time, dt, apply_sources_to_state); - // we pass in the stage time here - do_old_sources(old_source, Sburn, Sburn, node_time, dt, apply_sources_to_state); + // fill the ghost cells for the sources -- note since we have + // not defined the new_source yet, we either need to copy this + // into new_source for the time-interpolation in the ghost + // fill to make sense, or so long as we are not multilevel, + // just use the old time (prev_time) in the fill instead of + // the node time (time) + AmrLevel::FillPatch(*this, old_source, old_source.nGrow(), prev_time, Source_Type, 0, NSRC); - // fill the ghost cells for the sources -- note since we have - // not defined the new_source yet, we either need to copy this - // into new_source for the time-interpolation in the ghost - // fill to make sense, or so long as we are not multilevel, - // just use the old time (prev_time) in the fill instead of - // the node time (time) - AmrLevel::FillPatch(*this, old_source, old_source.nGrow(), prev_time, Source_Type, 0, NSRC); + // Now convert to cell averages. This loop cannot be tiled. + FArrayBox tmp; - // Now convert to cell averages. This loop cannot be tiled. - FArrayBox tmp; + for (MFIter mfi(S_new); mfi.isValid(); ++mfi) { + const Box& bx = mfi.tilebox(); - for (MFIter mfi(S_new); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); + tmp.resize(bx, 1, The_Async_Arena()); + auto tmp_arr = tmp.array(); - tmp.resize(bx, 1, The_Async_Arena()); - auto tmp_arr = tmp.array(); + make_fourth_in_place(bx, old_source.array(mfi), tmp_arr, domain_lo, domain_hi); + } - make_fourth_in_place(bx, old_source.array(mfi), tmp_arr, domain_lo, domain_hi); + } else { + // there is a ghost cell fill hidden in diffusion, so we need + // to pass in the time associate with Sborder + do_old_sources(old_source, Sborder, Sborder, cur_time, dt, apply_sources_to_state); } - } else { - // there is a ghost cell fill hidden in diffusion, so we need - // to pass in the time associate with Sborder - do_old_sources(old_source, Sborder, Sborder, cur_time, dt, apply_sources_to_state); - } - - // note: we don't need a FillPatch on the sources, since they - // are only used in the valid box in the conservative flux - // update construction. The only exception is if we are doing - // the well-balanced method in the reconstruction of the - // pressure. - if (sdc_order == 2 && use_pslope == 1) { - AmrLevel::FillPatch(*this, old_source, old_source.nGrow(), prev_time, Source_Type, 0, NSRC); - } + // note: we don't need a FillPatch on the sources, since they + // are only used in the valid box in the conservative flux + // update construction. The only exception is if we are doing + // the well-balanced method in the reconstruction of the + // pressure. + if (sdc_order == 2 && use_pslope == 1) { + AmrLevel::FillPatch(*this, old_source, old_source.nGrow(), prev_time, Source_Type, 0, NSRC); + } } // Now compute the advective term for the current node -- this diff --git a/Source/hydro/Castro_mol_hydro.cpp b/Source/hydro/Castro_mol_hydro.cpp index b73e6b7047..80af91c095 100644 --- a/Source/hydro/Castro_mol_hydro.cpp +++ b/Source/hydro/Castro_mol_hydro.cpp @@ -93,6 +93,7 @@ Castro::construct_mol_hydro_source(Real time, Real dt, MultiFab& A_update) const Box& obx = amrex::grow(bx, 1); const Box& obx2 = amrex::grow(bx, 2); + const Box& srcbx = amrex::grow(bx, old_source.nGrow()); Array4 const uin_arr = Sborder.array(mfi); @@ -145,7 +146,7 @@ Castro::construct_mol_hydro_source(Real time, Real dt, MultiFab& A_update) if (sdc_order == 2) { - amrex::ParallelFor(qbx, + amrex::ParallelFor(srcbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept { hydro::src_to_prim(i, j, k, dt, uin_arr, q_arr, source_in_arr, src_q_arr);