ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 update equations for rho and (rho theta) 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 2.

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]detJJacobian of the metric transformation (= 1 if use_terrain is false)
[in]cellSizeInvinverse of the mesh spacing
[in]mf_mmap factor at cell centers
[in]mf_umap factor at x-faces
[in]mf_vmap factor at y-faces
49 {
50  BL_PROFILE_VAR("AdvectionSrcForRho", AdvectionSrcForRho);
51  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
52 
53  const Box xbx = surroundingNodes(bx,0);
54  const Box ybx = surroundingNodes(bx,1);
55  const Box zbx = surroundingNodes(bx,2);
56 
57  ParallelFor(xbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
58  {
59  (flx_arr[0])(i,j,k,0) = ax_arr(i,j,k) * rho_u(i,j,k) / mf_uy(i,j,0);
60  avg_xmom(i,j,k) = (flx_arr[0])(i,j,k,0);
61  });
62  ParallelFor(ybx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
63  {
64  (flx_arr[1])(i,j,k,0) = ay_arr(i,j,k) * rho_v(i,j,k) / mf_vx(i,j,0);
65  avg_ymom(i,j,k) = (flx_arr[1])(i,j,k,0);
66  });
67  ParallelFor(zbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
68  {
69  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
70  (flx_arr[2])(i,j,k,0) = az_arr(i,j,k) * Omega(i,j,k) / mfsq;
71  avg_zmom(i,j,k) = (flx_arr[2])(i,j,k,0);
72  });
73 
74  if (fixed_rho) {
75  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
76  {
77  advectionSrc(i,j,k,0) = 0.0;
78  });
79  } else
80  {
81  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
82  {
83  if (detJ(i,j,k) > 0.) {
84  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
85  advectionSrc(i,j,k,0) = - mfsq / detJ(i,j,k) * (
86  ( (flx_arr[0])(i+1,j,k,0) - (flx_arr[0])(i ,j,k,0) ) * dxInv +
87  ( (flx_arr[1])(i,j+1,k,0) - (flx_arr[1])(i,j ,k,0) ) * dyInv +
88  ( (flx_arr[2])(i,j,k+1,0) - (flx_arr[2])(i,j,k ,0) ) * dzInv );
89  } else {
90  advectionSrc(i,j,k,0) = 0.;
91  }
92  });
93  }
94 }
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:30
const Box zbx
Definition: ERF_DiffSetup.H:23
const Box xbx
Definition: ERF_DiffSetup.H:21
const Box ybx
Definition: ERF_DiffSetup.H:22

◆ 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 the update equations for all scalars other than rho and (rho theta) 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 2.

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 mesh spacing
[in]mf_mmap 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)
139 {
140  BL_PROFILE_VAR("AdvectionSrcForScalars", AdvectionSrcForScalars);
141  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
142 
143  const Box xbx = surroundingNodes(bx,0);
144  const Box ybx = surroundingNodes(bx,1);
145  const Box zbx = surroundingNodes(bx,2);
146 
147  // Open bc will be imposed upon all vars (we only access cons here for simplicity)
148  const bool xlo_open = (bc_ptr_h[BCVars::cons_bc].lo(0) == ERFBCType::open);
149  const bool xhi_open = (bc_ptr_h[BCVars::cons_bc].hi(0) == ERFBCType::open);
150  const bool ylo_open = (bc_ptr_h[BCVars::cons_bc].lo(1) == ERFBCType::open);
151  const bool yhi_open = (bc_ptr_h[BCVars::cons_bc].hi(1) == ERFBCType::open);
152 
153  // Only advection operations in bndry normal direction with OPEN BC
154  Box bx_xlo, bx_xhi, bx_ylo, bx_yhi;
155  if (xlo_open) {
156  if ( bx.smallEnd(0) == domain.smallEnd(0)) { bx_xlo = makeSlab( bx,0,domain.smallEnd(0));}
157  }
158  if (xhi_open) {
159  if ( bx.bigEnd(0) == domain.bigEnd(0)) { bx_xhi = makeSlab( bx,0,domain.bigEnd(0) );}
160  }
161  if (ylo_open) {
162  if ( bx.smallEnd(1) == domain.smallEnd(1)) { bx_ylo = makeSlab( bx,1,domain.smallEnd(1));}
163  }
164  if (yhi_open) {
165  if ( bx.bigEnd(1) == domain.bigEnd(1)) { bx_yhi = makeSlab( bx,1,domain.bigEnd(1) );}
166  }
167 
168  for (int n(0); n<ncomp; ++n) {
169  const int cons_index = icomp + n;
170 
171  // Inline with 2nd order for efficiency
172  // NOTE: we don't need to weight avg_xmom, avg_ymom, avg_zmom with terrain metrics
173  // (or with EB area fractions)
174  // because that was done when they were constructed in AdvectionSrcForRhoAndTheta
175  if (horiz_adv_type == AdvType::Centered_2nd && vert_adv_type == AdvType::Centered_2nd)
176  {
177  ParallelFor(xbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
178  {
179  const int prim_index = cons_index - 1;
180  const Real prim_on_face = 0.5 * (cell_prim(i,j,k,prim_index) + cell_prim(i-1,j,k,prim_index));
181  (flx_arr[0])(i,j,k) = avg_xmom(i,j,k) * prim_on_face;
182  });
183  ParallelFor(ybx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
184  {
185  const int prim_index = cons_index - 1;
186  const Real prim_on_face = 0.5 * (cell_prim(i,j,k,prim_index) + cell_prim(i,j-1,k,prim_index));
187  (flx_arr[1])(i,j,k) = avg_ymom(i,j,k) * prim_on_face;
188  });
189  ParallelFor(zbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
190  {
191  const int prim_index = cons_index - 1;
192  const Real prim_on_face = 0.5 * (cell_prim(i,j,k,prim_index) + cell_prim(i,j,k-1,prim_index));
193  (flx_arr[2])(i,j,k) = avg_zmom(i,j,k) * prim_on_face;
194  });
195 
196  // Template higher order methods (horizontal first)
197  } else {
198  switch(horiz_adv_type) {
200  AdvectionSrcForScalarsVert<CENTERED2>(bx, cons_index, flx_arr, cell_prim,
201  avg_xmom, avg_ymom, avg_zmom,
202  horiz_upw_frac, vert_upw_frac, vert_adv_type);
203  break;
204  case AdvType::Upwind_3rd:
205  AdvectionSrcForScalarsVert<UPWIND3>(bx, cons_index, flx_arr, cell_prim,
206  avg_xmom, avg_ymom, avg_zmom,
207  horiz_upw_frac, vert_upw_frac, vert_adv_type);
208  break;
210  AdvectionSrcForScalarsVert<UPWIND3SL>(bx, cons_index, flx_arr, cell_prim,
211  avg_xmom, avg_ymom, avg_zmom,
212  horiz_upw_frac, vert_upw_frac, vert_adv_type);
213  break;
215  AdvectionSrcForScalarsVert<CENTERED4>(bx, cons_index, flx_arr, cell_prim,
216  avg_xmom, avg_ymom, avg_zmom,
217  horiz_upw_frac, vert_upw_frac, vert_adv_type);
218  break;
219  case AdvType::Upwind_5th:
220  AdvectionSrcForScalarsVert<UPWIND5>(bx, cons_index, flx_arr, cell_prim,
221  avg_xmom, avg_ymom, avg_zmom,
222  horiz_upw_frac, vert_upw_frac, vert_adv_type);
223  break;
225  AdvectionSrcForScalarsVert<CENTERED6>(bx, cons_index, flx_arr, cell_prim,
226  avg_xmom, avg_ymom, avg_zmom,
227  horiz_upw_frac, vert_upw_frac, vert_adv_type);
228  break;
229  case AdvType::Weno_3:
230  AdvectionSrcForScalarsWrapper<WENO3,WENO3>(bx, cons_index, flx_arr, cell_prim,
231  avg_xmom, avg_ymom, avg_zmom,
232  horiz_upw_frac, vert_upw_frac);
233  break;
234  case AdvType::Weno_5:
235  AdvectionSrcForScalarsWrapper<WENO5,WENO5>(bx, cons_index, flx_arr, cell_prim,
236  avg_xmom, avg_ymom, avg_zmom,
237  horiz_upw_frac, vert_upw_frac);
238  break;
239  case AdvType::Weno_7:
240  AdvectionSrcForScalarsWrapper<WENO7,WENO7>(bx, cons_index, flx_arr, cell_prim,
241  avg_xmom, avg_ymom, avg_zmom,
242  horiz_upw_frac, vert_upw_frac);
243  break;
244  case AdvType::Weno_3Z:
245  AdvectionSrcForScalarsWrapper<WENO_Z3,WENO_Z3>(bx, cons_index, flx_arr, cell_prim,
246  avg_xmom, avg_ymom, avg_zmom,
247  horiz_upw_frac, vert_upw_frac);
248  break;
249  case AdvType::Weno_3MZQ:
250  AdvectionSrcForScalarsWrapper<WENO_MZQ3,WENO_MZQ3>(bx, cons_index, flx_arr, cell_prim,
251  avg_xmom, avg_ymom, avg_zmom,
252  horiz_upw_frac, vert_upw_frac);
253  break;
254  case AdvType::Weno_5Z:
255  AdvectionSrcForScalarsWrapper<WENO_Z5,WENO_Z5>(bx, cons_index, flx_arr, cell_prim,
256  avg_xmom, avg_ymom, avg_zmom,
257  horiz_upw_frac, vert_upw_frac);
258  break;
259  case AdvType::Weno_7Z:
260  AdvectionSrcForScalarsWrapper<WENO_Z7,WENO_Z7>(bx, cons_index, flx_arr, cell_prim,
261  avg_xmom, avg_ymom, avg_zmom,
262  horiz_upw_frac, vert_upw_frac);
263  break;
264  default:
265  AMREX_ASSERT_WITH_MESSAGE(false, "Unknown advection scheme!");
266  }
267  }
268 
269  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
270  {
271  if (detJ(i,j,k) > 0.)
272  {
273  Real invdetJ = 1.0 / detJ(i,j,k);
274  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
275 
276  advectionSrc(i,j,k,cons_index) = - invdetJ * mfsq * (
277  ( (flx_arr[0])(i+1,j,k) - (flx_arr[0])(i,j,k) ) * dxInv +
278  ( (flx_arr[1])(i,j+1,k) - (flx_arr[1])(i,j,k) ) * dyInv +
279  ( (flx_arr[2])(i,j,k+1) - (flx_arr[2])(i,j,k) ) * dzInv );
280  } else {
281  advectionSrc(i,j,k) = 0.;
282  }
283  });
284 
285  // Special advection operator for open BC (bndry tangent operations)
286  if (xlo_open) {
287  bool do_lo = true;
288  AdvectionSrcForOpenBC_Tangent_Cons(bx_xlo, 0, icomp, ncomp, advectionSrc, cell_prim,
289  avg_xmom, avg_ymom, avg_zmom,
290  detJ, cellSizeInv, do_lo);
291  }
292  if (xhi_open) {
293  AdvectionSrcForOpenBC_Tangent_Cons(bx_xhi, 0, icomp, ncomp, advectionSrc, cell_prim,
294  avg_xmom, avg_ymom, avg_zmom,
295  detJ, cellSizeInv);
296  }
297  if (ylo_open) {
298  bool do_lo = true;
299  AdvectionSrcForOpenBC_Tangent_Cons(bx_ylo, 1, icomp, ncomp, advectionSrc, cell_prim,
300  avg_xmom, avg_ymom, avg_zmom,
301  detJ, cellSizeInv, do_lo);
302  }
303  if (yhi_open) {
304  AdvectionSrcForOpenBC_Tangent_Cons(bx_yhi, 1, icomp, ncomp, advectionSrc, cell_prim,
305  avg_xmom, avg_ymom, avg_zmom,
306  detJ, cellSizeInv);
307  }
308 
309  } // n
310 }
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:120
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)
@ Upwind_3rd_SL
@ Centered_4th
@ Centered_6th
@ Centered_2nd
@ cons_bc
Definition: ERF_IndexDefines.H:76
@ open
Definition: ERF_IndexDefines.H:215
Here is the call graph for this function: