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

Functions

void AdvectionSrcForMom_StretchedDz (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 > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &rho_u, const Array4< const Real > &rho_v, const Array4< const Real > &omega, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, const Gpu::DeviceVector< Real > &stretched_dz_d, const Array4< const Real > &mf_mx, const Array4< const Real > &mf_ux, const Array4< const Real > &mf_vx, const Array4< const Real > &mf_my, const Array4< const Real > &mf_uy, const Array4< const Real > &mf_vy, const AdvType horiz_adv_type, const AdvType vert_adv_type, const Real horiz_upw_frac, const Real vert_upw_frac, const int lo_z_face, const int hi_z_face)
 

Function Documentation

◆ AdvectionSrcForMom_StretchedDz()

void AdvectionSrcForMom_StretchedDz ( 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 > &  u,
const Array4< const Real > &  v,
const Array4< const Real > &  w,
const Array4< const Real > &  rho_u,
const Array4< const Real > &  rho_v,
const Array4< const Real > &  omega,
const GpuArray< Real, AMREX_SPACEDIM > &  cellSizeInv,
const Gpu::DeviceVector< Real > &  stretched_dz_d,
const Array4< const Real > &  mf_mx,
const Array4< const Real > &  mf_ux,
const Array4< const Real > &  mf_vx,
const Array4< const Real > &  mf_my,
const Array4< const Real > &  mf_uy,
const Array4< const Real > &  mf_vy,
const AdvType  horiz_adv_type,
const AdvType  vert_adv_type,
const Real  horiz_upw_frac,
const Real  vert_upw_frac,
const int  lo_z_face,
const int  hi_z_face 
)

Function for computing the advective tendency for the momentum equations when using stretched dz with no EB and no terrain-fitted coordinates.

Parameters
[in]bxxbox over which the x-momentum is updated
[in]bxybox over which the y-momentum is updated
[in]bxzbox over which the z-momentum is updated
[out]rho_u_rhstendency for the x-momentum equation
[out]rho_v_rhstendency for the y-momentum equation
[out]rho_w_rhstendency for the z-momentum equation
[in]ux-component of the velocity
[in]vy-component of the velocity
[in]wz-component of the velocity
[in]rho_ux-component of the momentum
[in]rho_vy-component of the momentum
[in]omegacomponent of the momentum normal to the z-coordinate surface
[in]cellSizeInvinverse of the grid spacing
[in]stretched_dz_ddevice vector of vertical cell spacing
[in]mf_mxx map factor at cell centers
[in]mf_uxx map factor at x-faces
[in]mf_vxx map factor at y-faces
[in]mf_myy map factor at cell centers
[in]mf_uyy map factor at x-faces
[in]mf_vyy map factor at y-faces
[in]horiz_adv_typesets the spatial order to be used for lateral derivatives
[in]vert_adv_typesets the spatial order to be used for vertical derivatives
[in]horiz_upw_frachorizontal upwind blending fraction
[in]vert_upw_fracvertical upwind blending fraction
[in]lo_z_faceminimum z-face k-index at this level
[in]hi_z_facemaximum z-face k-index at this level
64 {
65  BL_PROFILE_VAR("AdvectionSrcForMom_StretchedDz", AdvectionSrcForMom_StretchedDz);
66 
67  AMREX_ALWAYS_ASSERT(bxz.smallEnd(2) > 0);
68 
69  auto dxInv = cellSizeInv[0]; auto dyInv = cellSizeInv[1];
70 
71  // compute mapfactor inverses
72  Box box2d_u(bxx); box2d_u.setRange(2,0); box2d_u.grow({3,3,0});
73  Box box2d_v(bxy); box2d_v.setRange(2,0); box2d_v.grow({3,3,0});
74 
75  FArrayBox mf_ux_invFAB(box2d_u,1,The_Async_Arena());
76  FArrayBox mf_uy_invFAB(box2d_u,1,The_Async_Arena());
77  const Array4<Real>& mf_ux_inv = mf_ux_invFAB.array();
78  const Array4<Real>& mf_uy_inv = mf_uy_invFAB.array();
79 
80  FArrayBox mf_vx_invFAB(box2d_v,1,The_Async_Arena());
81  FArrayBox mf_vy_invFAB(box2d_v,1,The_Async_Arena());
82  const Array4<Real>& mf_vx_inv = mf_vx_invFAB.array();
83  const Array4<Real>& mf_vy_inv = mf_vy_invFAB.array();
84 
85  ParallelFor(box2d_u, box2d_v,
86  [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
87  {
88  mf_ux_inv(i,j,0) = one / mf_ux(i,j,0);
89  mf_uy_inv(i,j,0) = one / mf_uy(i,j,0);
90  },
91  [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
92  {
93  mf_vx_inv(i,j,0) = one / mf_vx(i,j,0);
94  mf_vy_inv(i,j,0) = one / mf_vy(i,j,0);
95  });
96 
97  auto dz_ptr = stretched_dz_d.data();
98 
99  // Inline with 2nd order for efficiency
100  if (horiz_adv_type == AdvType::Centered_2nd && vert_adv_type == AdvType::Centered_2nd)
101  {
102  ParallelFor(bxx, bxy, bxz,
103  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
104  {
105  Real xflux_hi = fourth * (rho_u(i, j , k) * mf_uy_inv(i,j,0) + rho_u(i+1, j , k) * mf_uy_inv(i+1,j,0)) * (u(i+1,j,k) + u(i,j,k));
106  Real xflux_lo = fourth * (rho_u(i, j , k) * mf_uy_inv(i,j,0) + rho_u(i-1, j , k) * mf_uy_inv(i-1,j,0)) * (u(i-1,j,k) + u(i,j,k));
107 
108  Real yflux_hi = fourth * (rho_v(i, j+1, k) * mf_vx_inv(i,j+1,0) + rho_v(i-1, j+1, k) * mf_vx_inv(i-1,j+1,0)) * (u(i,j+1,k) + u(i,j,k));
109  Real yflux_lo = fourth * (rho_v(i, j , k) * mf_vx_inv(i,j ,0) + rho_v(i-1, j , k) * mf_vx_inv(i-1,j ,0)) * (u(i,j-1,k) + u(i,j,k));
110 
111  Real zflux_hi = fourth * (omega(i, j, k+1) + omega(i-1, j, k+1)) * (u(i,j,k+1) + u(i,j,k));
112  Real zflux_lo = fourth * (omega(i, j, k ) + omega(i-1, j, k )) * (u(i,j,k-1) + u(i,j,k));
113 
114  Real mfsq = mf_ux(i,j,0) * mf_uy(i,j,0);
115 
116  Real dzInv = one/dz_ptr[k];
117 
118  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
119  + (yflux_hi - yflux_lo) * dyInv * mfsq
120  + (zflux_hi - zflux_lo) * dzInv;
121  rho_u_rhs(i, j, k) = -advectionSrc;
122  },
123  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
124  {
125  Real xflux_hi = fourth * (rho_u(i+1, j, k) * mf_uy_inv(i+1,j,0) + rho_u(i+1, j-1, k) * mf_uy_inv(i+1,j-1,0)) * (v(i+1,j,k) + v(i,j,k));
126  Real xflux_lo = fourth * (rho_u(i , j, k) * mf_uy_inv(i ,j,0) + rho_u(i , j-1, k) * mf_uy_inv(i ,j-1,0)) * (v(i-1,j,k) + v(i,j,k));
127 
128  Real yflux_hi = fourth * (rho_v(i ,j+1,k) * mf_vx_inv(i,j+1,0) + rho_v(i ,j ,k) * mf_vx_inv(i,j ,0)) * (v(i,j+1,k) + v(i,j,k));
129  Real yflux_lo = fourth * (rho_v(i ,j ,k) * mf_vx_inv(i,j ,0) + rho_v(i ,j-1,k) * mf_vx_inv(i,j-1,0)) * (v(i,j-1,k) + v(i,j,k));
130 
131  Real zflux_hi = fourth * (omega(i, j, k+1) + omega(i, j-1, k+1)) * (v(i,j,k+1) + v(i,j,k));
132  Real zflux_lo = fourth * (omega(i, j, k ) + omega(i, j-1, k )) * (v(i,j,k-1) + v(i,j,k));
133 
134  Real mfsq = mf_vx(i,j,0) * mf_vy(i,j,0);
135 
136  Real dzInv = one/dz_ptr[k];
137 
138  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
139  + (yflux_hi - yflux_lo) * dyInv * mfsq
140  + (zflux_hi - zflux_lo) * dzInv;
141  rho_v_rhs(i, j, k) = -advectionSrc;
142  },
143  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
144  {
145  Real xflux_hi = fourth*(rho_u(i+1,j ,k) + rho_u(i+1, j, k-1)) * mf_uy_inv(i+1,j ,0) * (w(i+1,j,k) + w(i,j,k));
146  Real xflux_lo = fourth*(rho_u(i ,j ,k) + rho_u(i , j, k-1)) * mf_uy_inv(i ,j ,0) * (w(i-1,j,k) + w(i,j,k));
147 
148  Real yflux_hi = fourth*(rho_v(i ,j+1,k) + rho_v(i, j+1, k-1)) * mf_vx_inv(i ,j+1,0) * (w(i,j+1,k) + w(i,j,k));
149  Real yflux_lo = fourth*(rho_v(i ,j ,k) + rho_v(i, j , k-1)) * mf_vx_inv(i ,j ,0) * (w(i,j-1,k) + w(i,j,k));
150 
151  Real zflux_lo = fourth * (omega(i,j,k) + omega(i,j,k-1)) * (w(i,j,k) + w(i,j,k-1));
152 
153  Real zflux_hi = (k == hi_z_face) ? omega(i,j,k) * w(i,j,k) :
154  fourth * (omega(i,j,k) + omega(i,j,k+1)) * (w(i,j,k) + w(i,j,k+1));
155 
156  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
157 
158  Real dzInv = (k == 0) ? one / dz_ptr[k] : two/(dz_ptr[k] + dz_ptr[k-1]);
159 
160  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
161  + (yflux_hi - yflux_lo) * dyInv * mfsq
162  + (zflux_hi - zflux_lo) * dzInv;
163  rho_w_rhs(i, j, k) = -advectionSrc;
164  });
165 
166  // Template higher order methods
167  } else {
168  if (horiz_adv_type == AdvType::Centered_2nd) {
169  AdvectionSrcForMomVert_N<CENTERED2>(bxx, bxy, bxz,
170  rho_u_rhs, rho_v_rhs, rho_w_rhs,
171  rho_u, rho_v, omega, u, v, w,
172  cellSizeInv, stretched_dz_d,
173  mf_mx, mf_ux_inv, mf_vx_inv,
174  mf_my, mf_uy_inv, mf_vy_inv,
175  horiz_upw_frac, vert_upw_frac,
176  vert_adv_type, lo_z_face, hi_z_face);
177  } else if (horiz_adv_type == AdvType::Upwind_3rd) {
178  AdvectionSrcForMomVert_N<UPWIND3>(bxx, bxy, bxz,
179  rho_u_rhs, rho_v_rhs, rho_w_rhs,
180  rho_u, rho_v, omega, u, v, w,
181  cellSizeInv, stretched_dz_d,
182  mf_mx, mf_ux_inv, mf_vx_inv,
183  mf_my, mf_uy_inv, mf_vy_inv,
184  horiz_upw_frac, vert_upw_frac,
185  vert_adv_type, lo_z_face, hi_z_face);
186  } else if (horiz_adv_type == AdvType::Centered_4th) {
187  AdvectionSrcForMomVert_N<CENTERED4>(bxx, bxy, bxz,
188  rho_u_rhs, rho_v_rhs, rho_w_rhs,
189  rho_u, rho_v, omega, u, v, w,
190  cellSizeInv, stretched_dz_d,
191  mf_mx, mf_ux_inv, mf_vx_inv,
192  mf_my, mf_uy_inv, mf_vy_inv,
193  horiz_upw_frac, vert_upw_frac,
194  vert_adv_type, lo_z_face, hi_z_face);
195  } else if (horiz_adv_type == AdvType::Upwind_5th) {
196  AdvectionSrcForMomVert_N<UPWIND5>(bxx, bxy, bxz,
197  rho_u_rhs, rho_v_rhs, rho_w_rhs,
198  rho_u, rho_v, omega, u, v, w,
199  cellSizeInv, stretched_dz_d,
200  mf_mx, mf_ux_inv, mf_vx_inv,
201  mf_my, mf_uy_inv, mf_vy_inv,
202  horiz_upw_frac, vert_upw_frac,
203  vert_adv_type, lo_z_face, hi_z_face);
204  } else if (horiz_adv_type == AdvType::Centered_6th) {
205  AdvectionSrcForMomVert_N<CENTERED6>(bxx, bxy, bxz,
206  rho_u_rhs, rho_v_rhs, rho_w_rhs,
207  rho_u, rho_v, omega, u, v, w,
208  cellSizeInv, stretched_dz_d,
209  mf_mx, mf_ux_inv, mf_vx_inv,
210  mf_my, mf_uy_inv, mf_vy_inv,
211  horiz_upw_frac, vert_upw_frac,
212  vert_adv_type, lo_z_face, hi_z_face);
213  } else if (horiz_adv_type == AdvType::Weno_3) {
214  AdvectionSrcForMomVert_N<WENO3>(bxx, bxy, bxz,
215  rho_u_rhs, rho_v_rhs, rho_w_rhs,
216  rho_u, rho_v, omega, u, v, w,
217  cellSizeInv, stretched_dz_d,
218  mf_mx, mf_ux_inv, mf_vx_inv,
219  mf_my, mf_uy_inv, mf_vy_inv,
220  horiz_upw_frac, vert_upw_frac,
221  vert_adv_type, lo_z_face, hi_z_face);
222  } else if (horiz_adv_type == AdvType::Weno_3Z) {
223  AdvectionSrcForMomVert_N<WENO_Z3>(bxx, bxy, bxz,
224  rho_u_rhs, rho_v_rhs, rho_w_rhs,
225  rho_u, rho_v, omega, u, v, w,
226  cellSizeInv, stretched_dz_d,
227  mf_mx, mf_ux_inv, mf_vx_inv,
228  mf_my, mf_uy_inv, mf_vy_inv,
229  horiz_upw_frac, vert_upw_frac,
230  vert_adv_type, lo_z_face, hi_z_face);
231  } else if (horiz_adv_type == AdvType::Weno_3MZQ) {
232  AdvectionSrcForMomVert_N<WENO_MZQ3>(bxx, bxy, bxz,
233  rho_u_rhs, rho_v_rhs, rho_w_rhs,
234  rho_u, rho_v, omega, u, v, w,
235  cellSizeInv, stretched_dz_d,
236  mf_mx, mf_ux_inv, mf_vx_inv,
237  mf_my, mf_uy_inv, mf_vy_inv,
238  horiz_upw_frac, vert_upw_frac,
239  vert_adv_type, lo_z_face, hi_z_face);
240  } else if (horiz_adv_type == AdvType::Weno_5) {
241  AdvectionSrcForMomVert_N<WENO5>(bxx, bxy, bxz,
242  rho_u_rhs, rho_v_rhs, rho_w_rhs,
243  rho_u, rho_v, omega, u, v, w,
244  cellSizeInv, stretched_dz_d,
245  mf_mx, mf_ux_inv, mf_vx_inv,
246  mf_my, mf_uy_inv, mf_vy_inv,
247  horiz_upw_frac, vert_upw_frac,
248  vert_adv_type, lo_z_face, hi_z_face);
249  } else if (horiz_adv_type == AdvType::Weno_5Z) {
250  AdvectionSrcForMomVert_N<WENO_Z5>(bxx, bxy, bxz,
251  rho_u_rhs, rho_v_rhs, rho_w_rhs,
252  rho_u, rho_v, omega, u, v, w,
253  cellSizeInv, stretched_dz_d,
254  mf_mx, mf_ux_inv, mf_vx_inv,
255  mf_my, mf_uy_inv, mf_vy_inv,
256  horiz_upw_frac, vert_upw_frac,
257  vert_adv_type, lo_z_face, hi_z_face);
258  } else if (horiz_adv_type == AdvType::Weno_7) {
259  AdvectionSrcForMomVert_N<WENO7>(bxx, bxy, bxz,
260  rho_u_rhs, rho_v_rhs, rho_w_rhs,
261  rho_u, rho_v, omega, u, v, w,
262  cellSizeInv, stretched_dz_d,
263  mf_mx, mf_ux_inv, mf_vx_inv,
264  mf_my, mf_uy_inv, mf_vy_inv,
265  horiz_upw_frac, vert_upw_frac,
266  vert_adv_type, lo_z_face, hi_z_face);
267  } else if (horiz_adv_type == AdvType::Weno_7Z) {
268  AdvectionSrcForMomVert_N<WENO_Z7>(bxx, bxy, bxz,
269  rho_u_rhs, rho_v_rhs, rho_w_rhs,
270  rho_u, rho_v, omega, u, v, w,
271  cellSizeInv, stretched_dz_d,
272  mf_mx, mf_ux_inv, mf_vx_inv,
273  mf_my, mf_uy_inv, mf_vy_inv,
274  horiz_upw_frac, vert_upw_frac,
275  vert_adv_type, lo_z_face, hi_z_face);
276  } else {
277  AMREX_ASSERT_WITH_MESSAGE(false, "Unknown advection scheme!");
278  }
279  }
280 }
void AdvectionSrcForMom_StretchedDz(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 > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &rho_u, const Array4< const Real > &rho_v, const Array4< const Real > &omega, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, const Gpu::DeviceVector< Real > &stretched_dz_d, const Array4< const Real > &mf_mx, const Array4< const Real > &mf_ux, const Array4< const Real > &mf_vx, const Array4< const Real > &mf_my, const Array4< const Real > &mf_uy, const Array4< const Real > &mf_vy, const AdvType horiz_adv_type, const AdvType vert_adv_type, const Real horiz_upw_frac, const Real vert_upw_frac, const int lo_z_face, const int hi_z_face)
Definition: ERF_AdvectionSrcForMom_StretchedDz.cpp:41
constexpr amrex::Real two
Definition: ERF_Constants.H:10
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real fourth
Definition: ERF_Constants.H:14
@ Centered_4th
@ Centered_6th
@ Centered_2nd
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:17
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
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);})
Real w
Definition: ERF_Plotfile2DInterpolator.cpp:22
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_ASSERT_WITH_MESSAGE(wbar_cutoff_min > wbar_cutoff_max, "ERROR: wbar_cutoff_min < wbar_cutoff_max")
@ omega
Definition: ERF_Morrison.H:54
Here is the call graph for this function: