ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_Substep_T.cpp File Reference
#include <ERF_TI_fast_headers.H>
#include "ERF_Constants.H"
Include dependency graph for ERF_Substep_T.cpp:

Macros

#define CF_OMEGA_STAGE(I, J, K)   cf_omega_stage(I,J,K,dklo,dkhi,stage_zmom,stage_xmom,stage_ymom,mf_ux,mf_vy,z_nd,dxInv)
 

Functions

void erf_substep_T (int step, int, int level, int finest_level, Vector< MultiFab > &S_slow_rhs, const Vector< MultiFab > &S_prev, Vector< MultiFab > &S_stage_data, const MultiFab &S_stage_prim, const MultiFab &qt, const MultiFab &pi_stage, const MultiFab &fast_coeffs, Vector< MultiFab > &S_data, MultiFab &lagged_delta_rt, MultiFab &avg_xmom, MultiFab &avg_ymom, MultiFab &avg_zmom, const MultiFab &cc_src, const MultiFab &xmom_src, const MultiFab &ymom_src, const MultiFab &zmom_src, const Geometry geom, const Real gravity, std::unique_ptr< MultiFab > &z_phys_nd, std::unique_ptr< MultiFab > &detJ_cc, const MultiFab &ax, const MultiFab &ay, const double dtau_d, const Real facinv, Vector< std::unique_ptr< MultiFab >> &mapfac, YAFluxRegister *fr_as_crse, YAFluxRegister *fr_as_fine, bool l_use_moisture, bool l_reflux, bool l_real_bc, const Real *sinesq_stag_d, const Real l_damp_coef, const Real beta_d, const CFFaceFluxes &cf_fluxes, const GpuArray< bool, 4 > &lateral_walls)
 

Macro Definition Documentation

◆ CF_OMEGA_STAGE

#define CF_OMEGA_STAGE (   I,
  J,
  K 
)    cf_omega_stage(I,J,K,dklo,dkhi,stage_zmom,stage_xmom,stage_ymom,mf_ux,mf_vy,z_nd,dxInv)

Function Documentation

◆ erf_substep_T()

void erf_substep_T ( int  step,
int  ,
int  level,
int  finest_level,
Vector< MultiFab > &  S_slow_rhs,
const Vector< MultiFab > &  S_prev,
Vector< MultiFab > &  S_stage_data,
const MultiFab &  S_stage_prim,
const MultiFab &  qt,
const MultiFab &  pi_stage,
const MultiFab &  fast_coeffs,
Vector< MultiFab > &  S_data,
MultiFab &  lagged_delta_rt,
MultiFab &  avg_xmom,
MultiFab &  avg_ymom,
MultiFab &  avg_zmom,
const MultiFab &  cc_src,
const MultiFab &  xmom_src,
const MultiFab &  ymom_src,
const MultiFab &  zmom_src,
const Geometry  geom,
const Real  gravity,
std::unique_ptr< MultiFab > &  z_phys_nd,
std::unique_ptr< MultiFab > &  detJ_cc,
const MultiFab &  ax,
const MultiFab &  ay,
const double  dtau_d,
const Real  facinv,
Vector< std::unique_ptr< MultiFab >> &  mapfac,
YAFluxRegister *  fr_as_crse,
YAFluxRegister *  fr_as_fine,
bool  l_use_moisture,
bool  l_reflux,
bool  l_real_bc,
const Real *  sinesq_stag_d,
const Real  l_damp_coef,
const Real  beta_d,
const CFFaceFluxes &  cf_fluxes,
const GpuArray< bool, 4 > &  lateral_walls 
)

Function for computing the fast RHS with fixed-in-time terrain

Parameters
[in]stepwhich fast time step within each Runge-Kutta step
[in]nrkwhich Runge-Kutta step
[in]levellevel of resolution
[in]finest_levelfinest level of resolution
[in]S_slow_rhsslow RHS computed in erf_slow_rhs_pre
[in]S_prevprevious solution
[in]S_stage_datasolution at previous RK stage
[in]S_stage_primprimitive variables at previous RK stage
[in]pi_stageExner function at previous RK stage
[in]fast_coeffscoefficients for the tridiagonal solve used in the fast integrator, and beta_s on the w-faces (component 5)
[out]S_datacurrent solution
[in,out]lagged_delta_rt
[in,out]avg_xmomtime-averaged x-momentum to be used for updating slow variables
[in,out]avg_ymomtime-averaged y-momentum to be used for updating slow variables
[in,out]avg_zmomtime-averaged z-momentum to be used for updating slow variables
[in]cc_srcsource terms for conserved variables
[in]xmom_srcsource terms for x-momentum
[in]ymom_srcsource terms for y-momentum
[in]zmom_srcsource terms for z-momentum
[in]geomcontainer for geometric information
[in]gravitymagnitude of gravity
[in]z_phys_ndheight coordinate at nodes
[in]detJ_ccJacobian of the metric transformation
[in]axarea fraction of x-faces
[in]ayarea fraction of y-faces
[in]dtaufast time step
[in]facinvinverse factor for time-averaging the momenta
[in]mapfacvector of map factors
[in,out]fr_as_crseYAFluxRegister at level l at level l / l+1 interface
[in,out]fr_as_fineYAFluxRegister at level l at level l-1 / l interface
[in]l_use_moisture
[in]l_refluxshould we add fluxes to the FluxRegisters?
[in]l_real_bc
[in]l_damp_coef
[in]beta_ddivergence damping coefficient: how far (rho theta) is projected forward
[in,out]cf_fluxescoarse/fine face fluxes: recorded here on a coarse level, imposed on a fine one
[in]lateral_wallswhether the xlo, xhi, ylo and yhi faces are walls (zero normal velocity)
108 {
109  BL_PROFILE_REGION("erf_substep_T()");
110 
111  Real dtau = static_cast<Real>(dtau_d);
112 
113  const Box& domain = geom.Domain();
114  auto const domlo = lbound(domain);
115  auto const domhi = ubound(domain);
116 
117  int ilo = domlo.x;
118  int ihi = domhi.x + 1;
119  int jlo = domlo.y;
120  int jhi = domhi.y + 1;
121 
122  // The substeps keep the normal momentum on a lateral wall face (slip, no-slip, symmetry or
123  // surface layer) at its stage value, zero on all but a symmetry face. Over terrain that
124  // slopes normal to the wall the terrain term of the pressure gradient is not zero on the
125  // wall face, and updating the face would carry mass through the wall until the boundary
126  // fill reset it after the substep. (Across a symmetry face the terrain is mirrored, so
127  // that term is zero there.)
128  const bool wall_xlo = lateral_walls[0];
129  const bool wall_xhi = lateral_walls[1];
130  const bool wall_ylo = lateral_walls[2];
131  const bool wall_yhi = lateral_walls[3];
132 
133  Real RvOverRd = R_v / R_d;
134 
135  bool l_rayleigh_impl_for_w = (sinesq_stag_d != nullptr);
136 
137  const Real* dx = geom.CellSize();
138  const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
139 
140  // Set gravity as a vector
141  const Array<Real,AMREX_SPACEDIM> grav{zero, zero, -gravity};
142  const GpuArray<Real,AMREX_SPACEDIM> grav_gpu{grav[0], grav[1], grav[2]};
143 
144  Real dxi = dxInv[0];
145  Real dyi = dxInv[1];
146  Real dzi = dxInv[2];
147  const auto& ba = S_stage_data[IntVars::cons].boxArray();
148  const auto& dm = S_stage_data[IntVars::cons].DistributionMap();
149 
150  MultiFab Delta_rho_u( convert(ba,IntVect(1,0,0)), dm, 1, 1);
151  MultiFab Delta_rho_v( convert(ba,IntVect(0,1,0)), dm, 1, 1);
152  MultiFab Delta_rho_w( convert(ba,IntVect(0,0,1)), dm, 1, IntVect(1,1,0));
153  MultiFab Delta_rho ( ba , dm, 1, 1);
154  MultiFab Delta_rho_theta( ba , dm, 1, 1);
155 
156  MultiFab New_rho_u(convert(ba,IntVect(1,0,0)), dm, 1, 1);
157  MultiFab New_rho_v(convert(ba,IntVect(0,1,0)), dm, 1, 1);
158 
159  MultiFab coeff_A_mf(fast_coeffs, make_alias, 0, 1);
160  MultiFab inv_coeff_B_mf(fast_coeffs, make_alias, 1, 1);
161  MultiFab coeff_C_mf(fast_coeffs, make_alias, 2, 1);
162  MultiFab coeff_P_mf(fast_coeffs, make_alias, 3, 1);
163  MultiFab coeff_Q_mf(fast_coeffs, make_alias, 4, 1);
164 
165  // beta_s on the w-faces, from which
166  // beta_1 = myhalf * (one - beta_s) multiplies explicit terms
167  // beta_2 = myhalf * (one + beta_s) multiplies implicit terms
168  MultiFab beta_s_mf(fast_coeffs, make_alias, 5, 1);
169 
170  MultiFab Omega(S_data[IntVars::zmom].boxArray(), dm, 1, 1);
171 
172  MultiFab extrap(S_data[IntVars::cons].boxArray(),S_data[IntVars::cons].DistributionMap(),1,1);
173 
174  // *************************************************************************
175  // Set up data that depends upon the "old" state
176  // *************************************************************************
177 #ifdef _OPENMP
178 #pragma omp parallel if (Gpu::notInLaunchRegion())
179 #endif
180  for ( MFIter mfi(S_stage_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi)
181  {
182  const Array4<Real> & cur_cons = S_data[IntVars::cons].array(mfi);
183  const Array4<const Real>& prev_cons = S_prev[IntVars::cons].const_array(mfi);
184  const Array4<const Real>& stage_cons = S_stage_data[IntVars::cons].const_array(mfi);
185  const Array4<Real>& lagged_arr = lagged_delta_rt.array(mfi);
186 
187  const Array4<Real>& old_drho = Delta_rho.array(mfi);
188  const Array4<Real>& old_drho_u = Delta_rho_u.array(mfi);
189  const Array4<Real>& old_drho_v = Delta_rho_v.array(mfi);
190  const Array4<Real>& old_drho_w = Delta_rho_w.array(mfi);
191  const Array4<Real>& old_drho_theta = Delta_rho_theta.array(mfi);
192 
193  const Array4<const Real>& prev_xmom = S_prev[IntVars::xmom].const_array(mfi);
194  const Array4<const Real>& prev_ymom = S_prev[IntVars::ymom].const_array(mfi);
195  const Array4<const Real>& prev_zmom = S_prev[IntVars::zmom].const_array(mfi);
196 
197  const Array4<const Real>& stage_xmom = S_stage_data[IntVars::xmom].const_array(mfi);
198  const Array4<const Real>& stage_ymom = S_stage_data[IntVars::ymom].const_array(mfi);
199  const Array4<const Real>& stage_zmom = S_stage_data[IntVars::zmom].const_array(mfi);
200 
201  const Array4<Real>& theta_extrap = extrap.array(mfi);
202  const Array4<const Real>& prim = S_stage_prim.const_array(mfi);
203 
204  Box bx = mfi.validbox();
205 
206  // NOTE: growntilebox / grownnodaltilebox, not the tilebox grown by hand. Growing by
207  // hand pushes every tile one cell past its own share of the grid, so once the
208  // grid is tiled two tiles store to the same cells -- a data race under OpenMP,
209  // even though both store the same value. The union of the tiles, and the values
210  // stored, are unchanged, and this is identical to the old expression when there
211  // is one tile per grid.
212  Box gbx = mfi.growntilebox(1);
213 
214  if (step == 0) {
215  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
216  cur_cons(i,j,k,Rho_comp) = prev_cons(i,j,k,Rho_comp);
217  cur_cons(i,j,k,RhoTheta_comp) = prev_cons(i,j,k,RhoTheta_comp);
218  });
219  } // step = 0
220 
221  Box gtbx = mfi.grownnodaltilebox(0,IntVect(1,1,0));
222  Box gtby = mfi.grownnodaltilebox(1,IntVect(1,1,0));
223  Box gtbz = mfi.grownnodaltilebox(2,IntVect(1,1,0));
224 
225  const auto& bx_lo = lbound(bx);
226  const auto& bx_hi = ubound(bx);
227 
228  // *********************************************************************
229  // Populate "old" perturbations in momenta
230  // *********************************************************************
231  ParallelFor(gtbx, gtby, gtbz,
232  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
233  old_drho_u(i,j,k) = prev_xmom(i,j,k) - stage_xmom(i,j,k);
234  if (k == bx_lo.z && k != domlo.z) {
235  old_drho_u(i,j,k-1) = old_drho_u(i,j,k);
236  }
237  if (k == bx_hi.z) {
238  old_drho_u(i,j,k+1) = old_drho_u(i,j,k);
239  }
240  },
241  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
242  old_drho_v(i,j,k) = prev_ymom(i,j,k) - stage_ymom(i,j,k);
243  if (k == bx_lo.z && k != domlo.z) {
244  old_drho_v(i,j,k-1) = old_drho_v(i,j,k);
245  }
246  if (k == bx_hi.z) {
247  old_drho_v(i,j,k+1) = old_drho_v(i,j,k);
248  }
249  },
250  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
251  old_drho_w(i,j,k) = prev_zmom(i,j,k) - stage_zmom(i,j,k);
252  });
253 
254  // *********************************************************************
255  // Populate "old" perturbations in Rho & RhoTheta and lagged RhoTheta
256  // *********************************************************************
257  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
258  old_drho(i,j,k) = cur_cons(i,j,k,Rho_comp) - stage_cons(i,j,k,Rho_comp);
259  old_drho_theta(i,j,k) = cur_cons(i,j,k,RhoTheta_comp) - stage_cons(i,j,k,RhoTheta_comp);
260 
261  // Compute theta extrap for lateral momenta pressure gradient
262  if (step == 0) {
263  theta_extrap(i,j,k) = old_drho_theta(i,j,k);
264  } else {
265  theta_extrap(i,j,k) = old_drho_theta(i,j,k) + beta_d *
266  ( old_drho_theta(i,j,k) - lagged_arr(i,j,k) );
267  }
268 
269  // Convert to Theta_m
270  // NOTE: qv is not changing over the fast steps so we use the stage data
271  Real qv = (l_use_moisture) ? prim(i,j,k,PrimQ1_comp) : zero;
272  theta_extrap(i,j,k) *= (one + RvOverRd*qv);
273 
274  // Save Theta^{'',n-1} for theta extrap next substep
275  lagged_arr(i,j,k) = old_drho_theta(i,j,k);
276  });
277  } // mfi
278 
279  // *************************************************************************
280  // Define updates in the current RK stage
281  // *************************************************************************
282 #ifdef _OPENMP
283 #pragma omp parallel if (Gpu::notInLaunchRegion())
284 #endif
285  for ( MFIter mfi(S_stage_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi)
286  {
287  Box bx = mfi.validbox();
288  Box tbx = mfi.nodaltilebox(0);
289  Box tby = mfi.nodaltilebox(1);
290 
291  const Array4<Real const>& xmom_src_arr = xmom_src.const_array(mfi);
292  const Array4<Real const>& ymom_src_arr = ymom_src.const_array(mfi);
293 
294  const Array4<const Real> & stage_xmom = S_stage_data[IntVars::xmom].const_array(mfi);
295  const Array4<const Real> & stage_ymom = S_stage_data[IntVars::ymom].const_array(mfi);
296  const Array4<const Real> & qt_arr = qt.const_array(mfi);
297 
298  const Array4<Real>& old_drho_u = Delta_rho_u.array(mfi);
299  const Array4<Real>& old_drho_v = Delta_rho_v.array(mfi);
300 
301  const Array4<const Real>& slow_rhs_rho_u = S_slow_rhs[IntVars::xmom].const_array(mfi);
302  const Array4<const Real>& slow_rhs_rho_v = S_slow_rhs[IntVars::ymom].const_array(mfi);
303 
304  const Array4<Real>& new_drho_u = New_rho_u.array(mfi);
305  const Array4<Real>& new_drho_v = New_rho_v.array(mfi);
306 
307  const Array4<Real>& cur_xmom = S_data[IntVars::xmom].array(mfi);
308  const Array4<Real>& cur_ymom = S_data[IntVars::ymom].array(mfi);
309 
310  // These store the advection momenta which we will use to update the slow variables
311  const Array4<Real>& avg_xmom_arr = avg_xmom.array(mfi);
312  const Array4<Real>& avg_ymom_arr = avg_ymom.array(mfi);
313 
314  const Array4<const Real>& z_nd = z_phys_nd->const_array(mfi);
315  const Array4<const Real>& ax_arr = ax.const_array(mfi);
316  const Array4<const Real>& ay_arr = ay.const_array(mfi);
317 
318  const Array4<const Real>& pi_stage_ca = pi_stage.const_array(mfi);
319 
320  const Array4<Real>& theta_extrap = extrap.array(mfi);
321 
322  // Map factors
323  const Array4<const Real>& mf_ux = mapfac[MapFacType::u_x]->const_array(mfi);
324  const Array4<const Real>& mf_uy = mapfac[MapFacType::u_y]->const_array(mfi);
325  const Array4<const Real>& mf_vx = mapfac[MapFacType::v_x]->const_array(mfi);
326  const Array4<const Real>& mf_vy = mapfac[MapFacType::v_y]->const_array(mfi);
327 
328  // Create old_drho_u/v/w/theta = U'', V'', W'', Theta'' in the docs
329  // Note that we do the Copy and Subtract including one ghost cell
330  // so that we don't have to fill ghost cells of the new MultiFabs
331  // Initialize New_rho_u/v/w to Delta_rho_u/v/w so that
332  // the ghost cells in New_rho_u/v/w will match old_drho_u/v/w
333 
334  // *********************************************************************
335  // Explicit update for lateral momenta
336  // *********************************************************************
337  {
338  BL_PROFILE("substep_xymom_T");
339 
340  const auto& bx_lo = lbound(bx);
341  const auto& bx_hi = ubound(bx);
342 
343  ParallelFor(tbx, tby,
344  [=] AMREX_GPU_DEVICE (int i, int j, int k)
345  {
346  // Add (negative) gradient of (rho theta) multiplied by lagged "pi"
347  Real met_h_xi = Compute_h_xi_AtIface (i, j, k, dxInv, z_nd);
348  Real met_h_zeta = Compute_h_zeta_AtIface(i, j, k, dxInv, z_nd);
349  Real gp_xi = (theta_extrap(i,j,k) - theta_extrap(i-1,j,k)) * dxi;
350  Real gp_zeta_on_iface = (k == 0) ?
351  myhalf * dzi * ( theta_extrap(i-1,j,k+1) + theta_extrap(i,j,k+1)
352  - theta_extrap(i-1,j,k ) - theta_extrap(i,j,k ) ) :
353  fourth * dzi * ( theta_extrap(i-1,j,k+1) + theta_extrap(i,j,k+1)
354  - theta_extrap(i-1,j,k-1) - theta_extrap(i,j,k-1) );
355  Real gpx = (l_real_bc && (level==0) && (i==ilo || i==ihi)) ? Real(0.) :
356  gp_xi - (met_h_xi / met_h_zeta) * gp_zeta_on_iface;
357 
358  gpx *= mf_ux(i,j,0);
359 
360  Real q = (l_use_moisture) ? myhalf * (qt_arr(i,j,k) + qt_arr(i-1,j,k)) : zero;
361 
362  Real pi_c = myhalf * (pi_stage_ca(i-1,j,k,0) + pi_stage_ca(i ,j,k,0));
363  Real fast_rhs_rho_u = -Gamma * R_d * pi_c * gpx / (one + q);
364 
365  new_drho_u(i, j, k) = old_drho_u(i,j,k) + dtau * fast_rhs_rho_u
366  + dtau * slow_rhs_rho_u(i,j,k)
367  + dtau * xmom_src_arr(i,j,k);
368  if ((wall_xlo && i == ilo) || (wall_xhi && i == ihi)) {
369  new_drho_u(i,j,k) = zero;
370  }
371  if (k == bx_lo.z && k != domlo.z) {
372  new_drho_u(i,j,k-1) = new_drho_u(i,j,k);
373  }
374  if (k == bx_hi.z) {
375  new_drho_u(i,j,k+1) = new_drho_u(i,j,k);
376  }
377 
378  // The x-face area ax, as in the base value of avg_xmom defined in
379  // AdvectionSrcForRho (ax*rho_u/mf_uy) and in the density flux formed below.
380  // It is not recomputed from z_nd: below the finest level ax is the average of
381  // the finest mesh's areas (make_metrics_from_finest), not the area of this
382  // level's own nodes.
383  avg_xmom_arr(i,j,k) += facinv * new_drho_u(i,j,k) * ax_arr(i,j,k) / mf_uy(i,j,0);
384 
385  cur_xmom(i,j,k) = stage_xmom(i,j,k) + new_drho_u(i,j,k);
386  },
387  [=] AMREX_GPU_DEVICE (int i, int j, int k)
388  {
389  // Add (negative) gradient of (rho theta) multiplied by lagged "pi"
390  Real met_h_eta = Compute_h_eta_AtJface(i, j, k, dxInv, z_nd);
391  Real met_h_zeta = Compute_h_zeta_AtJface(i, j, k, dxInv, z_nd);
392  Real gp_eta = (theta_extrap(i,j,k) - theta_extrap(i,j-1,k)) * dyi;
393  Real gp_zeta_on_jface = (k == 0) ?
394  myhalf * dzi * ( theta_extrap(i,j,k+1) + theta_extrap(i,j-1,k+1)
395  - theta_extrap(i,j,k ) - theta_extrap(i,j-1,k ) ) :
396  fourth * dzi * ( theta_extrap(i,j,k+1) + theta_extrap(i,j-1,k+1)
397  - theta_extrap(i,j,k-1) - theta_extrap(i,j-1,k-1) );
398  Real gpy = (l_real_bc && (level==0) && (j==jlo || j==jhi)) ? Real(0.) :
399  gp_eta - (met_h_eta / met_h_zeta) * gp_zeta_on_jface;
400 
401  gpy *= mf_vy(i,j,0);
402 
403  Real q = (l_use_moisture) ? myhalf * (qt_arr(i,j,k) + qt_arr(i,j-1,k)) : zero;
404 
405  Real pi_c = myhalf * (pi_stage_ca(i,j-1,k,0) + pi_stage_ca(i,j ,k,0));
406  Real fast_rhs_rho_v = -Gamma * R_d * pi_c * gpy / (one + q);
407 
408  new_drho_v(i, j, k) = old_drho_v(i,j,k) + dtau * fast_rhs_rho_v
409  + dtau * slow_rhs_rho_v(i,j,k)
410  + dtau * ymom_src_arr(i,j,k);
411  if ((wall_ylo && j == jlo) || (wall_yhi && j == jhi)) {
412  new_drho_v(i,j,k) = zero;
413  }
414 
415  if (k == bx_lo.z && k != domlo.z) {
416  new_drho_v(i,j,k-1) = new_drho_v(i,j,k);
417  }
418  if (k == bx_hi.z) {
419  new_drho_v(i,j,k+1) = new_drho_v(i,j,k);
420  }
421 
422  // The y-face area ay, as for avg_xmom
423  avg_ymom_arr(i,j,k) += facinv * new_drho_v(i,j,k) * ay_arr(i,j,k) / mf_vx(i,j,0);
424 
425  cur_ymom(i,j,k) = stage_ymom(i,j,k) + new_drho_v(i,j,k);
426  });
427 
428  // On the coarse/fine faces of a fine level, the coarse level's flux over this
429  // substep (CFFaceFluxes) in place of the level's own; on a coarse level, record
430  // the flux each face applied. In both, the flux is ax (rho u)/m_uy (ay (rho v)/m_vx),
431  // the density flux formed below.
432  for (int dir = 0; dir < 2; ++dir) {
433  if (!cf_fluxes.tgt[dir] && !cf_fluxes.rec[dir]) { continue; }
434  const bool has_tgt = (cf_fluxes.tgt[dir] != nullptr);
435  const bool has_rec = (cf_fluxes.rec[dir] != nullptr);
436  const Box& fbx = (dir == 0) ? tbx : tby;
437  const Array4<const Real> tgt = (has_tgt) ? cf_fluxes.tgt[dir]->const_array(mfi) : Array4<const Real>{};
438  const Array4< Real> rec = (has_rec) ? cf_fluxes.rec[dir]->array(mfi) : Array4<Real>{};
439  const Array4<Real>& pert = (dir == 0) ? new_drho_u : new_drho_v;
440  const Array4<Real>& cur = (dir == 0) ? cur_xmom : cur_ymom;
441  const Array4<Real>& avg = (dir == 0) ? avg_xmom_arr : avg_ymom_arr;
442  const Array4<const Real>& stage = (dir == 0) ? stage_xmom : stage_ymom;
443  const Array4<const Real>& mf = (dir == 0) ? mf_uy : mf_vx;
444  const Array4<const Real>& area = (dir == 0) ? ax_arr : ay_arr;
445  ParallelFor(fbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
446  {
447  Real h_zeta = area(i,j,k);
448  if (has_tgt && tgt(i,j,k,1) > myhalf) {
449  Real new_pert = tgt(i,j,k,0) * mf(i,j,0) / h_zeta - stage(i,j,k);
450  avg(i,j,k) += facinv * (new_pert - pert(i,j,k)) * h_zeta / mf(i,j,0);
451  pert(i,j,k) = new_pert;
452  if (k == bx_lo.z && k != domlo.z) {
453  pert(i,j,k-1) = new_pert;
454  } else if (k == bx_hi.z) {
455  pert(i,j,k+1) = new_pert;
456  }
457  cur(i,j,k) = stage(i,j,k) + new_pert;
458  }
459  if (has_rec) {
460  rec(i,j,k) = (stage(i,j,k) + pert(i,j,k)) * h_zeta / mf(i,j,0);
461  }
462  });
463  }
464  } // end profile
465  }
466 
467 #ifdef _OPENMP
468 #pragma omp parallel if (Gpu::notInLaunchRegion())
469 #endif
470  {
471  std::array<FArrayBox,AMREX_SPACEDIM> flux;
472  for ( MFIter mfi(S_stage_data[IntVars::cons],TileNoZ()); mfi.isValid(); ++mfi)
473  {
474  Box bx = mfi.tilebox();
475  Box tbz = surroundingNodes(bx,2);
476 
477  Box vbx = mfi.validbox();
478  const auto& vbx_hi = ubound(vbx);
479 
480  // The flux arrays cover the faces of the tile, so the faces on its high sides are
481  // written by the cells at the high end of the tile, not of the valid box
482  const auto& bx_hi = ubound(bx);
483 
484  const Array4<Real const>& zmom_src_arr = zmom_src.const_array(mfi);
485  const Array4<Real const>& cc_src_arr = cc_src.const_array(mfi);
486 
487  const Array4<const Real> & stage_xmom = S_stage_data[IntVars::xmom].const_array(mfi);
488  const Array4<const Real> & stage_ymom = S_stage_data[IntVars::ymom].const_array(mfi);
489  const Array4<const Real> & stage_zmom = S_stage_data[IntVars::zmom].const_array(mfi);
490  const Array4<const Real> & prim = S_stage_prim.const_array(mfi);
491 
492  const Array4<Real>& old_drho_u = Delta_rho_u.array(mfi);
493  const Array4<Real>& old_drho_v = Delta_rho_v.array(mfi);
494  const Array4<Real>& old_drho_w = Delta_rho_w.array(mfi);
495  const Array4<Real>& old_drho = Delta_rho.array(mfi);
496  const Array4<Real>& old_drho_theta = Delta_rho_theta.array(mfi);
497 
498  const Array4<const Real>& slow_rhs_cons = S_slow_rhs[IntVars::cons].const_array(mfi);
499  const Array4<const Real>& slow_rhs_rho_w = S_slow_rhs[IntVars::zmom].const_array(mfi);
500 
501  const Array4<Real>& new_drho_u = New_rho_u.array(mfi);
502  const Array4<Real>& new_drho_v = New_rho_v.array(mfi);
503 
504  const Array4<Real>& cur_cons = S_data[IntVars::cons].array(mfi);
505  const Array4<Real>& cur_zmom = S_data[IntVars::zmom].array(mfi);
506 
507  // These store the advection momenta which we will use to update the slow variables
508  const Array4<Real>& avg_zmom_arr = avg_zmom.array(mfi);
509 
510  const Array4<const Real>& z_nd = z_phys_nd->const_array(mfi);
511  const Array4<const Real>& detJ = detJ_cc->const_array(mfi);
512  const Array4<const Real>& ax_arr = ax.const_array(mfi);
513  const Array4<const Real>& ay_arr = ay.const_array(mfi);
514 
515  const Array4< Real>& omega_arr = Omega.array(mfi);
516 
517  // Map factors
518  const Array4<const Real>& mf_mx = mapfac[MapFacType::m_x]->const_array(mfi);
519  const Array4<const Real>& mf_my = mapfac[MapFacType::m_y]->const_array(mfi);
520  const Array4<const Real>& mf_ux = mapfac[MapFacType::u_x]->const_array(mfi);
521  const Array4<const Real>& mf_uy = mapfac[MapFacType::u_y]->const_array(mfi);
522  const Array4<const Real>& mf_vx = mapfac[MapFacType::v_x]->const_array(mfi);
523  const Array4<const Real>& mf_vy = mapfac[MapFacType::v_y]->const_array(mfi);
524 
525  // Create old_drho_u/v/w/theta = U'', V'', W'', Theta'' in the docs
526  // Note that we do the Copy and Subtract including one ghost cell
527  // so that we don't have to fill ghost cells of the new MultiFabs
528  // Initialize New_rho_u/v/w to Delta_rho_u/v/w so that
529  // the ghost cells in New_rho_u/v/w will match old_drho_u/v/w
530 
531  FArrayBox temp_rhs_fab;
532  FArrayBox RHS_fab;
533  FArrayBox soln_fab;
534 
535  RHS_fab.resize (tbz,1,The_Async_Arena());
536  soln_fab.resize (tbz,1,The_Async_Arena());
537  temp_rhs_fab.resize(tbz,2,The_Async_Arena());
538 
539  auto const& RHS_a = RHS_fab.array();
540  auto const& soln_a = soln_fab.array();
541  auto const& temp_rhs_arr = temp_rhs_fab.array();
542 
543  auto const& coeffA_a = coeff_A_mf.array(mfi);
544  auto const& inv_coeffB_a = inv_coeff_B_mf.array(mfi);
545  auto const& coeffC_a = coeff_C_mf.array(mfi);
546  auto const& coeffP_a = coeff_P_mf.array(mfi);
547  auto const& coeffQ_a = coeff_Q_mf.array(mfi);
548  auto const& beta_s_a = beta_s_mf.const_array(mfi);
549 
550  // *************************************************************************
551  // Define flux arrays for use in advection
552  // *************************************************************************
553  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
554  flux[dir].resize(surroundingNodes(bx,dir),2,The_Async_Arena());
555  flux[dir].setVal<RunOn::Device>(0);
556  }
557  const GpuArray<const Array4<Real>, AMREX_SPACEDIM>
558  flx_arr{{AMREX_D_DECL(flux[0].array(), flux[1].array(), flux[2].array())}};
559 
560  // *********************************************************************
561  // Lateral Advection RHS for Rho & RhoTheta
562  // *********************************************************************
563  {
564  BL_PROFILE("fast_T_making_rho_rhs");
565  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
566  // The lateral face areas ax and ay, the ones the slow advection and avg_xmom and
567  // avg_ymom use, so that every flux through a face sees the same area
568  Real xflux_lo = new_drho_u(i ,j,k)*ax_arr(i ,j,k) / mf_uy(i ,j,0);
569  Real xflux_hi = new_drho_u(i+1,j,k)*ax_arr(i+1,j,k) / mf_uy(i+1,j,0);
570  Real yflux_lo = new_drho_v(i,j ,k)*ay_arr(i,j ,k) / mf_vx(i,j ,0);
571  Real yflux_hi = new_drho_v(i,j+1,k)*ay_arr(i,j+1,k) / mf_vx(i,j+1,0);
572 
573  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
574 
575  // NOTE: we are saving the (1/J) weighting for later when we add this to rho and theta
576  temp_rhs_arr(i,j,k,0) = ( xflux_hi - xflux_lo ) * dxi * mfsq +
577  ( yflux_hi - yflux_lo ) * dyi * mfsq;
578  temp_rhs_arr(i,j,k,1) = (( xflux_hi * (prim(i,j,k,0) + prim(i+1,j,k,0)) -
579  xflux_lo * (prim(i,j,k,0) + prim(i-1,j,k,0)) ) * dxi * mfsq+
580  ( yflux_hi * (prim(i,j,k,0) + prim(i,j+1,k,0)) -
581  yflux_lo * (prim(i,j,k,0) + prim(i,j-1,k,0)) ) * dyi * mfsq) * myhalf;
582 
583  if (l_reflux) {
584  (flx_arr[0])(i,j,k,0) = xflux_lo;
585  (flx_arr[0])(i,j,k,1) = (flx_arr[0])(i ,j,k,0) * myhalf * (prim(i,j,k,0) + prim(i-1,j,k,0));
586 
587  (flx_arr[1])(i,j,k,0) = yflux_lo;
588  (flx_arr[1])(i,j,k,1) = (flx_arr[1])(i,j ,k,0) * myhalf * (prim(i,j,k,0) + prim(i,j-1,k,0));
589 
590  if (i == bx_hi.x) {
591  (flx_arr[0])(i+1,j,k,0) = xflux_hi;
592  (flx_arr[0])(i+1,j,k,1) = (flx_arr[0])(i+1,j,k,0) * myhalf * (prim(i,j,k,0) + prim(i+1,j,k,0));
593  }
594  if (j == bx_hi.y) {
595  (flx_arr[1])(i,j+1,k,0) = yflux_hi;
596  (flx_arr[1])(i,j+1,k,1) = (flx_arr[1])(i,j+1,k,0) * myhalf * (prim(i,j,k,0) + prim(i,j+1,k,0));
597  }
598  }
599  });
600  }
601 
602  // *********************************************************************
603  // Populate "old" Omega
604  // *********************************************************************
605  // NOTE: this must stay in a separate MFIter loop from the one that fills
606  // old_drho_u/v, since OmegaFromW reads old_drho_u/v at (i+1, j+1, k-1),
607  // which another tile fills when the grid is tiled under OpenMP
608  {
609  Box gbxo = mfi.nodaltilebox(2);
610  Box gbxo_mid = gbxo;
611 
612  if (gbxo.smallEnd(2) == domlo.z) {
613  Box gbxo_lo = gbxo; gbxo_lo.setBig(2,gbxo.smallEnd(2));
614  gbxo_mid.setSmall(2,gbxo.smallEnd(2)+1);
615  ParallelFor(gbxo_lo, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
616  omega_arr(i,j,k) = zero;
617  });
618  }
619  if (gbxo.bigEnd(2) == domhi.z+1) {
620  Box gbxo_hi = gbxo; gbxo_hi.setSmall(2,gbxo.bigEnd(2));
621  gbxo_mid.setBig(2,gbxo.bigEnd(2)-1);
622  ParallelFor(gbxo_hi, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
623  omega_arr(i,j,k) = old_drho_w(i,j,k);
624  });
625  }
626  ParallelFor(gbxo_mid, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
627  omega_arr(i,j,k) = OmegaFromW(i,j,k,old_drho_w(i,j,k),
628  old_drho_u,old_drho_v,
629  mf_ux,mf_vy,z_nd,dxInv);
630  });
631  }
632 
633  // *********************************************************************
634  // Build RHS for tridiagonal system
635  // *********************************************************************
636  // NOTE: we don't act on the bottom or top boundaries of the domain
637  Box bx_shrunk_in_k = bx;
638  int klo = tbz.smallEnd(2);
639  int khi = tbz.bigEnd(2);
640  bx_shrunk_in_k.setSmall(2,klo+1);
641  bx_shrunk_in_k.setBig(2,khi-1);
642 
643  // Note that the notes use "g" to mean the magnitude of gravity, so it is positive
644  // We set grav_gpu[2] to be the vector component which is negative
645  // We define halfg to match the notes (which is why we take the absolute value)
646  Real halfg = std::abs(myhalf * grav_gpu[2]);
647 
648  {
649  BL_PROFILE("fast_loop_on_shrunk_t");
650  ParallelFor(bx_shrunk_in_k, [=] AMREX_GPU_DEVICE (int i, int j, int k)
651  {
652  Real coeff_P = coeffP_a(i,j,k);
653  Real coeff_Q = coeffQ_a(i,j,k);
654 
655  Real theta_t_lo = myhalf * ( prim(i,j,k-2,PrimTheta_comp) + prim(i,j,k-1,PrimTheta_comp) );
656  Real theta_t_mid = myhalf * ( prim(i,j,k-1,PrimTheta_comp) + prim(i,j,k ,PrimTheta_comp) );
657  Real theta_t_hi = myhalf * ( prim(i,j,k ,PrimTheta_comp) + prim(i,j,k+1,PrimTheta_comp) );
658 
659  // line 2 last two terms (order dtau)
660  Real R0_tmp = -halfg * old_drho(i,j,k ) + coeff_P * old_drho_theta(i,j,k )
661  -halfg * old_drho(i,j,k-1) + coeff_Q * old_drho_theta(i,j,k-1);
662 
663  // line 3 residuals (order dtau^2) one <-> beta_2
664  Real R1_tmp = -halfg * ( slow_rhs_cons(i,j,k ,Rho_comp) + slow_rhs_cons(i,j,k-1,Rho_comp) );
665 
666  R1_tmp += coeff_P * slow_rhs_cons(i,j,k ,RhoTheta_comp)
667  + coeff_Q * slow_rhs_cons(i,j,k-1,RhoTheta_comp);
668 
669  Real Omega_kp1 = omega_arr(i,j,k+1);
670  Real Omega_k = omega_arr(i,j,k );
671  Real Omega_km1 = omega_arr(i,j,k-1);
672 
673  // Explicit part of the vertical flux on each face is beta_1 * Omega. beta_1 on face k
674  // is factored out, and dbeta_1 is how much larger beta_1 is on the neighboring faces,
675  // which is exactly zero (so the roundoff is that of a scalar beta_1) for uniform beta_s
676  Real beta_1 = myhalf * (one - beta_s_a(i,j,k));
677  Real dbeta_1_kp1 = myhalf * (one - beta_s_a(i,j,k+1)) - beta_1;
678  Real dbeta_1_km1 = myhalf * (one - beta_s_a(i,j,k-1)) - beta_1;
679 
680  Real detJdiff = (detJ(i,j,k) - detJ(i,j,k-1)) / (detJ(i,j,k)*detJ(i,j,k-1));
681 
682  // consolidate lines 4&5 (order dtau^2)
683  R1_tmp += halfg * ( beta_1 * dzi * (Omega_kp1/detJ(i,j,k) + detJdiff*Omega_k - Omega_km1/detJ(i,j,k-1))
684  + dzi * (dbeta_1_kp1*Omega_kp1/detJ(i,j,k) - dbeta_1_km1*Omega_km1/detJ(i,j,k-1))
685  + temp_rhs_arr(i,j,k,Rho_comp)/detJ(i,j,k) + temp_rhs_arr(i,j,k-1,Rho_comp)/detJ(i,j,k-1) );
686 
687  // consolidate lines 6&7 (order dtau^2)
688  R1_tmp += -( coeff_P/detJ(i,j,k ) * ( beta_1 * dzi * (Omega_kp1*theta_t_hi - Omega_k*theta_t_mid) + dzi * dbeta_1_kp1*Omega_kp1*theta_t_hi + temp_rhs_arr(i,j,k ,RhoTheta_comp) )
689  + coeff_Q/detJ(i,j,k-1) * ( beta_1 * dzi * (Omega_k*theta_t_mid - Omega_km1*theta_t_lo) - dzi * dbeta_1_km1*Omega_km1*theta_t_lo + temp_rhs_arr(i,j,k-1,RhoTheta_comp) ) );
690 
691  // consolidate terms proportional to dtau
692  Real beta_2 = myhalf * (one + beta_s_a(i,j,k));
693  RHS_a(i,j,k) = dtau * (slow_rhs_rho_w(i,j,k) + zmom_src_arr(i,j,k) + R0_tmp + dtau*beta_2*R1_tmp);
694 
695  // We cannot use omega_arr here since that was built with old_rho_u and old_rho_v ...
696  RHS_a(i,j,k) += old_drho_w(i,j,k) + OmegaFromW(i,j,k,zero,
697  new_drho_u,new_drho_v,
698  mf_ux,mf_vy,z_nd,dxInv);
699  });
700  } // end profile
701 
702  // *********************************************************************
703  // Solve tridiagonal system
704  // *********************************************************************
705  Box b2d = tbz;
706  b2d.setRange(2,0);
707  auto const lo = lbound(bx);
708  auto const hi = ubound(bx);
709 
710  // The coarse/fine face data (CFFaceFluxes) are in Omega, which is the full Omega of the
711  // stage -- built as in erf_slow_rhs_pre, zero at the bottom of the domain and (rho w) at
712  // its top -- plus the Omega'' of the solve
713  const bool has_tgt_z = (cf_fluxes.tgt[2] != nullptr);
714  const bool has_rec_z = (cf_fluxes.rec[2] != nullptr);
715  const Array4<const Real> tgt_z = (has_tgt_z) ? cf_fluxes.tgt[2]->const_array(mfi) : Array4<const Real>{};
716  const Array4<const Real> tgt_om = (has_tgt_z) ? cf_fluxes.tgt_w->const_array(mfi) : Array4<const Real>{};
717  const Array4< Real> rec_z = (has_rec_z) ? cf_fluxes.rec[2]->array(mfi) : Array4<Real>{};
718  const Array4< Real> rec_om = (has_rec_z) ? cf_fluxes.rec_w->array(mfi) : Array4<Real>{};
719  const bool has_rec_z_old = (cf_fluxes.rec_w_old != nullptr);
720  const Array4< Real> rec_om_old = (has_rec_z_old) ? cf_fluxes.rec_w_old->array(mfi) : Array4<Real>{};
721  const int dklo = domlo.z;
722  const int dkhi = domhi.z;
723 #define CF_OMEGA_STAGE(I,J,K) cf_omega_stage(I,J,K,dklo,dkhi,stage_zmom,stage_xmom,stage_ymom,mf_ux,mf_vy,z_nd,dxInv)
724 
725  {
726  BL_PROFILE("substep_b2d_loop_t");
727 
728  // NOTE: RHS is built on a shrunk box in z, explicitly set
729  // the lo and hi faces here
730  // On a box face inside the domain (a c/f face) the row carries the accumulated
731  // perturbation converted to Omega'', as in the interior rows. At the domain bottom
732  // and top the row is zero: Omega'' = 0 at the ground and at a wall, and
733  // Omega''_top = Omega''_top-1 for outflow, the matrix row set in make_fast_coeffs
734  // deciding which
735  ParallelFor(b2d, [=] AMREX_GPU_DEVICE (int i, int j, int)
736  {
737  // OmegaFromW takes its indices by non-const reference, hence the copies
738  int kf_lo = lo.z;
739  int kf_hi = hi.z+1;
740  RHS_a(i,j,lo.z ) = (lo.z == domlo.z)
741  ? zero
742  : old_drho_w(i,j,lo.z ) + OmegaFromW(i,j,kf_lo,zero,
743  new_drho_u,new_drho_v,
744  mf_ux,mf_vy,z_nd,dxInv)
745  + dtau * slow_rhs_rho_w(i,j,lo.z )
746  + dtau * zmom_src_arr(i,j,lo.z );
747  RHS_a(i,j,hi.z+1) = (hi.z == domhi.z)
748  ? zero
749  : old_drho_w(i,j,hi.z+1) + OmegaFromW(i,j,kf_hi,zero,
750  new_drho_u,new_drho_v,
751  mf_ux,mf_vy,z_nd,dxInv)
752  + dtau * slow_rhs_rho_w(i,j,hi.z+1)
753  + dtau * zmom_src_arr(i,j,hi.z+1);
754 
755  // On the coarse/fine faces of a fine level, Omega'' from the coarse level's record
756  if (has_tgt_z) {
757  if (tgt_z(i,j,lo.z ,1) > myhalf) { RHS_a(i,j,lo.z ) = tgt_om(i,j,lo.z ) - CF_OMEGA_STAGE(i,j,lo.z ); }
758  if (tgt_z(i,j,hi.z+1,1) > myhalf) { RHS_a(i,j,hi.z+1) = tgt_om(i,j,hi.z+1) - CF_OMEGA_STAGE(i,j,hi.z+1); }
759  }
760  });
761 
762 #ifdef AMREX_USE_GPU
763  ParallelFor(b2d, [=] AMREX_GPU_DEVICE (int i, int j, int)
764  {
765  // First row (coeffA = coeffC = 0) at k = lo.z
766  soln_a(i,j,lo.z) = RHS_a(i,j,lo.z) * inv_coeffB_a(i,j,lo.z);
767 
768  // Transform the RHS from r_i -> rho_i
769  for (int k = lo.z+1; k <= hi.z+1; k++) {
770  soln_a(i,j,k) = (RHS_a(i,j,k)-coeffA_a(i,j,k)*soln_a(i,j,k-1)) * inv_coeffB_a(i,j,k);
771  }
772 
773  // Back sweep to obtain the solution
774  for (int k = hi.z; k >= lo.z; k--) {
775  soln_a(i,j,k) -= ( coeffC_a(i,j,k) * inv_coeffB_a(i,j,k) ) *soln_a(i,j,k+1);
776  }
777  });
778 #else
779  // First row (coeffA = coeffC = 0) at k = lo.z
780  for (int j = lo.y; j <= hi.y; ++j) {
781  AMREX_PRAGMA_SIMD
782  for (int i = lo.x; i <= hi.x; ++i) {
783  soln_a(i,j,lo.z) = RHS_a(i,j,lo.z) * inv_coeffB_a(i,j,lo.z);
784  }
785  }
786 
787  // Transform the RHS from r_i -> rho_i
788  // NOTE: this must include k = hi.z+1 so that the top row picks up the sub-diagonal
789  // term, which is non-zero when the top of the domain is an outflow boundary
790  for (int k = lo.z+1; k <= hi.z+1; ++k) {
791  for (int j = lo.y; j <= hi.y; ++j) {
792  AMREX_PRAGMA_SIMD
793  for (int i = lo.x; i <= hi.x; ++i) {
794  soln_a(i,j,k) = (RHS_a(i,j,k)-coeffA_a(i,j,k)*soln_a(i,j,k-1)) * inv_coeffB_a(i,j,k);
795  }
796  }
797  }
798 
799  // Back sweep to obtain the solution
800  for (int k = hi.z; k >= lo.z; --k) {
801  for (int j = lo.y; j <= hi.y; ++j) {
802  AMREX_PRAGMA_SIMD
803  for (int i = lo.x; i <= hi.x; ++i) {
804  soln_a(i,j,k) -= ( coeffC_a(i,j,k) * inv_coeffB_a(i,j,k) ) * soln_a(i,j,k+1);
805  }
806  }
807  }
808 #endif
809  } // end profile
810 
811  // *********************************************************************
812  // Convert from Omega to W
813  // *********************************************************************
814  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
815  {
816  // NOTE: WfromOmega uses an interior stencil at domlo.z to touch valid data
817  // WfromOmega cannot be used at domhi.z+1 for outflow. We enforce
818  // zero metric terms at the domain high (W'' = Omega'')
819  Real wpp;
820  if (k == domhi.z+1) {
821  wpp = soln_a(i,j,k);
822  } else {
823  wpp = WFromOmega(i,j,k,soln_a(i,j,k),
824  new_drho_u,new_drho_v,
825  mf_ux,mf_vy,z_nd,dxInv);
826  }
827 
828  cur_zmom(i,j,k) = stage_zmom(i,j,k) + wpp;
829 
830  // W at the ground is kinematic and is not damped; the top face is, since with
831  // outflow it is no longer pinned to the stage value. A coarse/fine face whose
832  // value is imposed from the coarse level's record is not damped either: the coarse
833  // level has damped it already, and it must match the record
834  const bool imposed = has_tgt_z && (tgt_z(i,j,k,1) > myhalf);
835  if (k > domlo.z && !imposed && l_rayleigh_impl_for_w) {
836  Real damping_coeff = l_damp_coef * dtau * sinesq_stag_d[k];
837  cur_zmom(i,j,k) /= (one + damping_coeff);
838  }
839  });
840 
841  // **************************************************************************
842  // Update Rho & RhoTheta with lateral and vertical advection
843  // **************************************************************************
844  {
845  BL_PROFILE("fast_rho_final_update");
846  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
847  {
848  Real zflux_lo = myhalf * (one + beta_s_a(i,j,k )) * soln_a(i,j,k )
849  + myhalf * (one - beta_s_a(i,j,k )) * omega_arr(i,j,k );
850  Real zflux_hi = myhalf * (one + beta_s_a(i,j,k+1)) * soln_a(i,j,k+1)
851  + myhalf * (one - beta_s_a(i,j,k+1)) * omega_arr(i,j,k+1);
852 
853  // On the coarse/fine faces of a fine level, the coarse level's flux over this substep
854  if (has_tgt_z) {
855  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
856  if (tgt_z(i,j,k ,1) > myhalf) { zflux_lo = tgt_z(i,j,k ,0) * mfsq - CF_OMEGA_STAGE(i,j,k ); }
857  if (tgt_z(i,j,k+1,1) > myhalf) { zflux_hi = tgt_z(i,j,k+1,0) * mfsq - CF_OMEGA_STAGE(i,j,k+1); }
858  }
859 
860  // On a coarse level, the flux each face applied over this substep, and Omega at
861  // its end (and at its start when asked)
862  if (has_rec_z) {
863  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
864  Real om_k = CF_OMEGA_STAGE(i,j,k);
865  rec_z (i,j,k) = (zflux_lo + om_k) / mfsq;
866  rec_om(i,j,k) = om_k + soln_a(i,j,k);
867  if (has_rec_z_old) { rec_om_old(i,j,k) = om_k + omega_arr(i,j,k); }
868  if (k == vbx_hi.z) {
869  Real om_kp1 = CF_OMEGA_STAGE(i,j,k+1);
870  rec_z (i,j,k+1) = (zflux_hi + om_kp1) / mfsq;
871  rec_om(i,j,k+1) = om_kp1 + soln_a(i,j,k+1);
872  if (has_rec_z_old) { rec_om_old(i,j,k+1) = om_kp1 + omega_arr(i,j,k+1); }
873  }
874  }
875 
876  // avg_zmom at k=vbx_hi.z+1 is updated by the top cell of the box; the
877  // perturbation there is zero at a wall but not at an outflow top or a c/f face
878  avg_zmom_arr(i,j,k) += facinv*zflux_lo / (mf_mx(i,j,0) * mf_my(i,j,0));
879  if (l_reflux) {
880  (flx_arr[2])(i,j,k,0) = zflux_lo / (mf_mx(i,j,0) * mf_my(i,j,0));
881  }
882 
883  if (k == vbx_hi.z) {
884  avg_zmom_arr(i,j,k+1) += facinv * zflux_hi / (mf_mx(i,j,0) * mf_my(i,j,0));
885  if (l_reflux) {
886  (flx_arr[2])(i,j,k+1,0) = zflux_hi / (mf_mx(i,j,0) * mf_my(i,j,0));
887  (flx_arr[2])(i,j,k+1,1) = (flx_arr[2])(i,j,k+1,0) * myhalf * (prim(i,j,k) + prim(i,j,k+1));
888  }
889  }
890 
891  Real fast_rhs_rho = -(temp_rhs_arr(i,j,k,0) + ( zflux_hi - zflux_lo ) * dzi) / detJ(i,j,k);
892 
893  cur_cons(i,j,k,0) += dtau * (slow_rhs_cons(i,j,k,0) + fast_rhs_rho);
894 
895  Real fast_rhs_rhotheta = -( temp_rhs_arr(i,j,k,1) + myhalf *
896  ( zflux_hi * (prim(i,j,k) + prim(i,j,k+1)) -
897  zflux_lo * (prim(i,j,k) + prim(i,j,k-1)) ) * dzi ) / detJ(i,j,k);
898 
899  cur_cons(i,j,k,1) += dtau * (slow_rhs_cons(i,j,k,1) + fast_rhs_rhotheta);
900 
901  if (l_reflux) {
902  (flx_arr[2])(i,j,k,1) = (flx_arr[2])(i,j,k,0) * myhalf * (prim(i,j,k) + prim(i,j,k-1));
903  }
904 
905  // add in source terms for cell-centered conserved variables
906  cur_cons(i,j,k,Rho_comp) += dtau * cc_src_arr(i,j,k,Rho_comp);
907  cur_cons(i,j,k,RhoTheta_comp) += dtau * cc_src_arr(i,j,k,RhoTheta_comp);
908  });
909  } // end profile
910 
911  // We only add to the flux registers in the final RK step
912  if (l_reflux) {
913  int strt_comp_reflux = 0;
914  // rho and (rho theta); only (rho theta) is refluxed (see ERF::post_timestep), since the
915  // coarse/fine faces of a fine level carry the coarse mass flux (CFFaceFluxes)
916  int num_comp_reflux = 2;
917  if (level < finest_level) {
918  fr_as_crse->CrseAdd(mfi,
919  {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
920  dx, dtau, strt_comp_reflux, strt_comp_reflux, num_comp_reflux, RunOn::Device);
921  }
922  if (level > 0) {
923  fr_as_fine->FineAdd(mfi,
924  {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
925  dx, dtau, strt_comp_reflux, strt_comp_reflux, num_comp_reflux, RunOn::Device);
926  }
927 
928  // This is necessary here so we don't go on to the next FArrayBox without
929  // having finished copying the fluxes into the FluxRegisters (since the fluxes
930  // are stored in temporary FArrayBox's)
931  Gpu::streamSynchronize();
932 
933  } // two-way coupling
934 #undef CF_OMEGA_STAGE
935  } // mfi
936  } // OMP
937 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
constexpr amrex::Real R_v
Definition: ERF_Constants.H:50
constexpr amrex::Real R_d
Definition: ERF_Constants.H:49
constexpr amrex::Real Gamma
Definition: ERF_Constants.H:70
@ v_x
Definition: ERF_DataStruct.H:40
@ u_y
Definition: ERF_DataStruct.H:41
@ v_y
Definition: ERF_DataStruct.H:41
@ m_y
Definition: ERF_DataStruct.H:41
@ u_x
Definition: ERF_DataStruct.H:40
@ m_x
Definition: ERF_DataStruct.H:40
#define PrimQ1_comp
Definition: ERF_IndexDefines.H:94
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define PrimTheta_comp
Definition: ERF_IndexDefines.H:91
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
const int klo
Definition: ERF_InitCustomPert_KE.H:9
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);})
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
#define CF_OMEGA_STAGE(I, J, K)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_eta_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:397
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:281
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_ux, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv)
Definition: ERF_TerrainMetrics.H:802
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:351
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_xi_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:304
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ gpy
Definition: ERF_IndexDefines.H:242
@ gpx
Definition: ERF_IndexDefines.H:241
@ ymom
Definition: ERF_IndexDefines.H:251
@ cons
Definition: ERF_IndexDefines.H:249
@ zmom
Definition: ERF_IndexDefines.H:252
@ xmom
Definition: ERF_IndexDefines.H:250
@ qt
Definition: ERF_Kessler.H:30
@ qv
Definition: ERF_Kessler.H:31
@ q
Definition: ERF_WSM6.H:296
std::array< amrex::MultiFab *, AMREX_SPACEDIM > rec
Definition: ERF_TI_fast_headers.H:29
amrex::MultiFab * rec_w
Definition: ERF_TI_fast_headers.H:30
const amrex::MultiFab * tgt_w
Definition: ERF_TI_fast_headers.H:33
std::array< const amrex::MultiFab *, AMREX_SPACEDIM > tgt
Definition: ERF_TI_fast_headers.H:32
amrex::MultiFab * rec_w_old
Definition: ERF_TI_fast_headers.H:31
Here is the call graph for this function: