ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_MakeTauTerms.cpp File Reference
#include "AMReX_ArrayLim.H"
#include "AMReX_BCRec.H"
#include "AMReX_GpuContainers.H"
#include "ERF_TI_slow_headers.H"
#include "ERF_EOS.H"
#include "ERF_Utils.H"
Include dependency graph for ERF_MakeTauTerms.cpp:

Functions

void erf_make_tau_terms (int level, int nrk, const Vector< BCRec > &domain_bcs_type_h, const MultiFab &z_phys_nd, Vector< MultiFab > &S_data, const MultiFab &xvel, const MultiFab &yvel, const MultiFab &zvel, Vector< std::unique_ptr< MultiFab >> &Tau_lev, Vector< std::unique_ptr< MultiFab >> &Tau_corr_lev, MultiFab *SmnSmn, MultiFab *eddyDiffs, const Geometry geom, const SolverChoice &solverChoice, std::unique_ptr< SurfaceLayer > &, Gpu::DeviceVector< Real > &stretched_dz_d, const MultiFab &detJ, Vector< std::unique_ptr< MultiFab >> &mapfac)
 
void copy_surface_tau_for_implicit (Vector< std::unique_ptr< MultiFab >> &Tau_lev, Vector< std::unique_ptr< MultiFab >> &Tau_corr_lev)
 

Function Documentation

◆ copy_surface_tau_for_implicit()

void copy_surface_tau_for_implicit ( Vector< std::unique_ptr< MultiFab >> &  Tau_lev,
Vector< std::unique_ptr< MultiFab >> &  Tau_corr_lev 
)
611 {
612  // This is only needed if we're using a surface layer, which overwrites the
613  // shear stresses at klo -- at the moment, this is for testing
614 
615  for ( MFIter mfi(*Tau_lev[TauType::tau11],TileNoZ()); mfi.isValid(); ++mfi)
616  {
617  Array4<Real> tau13 = Tau_lev[TauType::tau13]->array(mfi);
618  Array4<Real> tau23 = Tau_lev[TauType::tau23]->array(mfi);
619 
620  Array4<Real> tau13_corr = Tau_corr_lev[0]->array(mfi);
621  Array4<Real> tau23_corr = Tau_corr_lev[1]->array(mfi);
622 
623  const int klo{0};
624  Box bx = mfi.tilebox();
625  bx.makeSlab(2,klo);
626  Box bxx = surroundingNodes(bx,0);
627  Box bxy = surroundingNodes(bx,1);
628 
629  ParallelFor(bxx, bxy,
630  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
631  tau13_corr(i,j,k) = tau13(i,j,k);
632  },
633  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
634  tau23_corr(i,j,k) = tau23(i,j,k);
635  });
636  }
637 }
@ tau23
Definition: ERF_DataStruct.H:31
@ tau11
Definition: ERF_DataStruct.H:31
@ tau13
Definition: ERF_DataStruct.H:31
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
Here is the call graph for this function:

◆ erf_make_tau_terms()

void erf_make_tau_terms ( int  level,
int  nrk,
const Vector< BCRec > &  domain_bcs_type_h,
const MultiFab &  z_phys_nd,
Vector< MultiFab > &  S_data,
const MultiFab &  xvel,
const MultiFab &  yvel,
const MultiFab &  zvel,
Vector< std::unique_ptr< MultiFab >> &  Tau_lev,
Vector< std::unique_ptr< MultiFab >> &  Tau_corr_lev,
MultiFab *  SmnSmn,
MultiFab *  eddyDiffs,
const Geometry  geom,
const SolverChoice solverChoice,
std::unique_ptr< SurfaceLayer > &  ,
Gpu::DeviceVector< Real > &  stretched_dz_d,
const MultiFab &  detJ,
Vector< std::unique_ptr< MultiFab >> &  mapfac 
)
29 {
30  BL_PROFILE_REGION("erf_make_tau_terms()");
31 
32  const BCRec* bc_ptr_h = domain_bcs_type_h.data();
33 
34  DiffChoice dc = solverChoice.diffChoice;
35  TurbChoice tc = solverChoice.turbChoice[level];
36 
37  const bool l_use_terrain_fitted_coords = (solverChoice.mesh_type != MeshType::ConstantDz);
38  const bool l_moving_terrain = (solverChoice.terrain_type == TerrainType::MovingFittedMesh);
39  if (l_moving_terrain) AMREX_ALWAYS_ASSERT (l_use_terrain_fitted_coords);
40 
41 
42  const bool l_use_diff = ( (dc.molec_diff_type != MolecDiffType::None) || tc.use_kturb );
43  const bool l_use_constAlpha = ( dc.molec_diff_type == MolecDiffType::ConstantAlpha );
44  const bool l_use_turb = ( tc.les_type == LESType::Smagorinsky ||
45  tc.les_type == LESType::Deardorff ||
46  tc.rans_type == RANSType::kEqn ||
47  tc.pbl_type == PBLType::MYJ ||
48  tc.pbl_type == PBLType::MYNN25 ||
49  tc.pbl_type == PBLType::MYNNEDMF ||
50  tc.pbl_type == PBLType::YSU ||
51  tc.pbl_type == PBLType::MRF);
52 
53  const bool need_SmnSmn = (tc.les_type == LESType::Deardorff ||
54  tc.rans_type == RANSType::kEqn);
55 
56  const bool do_implicit = (solverChoice.vert_implicit_fac[nrk] > 0) && solverChoice.implicit_momentum_diffusion;
57 
58  const Box& domain = geom.Domain();
59  const int domlo_z = domain.smallEnd(2);
60  const int domhi_z = domain.bigEnd(2);
61 
62  const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
63 
64  // *****************************************************************************
65  // Pre-computed quantities
66  // *****************************************************************************
67  const BoxArray& ba = S_data[IntVars::cons].boxArray();
68  const DistributionMapping& dm = S_data[IntVars::cons].DistributionMap();
69 
70  std::unique_ptr<MultiFab> expr;
71 
72  if (l_use_diff) {
73  expr = std::make_unique<MultiFab>(ba, dm, 1, IntVect(1,1,1));
74 
75  // if using constant alpha (mu = rho * alpha), then first divide by the
76  // reference density -- mu_eff will be scaled by the instantaneous
77  // local density later when ComputeStress*Visc_*() is called
78  Real mu_eff = (l_use_constAlpha) ? 2.0 * dc.dynamic_viscosity / dc.rho0_trans
79  : 2.0 * dc.dynamic_viscosity;
80 
81  auto dz_ptr = stretched_dz_d.data();
82 
83 #ifdef _OPENMP
84 #pragma omp parallel if (Gpu::notInLaunchRegion())
85 #endif
86  for ( MFIter mfi(S_data[IntVars::cons],TileNoZ()); mfi.isValid(); ++mfi)
87  {
88  const Box& valid_bx = mfi.validbox();
89 
90  // Velocities
91  const Array4<const Real> & u = xvel.array(mfi);
92  const Array4<const Real> & v = yvel.array(mfi);
93  const Array4<const Real> & w = zvel.array(mfi);
94 
95  // Map factors
96  const Array4<const Real>& mf_mx = mapfac[MapFacType::m_x]->const_array(mfi);
97  const Array4<const Real>& mf_ux = mapfac[MapFacType::u_x]->const_array(mfi);
98  const Array4<const Real>& mf_vx = mapfac[MapFacType::v_x]->const_array(mfi);
99  const Array4<const Real>& mf_my = mapfac[MapFacType::m_y]->const_array(mfi);
100  const Array4<const Real>& mf_uy = mapfac[MapFacType::u_y]->const_array(mfi);
101  const Array4<const Real>& mf_vy = mapfac[MapFacType::v_y]->const_array(mfi);
102 
103  // Eddy viscosity
104  const Array4<Real const>& mu_turb = l_use_turb ? eddyDiffs->const_array(mfi) :
105  Array4<const Real>{};
106  const Array4<Real const>& cell_data = l_use_constAlpha ? S_data[IntVars::cons].const_array(mfi) :
107  Array4<const Real>{};
108 
109  // Terrain metrics
110  const Array4<const Real>& z_nd = z_phys_nd.const_array(mfi);
111  const Array4<const Real>& detJ_arr = detJ.const_array(mfi);
112 
113  //-------------------------------------------------------------------------------
114  // NOTE: Tile boxes with terrain are not intuitive. The linear combination of
115  // stress terms requires care. Create a tile box that intersects the
116  // valid box, then grow the box in x/y. Compute the strain on the local
117  // FAB over this grown tile box. Compute the stress over the tile box,
118  // except tau_ii which still needs the halo cells. Finally, write from
119  // the local FAB to the Tau MF but only on the tile box.
120  //-------------------------------------------------------------------------------
121 
122  //-------------------------------------------------------------------------------
123  // TODO: Avoid recomputing strain on the first RK stage. One could populate
124  // the FABs with tau_ij, compute stress, and then write to tau_ij. The
125  // problem with this approach is you will over-write the needed halo layer
126  // needed by subsequent tile boxes (particularly S_ii becomes Tau_ii).
127  //-------------------------------------------------------------------------------
128 
129  // Strain/Stress tile boxes
130  Box bx = mfi.tilebox();
131  Box bxcc = mfi.tilebox();
132  Box tbxxy = mfi.tilebox(IntVect(1,1,0));
133  Box tbxxz = mfi.tilebox(IntVect(1,0,1));
134  Box tbxyz = mfi.tilebox(IntVect(0,1,1));
135 
136  // We need a halo cell for terrain
137  bxcc.grow(IntVect(1,1,0));
138  tbxxy.grow(IntVect(1,1,0));
139  tbxxz.grow(IntVect(1,1,0));
140  tbxyz.grow(IntVect(1,1,0));
141 
142  if (bxcc.smallEnd(2) != domain.smallEnd(2)) {
143  bxcc.growLo(2,1);
144  tbxxy.growLo(2,1);
145  tbxxz.growLo(2,1);
146  tbxyz.growLo(2,1);
147  }
148 
149  if (bxcc.bigEnd(2) != domain.bigEnd(2)) {
150  bxcc.growHi(2,1);
151  tbxxy.growHi(2,1);
152  tbxxz.growHi(2,1);
153  tbxyz.growHi(2,1);
154  }
155 
156  // Expansion rate
157  Array4<Real> er_arr = expr->array(mfi);
158 
159  // Temporary storage for tiling/OMP
160  FArrayBox S11,S22,S33;
161  FArrayBox S12,S13,S23;
162 
163  // Symmetric strain/stresses
164  S11.resize( bxcc,1,The_Async_Arena()); S22.resize( bxcc,1,The_Async_Arena()); S33.resize( bxcc,1,The_Async_Arena());
165  S12.resize(tbxxy,1,The_Async_Arena()); S13.resize(tbxxz,1,The_Async_Arena()); S23.resize(tbxyz,1,The_Async_Arena());
166  Array4<Real> s11 = S11.array(); Array4<Real> s22 = S22.array(); Array4<Real> s33 = S33.array();
167  Array4<Real> s12 = S12.array(); Array4<Real> s13 = S13.array(); Array4<Real> s23 = S23.array();
168  Array4<Real> tau11 = Tau_lev[TauType::tau11]->array(mfi); Array4<Real> tau22 = Tau_lev[TauType::tau22]->array(mfi);
169  Array4<Real> tau33 = Tau_lev[TauType::tau33]->array(mfi); Array4<Real> tau12 = Tau_lev[TauType::tau12]->array(mfi);
170  Array4<Real> tau13 = Tau_lev[TauType::tau13]->array(mfi); Array4<Real> tau23 = Tau_lev[TauType::tau23]->array(mfi);
171 
172  // We cannot simply scale the tau3* terms since our implicit
173  // correction to vertical diffusion only applies to the
174  // second-order derivatives in the vertical and we don't want to
175  // touch the cross terms -- we save the terms here and
176  // manipulate them later.
177  FArrayBox S13_for_impl, S23_for_impl;
178  S13_for_impl.resize(tbxxz,1,The_Async_Arena());
179  S23_for_impl.resize(tbxyz,1,The_Async_Arena());
180  Array4<Real> s13_corr = (do_implicit) ? S13_for_impl.array() : Array4<Real>{};
181  Array4<Real> s23_corr = (do_implicit) ? S23_for_impl.array() : Array4<Real>{};
182  Array4<Real> tau13_corr = (do_implicit) ? Tau_corr_lev[0]->array(mfi) : Array4<Real>{};
183  Array4<Real> tau23_corr = (do_implicit) ? Tau_corr_lev[1]->array(mfi) : Array4<Real>{};
184 #ifdef ERF_IMPLICIT_W
185  FArrayBox S33_for_impl;
186  S33_for_impl.resize( bxcc,1,The_Async_Arena());
187  Array4<Real> s33_corr = (do_implicit) ? S33_for_impl.array() : Array4<Real>{};
188  Array4<Real> tau33_corr = (do_implicit) ? Tau_corr_lev[2]->array(mfi) : Array4<Real>{};
189 #else
190  Array4<Real> s33_corr = Array4<Real>{};
191  Array4<Real> tau33_corr = Array4<Real>{};
192 #endif
193 
194  // Calculate the magnitude of the strain-rate tensor squared if
195  // using Deardorff or k-eqn RANS. This contributes to the production
196  // term, included in diffusion source in slow RHS post and in the
197  // first RK stage (TKE tendencies constant for nrk>0, following WRF)
198  Array4<Real> SmnSmn_a = ((nrk==0) && need_SmnSmn) ? SmnSmn->array(mfi) : Array4<Real>{};
199 
200  // ****************************************************************
201  //
202  // These are the steps taken below...
203  //
204  // 1. Calculate expansion rate
205  // - will be added to the normal strain rates in ComputeStress
206  //
207  // 2. Call ComputeStrain
208  // - IMPLICIT path: s31_corr and s32_corr are modified in here
209  //
210  // 3. Call ComputeSmnSmn, if needed for turbulence model
211  //
212  // 4. Call ComputeStress
213  // - add expansion rates to terms on diagonal
214  // - multiply strain rates by diffusivities, with the total
215  // viscosity calculated as the sum of a constant viscosity (or
216  // constant alpha with mu = rho*alpha) and the eddy viscosity
217  // from the turbulence model
218  // - IMPLICIT path: s33_corr is modified in here
219  //
220  // 5. Copy temp Sij fabs into Tau_lev multifabs
221  // - stress tensor is symmetric if no terrain and no implicit diffusion
222  // - otherwise, stress tensor is asymmetric
223  //
224  // ****************************************************************
225 
226  if (solverChoice.mesh_type == MeshType::StretchedDz) {
227  // Terrain non-symmetric terms
228  FArrayBox S21,S31,S32;
229  S21.resize(tbxxy,1,The_Async_Arena()); S31.resize(tbxxz,1,The_Async_Arena()); S32.resize(tbxyz,1,The_Async_Arena());
230  Array4<Real> s21 = S21.array(); Array4<Real> s31 = S31.array(); Array4<Real> s32 = S32.array();
231  Array4<Real> tau21 = Tau_lev[TauType::tau21]->array(mfi);
232  Array4<Real> tau31 = Tau_lev[TauType::tau31]->array(mfi);
233  Array4<Real> tau32 = Tau_lev[TauType::tau32]->array(mfi);
234 
235  // *****************************************************************************
236  // Expansion rate compute terrain
237  // *****************************************************************************
238  {
239  BL_PROFILE("slow_rhs_making_er_S");
240  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
241  {
242  Real mfsq = mf_mx(i,j,0)*mf_my(i,j,0);
243  er_arr(i,j,k) = (u(i+1, j , k )/mf_uy(i+1,j,0) - u(i, j, k)/mf_uy(i,j,0))*dxInv[0] * mfsq + // == du / (dη/dy) * (1/dξ) * (dξ/dx)*(dη/dy) = du/dx
244  (v(i , j+1, k )/mf_vx(i,j+1,0) - v(i, j, k)/mf_vx(i,j,0))*dxInv[1] * mfsq + // == dv / (dξ/dx) * (1/dη) * (dξ/dx)*(dη/dy) = dv/dy
245  (w(i , j , k+1) - w(i, j, k) )/dz_ptr[k];
246  });
247  } // end profile
248 
249  // *****************************************************************************
250  // Strain tensor compute terrain
251  // *****************************************************************************
252  {
253  BL_PROFILE("slow_rhs_making_strain_S");
254  ComputeStrain_S(bxcc, tbxxy, tbxxz, tbxyz, domain,
255  u, v, w,
256  s11, s22, s33,
257  s12, s21,
258  s13, s31,
259  s23, s32,
260  stretched_dz_d, dxInv,
261  mf_mx, mf_ux, mf_vx,
262  mf_my, mf_uy, mf_vy, bc_ptr_h,
263  s13_corr, s23_corr);
264  } // end profile
265 
266  if (SmnSmn_a) {
267  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
268  {
269  SmnSmn_a(i,j,k) = ComputeSmnSmn(i,j,k,
270  s11,s22,s33,
271  s12,s13,s23);
272  });
273  }
274 
275  // *****************************************************************************
276  // Stress tensor compute terrain
277  // *****************************************************************************
278  {
279  BL_PROFILE("slow_rhs_making_stress_T");
280 
281  // Remove Halo cells just for tau_ij comps
282  tbxxy.grow(IntVect(-1,-1,0));
283  tbxxz.grow(IntVect(-1,-1,0));
284  tbxyz.grow(IntVect(-1,-1,0));
285 
286  if (!l_use_turb) {
287  ComputeStressConsVisc_S(bxcc, tbxxy, tbxxz, tbxyz, mu_eff,
288  cell_data,
289  s11, s22, s33,
290  s12, s21,
291  s13, s31,
292  s23, s32,
293  er_arr,
294  mf_mx, mf_ux, mf_vx,
295  mf_my, mf_uy, mf_vy,
296  s13_corr, s23_corr, s33_corr);
297  } else {
298  ComputeStressVarVisc_S(bxcc, tbxxy, tbxxz, tbxyz, mu_eff, mu_turb,
299  cell_data,
300  s11, s22, s33,
301  s12, s21,
302  s13, s31,
303  s23, s32,
304  er_arr,
305  mf_mx, mf_ux, mf_vx,
306  mf_my, mf_uy, mf_vy,
307  s13_corr, s23_corr, s33_corr);
308  }
309 
310  // Remove halo cells from tau_ii but extend across valid_box bdry
311  bxcc.grow(IntVect(-1,-1,0));
312  if (bxcc.smallEnd(0) == valid_bx.smallEnd(0)) bxcc.growLo(0, 1);
313  if (bxcc.bigEnd(0) == valid_bx.bigEnd(0)) bxcc.growHi(0, 1);
314  if (bxcc.smallEnd(1) == valid_bx.smallEnd(1)) bxcc.growLo(1, 1);
315  if (bxcc.bigEnd(1) == valid_bx.bigEnd(1)) bxcc.growHi(1, 1);
316 
317  // Copy from temp FABs back to tau
318  ParallelFor(bxcc,
319  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
320  tau11(i,j,k) = s11(i,j,k);
321  tau22(i,j,k) = s22(i,j,k);
322  tau33(i,j,k) = s33(i,j,k);
323  if (tau33_corr) tau33_corr(i,j,k) = s33_corr(i,j,k);
324  });
325 
326  ParallelFor(tbxxy, tbxxz, tbxyz,
327  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
328  tau12(i,j,k) = s12(i,j,k);
329  tau21(i,j,k) = s21(i,j,k);
330  },
331  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
332  tau13(i,j,k) = s13(i,j,k);
333  tau31(i,j,k) = s31(i,j,k);
334  if (tau13_corr) tau13_corr(i,j,k) = s13_corr(i,j,k);
335  },
336  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
337  tau23(i,j,k) = s23(i,j,k);
338  tau32(i,j,k) = s32(i,j,k);
339  if (tau23_corr) tau23_corr(i,j,k) = s23_corr(i,j,k);
340  });
341  } // end profile
342 
343  } else if (l_use_terrain_fitted_coords) {
344 
345  // Terrain non-symmetric terms
346  FArrayBox S21,S31,S32;
347  S21.resize(tbxxy,1,The_Async_Arena()); S31.resize(tbxxz,1,The_Async_Arena()); S32.resize(tbxyz,1,The_Async_Arena());
348  Array4<Real> s21 = S21.array(); Array4<Real> s31 = S31.array(); Array4<Real> s32 = S32.array();
349  Array4<Real> tau21 = Tau_lev[TauType::tau21]->array(mfi);
350  Array4<Real> tau31 = Tau_lev[TauType::tau31]->array(mfi);
351  Array4<Real> tau32 = Tau_lev[TauType::tau32]->array(mfi);
352 
353 
354  // *****************************************************************************
355  // Expansion rate compute terrain
356  // *****************************************************************************
357  {
358  BL_PROFILE("slow_rhs_making_er_T");
359  Box gbxo = surroundingNodes(bxcc,2);
360 
361  // We make a temporary container for contravariant velocity Omega here
362  // -- it is only used to compute er_arr below
363  FArrayBox Omega;
364  Omega.resize(gbxo,1,The_Async_Arena());
365 
366  // First create Omega using velocity (not momentum)
367  Array4<Real> omega_arr = Omega.array();
368  ParallelFor(gbxo, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
369  {
370  omega_arr(i,j,k) = (k == 0) ? 0. : OmegaFromW(i,j,k,w(i,j,k),u,v,
371  mf_ux,mf_vy,z_nd,dxInv);
372  });
373 
374  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
375  {
376 
377  Real met_u_h_zeta_hi = Compute_h_zeta_AtIface(i+1, j , k, dxInv, z_nd);
378  Real met_u_h_zeta_lo = Compute_h_zeta_AtIface(i , j , k, dxInv, z_nd);
379 
380  Real met_v_h_zeta_hi = Compute_h_zeta_AtJface(i , j+1, k, dxInv, z_nd);
381  Real met_v_h_zeta_lo = Compute_h_zeta_AtJface(i , j , k, dxInv, z_nd);
382 
383  Real Omega_hi = omega_arr(i,j,k+1);
384  Real Omega_lo = omega_arr(i,j,k );
385 
386  Real mfsq = mf_mx(i,j,0)*mf_my(i,j,0);
387 
388  Real expansionRate = (u(i+1,j ,k)/mf_uy(i+1,j,0)*met_u_h_zeta_hi - u(i,j,k)/mf_uy(i,j,0)*met_u_h_zeta_lo)*dxInv[0]*mfsq +
389  (v(i ,j+1,k)/mf_vx(i,j+1,0)*met_v_h_zeta_hi - v(i,j,k)/mf_vx(i,j,0)*met_v_h_zeta_lo)*dxInv[1]*mfsq +
390  (Omega_hi - Omega_lo)*dxInv[2];
391 
392  er_arr(i,j,k) = expansionRate / detJ_arr(i,j,k);
393 
394  // Note:
395  // expansionRate ~ du / (dη/dy) * (dz/dζ) * (1/dξ) * (dξ/dx)*(dη/dy)
396  // + dv / (dξ/dx) * (dz/dζ) * (1/dη) * (dξ/dx)*(dη/dy)
397  // + dΩ/dζ
398  // ~ (du/dx)*(dz/dζ) + (dv/dy)*(dz/dζ) + dΩ/dζ
399  // Dividing by detJ==dz/dζ gives du/dx + dv/dy + dΩ/dz
400  });
401  } // end profile
402 
403  // *****************************************************************************
404  // Strain tensor compute terrain
405  // *****************************************************************************
406  {
407  BL_PROFILE("slow_rhs_making_strain_T");
408  ComputeStrain_T(bxcc, tbxxy, tbxxz, tbxyz, domain,
409  u, v, w,
410  s11, s22, s33,
411  s12, s21,
412  s13, s31,
413  s23, s32,
414  z_nd, detJ_arr, dxInv,
415  mf_mx, mf_ux, mf_vx,
416  mf_my, mf_uy, mf_vy, bc_ptr_h,
417  s13_corr, s23_corr);
418  } // end profile
419 
420  if (SmnSmn_a) {
421  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
422  {
423  SmnSmn_a(i,j,k) = ComputeSmnSmn(i,j,k,
424  s11,s22,s33,
425  s12,s13,s23);
426  });
427  }
428 
429  // *****************************************************************************
430  // Stress tensor compute terrain
431  // *****************************************************************************
432  {
433  BL_PROFILE("slow_rhs_making_stress_T");
434 
435  // Remove Halo cells just for tau_ij comps
436  tbxxy.grow(IntVect(-1,-1,0));
437  tbxxz.grow(IntVect(-1,-1,0));
438  tbxyz.grow(IntVect(-1,-1,0));
439 
440  if (!l_use_turb) {
441  ComputeStressConsVisc_T(bxcc, tbxxy, tbxxz, tbxyz, mu_eff,
442  cell_data,
443  s11, s22, s33,
444  s12, s21,
445  s13, s31,
446  s23, s32,
447  er_arr, z_nd, detJ_arr, dxInv,
448  mf_mx, mf_ux, mf_vx,
449  mf_my, mf_uy, mf_vy,
450  s13_corr, s23_corr, s33_corr);
451  } else {
452  ComputeStressVarVisc_T(bxcc, tbxxy, tbxxz, tbxyz, mu_eff, mu_turb,
453  cell_data,
454  s11, s22, s33,
455  s12, s21,
456  s13, s31,
457  s23, s32,
458  er_arr, z_nd, detJ_arr, dxInv,
459  mf_mx, mf_ux, mf_vx,
460  mf_my, mf_uy, mf_vy,
461  s13_corr, s23_corr, s33_corr);
462  }
463 
464  // Remove halo cells from tau_ii but extend across valid_box bdry
465  bxcc.grow(IntVect(-1,-1,0));
466  if (bxcc.smallEnd(0) == valid_bx.smallEnd(0)) bxcc.growLo(0, 1);
467  if (bxcc.bigEnd(0) == valid_bx.bigEnd(0)) bxcc.growHi(0, 1);
468  if (bxcc.smallEnd(1) == valid_bx.smallEnd(1)) bxcc.growLo(1, 1);
469  if (bxcc.bigEnd(1) == valid_bx.bigEnd(1)) bxcc.growHi(1, 1);
470 
471  // Copy from temp FABs back to tau
472  ParallelFor(bxcc,
473  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
474  tau11(i,j,k) = s11(i,j,k);
475  tau22(i,j,k) = s22(i,j,k);
476  tau33(i,j,k) = s33(i,j,k);
477  if (tau33_corr) tau33_corr(i,j,k) = s33_corr(i,j,k);
478  });
479 
480  ParallelFor(tbxxy, tbxxz, tbxyz,
481  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
482  tau12(i,j,k) = s12(i,j,k);
483  tau21(i,j,k) = s21(i,j,k);
484  },
485  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
486  tau13(i,j,k) = s13(i,j,k);
487  tau31(i,j,k) = s31(i,j,k);
488  if(tau13_corr) tau13_corr(i,j,k) = s13_corr(i,j,k);
489  },
490  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
491  tau23(i,j,k) = s23(i,j,k);
492  tau32(i,j,k) = s32(i,j,k);
493  if(tau23_corr) tau23_corr(i,j,k) = s23_corr(i,j,k);
494  });
495  } // end profile
496 
497  } else {
498 
499  // *****************************************************************************
500  // Expansion rate compute no terrain
501  // *****************************************************************************
502  {
503  BL_PROFILE("slow_rhs_making_er_N");
504  ParallelFor(bxcc, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
505  Real mfsq = mf_mx(i,j,0)*mf_my(i,j,0);
506  er_arr(i,j,k) = (u(i+1, j , k )/mf_uy(i+1,j,0) - u(i, j, k)/mf_uy(i,j,0))*dxInv[0]*mfsq +
507  (v(i , j+1, k )/mf_vx(i,j+1,0) - v(i, j, k)/mf_vx(i,j,0))*dxInv[1]*mfsq +
508  (w(i , j , k+1) - w(i, j, k))*dxInv[2];
509  });
510  } // end profile
511 
512 
513  // *****************************************************************************
514  // Strain tensor compute no terrain
515  // *****************************************************************************
516  {
517  BL_PROFILE("slow_rhs_making_strain_N");
518  ComputeStrain_N(bxcc, tbxxy, tbxxz, tbxyz, domain,
519  u, v, w,
520  s11, s22, s33,
521  s12, s13, s23,
522  dxInv,
523  mf_mx, mf_ux, mf_vx,
524  mf_my, mf_uy, mf_vy, bc_ptr_h,
525  s13_corr, s23_corr);
526  } // end profile
527 
528  if (SmnSmn_a) {
529  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
530  {
531  SmnSmn_a(i,j,k) = ComputeSmnSmn(i,j,k,
532  s11,s22,s33,
533  s12,s13,s23);
534  });
535  }
536 
537  // *****************************************************************************
538  // Stress tensor compute no terrain
539  // *****************************************************************************
540  {
541  BL_PROFILE("slow_rhs_making_stress_N");
542 
543  // Remove Halo cells just for tau_ij comps
544  tbxxy.grow(IntVect(-1,-1,0));
545  tbxxz.grow(IntVect(-1,-1,0));
546  tbxyz.grow(IntVect(-1,-1,0));
547  if (tbxxy.smallEnd(2) > domlo_z) {
548  tbxxy.growLo(2,-1);
549  tbxxz.growLo(2,-1);
550  tbxyz.growLo(2,-1);
551  }
552  if (tbxxy.bigEnd(2) < domhi_z) {
553  tbxxy.growHi(2,-1);
554  tbxxz.growHi(2,-1);
555  tbxyz.growHi(2,-1);
556  }
557 
558  if (!l_use_turb) {
559  ComputeStressConsVisc_N(bxcc, tbxxy, tbxxz, tbxyz, mu_eff,
560  cell_data,
561  s11, s22, s33,
562  s12, s13, s23,
563  er_arr,
564  s13_corr, s23_corr, s33_corr);
565  } else {
566  ComputeStressVarVisc_N(bxcc, tbxxy, tbxxz, tbxyz, mu_eff, mu_turb,
567  cell_data,
568  s11, s22, s33,
569  s12, s13, s23,
570  er_arr,
571  s13_corr, s23_corr, s33_corr);
572  }
573 
574  // Remove halo cells from tau_ii but extend across valid_box bdry
575  bxcc.grow(IntVect(-1,-1,0));
576  if (bxcc.smallEnd(0) == valid_bx.smallEnd(0)) bxcc.growLo(0, 1);
577  if (bxcc.bigEnd(0) == valid_bx.bigEnd(0)) bxcc.growHi(0, 1);
578  if (bxcc.smallEnd(1) == valid_bx.smallEnd(1)) bxcc.growLo(1, 1);
579  if (bxcc.bigEnd(1) == valid_bx.bigEnd(1)) bxcc.growHi(1, 1);
580 
581  // Copy from temp FABs back to tau
582  ParallelFor(bxcc,
583  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
584  tau11(i,j,k) = s11(i,j,k);
585  tau22(i,j,k) = s22(i,j,k);
586  tau33(i,j,k) = s33(i,j,k);
587  if (tau33_corr) tau33_corr(i,j,k) = s33_corr(i,j,k);
588  });
589  ParallelFor(tbxxy, tbxxz, tbxyz,
590  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
591  tau12(i,j,k) = s12(i,j,k);
592  },
593  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
594  tau13(i,j,k) = s13(i,j,k);
595  if (tau13_corr) tau13_corr(i,j,k) = s13_corr(i,j,k);
596  },
597  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
598  tau23(i,j,k) = s23(i,j,k);
599  if (tau23_corr) tau23_corr(i,j,k) = s23_corr(i,j,k);
600  });
601  } // end profile
602  } // no terrain
603  } // MFIter
604  } // l_use_diff
605 }
void ComputeStrain_N(Box bxcc, Box tbxxy, Box tbxxz, Box tbxyz, Box domain, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, Array4< Real > &tau11, Array4< Real > &tau22, Array4< Real > &tau33, Array4< Real > &tau12, Array4< Real > &tau13, Array4< Real > &tau23, 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 BCRec *bc_ptr, Array4< Real > &tau13i, Array4< Real > &tau23i)
Definition: ERF_ComputeStrain_N.cpp:31
void ComputeStrain_S(Box bxcc, Box tbxxy, Box tbxxz, Box tbxyz, Box domain, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, Array4< Real > &tau11, Array4< Real > &tau22, Array4< Real > &tau33, Array4< Real > &tau12, Array4< Real > &tau21, Array4< Real > &tau13, Array4< Real > &tau31, Array4< Real > &tau23, Array4< Real > &tau32, 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 BCRec *bc_ptr, Array4< Real > &tau13i, Array4< Real > &tau23i)
Definition: ERF_ComputeStrain_S.cpp:39
void ComputeStrain_T(Box bxcc, Box tbxxy, Box tbxxz, Box tbxyz, Box domain, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, Array4< Real > &tau11, Array4< Real > &tau22, Array4< Real > &tau33, Array4< Real > &tau12, Array4< Real > &tau21, Array4< Real > &tau13, Array4< Real > &tau31, Array4< Real > &tau23, Array4< Real > &tau32, const Array4< const Real > &z_nd, const Array4< const Real > &detJ, 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 BCRec *bc_ptr, Array4< Real > &tau13i, Array4< Real > &tau23i)
Definition: ERF_ComputeStrain_T.cpp:39
void ComputeStressConsVisc_N(Box bxcc, Box tbxxy, Box tbxxz, Box tbxyz, Real mu_eff, const Array4< const Real > &cell_data, Array4< Real > &tau11, Array4< Real > &tau22, Array4< Real > &tau33, Array4< Real > &tau12, Array4< Real > &tau13, Array4< Real > &tau23, const Array4< const Real > &er_arr, Array4< Real > &tau13i, Array4< Real > &tau23i, Array4< Real > &tau33i)
Definition: ERF_ComputeStress_N.cpp:26
void ComputeStressVarVisc_N(Box bxcc, Box tbxxy, Box tbxxz, Box tbxyz, Real mu_eff, const Array4< const Real > &mu_turb, const Array4< const Real > &cell_data, Array4< Real > &tau11, Array4< Real > &tau22, Array4< Real > &tau33, Array4< Real > &tau12, Array4< Real > &tau13, Array4< Real > &tau23, const Array4< const Real > &er_arr, Array4< Real > &tau13i, Array4< Real > &tau23i, Array4< Real > &tau33i)
Definition: ERF_ComputeStress_N.cpp:126
void ComputeStressVarVisc_S(Box bxcc, Box tbxxy, Box tbxxz, Box tbxyz, Real mu_eff, const Array4< const Real > &mu_turb, const Array4< const Real > &cell_data, Array4< Real > &tau11, Array4< Real > &tau22, Array4< Real > &tau33, Array4< Real > &tau12, Array4< Real > &tau21, Array4< Real > &tau13, Array4< Real > &tau31, Array4< Real > &tau23, Array4< Real > &tau32, const Array4< const Real > &er_arr, 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, Array4< Real > &tau13i, Array4< Real > &tau23i, Array4< Real > &tau33i)
Definition: ERF_ComputeStress_S.cpp:162
void ComputeStressConsVisc_S(Box bxcc, Box tbxxy, Box tbxxz, Box tbxyz, Real mu_eff, const Array4< const Real > &cell_data, Array4< Real > &tau11, Array4< Real > &tau22, Array4< Real > &tau33, Array4< Real > &tau12, Array4< Real > &tau21, Array4< Real > &tau13, Array4< Real > &tau31, Array4< Real > &tau23, Array4< Real > &tau32, const Array4< const Real > &er_arr, 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, Array4< Real > &tau13i, Array4< Real > &tau23i, Array4< Real > &tau33i)
Definition: ERF_ComputeStress_S.cpp:32
void ComputeStressVarVisc_T(Box bxcc, Box tbxxy, Box tbxxz, Box tbxyz, Real mu_eff, const Array4< const Real > &mu_turb, const Array4< const Real > &cell_data, Array4< Real > &tau11, Array4< Real > &tau22, Array4< Real > &tau33, Array4< Real > &tau12, Array4< Real > &tau21, Array4< Real > &tau13, Array4< Real > &tau31, Array4< Real > &tau23, Array4< Real > &tau32, const Array4< const Real > &er_arr, const Array4< const Real > &z_nd, const Array4< const Real > &detJ, 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, Array4< Real > &tau13i, Array4< Real > &tau23i, Array4< Real > &tau33i)
Definition: ERF_ComputeStress_T.cpp:363
void ComputeStressConsVisc_T(Box bxcc, Box tbxxy, Box tbxxz, Box tbxyz, Real mu_eff, const Array4< const Real > &cell_data, Array4< Real > &tau11, Array4< Real > &tau22, Array4< Real > &tau33, Array4< Real > &tau12, Array4< Real > &tau21, Array4< Real > &tau13, Array4< Real > &tau31, Array4< Real > &tau23, Array4< Real > &tau32, const Array4< const Real > &er_arr, const Array4< const Real > &z_nd, const Array4< const Real > &detJ, 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, Array4< Real > &tau13i, Array4< Real > &tau23i, Array4< Real > &tau33i)
Definition: ERF_ComputeStress_T.cpp:32
@ tau12
Definition: ERF_DataStruct.H:31
@ tau33
Definition: ERF_DataStruct.H:31
@ tau22
Definition: ERF_DataStruct.H:31
@ tau32
Definition: ERF_DataStruct.H:31
@ tau31
Definition: ERF_DataStruct.H:31
@ tau21
Definition: ERF_DataStruct.H:31
@ v_x
Definition: ERF_DataStruct.H:23
@ u_y
Definition: ERF_DataStruct.H:24
@ v_y
Definition: ERF_DataStruct.H:24
@ m_y
Definition: ERF_DataStruct.H:24
@ u_x
Definition: ERF_DataStruct.H:23
@ m_x
Definition: ERF_DataStruct.H:23
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeSmnSmn(int &i, int &j, int &k, const amrex::Array4< amrex::Real const > &tau11, const amrex::Array4< amrex::Real const > &tau22, const amrex::Array4< amrex::Real const > &tau33, const amrex::Array4< amrex::Real const > &tau12, const amrex::Array4< amrex::Real const > &tau13, const amrex::Array4< amrex::Real const > &tau23)
Definition: ERF_EddyViscosity.H:63
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real OmegaFromW(int &i, int &j, int &k, amrex::Real w, const amrex::Array4< const amrex::Real > &u_arr, const amrex::Array4< const amrex::Real > &v_arr, const amrex::Array4< const amrex::Real > &mf_u, const amrex::Array4< const amrex::Real > &mf_v, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv)
Definition: ERF_TerrainMetrics.H:412
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtIface(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:102
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtJface(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:142
@ cons
Definition: ERF_IndexDefines.H:158
@ xvel
Definition: ERF_IndexDefines.H:141
@ zvel
Definition: ERF_IndexDefines.H:143
@ yvel
Definition: ERF_IndexDefines.H:142
Definition: ERF_DiffStruct.H:19
amrex::Real rho0_trans
Definition: ERF_DiffStruct.H:91
MolecDiffType molec_diff_type
Definition: ERF_DiffStruct.H:84
amrex::Real dynamic_viscosity
Definition: ERF_DiffStruct.H:96
static MeshType mesh_type
Definition: ERF_DataStruct.H:983
DiffChoice diffChoice
Definition: ERF_DataStruct.H:992
amrex::Vector< amrex::Real > vert_implicit_fac
Definition: ERF_DataStruct.H:1016
amrex::Vector< TurbChoice > turbChoice
Definition: ERF_DataStruct.H:995
static TerrainType terrain_type
Definition: ERF_DataStruct.H:971
bool implicit_momentum_diffusion
Definition: ERF_DataStruct.H:1019
Definition: ERF_TurbStruct.H:41
PBLType pbl_type
Definition: ERF_TurbStruct.H:390
RANSType rans_type
Definition: ERF_TurbStruct.H:387
LESType les_type
Definition: ERF_TurbStruct.H:345
bool use_kturb
Definition: ERF_TurbStruct.H:396

Referenced by erf_slow_rhs_pre().

Here is the call graph for this function:
Here is the caller graph for this function: