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]differChoicecontainer with diffusion parameters
[in]dxInvinverse cell size array
[in]mf_mmap factor at cell center
51 {
52  BL_PROFILE_VAR("DiffusionSrcForMom()",DiffusionSrcForMom);
53 
54  auto dxinv = dxInv[0], dyinv = dxInv[1], dzinv = dxInv[2];
55 
56  if (l_variable_dz) { // Variable dz (i.e. terrain-fitted coordinates)
57  ParallelFor(bxx, bxy, bxz,
58  [=] AMREX_GPU_DEVICE (int i, int j, int k)
59  {
60  // Inv Jacobian
61  Real mfsq = mf_ux(i,j,0) * mf_uy(i,j,0);
62 
63  Real diffContrib = ( (tau11(i , j , k ) - tau11(i-1, j ,k )) * dxinv * mfsq // Contribution to x-mom eqn from diffusive flux in x-dir
64  + (tau12(i , j+1, k ) - tau12(i , j ,k )) * dyinv * mfsq // Contribution to x-mom eqn from diffusive flux in y-dir
65  + (tau13(i , j , k+1) - tau13(i , j ,k )) * dzinv ); // Contribution to x-mom eqn from diffusive flux in z-dir;
66  diffContrib /= 0.5*(detJ(i,j,k) + detJ(i-1,j,k));
67  rho_u_rhs(i,j,k) -= diffContrib;
68  },
69  [=] AMREX_GPU_DEVICE (int i, int j, int k)
70  {
71  // Inv Jacobian
72  Real mfsq = mf_vx(i,j,0) * mf_vy(i,j,0);
73 
74  Real diffContrib = ( (tau21(i+1, j , k ) - tau21(i , j , k )) * dxinv * mfsq // Contribution to y-mom eqn from diffusive flux in x-dir
75  + (tau22(i , j , k ) - tau22(i , j-1, k )) * dyinv * mfsq // Contribution to y-mom eqn from diffusive flux in y-dir
76  + (tau23(i , j , k+1) - tau23(i , j , k )) * dzinv ); // Contribution to y-mom eqn from diffusive flux in z-dir;
77  diffContrib /= 0.5*(detJ(i,j,k) + detJ(i,j-1,k));
78  rho_v_rhs(i,j,k) -= diffContrib;
79  },
80  [=] AMREX_GPU_DEVICE (int i, int j, int k)
81  {
82  // Inv Jacobian
83  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
84 
85  Real diffContrib = ( (tau31(i+1, j , k ) - tau31(i , j , k )) * dxinv * mfsq // Contribution to z-mom eqn from diffusive flux in x-dir
86  + (tau32(i , j+1, k ) - tau32(i , j , k )) * dyinv * mfsq // Contribution to z-mom eqn from diffusive flux in y-dir
87  + (tau33(i , j , k ) - tau33(i , j , k-1)) * dzinv ); // Contribution to z-mom eqn from diffusive flux in z-dir;
88  diffContrib /= 0.5*(detJ(i,j,k) + detJ(i,j,k-1));
89  rho_w_rhs(i,j,k) -= diffContrib;
90  });
91 
92  } else if (l_stretched_dz) { // Stretched dz
93 
94  auto dz_ptr = stretched_dz_d.data();
95 
96  ParallelFor(bxx, bxy, bxz,
97  [=] AMREX_GPU_DEVICE (int i, int j, int k)
98  {
99  Real mfsq = mf_ux(i,j,0) * mf_uy(i,j,0);
100 
101  Real diffContrib = ( (tau11(i , j , k ) - tau11(i-1, j ,k )) * dxinv * mfsq // Contribution to x-mom eqn from diffusive flux in x-dir
102  + (tau12(i , j+1, k ) - tau12(i , j ,k )) * dyinv * mfsq // Contribution to x-mom eqn from diffusive flux in y-dir
103  + (tau13(i , j , k+1) - tau13(i , j ,k )) / dz_ptr[k] ); // Contribution to x-mom eqn from diffusive flux in z-dir;
104 
105  rho_u_rhs(i,j,k) -= diffContrib;
106  },
107  [=] AMREX_GPU_DEVICE (int i, int j, int k)
108  {
109  Real mfsq = mf_vx(i,j,0) * mf_vy(i,j,0);
110 
111  Real diffContrib = ( (tau21(i+1, j , k ) - tau21(i , j , k )) * dxinv * mfsq // Contribution to y-mom eqn from diffusive flux in x-dir
112  + (tau22(i , j , k ) - tau22(i , j-1, k )) * dyinv * mfsq // Contribution to y-mom eqn from diffusive flux in y-dir
113  + (tau23(i , j , k+1) - tau23(i , j , k )) / dz_ptr[k] ); // Contribution to y-mom eqn from diffusive flux in z-dir;
114 
115  rho_v_rhs(i,j,k) -= diffContrib;
116  },
117  [=] AMREX_GPU_DEVICE (int i, int j, int k)
118  {
119  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
120 
121  // Note: We don't compute a source term for z-momentum on the bottom or top domain boundary (from erf_slow_rhs_pre)
122  Real dzinv_loc = 2.0 / (dz_ptr[k] + dz_ptr[k-1]);
123 
124  Real diffContrib = ( (tau31(i+1, j , k ) - tau31(i , j , k )) * dxinv * mfsq // Contribution to z-mom eqn from diffusive flux in x-dir
125  + (tau32(i , j+1, k ) - tau32(i , j , k )) * dyinv * mfsq // Contribution to z-mom eqn from diffusive flux in y-dir
126  + (tau33(i , j , k ) - tau33(i , j , k-1)) * dzinv_loc ); // Contribution to z-mom eqn from diffusive flux in z-dir;
127 
128  rho_w_rhs(i,j,k) -= diffContrib;
129  });
130 
131  } else { // Constant Dz
132 
133  ParallelFor(bxx, bxy, bxz,
134  [=] AMREX_GPU_DEVICE (int i, int j, int k)
135  {
136  // Inv Jacobian
137  Real mfsq = mf_ux(i,j,0) * mf_uy(i,j,0);
138 
139  // Area corrections
140  Real Imfy_hi = 1. / mf_my(i ,j,0);
141  Real Imfy_lo = 1. / mf_my(i-1,j,0);
142  Real Imfx_hi = 1. / (0.5 * (mf_vx(i,j+1,0) + mf_vx(i-1,j+1,0)));
143  Real Imfx_lo = 1. / (0.5 * (mf_vx(i,j ,0) + mf_vx(i-1,j ,0)));
144  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
145  + (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
146  + (tau13(i , j , k+1) - tau13(i , j ,k ) ) * dzinv ); // Contribution to x-mom eqn from diffusive flux in z-dir;
147  },
148  [=] AMREX_GPU_DEVICE (int i, int j, int k)
149  {
150  // Inv Jacobian
151  Real mfsq = mf_vx(i,j,0) * mf_vy(i,j,0);
152 
153  // Area corrections
154  Real Imfy_hi = 1. / (0.5 * (mf_uy(i+1,j,0) + mf_uy(i+1,j-1,0)));
155  Real Imfy_lo = 1. / (0.5 * (mf_uy(i ,j,0) + mf_uy(i ,j-1,0)));
156  Real Imfx_hi = 1. / mf_mx(i ,j,0);
157  Real Imfx_lo = 1. / mf_mx(i-1,j,0);
158  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
159  + (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
160  + (tau23(i , j , k+1) - tau23(i , j , k ) ) * dzinv ); // Contribution to y-mom eqn from diffusive flux in z-dir;
161  },
162  [=] AMREX_GPU_DEVICE (int i, int j, int k)
163  {
164  // Inv Jacobian
165  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
166 
167  // Area corrections
168  Real Imfy_hi = 1. / mf_uy(i+1,j ,0);
169  Real Imfy_lo = 1. / mf_uy(i ,j ,0);
170  Real Imfx_hi = 1. / mf_vx(i ,j+1,0);
171  Real Imfx_lo = 1. / mf_vx(i ,j ,0);
172  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
173  + (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
174  + (tau33(i , j , k ) - tau33(i , j , k-1) ) * dzinv ); // Contribution to z-mom eqn from diffusive flux in z-dir;
175  });
176  }
177 }
@ tau12
Definition: ERF_DataStruct.H:30
@ tau23
Definition: ERF_DataStruct.H:30
@ tau33
Definition: ERF_DataStruct.H:30
@ tau22
Definition: ERF_DataStruct.H:30
@ tau11
Definition: ERF_DataStruct.H:30
@ tau32
Definition: ERF_DataStruct.H:30
@ tau31
Definition: ERF_DataStruct.H:30
@ tau21
Definition: ERF_DataStruct.H:30
@ tau13
Definition: ERF_DataStruct.H:30
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:31
amrex::Real Real
Definition: ERF_ShocInterface.H:19