ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_DiffusionSrcForMom.cpp File Reference
#include <AMReX.H>
#include <ERF_Diffusion.H>
#include <ERF_IndexDefines.H>
Include dependency graph for ERF_DiffusionSrcForMom.cpp:

Functions

void DiffusionSrcForMom (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 > &tau11, const Array4< const Real > &tau22, const Array4< const Real > &tau33, const Array4< const Real > &tau12, const Array4< const Real > &tau21, const Array4< const Real > &tau13, const Array4< const Real > &tau31, const Array4< const Real > &tau23, const Array4< const Real > &tau32, const Array4< const Real > &detJ, const Gpu::DeviceVector< Real > &stretched_dz_d, const GpuArray< Real, AMREX_SPACEDIM > &dxInv, 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 bool l_stretched_dz, const bool l_variable_dz)
 

Function Documentation

◆ DiffusionSrcForMom()

void DiffusionSrcForMom ( 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 > &  tau11,
const Array4< const Real > &  tau22,
const Array4< const Real > &  tau33,
const Array4< const Real > &  tau12,
const Array4< const Real > &  tau21,
const Array4< const Real > &  tau13,
const Array4< const Real > &  tau31,
const Array4< const Real > &  tau23,
const Array4< const Real > &  tau32,
const Array4< const Real > &  detJ,
const Gpu::DeviceVector< Real > &  stretched_dz_d,
const GpuArray< Real, AMREX_SPACEDIM > &  dxInv,
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 bool  l_stretched_dz,
const bool  l_variable_dz 
)

Function for computing the momentum RHS from diffusion

Parameters
[in]bxxnodal x box for x-mom
[in]bxynodal y box for y-mom
[in]bxznodal z box for z-mom
[out]rho_u_rhsRHS for x-mom
[out]rho_v_rhsRHS for y-mom
[out]rho_w_rhsRHS for z-mom
[in]tau1111 stress
[in]tau2222 stress
[in]tau3333 stress
[in]tau1212 stress
[in]tau1313 stress
[in]tau2121 stress
[in]tau2323 stress
[in]tau3131 stress
[in]tau3232 stress
[in]detJJacobian determinant
[in]stretched_dz_darray of vertical grid spacings
[in]dxInvinverse cell size array
[in]mf_mxx map factor at cell centers
[in]mf_uxx map factor at x-faces
[in]mf_vxx map factor at y-faces
[in]mf_myy map factor at cell centers
[in]mf_uyy map factor at x-faces
[in]mf_vyy map factor at y-faces
[in]l_stretched_dzflag for stretched vertical spacing
[in]l_variable_dzflag for terrain-fitted vertical metrics
58 {
59  BL_PROFILE_VAR("DiffusionSrcForMom()",DiffusionSrcForMom);
60 
61  auto dxinv = dxInv[0], dyinv = dxInv[1], dzinv = dxInv[2];
62 
63  if (l_variable_dz) { // Variable dz (i.e. terrain-fitted coordinates)
64  ParallelFor(bxx, bxy, bxz,
65  [=] AMREX_GPU_DEVICE (int i, int j, int k)
66  {
67  // Inv Jacobian
68  Real mfsq = mf_ux(i,j,0) * mf_uy(i,j,0);
69 
70  Real diffContrib = ( (tau11(i , j , k ) - tau11(i-1, j ,k )) * dxinv * mfsq // Contribution to x-mom eqn from diffusive flux in x-dir
71  + (tau12(i , j+1, k ) - tau12(i , j ,k )) * dyinv * mfsq // Contribution to x-mom eqn from diffusive flux in y-dir
72  + (tau13(i , j , k+1) - tau13(i , j ,k )) * dzinv ); // Contribution to x-mom eqn from diffusive flux in z-dir;
73  diffContrib /= myhalf*(detJ(i,j,k) + detJ(i-1,j,k));
74  rho_u_rhs(i,j,k) -= diffContrib;
75  },
76  [=] AMREX_GPU_DEVICE (int i, int j, int k)
77  {
78  // Inv Jacobian
79  Real mfsq = mf_vx(i,j,0) * mf_vy(i,j,0);
80 
81  Real diffContrib = ( (tau21(i+1, j , k ) - tau21(i , j , k )) * dxinv * mfsq // Contribution to y-mom eqn from diffusive flux in x-dir
82  + (tau22(i , j , k ) - tau22(i , j-1, k )) * dyinv * mfsq // Contribution to y-mom eqn from diffusive flux in y-dir
83  + (tau23(i , j , k+1) - tau23(i , j , k )) * dzinv ); // Contribution to y-mom eqn from diffusive flux in z-dir;
84  diffContrib /= myhalf*(detJ(i,j,k) + detJ(i,j-1,k));
85  rho_v_rhs(i,j,k) -= diffContrib;
86  },
87  [=] AMREX_GPU_DEVICE (int i, int j, int k)
88  {
89  // Inv Jacobian
90  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
91 
92  Real diffContrib = ( (tau31(i+1, j , k ) - tau31(i , j , k )) * dxinv * mfsq // Contribution to z-mom eqn from diffusive flux in x-dir
93  + (tau32(i , j+1, k ) - tau32(i , j , k )) * dyinv * mfsq // Contribution to z-mom eqn from diffusive flux in y-dir
94  + (tau33(i , j , k ) - tau33(i , j , k-1)) * dzinv ); // Contribution to z-mom eqn from diffusive flux in z-dir;
95  diffContrib /= myhalf*(detJ(i,j,k) + detJ(i,j,k-1));
96  rho_w_rhs(i,j,k) -= diffContrib;
97  });
98 
99  } else if (l_stretched_dz) { // Stretched dz
100 
101  auto dz_ptr = stretched_dz_d.data();
102 
103  ParallelFor(bxx, bxy, bxz,
104  [=] AMREX_GPU_DEVICE (int i, int j, int k)
105  {
106  Real mfsq = mf_ux(i,j,0) * mf_uy(i,j,0);
107 
108  Real diffContrib = ( (tau11(i , j , k ) - tau11(i-1, j ,k )) * dxinv * mfsq // Contribution to x-mom eqn from diffusive flux in x-dir
109  + (tau12(i , j+1, k ) - tau12(i , j ,k )) * dyinv * mfsq // Contribution to x-mom eqn from diffusive flux in y-dir
110  + (tau13(i , j , k+1) - tau13(i , j ,k )) / dz_ptr[k] ); // Contribution to x-mom eqn from diffusive flux in z-dir;
111 
112  rho_u_rhs(i,j,k) -= diffContrib;
113  },
114  [=] AMREX_GPU_DEVICE (int i, int j, int k)
115  {
116  Real mfsq = mf_vx(i,j,0) * mf_vy(i,j,0);
117 
118  Real diffContrib = ( (tau21(i+1, j , k ) - tau21(i , j , k )) * dxinv * mfsq // Contribution to y-mom eqn from diffusive flux in x-dir
119  + (tau22(i , j , k ) - tau22(i , j-1, k )) * dyinv * mfsq // Contribution to y-mom eqn from diffusive flux in y-dir
120  + (tau23(i , j , k+1) - tau23(i , j , k )) / dz_ptr[k] ); // Contribution to y-mom eqn from diffusive flux in z-dir;
121 
122  rho_v_rhs(i,j,k) -= diffContrib;
123  },
124  [=] AMREX_GPU_DEVICE (int i, int j, int k)
125  {
126  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
127 
128  // Note: We don't compute a source term for z-momentum on the bottom or top domain boundary (from erf_slow_rhs_pre)
129  //Real dzinv_loc = (k == 0) ? one / dz_ptr[k] : two / (dz_ptr[k] + dz_ptr[k-1]);
130  Real dzinv_loc = two / (dz_ptr[k] + dz_ptr[k-1]);
131 
132  Real diffContrib = ( (tau31(i+1, j , k ) - tau31(i , j , k )) * dxinv * mfsq // Contribution to z-mom eqn from diffusive flux in x-dir
133  + (tau32(i , j+1, k ) - tau32(i , j , k )) * dyinv * mfsq // Contribution to z-mom eqn from diffusive flux in y-dir
134  + (tau33(i , j , k ) - tau33(i , j , k-1)) * dzinv_loc ); // Contribution to z-mom eqn from diffusive flux in z-dir;
135 
136  rho_w_rhs(i,j,k) -= diffContrib;
137  });
138 
139  } else { // Constant Dz
140 
141  ParallelFor(bxx, bxy, bxz,
142  [=] AMREX_GPU_DEVICE (int i, int j, int k)
143  {
144  // Inv Jacobian
145  Real mfsq = mf_ux(i,j,0) * mf_uy(i,j,0);
146 
147  // Area corrections
148  Real Imfy_hi = one / mf_my(i ,j,0);
149  Real Imfy_lo = one / mf_my(i-1,j,0);
150  Real Imfx_hi = one / (myhalf * (mf_vx(i,j+1,0) + mf_vx(i-1,j+1,0)));
151  Real Imfx_lo = one / (myhalf * (mf_vx(i,j ,0) + mf_vx(i-1,j ,0)));
152  rho_u_rhs(i,j,k) -= ( (tau11(i , j , k )*Imfy_hi - tau11(i-1, j ,k )*Imfy_lo) * dxinv * mfsq // Contribution to x-mom eqn from diffusive flux in x-dir
153  + (tau12(i , j+1, k )*Imfx_hi - tau12(i , j ,k )*Imfx_lo) * dyinv * mfsq // Contribution to x-mom eqn from diffusive flux in y-dir
154  + (tau13(i , j , k+1) - tau13(i , j ,k ) ) * dzinv ); // Contribution to x-mom eqn from diffusive flux in z-dir;
155  },
156  [=] AMREX_GPU_DEVICE (int i, int j, int k)
157  {
158  // Inv Jacobian
159  Real mfsq = mf_vx(i,j,0) * mf_vy(i,j,0);
160 
161  // Area corrections
162  Real Imfy_hi = one / (myhalf * (mf_uy(i+1,j,0) + mf_uy(i+1,j-1,0)));
163  Real Imfy_lo = one / (myhalf * (mf_uy(i ,j,0) + mf_uy(i ,j-1,0)));
164  Real Imfx_hi = one / mf_mx(i ,j,0);
165  Real Imfx_lo = one / mf_mx(i,j-1,0);
166  rho_v_rhs(i,j,k) -= ( (tau12(i+1, j , k )*Imfy_hi - tau12(i , j , k )*Imfy_lo) * dxinv * mfsq // Contribution to y-mom eqn from diffusive flux in x-dir
167  + (tau22(i , j , k )*Imfx_hi - tau22(i , j-1, k )*Imfx_lo) * dyinv * mfsq // Contribution to y-mom eqn from diffusive flux in y-dir
168  + (tau23(i , j , k+1) - tau23(i , j , k ) ) * dzinv ); // Contribution to y-mom eqn from diffusive flux in z-dir;
169  },
170  [=] AMREX_GPU_DEVICE (int i, int j, int k)
171  {
172  // Inv Jacobian
173  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
174 
175  // Area corrections
176  Real Imfy_hi = one / mf_uy(i+1,j ,0);
177  Real Imfy_lo = one / mf_uy(i ,j ,0);
178  Real Imfx_hi = one / mf_vx(i ,j+1,0);
179  Real Imfx_lo = one / mf_vx(i ,j ,0);
180  rho_w_rhs(i,j,k) -= ( (tau13(i+1, j , k )*Imfy_hi - tau13(i , j , k )*Imfy_lo) * dxinv * mfsq // Contribution to z-mom eqn from diffusive flux in x-dir
181  + (tau23(i , j+1, k )*Imfx_hi - tau23(i , j , k )*Imfx_lo) * dyinv * mfsq // Contribution to z-mom eqn from diffusive flux in y-dir
182  + (tau33(i , j , k ) - tau33(i , j , k-1) ) * dzinv ); // Contribution to z-mom eqn from diffusive flux in z-dir;
183  });
184  }
185 }
constexpr amrex::Real two
Definition: ERF_Constants.H:10
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
@ tau12
Definition: ERF_DataStruct.H:38
@ tau23
Definition: ERF_DataStruct.H:38
@ tau33
Definition: ERF_DataStruct.H:38
@ tau22
Definition: ERF_DataStruct.H:38
@ tau11
Definition: ERF_DataStruct.H:38
@ tau32
Definition: ERF_DataStruct.H:38
@ tau31
Definition: ERF_DataStruct.H:38
@ tau21
Definition: ERF_DataStruct.H:38
@ tau13
Definition: ERF_DataStruct.H:38
void DiffusionSrcForMom(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 > &tau11, const Array4< const Real > &tau22, const Array4< const Real > &tau33, const Array4< const Real > &tau12, const Array4< const Real > &tau21, const Array4< const Real > &tau13, const Array4< const Real > &tau31, const Array4< const Real > &tau23, const Array4< const Real > &tau32, const Array4< const Real > &detJ, const Gpu::DeviceVector< Real > &stretched_dz_d, const GpuArray< Real, AMREX_SPACEDIM > &dxInv, 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 bool l_stretched_dz, const bool l_variable_dz)
Definition: ERF_DiffusionSrcForMom.cpp:38
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:17
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Here is the call graph for this function: