ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_AdvectionSrcForOpenBC.cpp File Reference
#include <ERF_Advection.H>
Include dependency graph for ERF_AdvectionSrcForOpenBC.cpp:

Functions

void AdvectionSrcForOpenBC_Normal (const Box &bx, const int &dir, const Array4< Real > &rhs_arr, const Array4< const Real > &vel_norm_arr, const Array4< const Real > &cell_data_arr, const GpuArray< Real, AMREX_SPACEDIM > &dxInv, const bool do_lo)
 
void AdvectionSrcForOpenBC_Tangent_Xmom (const Box &bxx, const int &dir, const Array4< Real > &rho_u_rhs, const Array4< const Real > &u, const Array4< const Real > &rho_u, const Array4< const Real > &rho_v, const Array4< const Real > &Omega, const Array4< const Real > &ax, const Array4< const Real > &az, const Array4< const Real > &detJ, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, const bool do_lo)
 
void AdvectionSrcForOpenBC_Tangent_Ymom (const Box &bxy, const int &dir, const Array4< Real > &rho_v_rhs, const Array4< const Real > &v, const Array4< const Real > &rho_u, const Array4< const Real > &rho_v, const Array4< const Real > &Omega, const Array4< const Real > &ay, const Array4< const Real > &az, const Array4< const Real > &detJ, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, const bool do_lo)
 
void AdvectionSrcForOpenBC_Tangent_Zmom (const Box &bxz, const int &dir, const Array4< Real > &rho_w_rhs, const Array4< const Real > &w, const Array4< const Real > &rho_u, const Array4< const Real > &rho_v, const Array4< const Real > &Omega, const Array4< const Real > &ax, const Array4< const Real > &ay, const Array4< const Real > &az, const Array4< const Real > &detJ, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, const int domhi_z, const bool do_lo)
 
void AdvectionSrcForOpenBC_Tangent_Cons (const Box &bx, const int &dir, const int &icomp, const int &ncomp, const Array4< Real > &cell_rhs, const Array4< const Real > &cell_prim, const Array4< const Real > &avg_xmom, const Array4< const Real > &avg_ymom, const Array4< const Real > &avg_zmom, const Array4< const Real > &detJ, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, const bool do_lo)
 
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real AdvectionSrcForOpenBC_Tangent (const int &i, const int &j, const int &k, const int &nprim, const int &dir, const Array4< const Real > &prim_tang_arr, const Array4< const Real > &mom_norm_arr, const Real &dxInv, const bool do_lo)
 

Function Documentation

◆ AdvectionSrcForOpenBC_Normal()

void AdvectionSrcForOpenBC_Normal ( const Box &  bx,
const int &  dir,
const Array4< Real > &  rhs_arr,
const Array4< const Real > &  vel_norm_arr,
const Array4< const Real > &  cell_data_arr,
const GpuArray< Real, AMREX_SPACEDIM > &  dxInv,
const bool  do_lo 
)

Compute advection tendencies for momentum normal to an open boundary.

Parameters
[in]bxbox over which the boundary-normal momentum is updated
[in]dircoordinate direction normal to the open boundary
[out]rhs_arrtendency for the boundary-normal momentum equation
[in]vel_norm_arrvelocity component normal to the open boundary
[in]cell_data_arrcell-centered conservative state
[in]dxInvinverse grid spacing
[in]do_loflag for a low-side open boundary
24 {
25  // NOTE: Klemp, J. B., and R. Wilhelmson, 1978: The simulation of three-dimensional
26  // convective storm dynamics, J. Atmos. Sci., 35, 1070-Real(1096.)
27  // NOTE: Implementation is for the high bndry side. The low bndry side is obtained
28  // by flipping sgn = -one
29  // NOTE: Indices (i,j,k) correspond to data that is ON the open bdy.
30  int sgn = 1; if (do_lo) sgn = -1;
31  Real c_o_star = Real(sgn)*Real(30.0);
32  ParallelFor(bx, [=,zero_d=zero] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
33  {
34  IntVect ivu1(i,j,k); if ( do_lo) ivu1[dir] -= sgn; // Vel indexed into domain for do_lo
35  IntVect ivu2(i,j,k); if (!do_lo) ivu2[dir] -= sgn; // Vel indexed into domain for do_hi
36 
37  IntVect ivr1(i,j,k); if (!do_lo) ivr1[dir] -= sgn; // Rho indexed into domain for do_hi
38  IntVect ivr2(i,j,k); if ( do_lo) ivr2[dir] += sgn; // Rho indexed out domain for do_lo
39 
40  Real rho_face = myhalf * ( cell_data_arr(ivr1,Rho_comp) + cell_data_arr(ivr2,Rho_comp) );
41  Real mom_star = rho_face * Real(sgn) * max( Real(sgn)*(vel_norm_arr(ivu1) + c_o_star), zero_d );
42  Real vel_grad = ( vel_norm_arr(ivu1) - vel_norm_arr(ivu2) ) * dxInv[dir];
43  Real flux = -( mom_star * vel_grad );
44  rhs_arr(i,j,k) = flux;
45  });
46 }
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
#define Rho_comp
Definition: ERF_IndexDefines.H:36
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:17
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Here is the call graph for this function:

◆ AdvectionSrcForOpenBC_Tangent()

AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real AdvectionSrcForOpenBC_Tangent ( const int &  i,
const int &  j,
const int &  k,
const int &  nprim,
const int &  dir,
const Array4< const Real > &  prim_tang_arr,
const Array4< const Real > &  mom_norm_arr,
const Real dxInv,
const bool  do_lo 
)

Compute the open-boundary normal-direction source for a tangential primitive variable.

Parameters
[in]ii-index of the target cell
[in]jj-index of the target cell
[in]kk-index of the target cell
[in]nprimprimitive component to update
[in]dircoordinate direction normal to the open boundary
[in]prim_tang_arrprimitive variable tangent to the open boundary
[in]mom_norm_arrmomentum component normal to the open boundary
[in]dxInvinverse grid spacing in the open-boundary normal direction
[in]do_loflag for a low-side open boundary
Returns
source contribution before the wrapper applies its sign convention
334 {
335  // NOTE: Klemp, J. B., and R. Wilhelmson, 1978: The simulation of three-dimensional
336  // convective storm dynamics, J. Atmos. Sci., 35, 1070-Real(1096.)
337  // NOTE: Implementation is for the high bndry side. The low bndry side is obtained
338  // by flipping sgn = -one
339 
340  int sgn = 1; if (do_lo) { sgn = -1; }
341 
342  // NOTE: The indices (i,j,k) passed to this routine correspond to data that resides
343  // 1/2 dx away from the open boundary and into the domain. The momentum is
344  // face centered in dir, so it has one more cell than the scalar and cell
345  // (i,j,k) is bounded by the faces (i,j,k) and (i,j,k)+e_dir. One of those two
346  // faces resides on the physical boundary: the high face at a high open bndry,
347  // the low face at a low open bndry. Averaging and differencing that same pair
348  // of faces therefore yields the cell centered momentum and its exact cell
349  // centered gradient on both sides, so no sgn dependence is needed here.
350  IntVect ivm1(i,j,k); ivm1[dir] += 1; // Mom on the high face of cell (i,j,k)
351  IntVect ivm2(i,j,k); // Mom on the low face of cell (i,j,k)
352 
353  IntVect ivs1(i,j,k); if ( do_lo) { ivs1[dir] -= sgn; } // Scalar indexed into domain for do_lo
354  IntVect ivs2(i,j,k); if (!do_lo) { ivs2[dir] -= sgn; } // Scalar indexed into domain for do_hi
355 
356  Real mom_at_cc = myhalf * (mom_norm_arr(ivm1) + mom_norm_arr(ivm2));
357  Real mom_star = Real(sgn) * max( Real(sgn)*mom_at_cc, zero );
358  Real mom_grad = ( mom_norm_arr(ivm1) - mom_norm_arr(ivm2) ) * dxInv;
359  Real prim_grad = ( prim_tang_arr(ivs1,nprim) - prim_tang_arr(ivs2,nprim) ) * dxInv;
360 
361  // NOTE: Negative sign taken care of by wrapper function
362  Real src = ( mom_star*prim_grad + prim_tang_arr(i,j,k,nprim)*mom_grad );
363  return src;
364 }

Referenced by AdvectionSrcForOpenBC_Tangent_Cons(), AdvectionSrcForOpenBC_Tangent_Xmom(), AdvectionSrcForOpenBC_Tangent_Ymom(), and AdvectionSrcForOpenBC_Tangent_Zmom().

Here is the caller graph for this function:

◆ AdvectionSrcForOpenBC_Tangent_Cons()

void AdvectionSrcForOpenBC_Tangent_Cons ( const Box &  bx,
const int &  dir,
const int &  icomp,
const int &  ncomp,
const Array4< Real > &  cell_rhs,
const Array4< const Real > &  cell_prim,
const Array4< const Real > &  avg_xmom,
const Array4< const Real > &  avg_ymom,
const Array4< const Real > &  avg_zmom,
const Array4< const Real > &  detJ,
const GpuArray< Real, AMREX_SPACEDIM > &  cellSizeInv,
const bool  do_lo 
)

Compute second-order advection tendencies for conserved variables tangent to an open boundary.

Parameters
[in]bxbox over which conserved variables are updated
[in]dircoordinate direction normal to the open boundary
[in]icompfirst conserved component to update
[in]ncompnumber of conserved components to update
[out]cell_rhstendency for conserved variables
[in]cell_primprimitive scalar variables
[in]avg_xmomx-component of time-averaged momentum
[in]avg_ymomy-component of time-averaged momentum
[in]avg_zmomz-component of time-averaged momentum
[in]detJJacobian of the metric transformation
[in]cellSizeInvinverse grid spacing
[in]do_loflag for a low-side open boundary
264 {
265  AMREX_ALWAYS_ASSERT(dir!=2 && icomp>0);
266 
267  bool xopen = (dir==0);
268  bool yopen = (dir==1);
269 
270  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
271 
272  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
273  {
274  if (detJ(i,j,k) > zero) {
275  const int cons_index = icomp + n;
276  const int prim_index = cons_index - 1;
277  Real prim_xlo = myhalf * (cell_prim(i,j,k,prim_index) + cell_prim(i-1,j,k,prim_index));
278  Real prim_xhi = myhalf * (cell_prim(i,j,k,prim_index) + cell_prim(i+1,j,k,prim_index));
279  Real xflux_lo = avg_xmom(i ,j,k) * prim_xlo;
280  Real xflux_hi = avg_xmom(i+1,j,k) * prim_xhi;
281 
282  Real prim_ylo = myhalf * (cell_prim(i,j,k,prim_index) + cell_prim(i,j-1,k,prim_index));
283  Real prim_yhi = myhalf * (cell_prim(i,j,k,prim_index) + cell_prim(i,j+1,k,prim_index));
284  Real yflux_lo = avg_ymom(i,j ,k) * prim_ylo;
285  Real yflux_hi = avg_ymom(i,j+1,k) * prim_yhi;
286 
287  Real prim_zlo = myhalf * (cell_prim(i,j,k,prim_index) + cell_prim(i,j,k-1,prim_index));
288  Real prim_zhi = myhalf * (cell_prim(i,j,k,prim_index) + cell_prim(i,j,k+1,prim_index));
289  Real zflux_lo = avg_zmom(i,j,k ) * prim_zlo;
290  Real zflux_hi = avg_zmom(i,j,k+1) * prim_zhi;
291 
292  Real x_src = (xopen) ? AdvectionSrcForOpenBC_Tangent(i, j, k,
293  prim_index, dir, cell_prim,
294  avg_xmom, dxInv, do_lo) :
295  (xflux_hi - xflux_lo) * dxInv;
296  Real y_src = (yopen) ? AdvectionSrcForOpenBC_Tangent(i, j, k,
297  prim_index, dir, cell_prim,
298  avg_ymom, dyInv, do_lo) :
299  (yflux_hi - yflux_lo) * dyInv;
300  Real z_src = (zflux_hi - zflux_lo) * dzInv;
301  Real advectionSrc = x_src + y_src + z_src;
302  cell_rhs(i,j,k,cons_index) = -advectionSrc / detJ(i,j,k);
303  }
304  });
305 }
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Real AdvectionSrcForOpenBC_Tangent(const int &i, const int &j, const int &k, const int &nprim, const int &dir, const Array4< const Real > &prim_tang_arr, const Array4< const Real > &mom_norm_arr, const Real &dxInv, const bool do_lo)
Definition: ERF_AdvectionSrcForOpenBC.cpp:325
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
Here is the call graph for this function:

◆ AdvectionSrcForOpenBC_Tangent_Xmom()

void AdvectionSrcForOpenBC_Tangent_Xmom ( const Box &  bxx,
const int &  dir,
const Array4< Real > &  rho_u_rhs,
const Array4< const Real > &  u,
const Array4< const Real > &  rho_u,
const Array4< const Real > &  rho_v,
const Array4< const Real > &  Omega,
const Array4< const Real > &  ax,
const Array4< const Real > &  az,
const Array4< const Real > &  detJ,
const GpuArray< Real, AMREX_SPACEDIM > &  cellSizeInv,
const bool  do_lo 
)

Compute second-order advection tendencies for x-momentum tangent to an open boundary.

Parameters
[in]bxxbox over which x-momentum is updated
[in]dircoordinate direction normal to the open boundary
[out]rho_u_rhstendency for the x-momentum equation
[in]ux-component of velocity
[in]rho_ux-component of momentum
[in]rho_vy-component of momentum
[in]Omegacomponent of momentum normal to the z-coordinate surface
[in]axarea fraction of x-faces
[in]azarea fraction of z-faces
[in]detJJacobian of the metric transformation
[in]cellSizeInvinverse grid spacing
[in]do_loflag for a low-side open boundary
77 {
78  AMREX_ALWAYS_ASSERT(dir==1);
79 
80  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
81 
82  ParallelFor(bxx,[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
83  {
84  if (ax(i,j,k) > zero) {
85  Real xflux_hi = fourth * (rho_u(i, j , k) + rho_u(i+1, j , k)) * (u(i+1,j,k) + u(i,j,k)) * myhalf * (ax(i,j,k) + ax(i+1,j,k));
86  Real xflux_lo = fourth * (rho_u(i, j , k) + rho_u(i-1, j , k)) * (u(i-1,j,k) + u(i,j,k)) * myhalf * (ax(i,j,k) + ax(i-1,j,k));
87 
88  Real zflux_hi = fourth * (Omega(i, j, k+1) + Omega(i-1, j, k+1)) * (u(i,j,k+1) + u(i,j,k)) * az(i,j,k+1);
89  Real zflux_lo = fourth * (Omega(i, j, k ) + Omega(i-1, j, k )) * (u(i,j,k-1) + u(i,j,k)) * az(i,j,k );
90 
91  Real x_src = (xflux_hi - xflux_lo) * dxInv;
92  Real y_src = AdvectionSrcForOpenBC_Tangent(i, j, k, 0, dir, u, rho_v, dyInv, do_lo);
93  Real z_src = (zflux_hi - zflux_lo) * dzInv;
94  Real advectionSrc = x_src + y_src + z_src;
95 
96  rho_u_rhs(i, j, k) = -advectionSrc / (myhalf * (detJ(i,j,k) + detJ(i-1,j,k)));
97  } else {
98  rho_u_rhs(i, j, k) = zero;
99  }
100  });
101 }
constexpr amrex::Real fourth
Definition: ERF_Constants.H:14
Here is the call graph for this function:

◆ AdvectionSrcForOpenBC_Tangent_Ymom()

void AdvectionSrcForOpenBC_Tangent_Ymom ( const Box &  bxy,
const int &  dir,
const Array4< Real > &  rho_v_rhs,
const Array4< const Real > &  v,
const Array4< const Real > &  rho_u,
const Array4< const Real > &  rho_v,
const Array4< const Real > &  Omega,
const Array4< const Real > &  ay,
const Array4< const Real > &  az,
const Array4< const Real > &  detJ,
const GpuArray< Real, AMREX_SPACEDIM > &  cellSizeInv,
const bool  do_lo 
)

Compute second-order advection tendencies for y-momentum tangent to an open boundary.

Parameters
[in]bxybox over which y-momentum is updated
[in]dircoordinate direction normal to the open boundary
[out]rho_v_rhstendency for the y-momentum equation
[in]vy-component of velocity
[in]rho_ux-component of momentum
[in]rho_vy-component of momentum
[in]Omegacomponent of momentum normal to the z-coordinate surface
[in]ayarea fraction of y-faces
[in]azarea fraction of z-faces
[in]detJJacobian of the metric transformation
[in]cellSizeInvinverse grid spacing
[in]do_loflag for a low-side open boundary
132 {
133  AMREX_ALWAYS_ASSERT(dir==0);
134 
135  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
136 
137  ParallelFor(bxy,[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
138  {
139  if (ay(i,j,k) > zero) {
140  Real yflux_hi = fourth * (rho_v(i ,j+1,k) + rho_v(i ,j ,k)) * (v(i,j+1,k) + v(i,j,k)) * myhalf * (ay(i,j,k) + ay(i,j+1,k));
141  Real yflux_lo = fourth * (rho_v(i ,j ,k) + rho_v(i ,j-1,k)) * (v(i,j-1,k) + v(i,j,k)) * myhalf * (ay(i,j,k) + ay(i,j-1,k));
142 
143  Real zflux_hi = fourth * (Omega(i, j, k+1) + Omega(i, j-1, k+1)) * (v(i,j,k+1) + v(i,j,k)) * az(i,j,k+1);
144  Real zflux_lo = fourth * (Omega(i, j, k ) + Omega(i, j-1, k )) * (v(i,j,k-1) + v(i,j,k)) * az(i,j,k );
145 
146  Real x_src = AdvectionSrcForOpenBC_Tangent(i, j, k, 0, dir, v, rho_u, dxInv, do_lo);
147  Real y_src = (yflux_hi - yflux_lo) * dyInv;
148  Real z_src = (zflux_hi - zflux_lo) * dzInv;
149  Real advectionSrc = x_src + y_src + z_src;
150 
151  rho_v_rhs(i, j, k) = -advectionSrc / (myhalf * (detJ(i,j,k) + detJ(i,j-1,k)));
152  } else {
153  rho_v_rhs(i, j, k) = zero;
154  }
155  });
156 }
Here is the call graph for this function:

◆ AdvectionSrcForOpenBC_Tangent_Zmom()

void AdvectionSrcForOpenBC_Tangent_Zmom ( const Box &  bxz,
const int &  dir,
const Array4< Real > &  rho_w_rhs,
const Array4< const Real > &  w,
const Array4< const Real > &  rho_u,
const Array4< const Real > &  rho_v,
const Array4< const Real > &  Omega,
const Array4< const Real > &  ax,
const Array4< const Real > &  ay,
const Array4< const Real > &  az,
const Array4< const Real > &  detJ,
const GpuArray< Real, AMREX_SPACEDIM > &  cellSizeInv,
const int  domhi_z,
const bool  do_lo 
)

Compute second-order advection tendencies for z-momentum tangent to an open boundary.

Parameters
[in]bxzbox over which z-momentum is updated
[in]dircoordinate direction normal to the open boundary
[out]rho_w_rhstendency for the z-momentum equation
[in]wz-component of velocity
[in]rho_ux-component of momentum
[in]rho_vy-component of momentum
[in]Omegacomponent of momentum normal to the z-coordinate surface
[in]axarea fraction of x-faces
[in]ayarea fraction of y-faces
[in]azarea fraction of z-faces
[in]detJJacobian of the metric transformation
[in]cellSizeInvinverse grid spacing
[in]domhi_zmaximum cell-centered k-index in the domain
[in]do_loflag for a low-side open boundary
191 {
192  AMREX_ALWAYS_ASSERT(dir!=2);
193 
194  bool xopen = (dir==0);
195  bool yopen = (dir==1);
196 
197  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
198 
199  ParallelFor(bxz, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
200  {
201  if (az(i,j,k) > zero) {
202  Real xflux_hi = fourth*(rho_u(i+1,j ,k) + rho_u(i+1, j, k-1)) * (w(i+1,j,k) + w(i,j,k)) *
203  myhalf *(ax(i+1,j,k) + ax(i+1,j,k-1));
204 
205  Real xflux_lo = fourth*(rho_u(i ,j ,k) + rho_u(i , j, k-1)) * (w(i-1,j,k) + w(i,j,k)) *
206  myhalf *(ax(i,j,k) + ax(i,j,k-1));
207 
208  Real yflux_hi = fourth*(rho_v(i ,j+1,k) + rho_v(i, j+1, k-1)) * (w(i,j+1,k) + w(i,j,k)) *
209  myhalf *(ay(i,j+1,k) + ay(i,j+1,k-1));
210 
211  Real yflux_lo = fourth*(rho_v(i ,j ,k) + rho_v(i, j , k-1)) * (w(i,j-1,k) + w(i,j,k)) *
212  myhalf *(ay(i,j,k) + ay(i,j,k-1));
213 
214  Real zflux_lo = fourth * (Omega(i,j,k) + Omega(i,j,k-1)) * (w(i,j,k) + w(i,j,k-1)) *
215  myhalf *(az(i,j,k) + az(i,j,k-1));
216 
217  Real zflux_hi = (k == domhi_z+1) ? Omega(i,j,k) * w(i,j,k) * az(i,j,k):
218  fourth * (Omega(i,j,k) + Omega(i,j,k+1)) * (w(i,j,k) + w(i,j,k+1)) *
219  myhalf * (az(i,j,k) + az(i,j,k+1));
220 
221  Real x_src = (xopen) ? AdvectionSrcForOpenBC_Tangent(i, j, k, 0, dir, w, rho_u, dxInv, do_lo) :
222  (xflux_hi - xflux_lo) * dxInv;
223  Real y_src = (yopen) ? AdvectionSrcForOpenBC_Tangent(i, j, k, 0, dir, w, rho_v, dyInv, do_lo) :
224  (yflux_hi - yflux_lo) * dyInv;
225  Real z_src = (zflux_hi - zflux_lo) * dzInv;
226  Real advectionSrc = x_src + y_src + z_src;
227 
228  rho_w_rhs(i, j, k) = -advectionSrc / (myhalf*(detJ(i,j,k) + detJ(i,j,k-1)));
229  } else {
230  rho_w_rhs(i, j, k) = zero;
231  }
232  });
233 }
Real w
Definition: ERF_Plotfile2DInterpolator.cpp:22
Here is the call graph for this function: