ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ERF_AdvectionSrcForMom_TF.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_TF.cpp:

Functions

void AdvectionSrcForMom_TF (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 Array4< const Real > &z_nd, const Array4< const Real > &ax, const Array4< const Real > &ay, const Array4< const Real > &az, const Array4< const Real > &detJ, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, 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_TF()

void AdvectionSrcForMom_TF ( 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 Array4< const Real > &  z_nd,
const Array4< const Real > &  ax,
const Array4< const Real > &  ay,
const Array4< const Real > &  az,
const Array4< const Real > &  detJ,
const GpuArray< Real, AMREX_SPACEDIM > &  cellSizeInv,
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 ONLY when using 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]z_ndheight coordinate at nodes
[in]axArea fraction of x-faces
[in]ayArea fraction of y-faces
[in]azArea fraction of z-faces
[in]detJJacobian of the metric transformation
[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
[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
65 {
66  BL_PROFILE_VAR("AdvectionSrcForMom_TF", AdvectionSrcForMom_TF);
67 
68  AMREX_ALWAYS_ASSERT(bxz.smallEnd(2) > 0);
69 
70  auto dxInv = cellSizeInv[0], dyInv = cellSizeInv[1], dzInv = cellSizeInv[2];
71 
72  // Compute mapfactor inverses
73  Box box2d_u(bxx); box2d_u.setRange(2,0); box2d_u.grow({3,3,0});
74  Box box2d_v(bxy); box2d_v.setRange(2,0); box2d_v.grow({3,3,0});
75 
76  FArrayBox mf_ux_invFAB(box2d_u,1,The_Async_Arena());
77  FArrayBox mf_uy_invFAB(box2d_u,1,The_Async_Arena());
78  const Array4<Real>& mf_ux_inv = mf_ux_invFAB.array();
79  const Array4<Real>& mf_uy_inv = mf_uy_invFAB.array();
80 
81  FArrayBox mf_vx_invFAB(box2d_v,1,The_Async_Arena());
82  FArrayBox mf_vy_invFAB(box2d_v,1,The_Async_Arena());
83  const Array4<Real>& mf_vx_inv = mf_vx_invFAB.array();
84  const Array4<Real>& mf_vy_inv = mf_vy_invFAB.array();
85 
86  ParallelFor(box2d_u, box2d_v,
87  [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
88  {
89  mf_ux_inv(i,j,0) = 1. / mf_ux(i,j,0);
90  mf_uy_inv(i,j,0) = 1. / mf_uy(i,j,0);
91  },
92  [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept
93  {
94  mf_vx_inv(i,j,0) = 1. / mf_vx(i,j,0);
95  mf_vy_inv(i,j,0) = 1. / mf_vy(i,j,0);
96  });
97 
98  // Inline with 2nd order for efficiency
99  if (horiz_adv_type == AdvType::Centered_2nd && vert_adv_type == AdvType::Centered_2nd)
100  {
101  ParallelFor(bxx, bxy, bxz,
102  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
103  {
104  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)) *
105  (u(i+1,j,k) + u(i,j,k)) * 0.5 * (ax(i,j,k) + ax(i+1,j,k));
106 
107  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)) *
108  (u(i-1,j,k) + u(i,j,k)) * 0.5 * (ax(i,j,k) + ax(i-1,j,k));
109 
110  Real met_h_zeta_yhi = Compute_h_zeta_AtEdgeCenterK(i,j+1,k,cellSizeInv,z_nd);
111  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)) *
112  (u(i,j+1,k) + u(i,j,k)) * met_h_zeta_yhi;
113 
114  Real met_h_zeta_ylo = Compute_h_zeta_AtEdgeCenterK(i,j ,k,cellSizeInv,z_nd);
115  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)) *
116  (u(i,j-1,k) + u(i,j,k)) * met_h_zeta_ylo;
117 
118  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)) *
119  0.5 * (az(i,j,k+1) + az(i-1,j,k+1));
120  Real zflux_lo = 0.25 * (Omega(i,j,k ) + Omega(i-1,j,k )) * (u(i,j,k-1) + u(i,j,k)) *
121  0.5 * (az(i,j,k ) + az(i-1,j,k ));
122 
123  Real mfsq = mf_ux(i,j,0) * mf_uy(i,j,0);
124 
125  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
126  + (yflux_hi - yflux_lo) * dyInv * mfsq
127  + (zflux_hi - zflux_lo) * dzInv;
128  rho_u_rhs(i, j, k) = -advectionSrc / (0.5 * (detJ(i,j,k) + detJ(i-1,j,k)));
129  },
130  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
131  {
132 
133  Real met_h_zeta_xhi = Compute_h_zeta_AtEdgeCenterK(i+1,j,k,cellSizeInv,z_nd);
134  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)) *
135  (v(i+1,j,k) + v(i,j,k)) * met_h_zeta_xhi;
136 
137  Real met_h_zeta_xlo = Compute_h_zeta_AtEdgeCenterK(i ,j,k,cellSizeInv,z_nd);
138  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-1,j ,0)) *
139  (v(i-1,j,k) + v(i,j,k)) * met_h_zeta_xlo;
140 
141  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)) *
142  (v(i,j+1,k) + v(i,j,k)) * 0.5 * (ay(i,j,k) + ay(i,j+1,k));
143 
144  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)) *
145  (v(i,j-1,k) + v(i,j,k)) * 0.5 * (ay(i,j,k) + ay(i,j-1,k));
146 
147  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)) *
148  0.5 * (az(i,j,k+1) + az(i,j-1,k+1));
149  Real zflux_lo = 0.25 * (Omega(i,j,k ) + Omega(i, j-1, k )) * (v(i,j,k-1) + v(i,j,k)) *
150  0.5 * (az(i,j,k ) + az(i,j-1,k ));
151 
152  Real mfsq = mf_vx(i,j,0) * mf_vy(i,j,0);
153 
154  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
155  + (yflux_hi - yflux_lo) * dyInv * mfsq
156  + (zflux_hi - zflux_lo) * dzInv;
157  rho_v_rhs(i, j, k) = -advectionSrc / (0.5 * (detJ(i,j,k) + detJ(i,j-1,k)));
158  },
159  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
160  {
161  Real met_h_zeta_xhi = Compute_h_zeta_AtEdgeCenterJ(i+1,j ,k ,cellSizeInv,z_nd);
162  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) *
163  (w(i+1,j,k) + w(i,j,k)) * met_h_zeta_xhi;
164 
165  Real met_h_zeta_xlo = Compute_h_zeta_AtEdgeCenterJ(i ,j ,k ,cellSizeInv,z_nd);
166  Real xflux_lo = 0.25*(rho_u(i ,j ,k) + rho_u(i ,j,k-1)) * mf_uy_inv(i ,j,0) *
167  (w(i-1,j,k) + w(i,j,k)) * met_h_zeta_xlo;
168 
169  Real met_h_zeta_yhi = Compute_h_zeta_AtEdgeCenterI(i ,j+1,k ,cellSizeInv,z_nd);
170  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) *
171  (w(i,j+1,k) + w(i,j,k)) * met_h_zeta_yhi;
172 
173  Real met_h_zeta_ylo = Compute_h_zeta_AtEdgeCenterI(i ,j ,k ,cellSizeInv,z_nd);
174  Real yflux_lo = 0.25*(rho_v(i,j ,k) + rho_v(i,j ,k-1)) * mf_vx_inv(i,j ,0) *
175  (w(i,j-1,k) + w(i,j,k)) * met_h_zeta_ylo;
176 
177  Real zflux_lo = 0.25 * (Omega(i,j,k) + Omega(i,j,k-1)) * (w(i,j,k) + w(i,j,k-1));
178 
179  Real zflux_hi = (k == hi_z_face) ? Omega(i,j,k) * w(i,j,k) * az(i,j,k):
180  0.25 * (Omega(i,j,k) + Omega(i,j,k+1)) * (w(i,j,k) + w(i,j,k+1)) *
181  0.5 * (az(i,j,k) + az(i,j,k+1));
182 
183  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
184 
185  Real advectionSrc = (xflux_hi - xflux_lo) * dxInv * mfsq
186  + (yflux_hi - yflux_lo) * dyInv * mfsq
187  + (zflux_hi - zflux_lo) * dzInv;
188  rho_w_rhs(i, j, k) = -advectionSrc / (0.5*(detJ(i,j,k) + detJ(i,j,k-1)));
189  });
190 
191  // Template higher order methods
192  } else {
193  if (horiz_adv_type == AdvType::Centered_2nd) {
194  AdvectionSrcForMomVert<CENTERED2>(bxx, bxy, bxz,
195  rho_u_rhs, rho_v_rhs, rho_w_rhs,
196  rho_u, rho_v, Omega, u, v, w,
197  z_nd, ax, ay, az, detJ, cellSizeInv,
198  mf_mx, mf_ux_inv, mf_vx_inv,
199  mf_my, mf_uy_inv, mf_vy_inv,
200  horiz_upw_frac, vert_upw_frac,
201  vert_adv_type, lo_z_face, hi_z_face);
202  } else if (horiz_adv_type == AdvType::Upwind_3rd) {
203  AdvectionSrcForMomVert<UPWIND3>(bxx, bxy, bxz,
204  rho_u_rhs, rho_v_rhs, rho_w_rhs,
205  rho_u, rho_v, Omega, u, v, w,
206  z_nd, ax, ay, az, detJ, cellSizeInv,
207  mf_mx, mf_ux_inv, mf_vx_inv,
208  mf_my, mf_uy_inv, mf_vy_inv,
209  horiz_upw_frac, vert_upw_frac,
210  vert_adv_type, lo_z_face, hi_z_face);
211  } else if (horiz_adv_type == AdvType::Centered_4th) {
212  AdvectionSrcForMomVert<CENTERED4>(bxx, bxy, bxz,
213  rho_u_rhs, rho_v_rhs, rho_w_rhs,
214  rho_u, rho_v, Omega, u, v, w,
215  z_nd, ax, ay, az, detJ, cellSizeInv,
216  mf_mx, mf_ux_inv, mf_vx_inv,
217  mf_my, mf_uy_inv, mf_vy_inv,
218  horiz_upw_frac, vert_upw_frac,
219  vert_adv_type, lo_z_face, hi_z_face);
220  } else if (horiz_adv_type == AdvType::Upwind_5th) {
221  AdvectionSrcForMomVert<UPWIND5>(bxx, bxy, bxz,
222  rho_u_rhs, rho_v_rhs, rho_w_rhs,
223  rho_u, rho_v, Omega, u, v, w,
224  z_nd, ax, ay, az, detJ, cellSizeInv,
225  mf_mx, mf_ux_inv, mf_vx_inv,
226  mf_my, mf_uy_inv, mf_vy_inv,
227  horiz_upw_frac, vert_upw_frac,
228  vert_adv_type, lo_z_face, hi_z_face);
229  } else if (horiz_adv_type == AdvType::Centered_6th) {
230  AdvectionSrcForMomVert<CENTERED6>(bxx, bxy, bxz,
231  rho_u_rhs, rho_v_rhs, rho_w_rhs,
232  rho_u, rho_v, Omega, u, v, w,
233  z_nd, ax, ay, az, detJ, cellSizeInv,
234  mf_mx, mf_ux_inv, mf_vx_inv,
235  mf_my, mf_uy_inv, mf_vy_inv,
236  horiz_upw_frac, vert_upw_frac,
237  vert_adv_type, lo_z_face, hi_z_face);
238  } else {
239  AMREX_ASSERT_WITH_MESSAGE(false, "Unknown advection scheme!");
240  }
241  }
242 }
void AdvectionSrcForMom_TF(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 Array4< const Real > &z_nd, const Array4< const Real > &ax, const Array4< const Real > &ay, const Array4< const Real > &az, const Array4< const Real > &detJ, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, 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_TF.cpp:38
@ Centered_4th
@ Centered_6th
@ Centered_2nd
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtEdgeCenterJ(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:276
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtEdgeCenterK(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:231
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtEdgeCenterI(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:320
Here is the call graph for this function: