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

Add radiation BC for u/v/t #272

Merged
merged 5 commits into from
Oct 16, 2024
Merged
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
168 changes: 145 additions & 23 deletions Source/BoundaryConditions/BoundaryConditions_cons.cpp

Large diffs are not rendered by default.

142 changes: 132 additions & 10 deletions Source/BoundaryConditions/BoundaryConditions_netcdf.cpp

Large diffs are not rendered by default.

88 changes: 81 additions & 7 deletions Source/BoundaryConditions/BoundaryConditions_xvel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using namespace amrex;
//
void REMORAPhysBCFunct::impose_xvel_bcs (const Array4<Real>& dest_arr, const Box& bx, const Box& domain,
const GpuArray<Real,AMREX_SPACEDIM> /*dxInv*/, const Array4<const Real>& msku,
const Array4<const Real>& calc_arr,
Real /*time*/, int bccomp)
{
BL_PROFILE_VAR("impose_xvel_bcs()",impose_xvel_bcs);
Expand Down Expand Up @@ -39,7 +40,7 @@ void REMORAPhysBCFunct::impose_xvel_bcs (const Array4<Real>& dest_arr, const Box
#endif
const amrex::BCRec* bc_ptr = bcrs_d.data();

GpuArray<GpuArray<Real, AMREX_SPACEDIM*2>,AMREX_SPACEDIM+NCONS+5> l_bc_extdir_vals_d;
GpuArray<GpuArray<Real, AMREX_SPACEDIM*2>,AMREX_SPACEDIM+NCONS+8> l_bc_extdir_vals_d;

for (int i = 0; i < ncomp; i++)
for (int ori = 0; ori < 2*AMREX_SPACEDIM; ori++)
Expand All @@ -48,6 +49,7 @@ void REMORAPhysBCFunct::impose_xvel_bcs (const Array4<Real>& dest_arr, const Box
GeometryData const& geomdata = m_geom.data();
bool is_periodic_in_x = geomdata.isPeriodic(0);
bool is_periodic_in_y = geomdata.isPeriodic(1);
const Real eps= 1.0e-20_rt;


// First do all ext_dir bcs
Expand All @@ -58,48 +60,96 @@ void REMORAPhysBCFunct::impose_xvel_bcs (const Array4<Real>& dest_arr, const Box
Box bx_xlo_face(bx); bx_xlo_face.setSmall(0,dom_lo.x ); bx_xlo_face.setBig(0,dom_lo.x );
Box bx_xhi_face(bx); bx_xhi_face.setSmall(0,dom_hi.x+1); bx_xhi_face.setBig(0,dom_hi.x+1);
ParallelFor(
bx_xlo, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
grow(bx_xlo,IntVect(0,-1,0)), ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
int inner = (bc_ptr[n].lo(0) == REMORABCType::foextrap) ? 1 : 0;
int iflip = dom_lo.x - i;
if (bc_ptr[n].lo(0) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][0]*msku(i,j,0);
} else if (bc_ptr[n].lo(0) == REMORABCType::foextrap || bc_ptr[n].lo(0) == REMORABCType::clamped) {
dest_arr(i,j,k) = dest_arr(dom_lo.x+inner,j,k)*msku(i,j,0);
} else if (bc_ptr[n].lo(0) == REMORABCType::orlanski_rad) {
Real grad_lo = calc_arr(dom_lo.x ,j ,k) - calc_arr(dom_lo.x ,j-1,k);
Real grad_lo_ip1 = calc_arr(dom_lo.x+1,j ,k) - calc_arr(dom_lo.x+1,j-1,k);
Real grad_lo_jp1 = calc_arr(dom_lo.x ,j+1,k) - calc_arr(dom_lo.x ,j ,k);
Real grad_lo_ijp1 = calc_arr(dom_lo.x+1,j+1,k) - calc_arr(dom_lo.x+1,j ,k);
Real dUdt = calc_arr(dom_lo.x+1,j,k) - dest_arr(dom_lo.x+1,j,k);
Real dUdx = dest_arr(dom_lo.x+1,j,k) - dest_arr(dom_lo.x+2,j,k);
if (dUdt * dUdx < 0.0_rt) dUdt = 0.0_rt;
Real dUde = (dUdt * (grad_lo_ip1 + grad_lo_ijp1) > 0.0_rt) ? grad_lo_ip1 : grad_lo_ijp1;
Real cff = std::max(dUdx*dUdx+dUde*dUde,eps);
Real Cx = dUdt*dUdx;
dest_arr(i,j,k) = (cff * calc_arr(i,j,k) + Cx * dest_arr(dom_lo.x+1,j,k)) * msku(i,j,0) / (cff+Cx);
} else if (bc_ptr[n].lo(0) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(iflip,j,k)*msku(i,j,0);
} else if (bc_ptr[n].lo(0) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(iflip,j,k)*msku(i,j,0);
}
},
// We only set the values on the domain faces themselves if EXT_DIR or actual outflow
bx_xlo_face, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
grow(bx_xlo_face,IntVect(0,-1,0)), ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
if (bc_ptr[n].lo(0) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][0]*msku(i,j,0);
} else if (bc_ptr[n].lo(0) == REMORABCType::foextrap) {
dest_arr(i,j,k) = dest_arr(dom_lo.x+1,j,k)*msku(i,j,0);
} else if (bc_ptr[n].lo(0) == REMORABCType::orlanski_rad) {
Real grad_lo = calc_arr(dom_lo.x ,j ,k) - calc_arr(dom_lo.x ,j-1,k);
Real grad_lo_ip1 = calc_arr(dom_lo.x+1,j ,k) - calc_arr(dom_lo.x+1,j-1,k);
Real grad_lo_jp1 = calc_arr(dom_lo.x ,j+1,k) - calc_arr(dom_lo.x ,j ,k);
Real grad_lo_ijp1 = calc_arr(dom_lo.x+1,j+1,k) - calc_arr(dom_lo.x+1,j ,k);
Real dUdt = calc_arr(dom_lo.x+1,j,k) - dest_arr(dom_lo.x+1,j,k);
Real dUdx = dest_arr(dom_lo.x+1,j,k) - dest_arr(dom_lo.x+2,j,k);
if (dUdt * dUdx < 0.0_rt) dUdt = 0.0_rt;
Real dUde = (dUdt * (grad_lo_ip1 + grad_lo_ijp1) > 0.0_rt) ? grad_lo_ip1 : grad_lo_ijp1;
Real cff = std::max(dUdx*dUdx+dUde*dUde,eps);
Real Cx = dUdt*dUdx;
dest_arr(i,j,k) = (cff * calc_arr(i,j,k) + Cx * dest_arr(dom_lo.x+1,j,k)) * msku(i,j,0) / (cff+Cx);
}
}
);
ParallelFor(
bx_xhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
grow(bx_xhi,IntVect(0,-1,0)), ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
int iflip = 2*(dom_hi.x + 1) - i;
int inner = (bc_ptr[n].hi(0) == REMORABCType::foextrap) ? 1 : 0;
if (bc_ptr[n].hi(0) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][3]*msku(i,j,0);
} else if (bc_ptr[n].hi(0) == REMORABCType::foextrap || bc_ptr[n].hi(0) == REMORABCType::clamped) {
dest_arr(i,j,k) = dest_arr(dom_hi.x+1-inner,j,k)*msku(i,j,0);
} else if (bc_ptr[n].hi(0) == REMORABCType::orlanski_rad) {
Real grad_hi = calc_arr(dom_hi.x ,j ,k) - calc_arr(dom_hi.x ,j-1,k);
Real grad_hi_ip1 = calc_arr(dom_hi.x+1,j ,k) - calc_arr(dom_hi.x+1,j-1,k);
Real grad_hi_jp1 = calc_arr(dom_hi.x ,j+1,k) - calc_arr(dom_hi.x ,j ,k);
Real grad_hi_ijp1 = calc_arr(dom_hi.x+1,j+1,k) - calc_arr(dom_hi.x+1,j ,k);
Real dUdt = calc_arr(dom_hi.x,j,k) - dest_arr(dom_hi.x ,j,k);
Real dUdx = dest_arr(dom_hi.x,j,k) - dest_arr(dom_hi.x-1,j,k);
if (dUdt * dUdx < 0.0_rt) dUdt = 0.0_rt;
Real dUde = (dUdt * (grad_hi + grad_hi_jp1) > 0.0_rt) ? grad_hi : grad_hi_jp1;
Real cff = std::max(dUdx*dUdx+dUde*dUde,eps);
Real Cx = dUdt * dUdx;
dest_arr(i,j,k) = (cff * calc_arr(dom_hi.x+1,j,k) + Cx * dest_arr(dom_hi.x,j,k)) * msku(i,j,0) / (cff + Cx);
} else if (bc_ptr[n].hi(0) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(iflip,j,k)*msku(i,j,0);
} else if (bc_ptr[n].hi(0) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(iflip,j,k)*msku(i,j,0);
}
},
// We only set the values on the domain faces themselves if EXT_DIR or actual outflow
bx_xhi_face, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
grow(bx_xhi_face,IntVect(0,-1,0)), ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
if (bc_ptr[n].hi(0) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][3]*msku(i,j,0);
} else if (bc_ptr[n].hi(0) == REMORABCType::foextrap) {
dest_arr(i,j,k) = dest_arr(dom_hi.x,j,k)*msku(i,j,0);
} else if (bc_ptr[n].hi(0) == REMORABCType::orlanski_rad) {
Real grad_hi = calc_arr(dom_hi.x ,j ,k) - calc_arr(dom_hi.x ,j-1,k);
Real grad_hi_ip1 = calc_arr(dom_hi.x+1,j ,k) - calc_arr(dom_hi.x+1,j-1,k);
Real grad_hi_jp1 = calc_arr(dom_hi.x ,j+1,k) - calc_arr(dom_hi.x ,j ,k);
Real grad_hi_ijp1 = calc_arr(dom_hi.x+1,j+1,k) - calc_arr(dom_hi.x+1,j ,k);
Real dUdt = calc_arr(dom_hi.x,j,k) - dest_arr(dom_hi.x ,j,k);
Real dUdx = dest_arr(dom_hi.x,j,k) - dest_arr(dom_hi.x-1,j,k);
if (dUdt * dUdx < 0.0_rt) dUdt = 0.0_rt;
Real dUde = (dUdt * (grad_hi + grad_hi_jp1) > 0.0_rt) ? grad_hi : grad_hi_jp1;
Real cff = std::max(dUdx*dUdx+dUde*dUde,eps);
Real Cx = dUdt * dUdx;
dest_arr(i,j,k) = (cff * calc_arr(dom_hi.x+1,j,k) + Cx * dest_arr(dom_hi.x,j,k)) * msku(i,j,0) / (cff + Cx);
}
}
);
Expand All @@ -111,24 +161,48 @@ void REMORAPhysBCFunct::impose_xvel_bcs (const Array4<Real>& dest_arr, const Box
Box bx_ylo(bx); bx_ylo.setBig (1,dom_lo.y-1);
Box bx_yhi(bx); bx_yhi.setSmall(1,dom_hi.y+1);
ParallelFor(
bx_ylo, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
grow(bx_ylo,IntVect(-1,0,0)), ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
int jflip = dom_lo.y - 1 - j;
if (bc_ptr[n].lo(1) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][1]*msku(i,j,0);
} else if (bc_ptr[n].lo(1) == REMORABCType::foextrap || bc_ptr[n].lo(1) == REMORABCType::clamped) {
dest_arr(i,j,k) = dest_arr(i,dom_lo.y,k)*msku(i,j,0);
} else if (bc_ptr[n].lo(1) == REMORABCType::orlanski_rad) {
Real grad_lo_jm1 = calc_arr(i+1,dom_lo.y-1,k) - calc_arr(i ,dom_lo.y-1,k);
Real grad_lo = calc_arr(i+1,dom_lo.y ,k) - calc_arr(i ,dom_lo.y ,k);
Real grad_lo_ijm1 = calc_arr(i ,dom_lo.y-1,k) - calc_arr(i-1,dom_lo.y-1,k);
Real grad_lo_im1 = calc_arr(i ,dom_lo.y ,k) - calc_arr(i-1,dom_lo.y ,k);
Real dUdt = calc_arr(i,dom_lo.y,k) - dest_arr(i,dom_lo.y ,k);
Real dUde = dest_arr(i,dom_lo.y,k) - dest_arr(i,dom_lo.y+1,k);
if (dUdt * dUde < 0.0_rt) dUdt = 0.0_rt;
Real dUdx = (dUdt * (grad_lo_im1 + grad_lo) > 0.0_rt) ? grad_lo_im1 : grad_lo;
Real cff = std::max(dUdx * dUdx + dUde * dUde, eps);
Real Ce = dUdt * dUde;
dest_arr(i,j,k) = (cff * calc_arr(i,dom_lo.y-1,k) + Ce * dest_arr(i,dom_lo.y,k)) * msku(i,j,0) / (cff + Ce);
} else if (bc_ptr[n].lo(1) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(i,jflip,k)*msku(i,j,0);
} else if (bc_ptr[n].lo(1) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(i,jflip,k)*msku(i,j,0);
}
},
bx_yhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
grow(bx_yhi,IntVect(-1,0,0)), ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
int jflip = 2*dom_hi.y + 1 - j;
if (bc_ptr[n].hi(1) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][4]*msku(i,j,0);
} else if (bc_ptr[n].hi(1) == REMORABCType::foextrap || bc_ptr[n].hi(1) == REMORABCType::clamped) {
dest_arr(i,j,k) = dest_arr(i,dom_hi.y,k)*msku(i,j,0);
} else if (bc_ptr[n].hi(1) == REMORABCType::orlanski_rad) {
Real grad_hi = calc_arr(i+1,dom_hi.y ,k) - calc_arr(i ,dom_hi.y ,k);
Real grad_hi_jp1 = calc_arr(i+1,dom_hi.y+1,k) - calc_arr(i ,dom_hi.y+1,k);
Real grad_hi_im1 = calc_arr(i ,dom_hi.y ,k) - calc_arr(i-1,dom_hi.y ,k);
Real grad_hi_imjp1 = calc_arr(i ,dom_hi.y+1,k) - calc_arr(i-1,dom_hi.y+1,k);
Real dUdt = calc_arr(i,dom_hi.y,k) - dest_arr(i,dom_hi.y ,k);
Real dUde = dest_arr(i,dom_hi.y,k) - dest_arr(i,dom_hi.y-1,k);
if (dUdt * dUde < 0.0_rt) dUdt = 0.0_rt;
Real dUdx = (dUdt * (grad_hi_im1 + grad_hi) > 0.0_rt) ? grad_hi_im1 : grad_hi;
Real cff = std::max(dUdx*dUdx+dUde*dUde,eps);
Real Ce = dUdt * dUde;
dest_arr(i,j,k) = (cff * calc_arr(i,dom_hi.y+1,k) + Ce * dest_arr(i,dom_hi.y,k)) * msku(i,j,0) / (cff+Ce);
} else if (bc_ptr[n].hi(1) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(i,jflip,k)*msku(i,j,0);
} else if (bc_ptr[n].hi(1) == REMORABCType::reflect_odd) {
Expand Down
Loading
Loading