Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add clipping to the species interface states for true SDC #2630

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Source/hydro/Castro_hydro.H
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,14 @@
amrex::Array4<amrex::Real> const& qm,
amrex::Array4<amrex::Real> const& qp);

///
/// Clip the mass fractions to lie between [0, 1] and renormalize
/// so they sum to 1. This operates on interfaces.
///
void enforce_species_sum(const amrex::Box& bx,
amrex::Array4<amrex::Real> const& qm,
amrex::Array4<amrex::Real> const& qp);


void scale_flux(const amrex::Box& bx,
#if AMREX_SPACEDIM == 1
Expand Down
45 changes: 26 additions & 19 deletions Source/hydro/Castro_mol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,44 +95,47 @@ Castro::mol_plm_reconstruct(const Box& bx,
{


// this is a loop over zones. For each slope in the zone, fill the
// two adjacent edge states (e.g., the right state at i-1/2 and the
// left state at i+1/2
// this is a loop over zones. For each slope in the zone, fill the
// two adjacent edge states (e.g., the right state at i-1/2 and the
// left state at i+1/2

if (idir == 0) {
if (idir == 0) {

// left state at i+1/2 interface
qm(i+1,j,k,n) = q_arr(i,j,k,n) + 0.5_rt*dq(i,j,k,n);
// left state at i+1/2 interface
qm(i+1,j,k,n) = q_arr(i,j,k,n) + 0.5_rt*dq(i,j,k,n);

// right state at i-1/2 interface
qp(i,j,k,n) = q_arr(i,j,k,n) - 0.5_rt*dq(i,j,k,n);
// right state at i-1/2 interface
qp(i,j,k,n) = q_arr(i,j,k,n) - 0.5_rt*dq(i,j,k,n);


#if AMREX_SPACEDIM >= 2
} else if (idir == 1) {
} else if (idir == 1) {

// left state at j+1/2 interface
qm(i,j+1,k,n) = q_arr(i,j,k,n) + 0.5_rt*dq(i,j,k,n);
// left state at j+1/2 interface
qm(i,j+1,k,n) = q_arr(i,j,k,n) + 0.5_rt*dq(i,j,k,n);

// right state at j-1/2 interface
qp(i,j,k,n) = q_arr(i,j,k,n) - 0.5_rt*dq(i,j,k,n);
// right state at j-1/2 interface
qp(i,j,k,n) = q_arr(i,j,k,n) - 0.5_rt*dq(i,j,k,n);
#endif

#if AMREX_SPACEDIM == 3
} else {
} else {

// left state at k+1/2 interface
qm(i,j,k+1,n) = q_arr(i,j,k,n) + 0.5_rt*dq(i,j,k,n);
// left state at k+1/2 interface
qm(i,j,k+1,n) = q_arr(i,j,k,n) + 0.5_rt*dq(i,j,k,n);

// right state at k-1/2 interface
qp(i,j,k,n) = q_arr(i,j,k,n) - 0.5_rt*dq(i,j,k,n);
// right state at k-1/2 interface
qp(i,j,k,n) = q_arr(i,j,k,n) - 0.5_rt*dq(i,j,k,n);

#endif
}
}

});


// normalize species on interfaces
enforce_species_sum(bx, qm, qp);

// special care for reflecting BCs

// we have to do this after the loops above, since here we will
Expand Down Expand Up @@ -188,6 +191,10 @@ Castro::mol_ppm_reconstruct(const Box& bx,

});


// normalize species on interfaces
enforce_species_sum(bx, qm, qp);

// special care for reflecting BCs

// we have to do this after the loops above, since here we will
Expand Down
4 changes: 4 additions & 0 deletions Source/hydro/Castro_mol_hydro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ Castro::construct_mol_hydro_source(Real time, Real dt, MultiFab& A_update)
qm_arr, qp_arr);
}

// enforce that the species sum to 1 on interfaces

enforce_species_sum(ibx[idir], qm_arr, qp_arr);

// get the face-averaged state and flux, <q> and F(<q>),
// in the idir direction by solving the Riemann problem
// operate on ibx[idir]
Expand Down
31 changes: 31 additions & 0 deletions Source/hydro/advection_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,3 +745,34 @@ Castro::enforce_reflect_states(const Box& bx, const int idir,

}
}


void
Castro::enforce_species_sum(const Box& bx,
Array4<Real> const& qm,
Array4<Real> const& qp) {

// this is a loop over interfaces

amrex::ParallelFor(bx,
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
{
Real sum_xm{0.0};
Real sum_xp{0.0};

for (int n = 0; n < NumSpec; ++n) {
qm(i,j,k,QFS+n) = std::max(0.0, std::min(1.0, qm(i,j,k,QFS+n)));
sum_xm += qm(i,j,k,QFS+n);

qp(i,j,k,QFS+n) = std::max(0.0, std::min(1.0, qp(i,j,k,QFS+n)));
sum_xp += qp(i,j,k,QFS+n);
}

for (int n = 0; n < NumSpec; ++n) {
qm(i,j,k,QFS+n) /= sum_xm;
qp(i,j,k,QFS+n) /= sum_xp;
}

});

}