Skip to content

Commit

Permalink
clean up open bc stuff (#1546)
Browse files Browse the repository at this point in the history
  • Loading branch information
asalmgren authored Apr 1, 2024
1 parent 6f18955 commit af7f0f8
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 199 deletions.
9 changes: 7 additions & 2 deletions Source/Advection/Advection.H
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ void AdvectionSrcForScalars (const amrex::Box& bx,
const AdvType horiz_adv_type, const AdvType vert_adv_type,
const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac,
const bool use_terrain,
const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_arr);
const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM>& flx_arr,
const amrex::Box& domain,
const amrex::BCRec* bc_ptr_h);

/** Compute advection tendencies for all components of momentum */
void AdvectionSrcForMom (const amrex::Box& bxx, const amrex::Box& bxy, const amrex::Box& bxz,
const amrex::Array4< amrex::Real>& rho_u_rhs, const amrex::Array4< amrex::Real>& rho_v_rhs,
const amrex::Array4< amrex::Real>& rho_w_rhs,
const amrex::Array4<const amrex::Real>& rho,
const amrex::Array4<const amrex::Real>& u , const amrex::Array4<const amrex::Real>& v,
const amrex::Array4<const amrex::Real>& w ,
const amrex::Array4<const amrex::Real>& rho_u , const amrex::Array4<const amrex::Real>& rho_v,
Expand All @@ -64,7 +67,9 @@ void AdvectionSrcForMom (const amrex::Box& bxx, const amrex::Box& bxy, const amr
const amrex::Array4<const amrex::Real>& mf_v,
const AdvType horiz_adv_type, const AdvType vert_adv_type,
const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac,
const bool use_terrain, const int lo_z_face, const int hi_z_face);
const bool use_terrain, const int lo_z_face, const int hi_z_face,
const amrex::Box& domain,
const amrex::BCRec* bc_ptr_h);

/** Compute advection tendencies for all normal components of momentum */
void
Expand Down
89 changes: 87 additions & 2 deletions Source/Advection/AdvectionSrcForMom.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include "AMReX_BCRec.H"

#include <Advection.H>
#include <AdvectionSrcForMom_N.H>
#include <AdvectionSrcForMom_T.H>

Expand Down Expand Up @@ -30,13 +33,13 @@ using namespace amrex;
* @param[in] horiz_adv_type sets the spatial order to be used for lateral derivatives
* @param[in] vert_adv_type sets the spatial order to be used for vertical derivatives
* @param[in] use_terrain if true, use the terrain-aware derivatives (with metric terms)
* @param[in] domhi_z maximum k value in the domain
*/
void
AdvectionSrcForMom (const Box& bxx, const Box& bxy, const Box& bxz,
const Array4< Real>& rho_u_rhs,
const Array4< Real>& rho_v_rhs,
const Array4< Real>& rho_w_rhs,
const Array4<const Real>& cell_data,
const Array4<const Real>& u,
const Array4<const Real>& v,
const Array4<const Real>& w,
Expand All @@ -54,7 +57,9 @@ AdvectionSrcForMom (const Box& bxx, const Box& bxy, const Box& bxz,
const Real horiz_upw_frac,
const Real vert_upw_frac,
const bool use_terrain,
const int lo_z_face, const int hi_z_face)
const int lo_z_face, const int hi_z_face,
const Box& domain,
const BCRec* bc_ptr_h)
{
BL_PROFILE_VAR("AdvectionSrcForMom", AdvectionSrcForMom);

Expand Down Expand Up @@ -313,5 +318,85 @@ AdvectionSrcForMom (const Box& bxx, const Box& bxy, const Box& bxz,
}
}
}

// Open bc will be imposed upon all vars (we only access cons here for simplicity)
const bool xlo_open = (bc_ptr_h[BCVars::cons_bc].lo(0) == ERFBCType::open);
const bool xhi_open = (bc_ptr_h[BCVars::cons_bc].hi(0) == ERFBCType::open);
const bool ylo_open = (bc_ptr_h[BCVars::cons_bc].lo(1) == ERFBCType::open);
const bool yhi_open = (bc_ptr_h[BCVars::cons_bc].hi(1) == ERFBCType::open);

// Only advection operations in bndry normal direction with OPEN BC
const int domhi_z = domain.bigEnd(2);
Box tbx_xlo, tbx_xhi, tbx_ylo, tbx_yhi;
Box tby_xlo, tby_xhi, tby_ylo, tby_yhi;
Box tbz_xlo, tbz_xhi, tbz_ylo, tbz_yhi;
if (xlo_open) {
if (bxx.smallEnd(0) == domain.smallEnd(0)) { tbx_xlo = makeSlab(bxx,0,domain.smallEnd(0)); tbx_xlo.growLo(0,-1); }
if (bxy.smallEnd(0) == domain.smallEnd(0)) { tby_xlo = makeSlab(bxy,0,domain.smallEnd(0)); }
if (bxz.smallEnd(0) == domain.smallEnd(0)) { tbz_xlo = makeSlab(bxz,0,domain.smallEnd(0)); }
}
if (xhi_open) {
if (bxx.bigEnd(0) == domain.bigEnd(0)+1) { tbx_xhi = makeSlab(bxx,0,domain.bigEnd(0)+1); tbx_xhi.growHi(0,-1); }
if (bxy.bigEnd(0) == domain.bigEnd(0)) { tby_xhi = makeSlab(bxy,0,domain.bigEnd(0) ); }
if (bxz.bigEnd(0) == domain.bigEnd(0)) { tbz_xhi = makeSlab(bxz,0,domain.bigEnd(0) ); }
}
if (ylo_open) {
if (bxx.smallEnd(1) == domain.smallEnd(1)) { tbx_ylo = makeSlab(bxx,1,domain.smallEnd(1)); }
if (bxy.smallEnd(1) == domain.smallEnd(1)) { tby_ylo = makeSlab(bxy,1,domain.smallEnd(1)); tby_ylo.growLo(1,-1); }
if (bxz.smallEnd(1) == domain.smallEnd(1)) { tbz_ylo = makeSlab(bxz,1,domain.smallEnd(1)); }
}
if (yhi_open) {
if (bxx.bigEnd(1) == domain.bigEnd(1)) { tbx_yhi = makeSlab(bxx,1,domain.bigEnd(1) ); }
if (bxy.bigEnd(1) == domain.bigEnd(1)+1) { tby_yhi = makeSlab(bxy,1,domain.bigEnd(1)+1); tby_yhi.growHi(1,-1); }
if (bxz.bigEnd(1) == domain.bigEnd(1)) { tbz_yhi = makeSlab(bxz,1,domain.bigEnd(1) ); }
}

// Special advection operator for open BC (bndry normal/tangent operations)
if (xlo_open) {
bool do_lo = true;
AdvectionSrcForOpenBC_Normal(tbx_xlo, 0, rho_u_rhs, u, cell_data, cellSizeInv, do_lo);
AdvectionSrcForOpenBC_Tangent_Ymom(tby_xlo, 0, rho_v_rhs, v,
rho_u, rho_v, Omega,
z_nd, detJ, cellSizeInv,
use_terrain, do_lo);
AdvectionSrcForOpenBC_Tangent_Zmom(tbz_xlo, 0, rho_w_rhs, w,
rho_u, rho_v, Omega,
z_nd, detJ, cellSizeInv,
use_terrain, domhi_z, do_lo);
}
if (xhi_open) {
AdvectionSrcForOpenBC_Normal(tbx_xhi, 0, rho_u_rhs, u, cell_data, cellSizeInv);
AdvectionSrcForOpenBC_Tangent_Ymom(tby_xhi, 0, rho_v_rhs, v,
rho_u, rho_v, Omega,
z_nd, detJ, cellSizeInv,
use_terrain);
AdvectionSrcForOpenBC_Tangent_Zmom(tbz_xhi, 0, rho_w_rhs, w,
rho_u, rho_v, Omega,
z_nd, detJ, cellSizeInv,
use_terrain, domhi_z);
}
if (ylo_open) {
bool do_lo = true;
AdvectionSrcForOpenBC_Tangent_Xmom(tbx_ylo, 1, rho_u_rhs, u,
rho_u, rho_v, Omega,
z_nd, detJ, cellSizeInv,
use_terrain, do_lo);
AdvectionSrcForOpenBC_Normal(tby_ylo, 1, rho_v_rhs, v, cell_data, cellSizeInv, do_lo);
AdvectionSrcForOpenBC_Tangent_Zmom(tbz_ylo, 1, rho_w_rhs, w,
rho_u, rho_v, Omega,
z_nd, detJ, cellSizeInv,
use_terrain, domhi_z, do_lo);
}
if (yhi_open) {
AdvectionSrcForOpenBC_Tangent_Xmom(tbx_yhi, 1, rho_u_rhs, u,
rho_u, rho_v, Omega,
z_nd, detJ, cellSizeInv,
use_terrain);
AdvectionSrcForOpenBC_Normal(tby_yhi, 1, rho_v_rhs, v, cell_data, cellSizeInv);
AdvectionSrcForOpenBC_Tangent_Zmom(tbz_yhi, 1, rho_w_rhs, w,
rho_u, rho_v, Omega,
z_nd, detJ, cellSizeInv,
use_terrain, domhi_z);
}
}

49 changes: 48 additions & 1 deletion Source/Advection/AdvectionSrcForState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ AdvectionSrcForScalars (const Box& bx, const int icomp, const int ncomp,
const Real horiz_upw_frac,
const Real vert_upw_frac,
const bool use_terrain,
const GpuArray<const Array4<Real>, AMREX_SPACEDIM>& flx_arr)
const GpuArray<const Array4<Real>, AMREX_SPACEDIM>& flx_arr,
const Box& domain,
const BCRec* bc_ptr_h)
{
BL_PROFILE_VAR("AdvectionSrcForScalars", AdvectionSrcForScalars);
auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
Expand All @@ -177,6 +179,27 @@ AdvectionSrcForScalars (const Box& bx, const int icomp, const int ncomp,
const Box ybx = surroundingNodes(bx,1);
const Box zbx = surroundingNodes(bx,2);

// Open bc will be imposed upon all vars (we only access cons here for simplicity)
const bool xlo_open = (bc_ptr_h[BCVars::cons_bc].lo(0) == ERFBCType::open);
const bool xhi_open = (bc_ptr_h[BCVars::cons_bc].hi(0) == ERFBCType::open);
const bool ylo_open = (bc_ptr_h[BCVars::cons_bc].lo(1) == ERFBCType::open);
const bool yhi_open = (bc_ptr_h[BCVars::cons_bc].hi(1) == ERFBCType::open);

// Only advection operations in bndry normal direction with OPEN BC
Box bx_xlo, bx_xhi, bx_ylo, bx_yhi;
if (xlo_open) {
if ( bx.smallEnd(0) == domain.smallEnd(0)) { bx_xlo = makeSlab( bx,0,domain.smallEnd(0));}
}
if (xhi_open) {
if ( bx.bigEnd(0) == domain.bigEnd(0)) { bx_xhi = makeSlab( bx,0,domain.bigEnd(0) );}
}
if (ylo_open) {
if ( bx.smallEnd(1) == domain.smallEnd(1)) { bx_ylo = makeSlab( bx,1,domain.smallEnd(1));}
}
if (yhi_open) {
if ( bx.bigEnd(1) == domain.bigEnd(1)) { bx_yhi = makeSlab( bx,1,domain.bigEnd(1) );}
}

// Inline with 2nd order for efficiency
// NOTE: we don't need to weight avg_xmom, avg_ymom, avg_zmom with terrain metrics
// (or with EB area fractions)
Expand Down Expand Up @@ -279,4 +302,28 @@ AdvectionSrcForScalars (const Box& bx, const int icomp, const int ncomp,
( (flx_arr[1])(i,j+1,k,cons_index) - (flx_arr[1])(i,j ,k,cons_index) ) * dyInv +
( (flx_arr[2])(i,j,k+1,cons_index) - (flx_arr[2])(i,j,k ,cons_index) ) * dzInv );
});

// Special advection operator for open BC (bndry tangent operations)
if (xlo_open) {
bool do_lo = true;
AdvectionSrcForOpenBC_Tangent_Cons(bx_xlo, 0, icomp, ncomp, advectionSrc, cell_prim,
avg_xmom, avg_ymom, avg_zmom,
detJ, cellSizeInv, use_terrain, do_lo);
}
if (xhi_open) {
AdvectionSrcForOpenBC_Tangent_Cons(bx_xhi, 0, icomp, ncomp, advectionSrc, cell_prim,
avg_xmom, avg_ymom, avg_zmom,
detJ, cellSizeInv, use_terrain);
}
if (ylo_open) {
bool do_lo = true;
AdvectionSrcForOpenBC_Tangent_Cons(bx_ylo, 1, icomp, ncomp, advectionSrc, cell_prim,
avg_xmom, avg_ymom, avg_zmom,
detJ, cellSizeInv, use_terrain, do_lo);
}
if (yhi_open) {
AdvectionSrcForOpenBC_Tangent_Cons(bx_yhi, 1, icomp, ncomp, advectionSrc, cell_prim,
avg_xmom, avg_ymom, avg_zmom,
detJ, cellSizeInv, use_terrain);
}
}
Loading

0 comments on commit af7f0f8

Please sign in to comment.