ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 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]mf_mmap factor at cell centers
[in]mf_umap factor at x-faces
[in]mf_vmap 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
55 {
56  BL_PROFILE_VAR("AdvectionSrcForMom_StretchedDz", AdvectionSrcForMom_StretchedDz);
57 
58  AMREX_ALWAYS_ASSERT(bxz.smallEnd(2) > 0);
59 
60  auto dxInv = cellSizeInv[0]; auto dyInv = cellSizeInv[1];
61 
62  // compute mapfactor inverses
63  Box box2d_u(bxx); box2d_u.setRange(2,0); box2d_u.grow({3,3,0});
64  Box box2d_v(bxy); box2d_v.setRange(2,0); box2d_v.grow({3,3,0});
65 
66  FArrayBox mf_ux_invFAB(box2d_u,1,The_Async_Arena());
67  FArrayBox mf_uy_invFAB(box2d_u,1,The_Async_Arena());
68  const Array4<Real>& mf_ux_inv = mf_ux_invFAB.array();
69  const Array4<Real>& mf_uy_inv = mf_uy_invFAB.array();
70 
71  FArrayBox mf_vx_invFAB(box2d_v,1,The_Async_Arena());
72  FArrayBox mf_vy_invFAB(box2d_v,1,The_Async_Arena());
73  const Array4<Real>& mf_vx_inv = mf_vx_invFAB.array();
74  const Array4<Real>& mf_vy_inv = mf_vy_invFAB.array();
75 
76  ParallelFor(box2d_u, box2d_v,
77  [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
78  {
79  mf_ux_inv(i,j,0) = 1. / mf_ux(i,j,0);
80  mf_uy_inv(i,j,0) = 1. / mf_uy(i,j,0);
81  },
82  [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
83  {
84  mf_vx_inv(i,j,0) = 1. / mf_vx(i,j,0);
85  mf_vy_inv(i,j,0) = 1. / mf_vy(i,j,0);
86  });
87 
88  auto dz_ptr = stretched_dz_d.data();
89 
90  // Inline with 2nd order for efficiency
91  if (horiz_adv_type == AdvType::Centered_2nd && vert_adv_type == AdvType::Centered_2nd)
92  {
93  ParallelFor(bxx, bxy, bxz,
94  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
95  {
96  Real xflux_hi = 0.25 * (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));
97  Real xflux_lo = 0.25 * (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));
98 
99  Real yflux_hi = 0.25 * (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));
100  Real yflux_lo = 0.25 * (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));
101 
102  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));
103  Real zflux_lo = 0.25 * (omega(i, j, k ) + omega(i-1, j, k )) * (u(i,j,k-1) + u(i,j,k));
104 
105  Real mfsq = mf_ux(i,j,0) * mf_uy(i,j,0);
106 
107  Real dzInv = 1.0/dz_ptr[k];
108 
109  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
110  + (yflux_hi - yflux_lo) * dyInv * mfsq
111  + (zflux_hi - zflux_lo) * dzInv;
112  rho_u_rhs(i, j, k) = -advectionSrc;
113  },
114  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
115  {
116  Real xflux_hi = 0.25 * (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));
117  Real xflux_lo = 0.25 * (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));
118 
119  Real yflux_hi = 0.25 * (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));
120  Real yflux_lo = 0.25 * (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));
121 
122  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));
123  Real zflux_lo = 0.25 * (omega(i, j, k ) + omega(i, j-1, k )) * (v(i,j,k-1) + v(i,j,k));
124 
125  Real mfsq = mf_vx(i,j,0) * mf_vy(i,j,0);
126 
127  Real dzInv = 1.0/dz_ptr[k];
128 
129  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
130  + (yflux_hi - yflux_lo) * dyInv * mfsq
131  + (zflux_hi - zflux_lo) * dzInv;
132  rho_v_rhs(i, j, k) = -advectionSrc;
133  },
134  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
135  {
136  Real xflux_hi = 0.25*(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));
137  Real xflux_lo = 0.25*(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));
138 
139  Real yflux_hi = 0.25*(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));
140  Real yflux_lo = 0.25*(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));
141 
142  Real zflux_lo = 0.25 * (omega(i,j,k) + omega(i,j,k-1)) * (w(i,j,k) + w(i,j,k-1));
143 
144  Real zflux_hi = (k == hi_z_face) ? omega(i,j,k) * w(i,j,k) :
145  0.25 * (omega(i,j,k) + omega(i,j,k+1)) * (w(i,j,k) + w(i,j,k+1));
146 
147  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
148 
149  Real dzInv = 2.0 / (dz_ptr[k] + dz_ptr[k-1]);
150 
151  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
152  + (yflux_hi - yflux_lo) * dyInv * mfsq
153  + (zflux_hi - zflux_lo) * dzInv;
154  rho_w_rhs(i, j, k) = -advectionSrc;
155  });
156 
157  // Template higher order methods
158  } else {
159  if (horiz_adv_type == AdvType::Centered_2nd) {
160  AdvectionSrcForMomVert_N<CENTERED2>(bxx, bxy, bxz,
161  rho_u_rhs, rho_v_rhs, rho_w_rhs,
162  rho_u, rho_v, omega, u, v, w,
163  cellSizeInv, stretched_dz_d,
164  mf_mx, mf_ux_inv, mf_vx_inv,
165  mf_my, mf_uy_inv, mf_vy_inv,
166  horiz_upw_frac, vert_upw_frac,
167  vert_adv_type, lo_z_face, hi_z_face);
168  } else if (horiz_adv_type == AdvType::Upwind_3rd) {
169  AdvectionSrcForMomVert_N<UPWIND3>(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::Centered_4th) {
178  AdvectionSrcForMomVert_N<CENTERED4>(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::Upwind_5th) {
187  AdvectionSrcForMomVert_N<UPWIND5>(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::Centered_6th) {
196  AdvectionSrcForMomVert_N<CENTERED6>(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 {
205  AMREX_ASSERT_WITH_MESSAGE(false, "Unknown advection scheme!");
206  }
207  }
208 }
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:32
@ Centered_4th
@ Centered_6th
@ Centered_2nd
@ omega
Definition: ERF_Morrison.H:53