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