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 BC

14 {
15  // NOTE: Klemp, J. B., and R. Wilhelmson, 1978: The simulation of three-dimensional
16  // convective storm dynamics, J. Atmos. Sci., 35, 1070-1096.
17  // NOTE: Implementation is for the high bndry side. The low bndry side is obtained
18  // by flipping sgn = -1.
19  // NOTE: Indices (i,j,k) correspond to data that is ON the open bdy.
20  int sgn = 1; if (do_lo) sgn = -1;
21  Real c_o_star = Real(sgn)*30.0;
22  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
23  {
24  IntVect ivu1(i,j,k); if ( do_lo) ivu1[dir] -= sgn; // Vel indexed into domain for do_lo
25  IntVect ivu2(i,j,k); if (!do_lo) ivu2[dir] -= sgn; // Vel indexed into domain for do_hi
26 
27  IntVect ivr1(i,j,k); if (!do_lo) ivr1[dir] -= sgn; // Rho indexed into domain for do_hi
28  IntVect ivr2(i,j,k); if ( do_lo) ivr2[dir] += sgn; // Rho indexed out domain for do_lo
29 
30  Real rho_face = 0.5 * ( cell_data_arr(ivr1,Rho_comp) + cell_data_arr(ivr2,Rho_comp) );
31  Real mom_star = rho_face * Real(sgn) * max( Real(sgn)*(vel_norm_arr(ivu1) + c_o_star), 0.0 );
32  Real vel_grad = ( vel_norm_arr(ivu1) - vel_norm_arr(ivu2) ) * dxInv[dir];
33  Real flux = -( mom_star * vel_grad );
34  rhs_arr(i,j,k) = flux;
35  });
36 }
#define Rho_comp
Definition: ERF_IndexDefines.H:36

◆ 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 
)
245 {
246  // NOTE: Klemp, J. B., and R. Wilhelmson, 1978: The simulation of three-dimensional
247  // convective storm dynamics, J. Atmos. Sci., 35, 1070-1096.
248  // NOTE: Implementation is for the high bndry side. The low bndry side is obtained
249  // by flipping sgn = -1.
250  // NOTE: Indices (i,j,k) correspond to data that is index 1/2 dx off open bdy.
251  int sgn = 1; if (do_lo) sgn = -1;
252 
253  IntVect ivm1(i,j,k); if ( do_lo) ivm1[dir] -= sgn; // Mom indexed into domain for do_lo
254  IntVect ivm2(i,j,k); if (!do_lo) ivm1[dir] += sgn; // Mom indexed out domain for do_hi
255 
256  IntVect ivs1(i,j,k); if ( do_lo) ivs1[dir] -= sgn; // Scalar indexed into domain for do_hi
257  IntVect ivs2(i,j,k); if (!do_lo) ivs2[dir] -= sgn; // Scalar indexed into domain for do_lo
258 
259  Real mom_at_cc = 0.5 * (mom_norm_arr(ivm1) + mom_norm_arr(ivm2));
260  Real mom_star = Real(sgn) * max( Real(sgn)*mom_at_cc, 0.0 );
261  Real mom_grad = ( mom_norm_arr(ivm1) - mom_norm_arr(ivm2) ) * dxInv;
262  Real prim_grad = ( prim_tang_arr(ivs1,nprim) - prim_tang_arr(ivs2,nprim) ) * dxInv;
263 
264  // NOTE: Negative sign taken care of by wrapper function
265  Real src = ( mom_star*prim_grad + prim_tang_arr(ivs1,nprim)*mom_grad );
266  return src;
267 }

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 advection tendencies for x momentum tangential to BC (2nd order)

192 {
193  AMREX_ALWAYS_ASSERT(dir!=2 && icomp>0);
194 
195  bool xopen = (dir==0);
196  bool yopen = (dir==1);
197 
198  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
199 
200  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
201  {
202  if (detJ(i,j,k) > 0.) {
203  const int cons_index = icomp + n;
204  const int prim_index = cons_index - 1;
205 
206  Real prim_xlo = 0.5 * (cell_prim(i,j,k,prim_index) + cell_prim(i-1,j,k,prim_index));
207  Real prim_xhi = 0.5 * (cell_prim(i,j,k,prim_index) + cell_prim(i+1,j,k,prim_index));
208  Real xflux_lo = avg_xmom(i ,j,k) * prim_xlo;
209  Real xflux_hi = avg_xmom(i+1,j,k) * prim_xhi;
210 
211  Real prim_ylo = 0.5 * (cell_prim(i,j,k,prim_index) + cell_prim(i,j-1,k,prim_index));
212  Real prim_yhi = 0.5 * (cell_prim(i,j,k,prim_index) + cell_prim(i,j+1,k,prim_index));
213  Real yflux_lo = avg_ymom(i,j ,k) * prim_ylo;
214  Real yflux_hi = avg_ymom(i,j+1,k) * prim_yhi;
215 
216  Real prim_zlo = 0.5 * (cell_prim(i,j,k,prim_index) + cell_prim(i,j,k-1,prim_index));
217  Real prim_zhi = 0.5 * (cell_prim(i,j,k,prim_index) + cell_prim(i,j,k+1,prim_index));
218  Real zflux_lo = avg_zmom(i,j,k ) * prim_zlo;
219  Real zflux_hi = avg_zmom(i,j,k+1) * prim_zhi;
220 
221  Real x_src = (xopen) ? AdvectionSrcForOpenBC_Tangent(i, j, k, prim_index, dir, cell_prim, avg_xmom, dxInv, do_lo) :
222  (xflux_hi - xflux_lo) * dxInv;
223  Real y_src = (yopen) ? AdvectionSrcForOpenBC_Tangent(i, j, k, prim_index, dir, cell_prim, avg_ymom, 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  cell_rhs(i,j,k,cons_index) = -advectionSrc / detJ(i,j,k);
228  }
229  });
230 }
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:236
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 advection tendencies for x momentum tangential to BC (2nd order)

52 {
53  AMREX_ALWAYS_ASSERT(dir==1);
54 
55  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
56 
57  ParallelFor(bxx,[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
58  {
59  if (ax(i,j,k) > 0.) {
60  Real xflux_hi = 0.25 * (rho_u(i, j , k) + rho_u(i+1, j , k)) * (u(i+1,j,k) + u(i,j,k)) * 0.5 * (ax(i,j,k) + ax(i+1,j,k));
61  Real xflux_lo = 0.25 * (rho_u(i, j , k) + rho_u(i-1, j , k)) * (u(i-1,j,k) + u(i,j,k)) * 0.5 * (ax(i,j,k) + ax(i-1,j,k));
62 
63  Real zflux_hi = 0.25 * (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);
64  Real zflux_lo = 0.25 * (Omega(i, j, k ) + Omega(i-1, j, k )) * (u(i,j,k-1) + u(i,j,k)) * az(i,j,k );
65 
66  Real x_src = (xflux_hi - xflux_lo) * dxInv;
67  Real y_src = AdvectionSrcForOpenBC_Tangent(i, j, k, 0, dir, u, rho_v, dyInv, do_lo);
68  Real z_src = (zflux_hi - zflux_lo) * dzInv;
69  Real advectionSrc = x_src + y_src + z_src;
70 
71  rho_u_rhs(i, j, k) = -advectionSrc / (0.5 * (detJ(i,j,k) + detJ(i-1,j,k)));
72  } else {
73  rho_u_rhs(i, j, k) = 0.0;
74  }
75  });
76 }
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 advection tendencies for x momentum tangential to BC (2nd order)

92 {
93  AMREX_ALWAYS_ASSERT(dir==0);
94 
95  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
96 
97  ParallelFor(bxy,[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
98  {
99  if (ay(i,j,k) > 0.) {
100  Real yflux_hi = 0.25 * (rho_v(i ,j+1,k) + rho_v(i ,j ,k)) * (v(i,j+1,k) + v(i,j,k)) * 0.5 * (ay(i,j,k) + ay(i,j+1,k));
101  Real yflux_lo = 0.25 * (rho_v(i ,j ,k) + rho_v(i ,j-1,k)) * (v(i,j-1,k) + v(i,j,k)) * 0.5 * (ay(i,j,k) + ay(i,j-1,k));
102 
103  Real zflux_hi = 0.25 * (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);
104  Real zflux_lo = 0.25 * (Omega(i, j, k ) + Omega(i, j-1, k )) * (v(i,j,k-1) + v(i,j,k)) * az(i,j,k );
105 
106  Real x_src = AdvectionSrcForOpenBC_Tangent(i, j, k, 0, dir, v, rho_u, dxInv, do_lo);
107  Real y_src = (yflux_hi - yflux_lo) * dyInv;
108  Real z_src = (zflux_hi - zflux_lo) * dzInv;
109  Real advectionSrc = x_src + y_src + z_src;
110 
111  rho_v_rhs(i, j, k) = -advectionSrc / (0.5 * (detJ(i,j,k) + detJ(i,j-1,k)));
112  } else {
113  rho_v_rhs(i, j, k) = 0.0;
114  }
115  });
116 }
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 advection tendencies for x momentum tangential to BC (2nd order)

134 {
135  AMREX_ALWAYS_ASSERT(dir!=2);
136 
137  bool xopen = (dir==0);
138  bool yopen = (dir==1);
139 
140  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
141 
142  ParallelFor(bxz, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
143  {
144  if (az(i,j,k) > 0.) {
145  Real xflux_hi = 0.25*(rho_u(i+1,j ,k) + rho_u(i+1, j, k-1)) * (w(i+1,j,k) + w(i,j,k)) *
146  0.5 *(ax(i+1,j,k) + ax(i+1,j,k-1));
147 
148  Real xflux_lo = 0.25*(rho_u(i ,j ,k) + rho_u(i , j, k-1)) * (w(i-1,j,k) + w(i,j,k)) *
149  0.5 *(ax(i,j,k) + ax(i,j,k-1));
150 
151  Real yflux_hi = 0.25*(rho_v(i ,j+1,k) + rho_v(i, j+1, k-1)) * (w(i,j+1,k) + w(i,j,k)) *
152  0.5 *(ay(i,j+1,k) + ay(i,j+1,k-1));
153 
154  Real yflux_lo = 0.25*(rho_v(i ,j ,k) + rho_v(i, j , k-1)) * (w(i,j-1,k) + w(i,j,k)) *
155  0.5 *(ay(i,j,k) + ay(i,j,k-1));
156 
157  Real zflux_lo = 0.25 * (Omega(i,j,k) + Omega(i,j,k-1)) * (w(i,j,k) + w(i,j,k-1)) *
158  0.5 *(az(i,j,k) + az(i,j,k-1));
159 
160  Real zflux_hi = (k == domhi_z+1) ? Omega(i,j,k) * w(i,j,k) * az(i,j,k):
161  0.25 * (Omega(i,j,k) + Omega(i,j,k+1)) * (w(i,j,k) + w(i,j,k+1)) *
162  0.5 * (az(i,j,k) + az(i,j,k-1));
163 
164  Real x_src = (xopen) ? AdvectionSrcForOpenBC_Tangent(i, j, k, 0, dir, w, rho_u, dxInv, do_lo) :
165  (xflux_hi - xflux_lo) * dxInv;
166  Real y_src = (yopen) ? AdvectionSrcForOpenBC_Tangent(i, j, k, 0, dir, w, rho_v, dyInv, do_lo) :
167  (yflux_hi - yflux_lo) * dyInv;
168  Real z_src = (zflux_hi - zflux_lo) * dzInv;
169  Real advectionSrc = x_src + y_src + z_src;
170 
171  rho_w_rhs(i, j, k) = -advectionSrc / (0.5*(detJ(i,j,k) + detJ(i,j,k-1)));
172  } else {
173  rho_w_rhs(i, j, k) = 0.0;
174  }
175  });
176 }
Here is the call graph for this function: