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_m, const Array4< const Real > &mf_u, const Array4< const Real > &mf_v, 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_m,
const Array4< const Real > &  mf_u,
const Array4< const Real > &  mf_v,
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
52 {
53  BL_PROFILE_VAR("AdvectionSrcForMom_StretchedDz", AdvectionSrcForMom_StretchedDz);
54 
55  AMREX_ALWAYS_ASSERT(bxz.smallEnd(2) > 0);
56 
57  auto dxInv = cellSizeInv[0]; auto dyInv = cellSizeInv[1];
58 
59  // compute mapfactor inverses
60  Box box2d_u(bxx); box2d_u.setRange(2,0); box2d_u.grow({3,3,0});
61  Box box2d_v(bxy); box2d_v.setRange(2,0); box2d_v.grow({3,3,0});
62  FArrayBox mf_u_invFAB(box2d_u,1,The_Async_Arena());
63  FArrayBox mf_v_invFAB(box2d_v,1,The_Async_Arena());
64  const Array4<Real>& mf_u_inv = mf_u_invFAB.array();
65  const Array4<Real>& mf_v_inv = mf_v_invFAB.array();
66 
67  ParallelFor(box2d_u, box2d_v,
68  [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
69  {
70  mf_u_inv(i,j,0) = 1. / mf_u(i,j,0);
71  },
72  [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
73  {
74  mf_v_inv(i,j,0) = 1. / mf_v(i,j,0);
75  });
76 
77  auto dz_ptr = stretched_dz_d.data();
78 
79  // Inline with 2nd order for efficiency
80  if (horiz_adv_type == AdvType::Centered_2nd && vert_adv_type == AdvType::Centered_2nd)
81  {
82  ParallelFor(bxx, bxy, bxz,
83  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
84  {
85  Real xflux_hi = 0.25 * (rho_u(i, j , k) * mf_u_inv(i,j,0) + rho_u(i+1, j , k) * mf_u_inv(i+1,j,0)) * (u(i+1,j,k) + u(i,j,k));
86  Real xflux_lo = 0.25 * (rho_u(i, j , k) * mf_u_inv(i,j,0) + rho_u(i-1, j , k) * mf_u_inv(i-1,j,0)) * (u(i-1,j,k) + u(i,j,k));
87 
88  Real yflux_hi = 0.25 * (rho_v(i, j+1, k) * mf_v_inv(i,j+1,0) + rho_v(i-1, j+1, k) * mf_v_inv(i-1,j+1,0)) * (u(i,j+1,k) + u(i,j,k));
89  Real yflux_lo = 0.25 * (rho_v(i, j , k) * mf_v_inv(i,j ,0) + rho_v(i-1, j , k) * mf_v_inv(i-1,j ,0)) * (u(i,j-1,k) + u(i,j,k));
90 
91  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));
92  Real zflux_lo = 0.25 * (omega(i, j, k ) + omega(i-1, j, k )) * (u(i,j,k-1) + u(i,j,k));
93 
94  Real mfsq = mf_u(i,j,0) * mf_u(i,j,0);
95 
96  Real dzInv = 1.0/dz_ptr[k];
97 
98  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
99  + (yflux_hi - yflux_lo) * dyInv * mfsq
100  + (zflux_hi - zflux_lo) * dzInv;
101  rho_u_rhs(i, j, k) = -advectionSrc;
102  },
103  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
104  {
105  Real xflux_hi = 0.25 * (rho_u(i+1, j, k) * mf_u_inv(i+1,j,0) + rho_u(i+1, j-1, k) * mf_u_inv(i+1,j-1,0)) * (v(i+1,j,k) + v(i,j,k));
106  Real xflux_lo = 0.25 * (rho_u(i , j, k) * mf_u_inv(i ,j,0) + rho_u(i , j-1, k) * mf_u_inv(i ,j-1,0)) * (v(i-1,j,k) + v(i,j,k));
107 
108  Real yflux_hi = 0.25 * (rho_v(i ,j+1,k) * mf_v_inv(i,j+1,0) + rho_v(i ,j ,k) * mf_v_inv(i,j ,0)) * (v(i,j+1,k) + v(i,j,k));
109  Real yflux_lo = 0.25 * (rho_v(i ,j ,k) * mf_v_inv(i,j ,0) + rho_v(i ,j-1,k) * mf_v_inv(i,j-1,0) ) * (v(i,j-1,k) + v(i,j,k));
110 
111  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));
112  Real zflux_lo = 0.25 * (omega(i, j, k ) + omega(i, j-1, k )) * (v(i,j,k-1) + v(i,j,k));
113 
114  Real mfsq = mf_v(i,j,0) * mf_v(i,j,0);
115 
116  Real dzInv = 1.0/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_v_rhs(i, j, k) = -advectionSrc;
122  },
123  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
124  {
125  Real xflux_hi = 0.25*(rho_u(i+1,j ,k) + rho_u(i+1, j, k-1)) * mf_u_inv(i+1,j ,0) * (w(i+1,j,k) + w(i,j,k));
126  Real xflux_lo = 0.25*(rho_u(i ,j ,k) + rho_u(i , j, k-1)) * mf_u_inv(i ,j ,0) * (w(i-1,j,k) + w(i,j,k));
127 
128  Real yflux_hi = 0.25*(rho_v(i ,j+1,k) + rho_v(i, j+1, k-1)) * mf_v_inv(i ,j+1,0) * (w(i,j+1,k) + w(i,j,k));
129  Real yflux_lo = 0.25*(rho_v(i ,j ,k) + rho_v(i, j , k-1)) * mf_v_inv(i ,j ,0) * (w(i,j-1,k) + w(i,j,k));
130 
131  Real zflux_lo = 0.25 * (omega(i,j,k) + omega(i,j,k-1)) * (w(i,j,k) + w(i,j,k-1));
132 
133  Real zflux_hi = (k == hi_z_face) ? omega(i,j,k) * w(i,j,k) :
134  0.25 * (omega(i,j,k) + omega(i,j,k+1)) * (w(i,j,k) + w(i,j,k+1));
135 
136  Real mfsq = mf_m(i,j,0) * mf_m(i,j,0);
137 
138  Real dzInv = 2.0 / (dz_ptr[k] + dz_ptr[k-1]);
139 
140  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
141  + (yflux_hi - yflux_lo) * dyInv * mfsq
142  + (zflux_hi - zflux_lo) * dzInv;
143  rho_w_rhs(i, j, k) = -advectionSrc;
144  });
145 
146  // Template higher order methods
147  } else {
148  if (horiz_adv_type == AdvType::Centered_2nd) {
149  AdvectionSrcForMomVert_N<CENTERED2>(bxx, bxy, bxz,
150  rho_u_rhs, rho_v_rhs, rho_w_rhs,
151  rho_u, rho_v, omega, u, v, w,
152  cellSizeInv, stretched_dz_d, mf_m,
153  mf_u_inv, mf_v_inv,
154  horiz_upw_frac, vert_upw_frac,
155  vert_adv_type, lo_z_face, hi_z_face);
156  } else if (horiz_adv_type == AdvType::Upwind_3rd) {
157  AdvectionSrcForMomVert_N<UPWIND3>(bxx, bxy, bxz,
158  rho_u_rhs, rho_v_rhs, rho_w_rhs,
159  rho_u, rho_v, omega, u, v, w,
160  cellSizeInv, stretched_dz_d, mf_m,
161  mf_u_inv, mf_v_inv,
162  horiz_upw_frac, vert_upw_frac,
163  vert_adv_type, lo_z_face, hi_z_face);
164  } else if (horiz_adv_type == AdvType::Centered_4th) {
165  AdvectionSrcForMomVert_N<CENTERED4>(bxx, bxy, bxz,
166  rho_u_rhs, rho_v_rhs, rho_w_rhs,
167  rho_u, rho_v, omega, u, v, w,
168  cellSizeInv, stretched_dz_d, mf_m,
169  mf_u_inv, mf_v_inv,
170  horiz_upw_frac, vert_upw_frac,
171  vert_adv_type, lo_z_face, hi_z_face);
172  } else if (horiz_adv_type == AdvType::Upwind_5th) {
173  AdvectionSrcForMomVert_N<UPWIND5>(bxx, bxy, bxz,
174  rho_u_rhs, rho_v_rhs, rho_w_rhs,
175  rho_u, rho_v, omega, u, v, w,
176  cellSizeInv, stretched_dz_d, mf_m,
177  mf_u_inv, mf_v_inv,
178  horiz_upw_frac, vert_upw_frac,
179  vert_adv_type, lo_z_face, hi_z_face);
180  } else if (horiz_adv_type == AdvType::Centered_6th) {
181  AdvectionSrcForMomVert_N<CENTERED6>(bxx, bxy, bxz,
182  rho_u_rhs, rho_v_rhs, rho_w_rhs,
183  rho_u, rho_v, omega, u, v, w,
184  cellSizeInv, stretched_dz_d, mf_m,
185  mf_u_inv, mf_v_inv,
186  horiz_upw_frac, vert_upw_frac,
187  vert_adv_type, lo_z_face, hi_z_face);
188  } else {
189  AMREX_ASSERT_WITH_MESSAGE(false, "Unknown advection scheme!");
190  }
191  }
192 }
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_m, const Array4< const Real > &mf_u, const Array4< const Real > &mf_v, 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_SAM.H:49