ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
erf_detail_DiffusionSrcForMom_EB Namespace Reference

Functions

template<int MomDir, EBBoundaryType WallModel>
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real eb_wall_correction (int i, int j, int k, const Array4< const Real > &u_arr, const Array4< const Real > &v_arr, const Array4< const Real > &w_arr, const Array4< const EBCellFlag > &u_cellflg, const Array4< const EBCellFlag > &v_cellflg, const Array4< const EBCellFlag > &w_cellflg, const Array4< const Real > &u_volcent, const Array4< const Real > &v_volcent, const Array4< const Real > &w_volcent, const Array4< const Real > &u_vfrac, const Array4< const Real > &v_vfrac, const Array4< const Real > &w_vfrac, const Array4< const Real > &mom_volfrac, const Array4< const Real > &mom_afrac_x, const Array4< const Real > &mom_afrac_y, const Array4< const Real > &mom_afrac_z, const Array4< const Real > &mom_bcent, const Array4< const Real > &mom_bnorm, const Array4< const Real > &mom_tau_eb13, const Array4< const Real > &mom_tau_eb23, Real dx, Real dy, Real dz, Real vol, Real mu_eff) noexcept
 
template<int MomDir, EBBoundaryType WallModel>
void launch_eb_wall_correction (Box const &bx, [[maybe_unused]] eb_::CutCellList const &cut_cells, Array4< Real > const &mom_rhs, const Array4< const Real > &u_arr, const Array4< const Real > &v_arr, const Array4< const Real > &w_arr, const Array4< const EBCellFlag > &u_cellflg, const Array4< const EBCellFlag > &v_cellflg, const Array4< const EBCellFlag > &w_cellflg, const Array4< const Real > &u_volcent, const Array4< const Real > &v_volcent, const Array4< const Real > &w_volcent, const Array4< const Real > &u_vfrac, const Array4< const Real > &v_vfrac, const Array4< const Real > &w_vfrac, const Array4< const Real > &mom_volfrac, const Array4< const Real > &mom_afrac_x, const Array4< const Real > &mom_afrac_y, const Array4< const Real > &mom_afrac_z, const Array4< const Real > &mom_bcent, const Array4< const Real > &mom_bnorm, const Array4< const Real > &mom_tau_eb13, const Array4< const Real > &mom_tau_eb23, Real dx, Real dy, Real dz, Real vol, Real mu_eff) noexcept
 

Function Documentation

◆ eb_wall_correction()

template<int MomDir, EBBoundaryType WallModel>
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real erf_detail_DiffusionSrcForMom_EB::eb_wall_correction ( int  i,
int  j,
int  k,
const Array4< const Real > &  u_arr,
const Array4< const Real > &  v_arr,
const Array4< const Real > &  w_arr,
const Array4< const EBCellFlag > &  u_cellflg,
const Array4< const EBCellFlag > &  v_cellflg,
const Array4< const EBCellFlag > &  w_cellflg,
const Array4< const Real > &  u_volcent,
const Array4< const Real > &  v_volcent,
const Array4< const Real > &  w_volcent,
const Array4< const Real > &  u_vfrac,
const Array4< const Real > &  v_vfrac,
const Array4< const Real > &  w_vfrac,
const Array4< const Real > &  mom_volfrac,
const Array4< const Real > &  mom_afrac_x,
const Array4< const Real > &  mom_afrac_y,
const Array4< const Real > &  mom_afrac_z,
const Array4< const Real > &  mom_bcent,
const Array4< const Real > &  mom_bnorm,
const Array4< const Real > &  mom_tau_eb13,
const Array4< const Real > &  mom_tau_eb23,
Real  dx,
Real  dy,
Real  dz,
Real  vol,
Real  mu_eff 
)
noexcept

Compute the EB wall contribution for one staggered momentum component.

The momentum direction and wall model are compile-time parameters so that a correction kernel contains only the selected component and boundary model. This routine is called only for single-valued cells.

118 {
119  static_assert(MomDir >= 0 && MomDir < AMREX_SPACEDIM);
120  static_assert(WallModel == EBBoundaryType::NoSlipWall ||
121  WallModel == EBBoundaryType::SurfaceLayer);
122 
123  RealVect bcent_eb {mom_bcent(i,j,k,0), mom_bcent(i,j,k,1), mom_bcent(i,j,k,2)};
124 
125  Real nx = mom_bnorm(i,j,k,0);
126  Real ny = mom_bnorm(i,j,k,1);
127  Real nz = mom_bnorm(i,j,k,2);
128 
129  Real Dirichlet_u {zero};
130  Real Dirichlet_v {zero};
131  Real Dirichlet_w {zero};
132 
133  if constexpr (WallModel == EBBoundaryType::SurfaceLayer) {
134  Real velx;
135  Real vely;
136  Real velz;
137 
138  if constexpr (MomDir == 0) {
139  // Average v and w onto the x-face.
140  velx = u_arr(i,j,k);
141  vely = (v_vfrac(i-1,j ,k) * v_arr(i-1,j ,k) + v_vfrac(i,j ,k) * v_arr(i,j ,k)
142  + v_vfrac(i-1,j+1,k) * v_arr(i-1,j+1,k) + v_vfrac(i,j+1,k) * v_arr(i,j+1,k))
143  / (v_vfrac(i-1,j,k) + v_vfrac(i,j,k) + v_vfrac(i-1,j+1,k) + v_vfrac(i,j+1,k));
144  velz = (w_vfrac(i-1,j,k ) * w_arr(i-1,j,k ) + w_vfrac(i,j,k ) * w_arr(i,j,k )
145  + w_vfrac(i-1,j,k+1) * w_arr(i-1,j,k+1) + w_vfrac(i,j,k+1) * w_arr(i,j,k+1))
146  / (w_vfrac(i-1,j,k) + w_vfrac(i,j,k) + w_vfrac(i-1,j,k+1) + w_vfrac(i,j,k+1));
147  } else if constexpr (MomDir == 1) {
148  // Average u and w onto the y-face.
149  velx = (u_vfrac(i ,j-1,k) * u_arr(i ,j-1,k) + u_vfrac(i+1,j-1,k) * u_arr(i+1,j-1,k)
150  + u_vfrac(i+1,j ,k) * u_arr(i+1,j ,k) + u_vfrac(i ,j ,k) * u_arr(i ,j ,k))
151  / (u_vfrac(i,j-1,k) + u_vfrac(i+1,j-1,k) + u_vfrac(i+1,j,k) + u_vfrac(i,j,k));
152  vely = v_arr(i,j,k);
153  velz = (w_vfrac(i,j-1,k ) * w_arr(i,j-1,k ) + w_vfrac(i,j,k ) * w_arr(i,j,k )
154  + w_vfrac(i,j ,k+1) * w_arr(i,j ,k+1) + w_vfrac(i,j-1,k+1) * w_arr(i,j-1,k+1))
155  / (w_vfrac(i,j-1,k) + w_vfrac(i,j,k) + w_vfrac(i,j,k+1) + w_vfrac(i,j-1,k+1));
156  } else {
157  // Average u and v onto the z-face.
158  velx = (u_vfrac(i ,j,k-1) * u_arr(i ,j,k-1) + u_vfrac(i+1,j,k-1) * u_arr(i+1,j,k-1)
159  + u_vfrac(i+1,j,k ) * u_arr(i+1,j,k ) + u_vfrac(i ,j,k ) * u_arr(i ,j,k ))
160  / (u_vfrac(i,j,k-1) + u_vfrac(i+1,j,k-1) + u_vfrac(i+1,j,k) + u_vfrac(i,j,k));
161  vely = (v_vfrac(i,j ,k-1) * v_arr(i,j ,k-1) + v_vfrac(i,j+1,k-1) * v_arr(i,j+1,k-1)
162  + v_vfrac(i,j+1,k ) * v_arr(i,j+1,k ) + v_vfrac(i,j ,k ) * v_arr(i,j ,k ))
163  / (v_vfrac(i,j,k-1) + v_vfrac(i,j+1,k-1) + v_vfrac(i,j+1,k) + v_vfrac(i,j,k));
164  velz = w_arr(i,j,k);
165  }
166 
167  Real v_dot_n = velx * nx + vely * ny + velz * nz;
168  Dirichlet_u = velx - v_dot_n * nx;
169  Dirichlet_v = vely - v_dot_n * ny;
170  Dirichlet_w = velz - v_dot_n * nz;
171  }
172 
173  GpuArray<Real,AMREX_SPACEDIM> slopes_u;
174  GpuArray<Real,AMREX_SPACEDIM> slopes_v;
175  GpuArray<Real,AMREX_SPACEDIM> slopes_w;
176 
177  if constexpr (MomDir == 0) {
178  slopes_u = erf_calc_slopes_eb_Dirichlet ( dx, dy, dz, i, j, k, bcent_eb, Dirichlet_u, u_arr, u_volcent, u_cellflg);
179  slopes_v = erf_calc_slopes_eb_Dirichlet_staggered<Vars::xvel,Vars::yvel>(dx, dy, dz, i, j, k, bcent_eb, Dirichlet_v, v_arr, v_volcent, v_cellflg);
180  slopes_w = erf_calc_slopes_eb_Dirichlet_staggered<Vars::xvel,Vars::zvel>(dx, dy, dz, i, j, k, bcent_eb, Dirichlet_w, w_arr, w_volcent, w_cellflg);
181  } else if constexpr (MomDir == 1) {
182  slopes_u = erf_calc_slopes_eb_Dirichlet_staggered<Vars::yvel,Vars::xvel>(dx, dy, dz, i, j, k, bcent_eb, Dirichlet_u, u_arr, u_volcent, u_cellflg);
183  slopes_v = erf_calc_slopes_eb_Dirichlet ( dx, dy, dz, i, j, k, bcent_eb, Dirichlet_v, v_arr, v_volcent, v_cellflg);
184  slopes_w = erf_calc_slopes_eb_Dirichlet_staggered<Vars::yvel,Vars::zvel>(dx, dy, dz, i, j, k, bcent_eb, Dirichlet_w, w_arr, w_volcent, w_cellflg);
185  } else {
186  slopes_u = erf_calc_slopes_eb_Dirichlet_staggered<Vars::zvel,Vars::xvel>(dx, dy, dz, i, j, k, bcent_eb, Dirichlet_u, u_arr, u_volcent, u_cellflg);
187  slopes_v = erf_calc_slopes_eb_Dirichlet_staggered<Vars::zvel,Vars::yvel>(dx, dy, dz, i, j, k, bcent_eb, Dirichlet_v, v_arr, v_volcent, v_cellflg);
188  slopes_w = erf_calc_slopes_eb_Dirichlet ( dx, dy, dz, i, j, k, bcent_eb, Dirichlet_w, w_arr, w_volcent, w_cellflg);
189  }
190 
191  Real dudx = slopes_u[0];
192  Real dudy = slopes_u[1];
193  Real dudz = slopes_u[2];
194  Real dvdx = slopes_v[0];
195  Real dvdy = slopes_v[1];
196  Real dvdz = slopes_v[2];
197  Real dwdx = slopes_w[0];
198  Real dwdy = slopes_w[1];
199  Real dwdz = slopes_w[2];
200 
201  Real divergence = dudx + dvdy + dwdz;
202  Real dmomdn;
203 
204  if constexpr (WallModel == EBBoundaryType::NoSlipWall) {
205  if constexpr (MomDir == 0) {
206  Real tau11_eb = dudx - divergence / three;
207  Real tau12_eb = myhalf * (dudy + dvdx);
208  Real tau13_eb = myhalf * (dudz + dwdx);
209  dmomdn = -mu_eff * (nx * tau11_eb + ny * tau12_eb + nz * tau13_eb);
210  } else if constexpr (MomDir == 1) {
211  Real tau22_eb = dvdy - divergence / three;
212  Real tau12_eb = myhalf * (dudy + dvdx);
213  Real tau23_eb = myhalf * (dvdz + dwdy);
214  dmomdn = -mu_eff * (nx * tau12_eb + ny * tau22_eb + nz * tau23_eb);
215  } else {
216  Real tau33_eb = dwdz - divergence / three;
217  Real tau13_eb = myhalf * (dudz + dwdx);
218  Real tau23_eb = myhalf * (dvdz + dwdy);
219  dmomdn = -mu_eff * (nx * tau13_eb + ny * tau23_eb + nz * tau33_eb);
220  }
221  } else {
222  Real tau11_eb = dudx - divergence / three;
223  Real tau22_eb = dvdy - divergence / three;
224  Real tau33_eb = dwdz - divergence / three;
225  Real tau12_eb = myhalf * (dudy + dvdx);
226  Real tau13_eb = myhalf * (dudz + dwdx);
227  Real tau23_eb = myhalf * (dvdz + dwdy);
228 
229  Real tauzz = mu_eff * ( nx*nx*tau11_eb + ny*ny*tau22_eb + nz*nz*tau33_eb
230  + two * (nx*ny*tau12_eb + ny*nz*tau23_eb + nx*nz*tau13_eb) );
231 
232  Real tbx_x, tbx_y, tbx_z, tby_x, tby_y, tby_z;
233  compute_tangent_vectors(nx, ny, nz, tbx_x, tbx_y, tbx_z, tby_x, tby_y, tby_z);
234 
235  if constexpr (MomDir == 0) {
236  dmomdn = -tbx_x * mom_tau_eb13(i,j,k) - tby_x * mom_tau_eb23(i,j,k) - nx * tauzz;
237  } else if constexpr (MomDir == 1) {
238  dmomdn = -tbx_y * mom_tau_eb13(i,j,k) - tby_y * mom_tau_eb23(i,j,k) - ny * tauzz;
239  } else {
240  dmomdn = -tbx_z * mom_tau_eb13(i,j,k) - tby_z * mom_tau_eb23(i,j,k) - nz * tauzz;
241  }
242  }
243 
244  Real axm = mom_afrac_x(i ,j ,k );
245  Real axp = mom_afrac_x(i+1,j ,k );
246  Real aym = mom_afrac_y(i ,j ,k );
247  Real ayp = mom_afrac_y(i ,j+1,k );
248  Real azm = mom_afrac_z(i ,j ,k );
249  Real azp = mom_afrac_z(i ,j ,k+1);
250 
251  Real adx = (axm-axp) * dy * dz;
252  Real ady = (aym-ayp) * dx * dz;
253  Real adz = (azm-azp) * dx * dy;
254  Real barea = std::sqrt(adx*adx + ady*ady + adz*adz);
255 
256  return barea * dmomdn / (vol * mom_volfrac(i,j,k));
257 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void compute_tangent_vectors(Real nx, Real ny, Real nz, Real &tbx_x, Real &tbx_y, Real &tbx_z, Real &tby_x, Real &tby_y, Real &tby_z)
Definition: ERF_DiffusionSrcForMom_EB.cpp:43
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > erf_calc_slopes_eb_Dirichlet(amrex::Real dx, amrex::Real dy, amrex::Real dz, int i, int j, int k, amrex::RealVect const &bcent_eb, amrex::Real const state_eb, amrex::Array4< amrex::Real const > const &state, amrex::Array4< amrex::Real const > const &ccent, amrex::Array4< amrex::EBCellFlag const > const &flag)
Compute least-squares slopes using EB Dirichlet data.
Definition: ERF_EBSlopes.H:29
const int nx
Definition: ERF_InitCustomPertVels_CloudChamber.H:14
const int ny
Definition: ERF_InitCustomPertVels_CloudChamber.H:15
const Real dy
Definition: ERF_InitCustomPert_ABL.H:101
constexpr amrex::Real three
Definition: ERF_NumericalConstants.H:39
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
Here is the call graph for this function:

◆ launch_eb_wall_correction()

template<int MomDir, EBBoundaryType WallModel>
void erf_detail_DiffusionSrcForMom_EB::launch_eb_wall_correction ( Box const &  bx,
[[maybe_unused] ] eb_::CutCellList const &  cut_cells,
Array4< Real > const &  mom_rhs,
const Array4< const Real > &  u_arr,
const Array4< const Real > &  v_arr,
const Array4< const Real > &  w_arr,
const Array4< const EBCellFlag > &  u_cellflg,
const Array4< const EBCellFlag > &  v_cellflg,
const Array4< const EBCellFlag > &  w_cellflg,
const Array4< const Real > &  u_volcent,
const Array4< const Real > &  v_volcent,
const Array4< const Real > &  w_volcent,
const Array4< const Real > &  u_vfrac,
const Array4< const Real > &  v_vfrac,
const Array4< const Real > &  w_vfrac,
const Array4< const Real > &  mom_volfrac,
const Array4< const Real > &  mom_afrac_x,
const Array4< const Real > &  mom_afrac_y,
const Array4< const Real > &  mom_afrac_z,
const Array4< const Real > &  mom_bcent,
const Array4< const Real > &  mom_bnorm,
const Array4< const Real > &  mom_tau_eb13,
const Array4< const Real > &  mom_tau_eb23,
Real  dx,
Real  dy,
Real  dz,
Real  vol,
Real  mu_eff 
)
noexcept

Launch an EB wall-correction kernel over the cached cut-face list on GPU. CPU execution retains the full-box kernel.

289 {
290  static_assert(MomDir >= 0 && MomDir < AMREX_SPACEDIM);
291 
292 #ifdef AMREX_USE_GPU
293  if (Gpu::inLaunchRegion()) {
294  Dim3 const* const cut_cells_ptr = cut_cells.data();
295  int const num_cut_cells = static_cast<int>(cut_cells.size());
296  ParallelFor(num_cut_cells, [=] AMREX_GPU_DEVICE (int cut_index) noexcept {
297  Dim3 const cell = cut_cells_ptr[cut_index];
298  if (!bx.contains(cell)) { return; }
299  mom_rhs(cell.x,cell.y,cell.z) -= eb_wall_correction<MomDir,WallModel>(
300  cell.x, cell.y, cell.z, u_arr, v_arr, w_arr,
301  u_cellflg, v_cellflg, w_cellflg, u_volcent, v_volcent, w_volcent,
302  u_vfrac, v_vfrac, w_vfrac, mom_volfrac,
303  mom_afrac_x, mom_afrac_y, mom_afrac_z, mom_bcent, mom_bnorm,
304  mom_tau_eb13, mom_tau_eb23, dx, dy, dz, vol, mu_eff);
305  });
306  return;
307  }
308 #endif
309 
310  Array4<const EBCellFlag> mom_cellflg;
311  if constexpr (MomDir == 0) {
312  mom_cellflg = u_cellflg;
313  } else if constexpr (MomDir == 1) {
314  mom_cellflg = v_cellflg;
315  } else {
316  mom_cellflg = w_cellflg;
317  }
318 
319  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
320  if (mom_cellflg(i,j,k).isSingleValued()) {
321  mom_rhs(i,j,k) -= eb_wall_correction<MomDir,WallModel>(
322  i, j, k, u_arr, v_arr, w_arr,
323  u_cellflg, v_cellflg, w_cellflg, u_volcent, v_volcent, w_volcent,
324  u_vfrac, v_vfrac, w_vfrac, mom_volfrac,
325  mom_afrac_x, mom_afrac_y, mom_afrac_z, mom_bcent, mom_bnorm,
326  mom_tau_eb13, mom_tau_eb23, dx, dy, dz, vol, mu_eff);
327  }
328  });
329 }
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);})
Here is the call graph for this function: