ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_AdvectionSrcForState.cpp File Reference
Include dependency graph for ERF_AdvectionSrcForState.cpp:

Functions

void AdvectionSrcForRho (const Box &bx, const Array4< Real > &advectionSrc, const Array4< const Real > &rho_u, const Array4< const Real > &rho_v, const Array4< const Real > &Omega, const Array4< Real > &avg_xmom, const Array4< Real > &avg_ymom, const Array4< Real > &avg_zmom, const Array4< const Real > &ax_arr, const Array4< const Real > &ay_arr, const Array4< const Real > &az_arr, const Array4< const Real > &detJ, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, const Array4< const Real > &mf_mx, const Array4< const Real > &mf_my, const Array4< const Real > &mf_uy, const Array4< const Real > &mf_vx, const GpuArray< const Array4< Real >, AMREX_SPACEDIM > &flx_arr, const bool fixed_rho)
 
void AdvectionSrcForScalars (const Box &bx, const int icomp, const int ncomp, const Array4< const Real > &avg_xmom, const Array4< const Real > &avg_ymom, const Array4< const Real > &avg_zmom, const Array4< const Real > &cell_prim, const Array4< Real > &advectionSrc, const Array4< const Real > &detJ, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, const Array4< const Real > &mf_mx, const Array4< const Real > &mf_my, const AdvType horiz_adv_type, const AdvType vert_adv_type, const Real horiz_upw_frac, const Real vert_upw_frac, const GpuArray< const Array4< Real >, AMREX_SPACEDIM > &flx_arr, const Box &domain, const BCRec *bc_ptr_h)
 

Function Documentation

◆ AdvectionSrcForRho()

void AdvectionSrcForRho ( const Box &  bx,
const Array4< Real > &  advectionSrc,
const Array4< const Real > &  rho_u,
const Array4< const Real > &  rho_v,
const Array4< const Real > &  Omega,
const Array4< Real > &  avg_xmom,
const Array4< Real > &  avg_ymom,
const Array4< Real > &  avg_zmom,
const Array4< const Real > &  ax_arr,
const Array4< const Real > &  ay_arr,
const Array4< const Real > &  az_arr,
const Array4< const Real > &  detJ,
const GpuArray< Real, AMREX_SPACEDIM > &  cellSizeInv,
const Array4< const Real > &  mf_mx,
const Array4< const Real > &  mf_my,
const Array4< const Real > &  mf_uy,
const Array4< const Real > &  mf_vx,
const GpuArray< const Array4< Real >, AMREX_SPACEDIM > &  flx_arr,
const bool  fixed_rho 
)

Function for computing the advective tendency for the density update equation This routine also constructs the time-averaged momentum fluxes used by scalar advection.

Parameters
[in]bxbox over which the scalars are updated
[out]advectionSrctendency for the scalar update equation
[in]rho_ux-component of momentum
[in]rho_vy-component of momentum
[in]Omegacomponent of momentum normal to the z-coordinate surface
[out]avg_xmomx-component of time-averaged momentum defined in this routine
[out]avg_ymomy-component of time-averaged momentum defined in this routine
[out]avg_zmomz-component of time-averaged momentum defined in this routine
[in]ax_arrarea fraction of x-faces
[in]ay_arrarea fraction of y-faces
[in]az_arrarea fraction of z-faces
[in]detJJacobian of the metric transformation (= 1 if use_terrain is false)
[in]cellSizeInvinverse of the grid spacing
[in]mf_mxx map factor at cell centers
[in]mf_myy map factor at cell centers
[in]mf_uyy map factor at x-faces
[in]mf_vxx map factor at y-faces
[out]flx_arrdensity flux arrays
[in]fixed_rhoflag to zero the density tendency
54 {
55  BL_PROFILE_VAR("AdvectionSrcForRho", AdvectionSrcForRho);
56  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
57 
58  const Box xbx = surroundingNodes(bx,0);
59  const Box ybx = surroundingNodes(bx,1);
60  const Box zbx = surroundingNodes(bx,2);
61 
62  ParallelFor(xbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
63  {
64  (flx_arr[0])(i,j,k,0) = ax_arr(i,j,k) * rho_u(i,j,k) / mf_uy(i,j,0);
65  avg_xmom(i,j,k) = (flx_arr[0])(i,j,k,0);
66  });
67  ParallelFor(ybx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
68  {
69  (flx_arr[1])(i,j,k,0) = ay_arr(i,j,k) * rho_v(i,j,k) / mf_vx(i,j,0);
70  avg_ymom(i,j,k) = (flx_arr[1])(i,j,k,0);
71  });
72  ParallelFor(zbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
73  {
74  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
75  (flx_arr[2])(i,j,k,0) = az_arr(i,j,k) * Omega(i,j,k) / mfsq;
76  avg_zmom(i,j,k) = (flx_arr[2])(i,j,k,0);
77  });
78 
79  if (fixed_rho) {
80  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
81  {
82  advectionSrc(i,j,k,0) = zero;
83  });
84  } else
85  {
86  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
87  {
88  if (detJ(i,j,k) > zero) {
89  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
90  advectionSrc(i,j,k,0) = - mfsq / detJ(i,j,k) * (
91  ( (flx_arr[0])(i+1,j,k,0) - (flx_arr[0])(i ,j,k,0) ) * dxInv +
92  ( (flx_arr[1])(i,j+1,k,0) - (flx_arr[1])(i,j ,k,0) ) * dyInv +
93  ( (flx_arr[2])(i,j,k+1,0) - (flx_arr[2])(i,j,k ,0) ) * dzInv );
94  } else {
95  advectionSrc(i,j,k,0) = zero;
96  }
97  });
98  }
99 }
void AdvectionSrcForRho(const Box &bx, const Array4< Real > &advectionSrc, const Array4< const Real > &rho_u, const Array4< const Real > &rho_v, const Array4< const Real > &Omega, const Array4< Real > &avg_xmom, const Array4< Real > &avg_ymom, const Array4< Real > &avg_zmom, const Array4< const Real > &ax_arr, const Array4< const Real > &ay_arr, const Array4< const Real > &az_arr, const Array4< const Real > &detJ, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, const Array4< const Real > &mf_mx, const Array4< const Real > &mf_my, const Array4< const Real > &mf_uy, const Array4< const Real > &mf_vx, const GpuArray< const Array4< Real >, AMREX_SPACEDIM > &flx_arr, const bool fixed_rho)
Definition: ERF_AdvectionSrcForState.cpp:35
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
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:

◆ AdvectionSrcForScalars()

void AdvectionSrcForScalars ( const Box &  bx,
const int  icomp,
const int  ncomp,
const Array4< const Real > &  avg_xmom,
const Array4< const Real > &  avg_ymom,
const Array4< const Real > &  avg_zmom,
const Array4< const Real > &  cell_prim,
const Array4< Real > &  advectionSrc,
const Array4< const Real > &  detJ,
const GpuArray< Real, AMREX_SPACEDIM > &  cellSizeInv,
const Array4< const Real > &  mf_mx,
const Array4< const Real > &  mf_my,
const AdvType  horiz_adv_type,
const AdvType  vert_adv_type,
const Real  horiz_upw_frac,
const Real  vert_upw_frac,
const GpuArray< const Array4< Real >, AMREX_SPACEDIM > &  flx_arr,
const Box &  domain,
const BCRec *  bc_ptr_h 
)

Function for computing the advective tendency for scalar update equations other than density This routine has explicit expressions for all cases (terrain or not) when the horizontal and vertical spatial orders are <= 2, and calls more specialized functions when either (or both) spatial order(s) is greater than two

Parameters
[in]bxbox over which the scalars are updated if no external boundary conditions
[in]icompcomponent of first scalar to be updated
[in]ncompnumber of components to be updated
[in]avg_xmomx-component of time-averaged momentum defined in this routine
[in]avg_ymomy-component of time-averaged momentum defined in this routine
[in]avg_zmomz-component of time-averaged momentum defined in this routine
[in]cell_primprimitive form of scalar variables, here only potential temperature theta
[out]advectionSrctendency for the scalar update equation
[in]detJJacobian of the metric transformation (= 1 if use_terrain is false)
[in]cellSizeInvinverse of the grid spacing
[in]mf_mxx map factor at cell centers
[in]mf_myy map factor at cell centers
[in]horiz_adv_typeadvection scheme to be used in horiz. directions for dry scalars
[in]vert_adv_typeadvection scheme to be used in vert. directions for dry scalars
[in]horiz_upw_fracupwinding fraction to be used in horiz. directions for dry scalars (for Blended schemes only)
[in]vert_upw_fracupwinding fraction to be used in vert. directions for dry scalars (for Blended schemes only)
[out]flx_arrscalar flux arrays
[in]domaincomputational domain
[in]bc_ptr_hboundary condition records on host
148 {
149  BL_PROFILE_VAR("AdvectionSrcForScalars", AdvectionSrcForScalars);
150  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
151 
152  const Box xbx = surroundingNodes(bx,0);
153  const Box ybx = surroundingNodes(bx,1);
154  const Box zbx = surroundingNodes(bx,2);
155 
156  // Open bc will be imposed upon all vars (we only access cons here for simplicity)
157  const bool xlo_open = (bc_ptr_h[BCVars::cons_bc].lo(0) == ERFBCType::open);
158  const bool xhi_open = (bc_ptr_h[BCVars::cons_bc].hi(0) == ERFBCType::open);
159  const bool ylo_open = (bc_ptr_h[BCVars::cons_bc].lo(1) == ERFBCType::open);
160  const bool yhi_open = (bc_ptr_h[BCVars::cons_bc].hi(1) == ERFBCType::open);
161 
162  // Only advection operations in bndry normal direction with OPEN BC
163  Box bx_xlo, bx_xhi, bx_ylo, bx_yhi;
164  if (xlo_open) {
165  if ( bx.smallEnd(0) == domain.smallEnd(0)) { bx_xlo = makeSlab( bx,0,domain.smallEnd(0));}
166  }
167  if (xhi_open) {
168  if ( bx.bigEnd(0) == domain.bigEnd(0)) { bx_xhi = makeSlab( bx,0,domain.bigEnd(0) );}
169  }
170  if (ylo_open) {
171  if ( bx.smallEnd(1) == domain.smallEnd(1)) { bx_ylo = makeSlab( bx,1,domain.smallEnd(1));}
172  }
173  if (yhi_open) {
174  if ( bx.bigEnd(1) == domain.bigEnd(1)) { bx_yhi = makeSlab( bx,1,domain.bigEnd(1) );}
175  }
176 
177  for (int n(0); n<ncomp; ++n) {
178  const int cons_index = icomp + n;
179 
180  // Inline with 2nd order for efficiency
181  // NOTE: we don't need to weight avg_xmom, avg_ymom, avg_zmom with terrain metrics
182  // (or with EB area fractions)
183  // because that was done when they were constructed in AdvectionSrcForRhoAndTheta
184  if (horiz_adv_type == AdvType::Centered_2nd && vert_adv_type == AdvType::Centered_2nd)
185  {
186  ParallelFor(xbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
187  {
188  const int prim_index = cons_index - 1;
189  const Real prim_on_face = myhalf * (cell_prim(i,j,k,prim_index) + cell_prim(i-1,j,k,prim_index));
190  (flx_arr[0])(i,j,k) = avg_xmom(i,j,k) * prim_on_face;
191  });
192  ParallelFor(ybx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
193  {
194  const int prim_index = cons_index - 1;
195  const Real prim_on_face = myhalf * (cell_prim(i,j,k,prim_index) + cell_prim(i,j-1,k,prim_index));
196  (flx_arr[1])(i,j,k) = avg_ymom(i,j,k) * prim_on_face;
197  });
198  ParallelFor(zbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
199  {
200  const int prim_index = cons_index - 1;
201  const Real prim_on_face = myhalf * (cell_prim(i,j,k,prim_index) + cell_prim(i,j,k-1,prim_index));
202  (flx_arr[2])(i,j,k) = avg_zmom(i,j,k) * prim_on_face;
203  });
204 
205  // Template higher order methods (horizontal first)
206  } else {
207  switch(horiz_adv_type) {
209  AdvectionSrcForScalarsVert<CENTERED2>(bx, cons_index, flx_arr, cell_prim,
210  avg_xmom, avg_ymom, avg_zmom,
211  horiz_upw_frac, vert_upw_frac, vert_adv_type);
212  break;
213  case AdvType::Upwind_3rd:
214  AdvectionSrcForScalarsVert<UPWIND3>(bx, cons_index, flx_arr, cell_prim,
215  avg_xmom, avg_ymom, avg_zmom,
216  horiz_upw_frac, vert_upw_frac, vert_adv_type);
217  break;
219  AdvectionSrcForScalarsVert<UPWIND3SL>(bx, cons_index, flx_arr, cell_prim,
220  avg_xmom, avg_ymom, avg_zmom,
221  horiz_upw_frac, vert_upw_frac, vert_adv_type);
222  break;
224  AdvectionSrcForScalarsVert<CENTERED4>(bx, cons_index, flx_arr, cell_prim,
225  avg_xmom, avg_ymom, avg_zmom,
226  horiz_upw_frac, vert_upw_frac, vert_adv_type);
227  break;
228  case AdvType::Upwind_5th:
229  AdvectionSrcForScalarsVert<UPWIND5>(bx, cons_index, flx_arr, cell_prim,
230  avg_xmom, avg_ymom, avg_zmom,
231  horiz_upw_frac, vert_upw_frac, vert_adv_type);
232  break;
234  AdvectionSrcForScalarsVert<CENTERED6>(bx, cons_index, flx_arr, cell_prim,
235  avg_xmom, avg_ymom, avg_zmom,
236  horiz_upw_frac, vert_upw_frac, vert_adv_type);
237  break;
238  case AdvType::Weno_3:
239  AdvectionSrcForScalarsWrapper<WENO3,WENO3>(bx, cons_index, flx_arr, cell_prim,
240  avg_xmom, avg_ymom, avg_zmom,
241  horiz_upw_frac, vert_upw_frac);
242  break;
243  case AdvType::Weno_5:
244  AdvectionSrcForScalarsWrapper<WENO5,WENO5>(bx, cons_index, flx_arr, cell_prim,
245  avg_xmom, avg_ymom, avg_zmom,
246  horiz_upw_frac, vert_upw_frac);
247  break;
248  case AdvType::Weno_7:
249  AdvectionSrcForScalarsWrapper<WENO7,WENO7>(bx, cons_index, flx_arr, cell_prim,
250  avg_xmom, avg_ymom, avg_zmom,
251  horiz_upw_frac, vert_upw_frac);
252  break;
253  case AdvType::Weno_3Z:
254  AdvectionSrcForScalarsWrapper<WENO_Z3,WENO_Z3>(bx, cons_index, flx_arr, cell_prim,
255  avg_xmom, avg_ymom, avg_zmom,
256  horiz_upw_frac, vert_upw_frac);
257  break;
258  case AdvType::Weno_3MZQ:
259  AdvectionSrcForScalarsWrapper<WENO_MZQ3,WENO_MZQ3>(bx, cons_index, flx_arr, cell_prim,
260  avg_xmom, avg_ymom, avg_zmom,
261  horiz_upw_frac, vert_upw_frac);
262  break;
263  case AdvType::Weno_5Z:
264  AdvectionSrcForScalarsWrapper<WENO_Z5,WENO_Z5>(bx, cons_index, flx_arr, cell_prim,
265  avg_xmom, avg_ymom, avg_zmom,
266  horiz_upw_frac, vert_upw_frac);
267  break;
268  case AdvType::Weno_7Z:
269  AdvectionSrcForScalarsWrapper<WENO_Z7,WENO_Z7>(bx, cons_index, flx_arr, cell_prim,
270  avg_xmom, avg_ymom, avg_zmom,
271  horiz_upw_frac, vert_upw_frac);
272  break;
273  default:
274  AMREX_ASSERT_WITH_MESSAGE(false, "Unknown advection scheme!");
275  }
276  }
277 
278  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
279  {
280  if (detJ(i,j,k) > zero)
281  {
282  Real invdetJ = one / detJ(i,j,k);
283  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
284 
285  advectionSrc(i,j,k,cons_index) = - invdetJ * mfsq * (
286  ( (flx_arr[0])(i+1,j,k) - (flx_arr[0])(i,j,k) ) * dxInv +
287  ( (flx_arr[1])(i,j+1,k) - (flx_arr[1])(i,j,k) ) * dyInv +
288  ( (flx_arr[2])(i,j,k+1) - (flx_arr[2])(i,j,k) ) * dzInv );
289  } else {
290  advectionSrc(i,j,k,cons_index) = zero;
291  }
292  });
293 
294  } // n
295 
296  // Special advection operator for open BC (bndry tangent operations)
297  if (xlo_open) {
298  bool do_lo = true;
299  AdvectionSrcForOpenBC_Tangent_Cons(bx_xlo, 0, icomp, ncomp, advectionSrc, cell_prim,
300  avg_xmom, avg_ymom, avg_zmom,
301  detJ, cellSizeInv, do_lo);
302  }
303  if (xhi_open) {
304  AdvectionSrcForOpenBC_Tangent_Cons(bx_xhi, 0, icomp, ncomp, advectionSrc, cell_prim,
305  avg_xmom, avg_ymom, avg_zmom,
306  detJ, cellSizeInv);
307  }
308  if (ylo_open) {
309  bool do_lo = true;
310  AdvectionSrcForOpenBC_Tangent_Cons(bx_ylo, 1, icomp, ncomp, advectionSrc, cell_prim,
311  avg_xmom, avg_ymom, avg_zmom,
312  detJ, cellSizeInv, do_lo);
313  }
314  if (yhi_open) {
315  AdvectionSrcForOpenBC_Tangent_Cons(bx_yhi, 1, icomp, ncomp, advectionSrc, cell_prim,
316  avg_xmom, avg_ymom, avg_zmom,
317  detJ, cellSizeInv);
318  }
319 }
void AdvectionSrcForScalars(const Box &bx, const int icomp, const int ncomp, const Array4< const Real > &avg_xmom, const Array4< const Real > &avg_ymom, const Array4< const Real > &avg_zmom, const Array4< const Real > &cell_prim, const Array4< Real > &advectionSrc, const Array4< const Real > &detJ, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, const Array4< const Real > &mf_mx, const Array4< const Real > &mf_my, const AdvType horiz_adv_type, const AdvType vert_adv_type, const Real horiz_upw_frac, const Real vert_upw_frac, const GpuArray< const Array4< Real >, AMREX_SPACEDIM > &flx_arr, const Box &domain, const BCRec *bc_ptr_h)
Definition: ERF_AdvectionSrcForState.cpp:129
void AdvectionSrcForOpenBC_Tangent_Cons(const amrex::Box &bx, const int &dir, const int &icomp, const int &ncomp, const amrex::Array4< amrex::Real > &cell_rhs, const amrex::Array4< const amrex::Real > &cell_prim, const amrex::Array4< const amrex::Real > &avg_xmom, const amrex::Array4< const amrex::Real > &avg_ymom, const amrex::Array4< const amrex::Real > &avg_zmom, const amrex::Array4< const amrex::Real > &detJ, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const bool do_lo=false)
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
@ Upwind_3rd_SL
@ Centered_4th
@ Centered_6th
@ Centered_2nd
AMREX_ASSERT_WITH_MESSAGE(wbar_cutoff_min > wbar_cutoff_max, "ERROR: wbar_cutoff_min < wbar_cutoff_max")
@ cons_bc
Definition: ERF_IndexDefines.H:86
@ open
Definition: ERF_IndexDefines.H:256
Here is the call graph for this function: