Skip to content

Commit

Permalink
fix a bounds issue in sources in true SDC (#2775)
Browse files Browse the repository at this point in the history
We were sometimes reading invalid data depending on what options were set.
  • Loading branch information
zingale authored Mar 15, 2024
1 parent e19c0bd commit 46ece2f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
74 changes: 37 additions & 37 deletions Source/driver/Castro_advance_sdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Source/hydro/Castro_mol_hydro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Real const> const uin_arr = Sborder.array(mfi);

Expand Down Expand Up @@ -140,12 +141,12 @@ Castro::construct_mol_hydro_source(Real time, Real dt, MultiFab& A_update)
// primitive variable source terms

const Box& qbx = amrex::grow(bx, NUM_GROW_SRC);
src_q.resize(qbx, NQSRC);
src_q.resize(srcbx, NQSRC);
Array4<Real> const src_q_arr = src_q.array();

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);
Expand Down

0 comments on commit 46ece2f

Please sign in to comment.