ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_AdvectionSrcForMom_ConstantDz.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_ConstantDz.cpp:

Functions

void AdvectionSrcForMom_ConstantDz (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 amrex::Gpu::DeviceVector< amrex::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, TerrainType &terrain_type, const int lo_z_face, const int hi_z_face)
 

Function Documentation

◆ AdvectionSrcForMom_ConstantDz()

void AdvectionSrcForMom_ConstantDz ( 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 amrex::Gpu::DeviceVector< amrex::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,
TerrainType &  terrain_type,
const int  lo_z_face,
const int  hi_z_face 
)

Function for computing the advective tendency for the momentum equations when using constant 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]terrain_typeterrain representation type
[in]lo_z_faceminimum z-face k-index at this level
[in]hi_z_facemaximum z-face k-index at this level
66 {
67  BL_PROFILE_VAR("AdvectionSrcForMom_ConstantDz", AdvectionSrcForMom_ConstantDz);
68 
69  AMREX_ALWAYS_ASSERT(bxz.smallEnd(2) > 0);
70 
71  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
72 
73  const bool use_terrain_fitted_coords = ( terrain_type == TerrainType::StaticFittedMesh ||
74  terrain_type == TerrainType::MovingFittedMesh);
75 
76  AMREX_ALWAYS_ASSERT(!use_terrain_fitted_coords && (terrain_type != TerrainType::EB));
77 
78  // compute mapfactor inverses
79  Box box2d_u(bxx); box2d_u.setRange(2,0); box2d_u.grow({3,3,0});
80  Box box2d_v(bxy); box2d_v.setRange(2,0); box2d_v.grow({3,3,0});
81 
82  FArrayBox mf_ux_invFAB(box2d_u,1,The_Async_Arena());
83  FArrayBox mf_uy_invFAB(box2d_u,1,The_Async_Arena());
84  const Array4<Real>& mf_ux_inv = mf_ux_invFAB.array();
85  const Array4<Real>& mf_uy_inv = mf_uy_invFAB.array();
86 
87  FArrayBox mf_vx_invFAB(box2d_v,1,The_Async_Arena());
88  FArrayBox mf_vy_invFAB(box2d_v,1,The_Async_Arena());
89  const Array4<Real>& mf_vx_inv = mf_vx_invFAB.array();
90  const Array4<Real>& mf_vy_inv = mf_vy_invFAB.array();
91 
92  ParallelFor(box2d_u, box2d_v,
93  [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
94  {
95  mf_ux_inv(i,j,0) = one / mf_ux(i,j,0);
96  mf_uy_inv(i,j,0) = one / mf_uy(i,j,0);
97  },
98  [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
99  {
100  mf_vx_inv(i,j,0) = one / mf_vx(i,j,0);
101  mf_vy_inv(i,j,0) = one / mf_vy(i,j,0);
102  });
103 
104  // Inline with 2nd order for efficiency
105  if (horiz_adv_type == AdvType::Centered_2nd && vert_adv_type == AdvType::Centered_2nd)
106  {
107  ParallelFor(bxx, bxy, bxz,
108  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
109  {
110  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));
111  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));
112 
113  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));
114  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));
115 
116  Real zflux_hi = fourth * (omega(i, j, k+1) + omega(i-1, j, k+1)) * (u(i,j,k+1) + u(i,j,k));
117  Real zflux_lo = fourth * (omega(i, j, k ) + omega(i-1, j, k )) * (u(i,j,k-1) + u(i,j,k));
118 
119  Real mfsq = mf_ux(i,j,0) * mf_uy(i,j,0);
120 
121  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
122  + (yflux_hi - yflux_lo) * dyInv * mfsq
123  + (zflux_hi - zflux_lo) * dzInv;
124  rho_u_rhs(i, j, k) = -advectionSrc;
125  },
126  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
127  {
128  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));
129  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));
130 
131  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));
132  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));
133 
134  Real zflux_hi = fourth * (omega(i, j, k+1) + omega(i, j-1, k+1)) * (v(i,j,k+1) + v(i,j,k));
135  Real zflux_lo = fourth * (omega(i, j, k ) + omega(i, j-1, k )) * (v(i,j,k-1) + v(i,j,k));
136 
137  Real mfsq = mf_vx(i,j,0) * mf_vy(i,j,0);
138 
139  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
140  + (yflux_hi - yflux_lo) * dyInv * mfsq
141  + (zflux_hi - zflux_lo) * dzInv;
142  rho_v_rhs(i, j, k) = -advectionSrc;
143  },
144  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
145  {
146  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));
147  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));
148 
149  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));
150  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));
151 
152  Real zflux_lo = fourth * (omega(i,j,k) + omega(i,j,k-1)) * (w(i,j,k) + w(i,j,k-1));
153 
154  Real zflux_hi = (k == hi_z_face) ? omega(i,j,k) * w(i,j,k) :
155  fourth * (omega(i,j,k) + omega(i,j,k+1)) * (w(i,j,k) + w(i,j,k+1));
156 
157  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
158 
159  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
160  + (yflux_hi - yflux_lo) * dyInv * mfsq
161  + (zflux_hi - zflux_lo) * dzInv;
162  rho_w_rhs(i, j, k) = -advectionSrc;
163  });
164 
165  // Template higher order methods
166  } else {
167  if (horiz_adv_type == AdvType::Centered_2nd) {
168  AdvectionSrcForMomVert_N<CENTERED2>(bxx, bxy, bxz,
169  rho_u_rhs, rho_v_rhs, rho_w_rhs,
170  rho_u, rho_v, omega, u, v, w,
171  cellSizeInv, stretched_dz_d,
172  mf_mx, mf_ux_inv, mf_vx_inv,
173  mf_my, mf_uy_inv, mf_vy_inv,
174  horiz_upw_frac, vert_upw_frac,
175  vert_adv_type, lo_z_face, hi_z_face);
176  } else if (horiz_adv_type == AdvType::Upwind_3rd) {
177  AdvectionSrcForMomVert_N<UPWIND3>(bxx, bxy, bxz,
178  rho_u_rhs, rho_v_rhs, rho_w_rhs,
179  rho_u, rho_v, omega, u, v, w,
180  cellSizeInv, stretched_dz_d,
181  mf_mx, mf_ux_inv, mf_vx_inv,
182  mf_my, mf_uy_inv, mf_vy_inv,
183  horiz_upw_frac, vert_upw_frac,
184  vert_adv_type, lo_z_face, hi_z_face);
185  } else if (horiz_adv_type == AdvType::Centered_4th) {
186  AdvectionSrcForMomVert_N<CENTERED4>(bxx, bxy, bxz,
187  rho_u_rhs, rho_v_rhs, rho_w_rhs,
188  rho_u, rho_v, omega, u, v, w,
189  cellSizeInv, stretched_dz_d,
190  mf_mx, mf_ux_inv, mf_vx_inv,
191  mf_my, mf_uy_inv, mf_vy_inv,
192  horiz_upw_frac, vert_upw_frac,
193  vert_adv_type, lo_z_face, hi_z_face);
194  } else if (horiz_adv_type == AdvType::Upwind_5th) {
195  AdvectionSrcForMomVert_N<UPWIND5>(bxx, bxy, bxz,
196  rho_u_rhs, rho_v_rhs, rho_w_rhs,
197  rho_u, rho_v, omega, u, v, w,
198  cellSizeInv, stretched_dz_d,
199  mf_mx, mf_ux_inv, mf_vx_inv,
200  mf_my, mf_uy_inv, mf_vy_inv,
201  horiz_upw_frac, vert_upw_frac,
202  vert_adv_type, lo_z_face, hi_z_face);
203  } else if (horiz_adv_type == AdvType::Centered_6th) {
204  AdvectionSrcForMomVert_N<CENTERED6>(bxx, bxy, bxz,
205  rho_u_rhs, rho_v_rhs, rho_w_rhs,
206  rho_u, rho_v, omega, u, v, w,
207  cellSizeInv, stretched_dz_d,
208  mf_mx, mf_ux_inv, mf_vx_inv,
209  mf_my, mf_uy_inv, mf_vy_inv,
210  horiz_upw_frac, vert_upw_frac,
211  vert_adv_type, lo_z_face, hi_z_face);
212  } else if (horiz_adv_type == AdvType::Weno_3) {
213  AdvectionSrcForMomVert_N<WENO3>(bxx, bxy, bxz,
214  rho_u_rhs, rho_v_rhs, rho_w_rhs,
215  rho_u, rho_v, omega, u, v, w,
216  cellSizeInv, stretched_dz_d,
217  mf_mx, mf_ux_inv, mf_vx_inv,
218  mf_my, mf_uy_inv, mf_vy_inv,
219  horiz_upw_frac, vert_upw_frac,
220  vert_adv_type, lo_z_face, hi_z_face);
221  } else if (horiz_adv_type == AdvType::Weno_3Z) {
222  AdvectionSrcForMomVert_N<WENO_Z3>(bxx, bxy, bxz,
223  rho_u_rhs, rho_v_rhs, rho_w_rhs,
224  rho_u, rho_v, omega, u, v, w,
225  cellSizeInv, stretched_dz_d,
226  mf_mx, mf_ux_inv, mf_vx_inv,
227  mf_my, mf_uy_inv, mf_vy_inv,
228  horiz_upw_frac, vert_upw_frac,
229  vert_adv_type, lo_z_face, hi_z_face);
230  } else if (horiz_adv_type == AdvType::Weno_3MZQ) {
231  AdvectionSrcForMomVert_N<WENO_MZQ3>(bxx, bxy, bxz,
232  rho_u_rhs, rho_v_rhs, rho_w_rhs,
233  rho_u, rho_v, omega, u, v, w,
234  cellSizeInv, stretched_dz_d,
235  mf_mx, mf_ux_inv, mf_vx_inv,
236  mf_my, mf_uy_inv, mf_vy_inv,
237  horiz_upw_frac, vert_upw_frac,
238  vert_adv_type, lo_z_face, hi_z_face);
239  } else if (horiz_adv_type == AdvType::Weno_5) {
240  AdvectionSrcForMomVert_N<WENO5>(bxx, bxy, bxz,
241  rho_u_rhs, rho_v_rhs, rho_w_rhs,
242  rho_u, rho_v, omega, u, v, w,
243  cellSizeInv, stretched_dz_d,
244  mf_mx, mf_ux_inv, mf_vx_inv,
245  mf_my, mf_uy_inv, mf_vy_inv,
246  horiz_upw_frac, vert_upw_frac,
247  vert_adv_type, lo_z_face, hi_z_face);
248  } else if (horiz_adv_type == AdvType::Weno_5Z) {
249  AdvectionSrcForMomVert_N<WENO_Z5>(bxx, bxy, bxz,
250  rho_u_rhs, rho_v_rhs, rho_w_rhs,
251  rho_u, rho_v, omega, u, v, w,
252  cellSizeInv, stretched_dz_d,
253  mf_mx, mf_ux_inv, mf_vx_inv,
254  mf_my, mf_uy_inv, mf_vy_inv,
255  horiz_upw_frac, vert_upw_frac,
256  vert_adv_type, lo_z_face, hi_z_face);
257  } else if (horiz_adv_type == AdvType::Weno_7) {
258  AdvectionSrcForMomVert_N<WENO7>(bxx, bxy, bxz,
259  rho_u_rhs, rho_v_rhs, rho_w_rhs,
260  rho_u, rho_v, omega, u, v, w,
261  cellSizeInv, stretched_dz_d,
262  mf_mx, mf_ux_inv, mf_vx_inv,
263  mf_my, mf_uy_inv, mf_vy_inv,
264  horiz_upw_frac, vert_upw_frac,
265  vert_adv_type, lo_z_face, hi_z_face);
266  } else if (horiz_adv_type == AdvType::Weno_7Z) {
267  AdvectionSrcForMomVert_N<WENO_Z7>(bxx, bxy, bxz,
268  rho_u_rhs, rho_v_rhs, rho_w_rhs,
269  rho_u, rho_v, omega, u, v, w,
270  cellSizeInv, stretched_dz_d,
271  mf_mx, mf_ux_inv, mf_vx_inv,
272  mf_my, mf_uy_inv, mf_vy_inv,
273  horiz_upw_frac, vert_upw_frac,
274  vert_adv_type, lo_z_face, hi_z_face);
275  } else {
276  AMREX_ASSERT_WITH_MESSAGE(false, "Unknown advection scheme!");
277  }
278  }
279 }
void AdvectionSrcForMom_ConstantDz(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 amrex::Gpu::DeviceVector< amrex::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, TerrainType &terrain_type, const int lo_z_face, const int hi_z_face)
Definition: ERF_AdvectionSrcForMom_ConstantDz.cpp:42
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: