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