ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_Substep_T.cpp File Reference
Include dependency graph for ERF_Substep_T.cpp:

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 double dtau_d, const Real beta_s, 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)
 

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 double  dtau_d,
const Real  beta_s,
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 
)

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
[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]dtaufast time step
[in]beta_sCoefficient which determines how implicit vs explicit the solve is
[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_damp_coef
75 {
76  BL_PROFILE_REGION("erf_substep_T()");
77 
78  Real dtau = static_cast<Real>(dtau_d);
79 
80  const Box& domain = geom.Domain();
81  auto const domlo = lbound(domain);
82  auto const domhi = ubound(domain);
83 
84  int ilo = domlo.x;
85  int ihi = domhi.x + 1;
86  int jlo = domlo.y;
87  int jhi = domhi.y + 1;
88 
89  Real beta_1 = myhalf * (one - beta_s); // multiplies explicit terms
90  Real beta_2 = myhalf * (one + beta_s); // multiplies implicit terms
91 
92  // How much do we project forward the (rho theta) that is used in the horizontal momentum equations
93  Real beta_d = Real(0.1);
94 
95  Real RvOverRd = R_v / R_d;
96 
97  bool l_rayleigh_impl_for_w = (sinesq_stag_d != nullptr);
98 
99  const Real* dx = geom.CellSize();
100  const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
101 
102  Real dxi = dxInv[0];
103  Real dyi = dxInv[1];
104  Real dzi = dxInv[2];
105  const auto& ba = S_stage_data[IntVars::cons].boxArray();
106  const auto& dm = S_stage_data[IntVars::cons].DistributionMap();
107 
108  MultiFab Delta_rho_u( convert(ba,IntVect(1,0,0)), dm, 1, 1);
109  MultiFab Delta_rho_v( convert(ba,IntVect(0,1,0)), dm, 1, 1);
110  MultiFab Delta_rho_w( convert(ba,IntVect(0,0,1)), dm, 1, IntVect(1,1,0));
111  MultiFab Delta_rho ( ba , dm, 1, 1);
112  MultiFab Delta_rho_theta( ba , dm, 1, 1);
113 
114  MultiFab New_rho_u(convert(ba,IntVect(1,0,0)), dm, 1, 1);
115  MultiFab New_rho_v(convert(ba,IntVect(0,1,0)), dm, 1, 1);
116 
117  MultiFab coeff_A_mf(fast_coeffs, make_alias, 0, 1);
118  MultiFab inv_coeff_B_mf(fast_coeffs, make_alias, 1, 1);
119  MultiFab coeff_C_mf(fast_coeffs, make_alias, 2, 1);
120  MultiFab coeff_P_mf(fast_coeffs, make_alias, 3, 1);
121  MultiFab coeff_Q_mf(fast_coeffs, make_alias, 4, 1);
122 
123  // *************************************************************************
124  // Set gravity as a vector
125  const Array<Real,AMREX_SPACEDIM> grav{zero, zero, -gravity};
126  const GpuArray<Real,AMREX_SPACEDIM> grav_gpu{grav[0], grav[1], grav[2]};
127 
128  MultiFab extrap(S_data[IntVars::cons].boxArray(),S_data[IntVars::cons].DistributionMap(),1,1);
129 
130  // *************************************************************************
131  // First set up some arrays we'll need
132  // *************************************************************************
133 
134 #ifdef _OPENMP
135 #pragma omp parallel if (Gpu::notInLaunchRegion())
136 #endif
137  for ( MFIter mfi(S_stage_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi)
138  {
139  const Array4<Real> & cur_cons = S_data[IntVars::cons].array(mfi);
140  const Array4<const Real>& prev_cons = S_prev[IntVars::cons].const_array(mfi);
141  const Array4<const Real>& stage_cons = S_stage_data[IntVars::cons].const_array(mfi);
142  const Array4<Real>& lagged_arr = lagged_delta_rt.array(mfi);
143 
144  const Array4<Real>& old_drho = Delta_rho.array(mfi);
145  const Array4<Real>& old_drho_u = Delta_rho_u.array(mfi);
146  const Array4<Real>& old_drho_v = Delta_rho_v.array(mfi);
147  const Array4<Real>& old_drho_w = Delta_rho_w.array(mfi);
148  const Array4<Real>& old_drho_theta = Delta_rho_theta.array(mfi);
149 
150  const Array4<const Real>& prev_xmom = S_prev[IntVars::xmom].const_array(mfi);
151  const Array4<const Real>& prev_ymom = S_prev[IntVars::ymom].const_array(mfi);
152  const Array4<const Real>& prev_zmom = S_prev[IntVars::zmom].const_array(mfi);
153 
154  const Array4<const Real>& stage_xmom = S_stage_data[IntVars::xmom].const_array(mfi);
155  const Array4<const Real>& stage_ymom = S_stage_data[IntVars::ymom].const_array(mfi);
156  const Array4<const Real>& stage_zmom = S_stage_data[IntVars::zmom].const_array(mfi);
157 
158  Box bx = mfi.validbox();
159  Box gbx = mfi.tilebox(); gbx.grow(1);
160 
161  if (step == 0) {
162  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
163  cur_cons(i,j,k,Rho_comp) = prev_cons(i,j,k,Rho_comp);
164  cur_cons(i,j,k,RhoTheta_comp) = prev_cons(i,j,k,RhoTheta_comp);
165  });
166  } // step = 0
167 
168  Box gtbx = mfi.nodaltilebox(0); gtbx.grow(IntVect(1,1,0));
169  Box gtby = mfi.nodaltilebox(1); gtby.grow(IntVect(1,1,0));
170  Box gtbz = mfi.nodaltilebox(2); gtbz.grow(IntVect(1,1,0));
171 
172  const auto& bx_lo = lbound(bx);
173  const auto& bx_hi = ubound(bx);
174 
175  ParallelFor(gtbx, gtby, gtbz,
176  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
177  old_drho_u(i,j,k) = prev_xmom(i,j,k) - stage_xmom(i,j,k);
178  if (k == bx_lo.z && k != domlo.z) {
179  old_drho_u(i,j,k-1) = old_drho_u(i,j,k);
180  } else if (k == bx_hi.z) {
181  old_drho_u(i,j,k+1) = old_drho_u(i,j,k);
182  }
183  },
184  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
185  old_drho_v(i,j,k) = prev_ymom(i,j,k) - stage_ymom(i,j,k);
186  if (k == bx_lo.z && k != domlo.z) {
187  old_drho_v(i,j,k-1) = old_drho_v(i,j,k);
188  } else if (k == bx_hi.z) {
189  old_drho_v(i,j,k+1) = old_drho_v(i,j,k);
190  }
191  },
192  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
193  old_drho_w(i,j,k) = prev_zmom(i,j,k) - stage_zmom(i,j,k);
194  });
195 
196  const Array4<Real>& theta_extrap = extrap.array(mfi);
197  const Array4<const Real>& prim = S_stage_prim.const_array(mfi);
198 
199  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
200  old_drho(i,j,k) = cur_cons(i,j,k,Rho_comp) - stage_cons(i,j,k,Rho_comp);
201  old_drho_theta(i,j,k) = cur_cons(i,j,k,RhoTheta_comp) - stage_cons(i,j,k,RhoTheta_comp);
202  if (step == 0) {
203  theta_extrap(i,j,k) = old_drho_theta(i,j,k);
204  } else {
205  theta_extrap(i,j,k) = old_drho_theta(i,j,k) + beta_d *
206  ( old_drho_theta(i,j,k) - lagged_arr(i,j,k) );
207  }
208 
209  // NOTE: qv is not changing over the fast steps so we use the stage data
210  Real qv = (l_use_moisture) ? prim(i,j,k,PrimQ1_comp) : zero;
211  theta_extrap(i,j,k) *= (one + RvOverRd*qv);
212  });
213  } // mfi
214 
215 #ifdef _OPENMP
216 #pragma omp parallel if (Gpu::notInLaunchRegion())
217 #endif
218  for ( MFIter mfi(S_stage_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi)
219  {
220  // We define lagged_delta_rt for our next step as the current delta_rt
221  Box gbx = mfi.tilebox(); gbx.grow(1);
222  const Array4<Real>& old_drho_theta = Delta_rho_theta.array(mfi);
223  const Array4<Real>& lagged_arr = lagged_delta_rt.array(mfi);
224  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
225  lagged_arr(i,j,k) = old_drho_theta(i,j,k);
226  });
227  } // mfi
228 
229  // *************************************************************************
230  // Define updates in the current RK stage
231  // *************************************************************************
232 
233 #ifdef _OPENMP
234 #pragma omp parallel if (Gpu::notInLaunchRegion())
235 #endif
236  for ( MFIter mfi(S_stage_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi)
237  {
238  Box bx = mfi.validbox();
239  Box tbx = mfi.nodaltilebox(0);
240  Box tby = mfi.nodaltilebox(1);
241 
242  const Array4<Real const>& xmom_src_arr = xmom_src.const_array(mfi);
243  const Array4<Real const>& ymom_src_arr = ymom_src.const_array(mfi);
244 
245  const Array4<const Real> & stage_xmom = S_stage_data[IntVars::xmom].const_array(mfi);
246  const Array4<const Real> & stage_ymom = S_stage_data[IntVars::ymom].const_array(mfi);
247  const Array4<const Real> & qt_arr = qt.const_array(mfi);
248 
249  const Array4<Real>& old_drho_u = Delta_rho_u.array(mfi);
250  const Array4<Real>& old_drho_v = Delta_rho_v.array(mfi);
251 
252  const Array4<const Real>& slow_rhs_rho_u = S_slow_rhs[IntVars::xmom].const_array(mfi);
253  const Array4<const Real>& slow_rhs_rho_v = S_slow_rhs[IntVars::ymom].const_array(mfi);
254 
255  const Array4<Real>& new_drho_u = New_rho_u.array(mfi);
256  const Array4<Real>& new_drho_v = New_rho_v.array(mfi);
257 
258  const Array4<Real>& cur_xmom = S_data[IntVars::xmom].array(mfi);
259  const Array4<Real>& cur_ymom = S_data[IntVars::ymom].array(mfi);
260 
261  // These store the advection momenta which we will use to update the slow variables
262  const Array4<Real>& avg_xmom_arr = avg_xmom.array(mfi);
263  const Array4<Real>& avg_ymom_arr = avg_ymom.array(mfi);
264 
265  const Array4<const Real>& z_nd = z_phys_nd->const_array(mfi);
266 
267  const Array4<const Real>& pi_stage_ca = pi_stage.const_array(mfi);
268 
269  const Array4<Real>& theta_extrap = extrap.array(mfi);
270 
271  // Map factors
272  const Array4<const Real>& mf_ux = mapfac[MapFacType::u_x]->const_array(mfi);
273  const Array4<const Real>& mf_vy = mapfac[MapFacType::v_y]->const_array(mfi);
274 
275  // Create old_drho_u/v/w/theta = U'', V'', W'', Theta'' in the docs
276  // Note that we do the Copy and Subtract including one ghost cell
277  // so that we don't have to fill ghost cells of the new MultiFabs
278  // Initialize New_rho_u/v/w to Delta_rho_u/v/w so that
279  // the ghost cells in New_rho_u/v/w will match old_drho_u/v/w
280 
281  // *********************************************************************
282  // Define updates in the RHS of {x, y, z}-momentum equations
283  // *********************************************************************
284  {
285  BL_PROFILE("substep_xymom_T");
286 
287  const auto& bx_lo = lbound(bx);
288  const auto& bx_hi = ubound(bx);
289 
290  ParallelFor(tbx, tby,
291  [=] AMREX_GPU_DEVICE (int i, int j, int k)
292  {
293  // Add (negative) gradient of (rho theta) multiplied by lagged "pi"
294  Real met_h_xi = Compute_h_xi_AtIface (i, j, k, dxInv, z_nd);
295  Real met_h_zeta = Compute_h_zeta_AtIface(i, j, k, dxInv, z_nd);
296  Real gp_xi = (theta_extrap(i,j,k) - theta_extrap(i-1,j,k)) * dxi;
297  Real gp_zeta_on_iface = (k == 0) ?
298  myhalf * dzi * ( theta_extrap(i-1,j,k+1) + theta_extrap(i,j,k+1)
299  - theta_extrap(i-1,j,k ) - theta_extrap(i,j,k ) ) :
300  fourth * dzi * ( theta_extrap(i-1,j,k+1) + theta_extrap(i,j,k+1)
301  - theta_extrap(i-1,j,k-1) - theta_extrap(i,j,k-1) );
302  Real gpx = (l_real_bc && (level==0) && (i==ilo || i==ihi)) ? Real(0.) :
303  gp_xi - (met_h_xi / met_h_zeta) * gp_zeta_on_iface;
304 
305  gpx *= mf_ux(i,j,0);
306 
307  Real q = (l_use_moisture) ? myhalf * (qt_arr(i,j,k) + qt_arr(i-1,j,k)) : zero;
308 
309  Real pi_c = myhalf * (pi_stage_ca(i-1,j,k,0) + pi_stage_ca(i ,j,k,0));
310  Real fast_rhs_rho_u = -Gamma * R_d * pi_c * gpx / (one + q);
311 
312  new_drho_u(i, j, k) = old_drho_u(i,j,k) + dtau * fast_rhs_rho_u
313  + dtau * slow_rhs_rho_u(i,j,k)
314  + dtau * xmom_src_arr(i,j,k);
315  if (k == bx_lo.z && k != domlo.z) {
316  new_drho_u(i,j,k-1) = new_drho_u(i,j,k);
317  } else if (k == bx_hi.z) {
318  new_drho_u(i,j,k+1) = new_drho_u(i,j,k);
319  }
320 
321  avg_xmom_arr(i,j,k) += facinv*new_drho_u(i,j,k);
322 
323  cur_xmom(i,j,k) = stage_xmom(i,j,k) + new_drho_u(i,j,k);
324  },
325  [=] AMREX_GPU_DEVICE (int i, int j, int k)
326  {
327  // Add (negative) gradient of (rho theta) multiplied by lagged "pi"
328  Real met_h_eta = Compute_h_eta_AtJface(i, j, k, dxInv, z_nd);
329  Real met_h_zeta = Compute_h_zeta_AtJface(i, j, k, dxInv, z_nd);
330  Real gp_eta = (theta_extrap(i,j,k) -theta_extrap(i,j-1,k)) * dyi;
331  Real gp_zeta_on_jface = (k == 0) ?
332  myhalf * dzi * ( theta_extrap(i,j,k+1) + theta_extrap(i,j-1,k+1)
333  - theta_extrap(i,j,k ) - theta_extrap(i,j-1,k ) ) :
334  fourth * dzi * ( theta_extrap(i,j,k+1) + theta_extrap(i,j-1,k+1)
335  - theta_extrap(i,j,k-1) - theta_extrap(i,j-1,k-1) );
336  Real gpy = (l_real_bc && (level==0) && (j==jlo || j==jhi)) ? Real(0.) :
337  gp_eta - (met_h_eta / met_h_zeta) * gp_zeta_on_jface;
338 
339  gpy *= mf_vy(i,j,0);
340 
341  Real q = (l_use_moisture) ? myhalf * (qt_arr(i,j,k) + qt_arr(i,j-1,k)) : zero;
342 
343  Real pi_c = myhalf * (pi_stage_ca(i,j-1,k,0) + pi_stage_ca(i,j ,k,0));
344  Real fast_rhs_rho_v = -Gamma * R_d * pi_c * gpy / (one + q);
345 
346  new_drho_v(i, j, k) = old_drho_v(i,j,k) + dtau * fast_rhs_rho_v
347  + dtau * slow_rhs_rho_v(i,j,k)
348  + dtau * ymom_src_arr(i,j,k);
349 
350  if (k == bx_lo.z && k != domlo.z) {
351  new_drho_v(i,j,k-1) = new_drho_v(i,j,k);
352  } else if (k == bx_hi.z) {
353  new_drho_v(i,j,k+1) = new_drho_v(i,j,k);
354  }
355 
356  avg_ymom_arr(i,j,k) += facinv*new_drho_v(i,j,k);
357 
358  cur_ymom(i,j,k) = stage_ymom(i,j,k) + new_drho_v(i,j,k);
359  });
360  } // end profile
361  }
362 
363  MultiFab Omega(S_data[IntVars::zmom].boxArray(), dm, 1, 1);
364 
365 #ifdef _OPENMP
366 #pragma omp parallel if (Gpu::notInLaunchRegion())
367 #endif
368  {
369  std::array<FArrayBox,AMREX_SPACEDIM> flux;
370  for ( MFIter mfi(S_stage_data[IntVars::cons],TileNoZ()); mfi.isValid(); ++mfi)
371  {
372  Box bx = mfi.tilebox();
373  Box tbz = surroundingNodes(bx,2);
374 
375  Box vbx = mfi.validbox();
376  const auto& vbx_hi = ubound(vbx);
377 
378  const Array4<Real const>& zmom_src_arr = zmom_src.const_array(mfi);
379  const Array4<Real const>& cc_src_arr = cc_src.const_array(mfi);
380 
381  const Array4<const Real> & stage_zmom = S_stage_data[IntVars::zmom].const_array(mfi);
382  const Array4<const Real> & prim = S_stage_prim.const_array(mfi);
383 
384  const Array4<Real>& old_drho_u = Delta_rho_u.array(mfi);
385  const Array4<Real>& old_drho_v = Delta_rho_v.array(mfi);
386  const Array4<Real>& old_drho_w = Delta_rho_w.array(mfi);
387  const Array4<Real>& old_drho = Delta_rho.array(mfi);
388  const Array4<Real>& old_drho_theta = Delta_rho_theta.array(mfi);
389 
390  const Array4<const Real>& slow_rhs_cons = S_slow_rhs[IntVars::cons].const_array(mfi);
391  const Array4<const Real>& slow_rhs_rho_w = S_slow_rhs[IntVars::zmom].const_array(mfi);
392 
393  const Array4<Real>& new_drho_u = New_rho_u.array(mfi);
394  const Array4<Real>& new_drho_v = New_rho_v.array(mfi);
395 
396  const Array4<Real>& cur_cons = S_data[IntVars::cons].array(mfi);
397  const Array4<Real>& cur_zmom = S_data[IntVars::zmom].array(mfi);
398 
399  // These store the advection momenta which we will use to update the slow variables
400  const Array4<Real>& avg_zmom_arr = avg_zmom.array(mfi);
401 
402  const Array4<const Real>& z_nd = z_phys_nd->const_array(mfi);
403  const Array4<const Real>& detJ = detJ_cc->const_array(mfi);
404 
405  const Array4< Real>& omega_arr = Omega.array(mfi);
406 
407  // Map factors
408  const Array4<const Real>& mf_mx = mapfac[MapFacType::m_x]->const_array(mfi);
409  const Array4<const Real>& mf_my = mapfac[MapFacType::m_y]->const_array(mfi);
410  const Array4<const Real>& mf_ux = mapfac[MapFacType::u_x]->const_array(mfi);
411  const Array4<const Real>& mf_uy = mapfac[MapFacType::u_y]->const_array(mfi);
412  const Array4<const Real>& mf_vx = mapfac[MapFacType::v_x]->const_array(mfi);
413  const Array4<const Real>& mf_vy = mapfac[MapFacType::v_y]->const_array(mfi);
414 
415  // Create old_drho_u/v/w/theta = U'', V'', W'', Theta'' in the docs
416  // Note that we do the Copy and Subtract including one ghost cell
417  // so that we don't have to fill ghost cells of the new MultiFabs
418  // Initialize New_rho_u/v/w to Delta_rho_u/v/w so that
419  // the ghost cells in New_rho_u/v/w will match old_drho_u/v/w
420 
421  FArrayBox temp_rhs_fab;
422  FArrayBox RHS_fab;
423  FArrayBox soln_fab;
424 
425  RHS_fab.resize (tbz,1,The_Async_Arena());
426  soln_fab.resize (tbz,1,The_Async_Arena());
427  temp_rhs_fab.resize(tbz,2,The_Async_Arena());
428 
429  auto const& RHS_a = RHS_fab.array();
430  auto const& soln_a = soln_fab.array();
431  auto const& temp_rhs_arr = temp_rhs_fab.array();
432 
433  auto const& coeffA_a = coeff_A_mf.array(mfi);
434  auto const& inv_coeffB_a = inv_coeff_B_mf.array(mfi);
435  auto const& coeffC_a = coeff_C_mf.array(mfi);
436  auto const& coeffP_a = coeff_P_mf.array(mfi);
437  auto const& coeffQ_a = coeff_Q_mf.array(mfi);
438 
439  // *************************************************************************
440  // Define flux arrays for use in advection
441  // *************************************************************************
442  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
443  flux[dir].resize(surroundingNodes(bx,dir),2,The_Async_Arena());
444  flux[dir].setVal<RunOn::Device>(0);
445  }
446  const GpuArray<const Array4<Real>, AMREX_SPACEDIM>
447  flx_arr{{AMREX_D_DECL(flux[0].array(), flux[1].array(), flux[2].array())}};
448 
449  // *********************************************************************
450  {
451  BL_PROFILE("fast_T_making_rho_rhs");
452  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
453  Real h_zeta_cc_xface_hi = myhalf * dzi *
454  ( z_nd(i+1,j ,k+1) + z_nd(i+1,j+1,k+1)
455  -z_nd(i+1,j ,k ) - z_nd(i+1,j+1,k ) );
456 
457  Real h_zeta_cc_xface_lo = myhalf * dzi *
458  ( z_nd(i ,j ,k+1) + z_nd(i ,j+1,k+1)
459  -z_nd(i ,j ,k ) - z_nd(i ,j+1,k ) );
460 
461  Real h_zeta_cc_yface_hi = myhalf * dzi *
462  ( z_nd(i ,j+1,k+1) + z_nd(i+1,j+1,k+1)
463  -z_nd(i ,j+1,k ) - z_nd(i+1,j+1,k ) );
464 
465  Real h_zeta_cc_yface_lo = myhalf * dzi *
466  ( z_nd(i ,j ,k+1) + z_nd(i+1,j ,k+1)
467  -z_nd(i ,j ,k ) - z_nd(i+1,j ,k ) );
468 
469  Real xflux_lo = new_drho_u(i ,j,k)*h_zeta_cc_xface_lo / mf_uy(i ,j,0);
470  Real xflux_hi = new_drho_u(i+1,j,k)*h_zeta_cc_xface_hi / mf_uy(i+1,j,0);
471  Real yflux_lo = new_drho_v(i,j ,k)*h_zeta_cc_yface_lo / mf_vx(i,j ,0);
472  Real yflux_hi = new_drho_v(i,j+1,k)*h_zeta_cc_yface_hi / mf_vx(i,j+1,0);
473 
474  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
475 
476  // NOTE: we are saving the (1/J) weighting for later when we add this to rho and theta
477  temp_rhs_arr(i,j,k,0) = ( xflux_hi - xflux_lo ) * dxi * mfsq +
478  ( yflux_hi - yflux_lo ) * dyi * mfsq;
479  temp_rhs_arr(i,j,k,1) = (( xflux_hi * (prim(i,j,k,0) + prim(i+1,j,k,0)) -
480  xflux_lo * (prim(i,j,k,0) + prim(i-1,j,k,0)) ) * dxi * mfsq+
481  ( yflux_hi * (prim(i,j,k,0) + prim(i,j+1,k,0)) -
482  yflux_lo * (prim(i,j,k,0) + prim(i,j-1,k,0)) ) * dyi * mfsq) * myhalf;
483 
484  if (l_reflux) {
485  (flx_arr[0])(i,j,k,0) = xflux_lo;
486  (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));
487 
488  (flx_arr[1])(i,j,k,0) = yflux_lo;
489  (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));
490 
491  if (i == vbx_hi.x) {
492  (flx_arr[0])(i+1,j,k,0) = xflux_hi;
493  (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));
494  }
495  if (j == vbx_hi.y) {
496  (flx_arr[1])(i,j+1,k,0) = yflux_hi;
497  (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));
498  }
499  }
500  });
501  } // end profile
502 
503  // *********************************************************************
504  {
505  Box gbxo = mfi.nodaltilebox(2);
506  Box gbxo_mid = gbxo;
507 
508  if (gbxo.smallEnd(2) == domlo.z) {
509  Box gbxo_lo = gbxo; gbxo_lo.setBig(2,gbxo.smallEnd(2));
510  gbxo_mid.setSmall(2,gbxo.smallEnd(2)+1);
511  ParallelFor(gbxo_lo, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
512  omega_arr(i,j,k) = zero;
513  });
514  }
515  if (gbxo.bigEnd(2) == domhi.z+1) {
516  Box gbxo_hi = gbxo; gbxo_hi.setSmall(2,gbxo.bigEnd(2));
517  gbxo_mid.setBig(2,gbxo.bigEnd(2)-1);
518  ParallelFor(gbxo_hi, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
519  omega_arr(i,j,k) = old_drho_w(i,j,k);
520  });
521  }
522  ParallelFor(gbxo_mid, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
523  omega_arr(i,j,k) = OmegaFromW(i,j,k,old_drho_w(i,j,k),
524  old_drho_u,old_drho_v,
525  mf_ux,mf_vy,z_nd,dxInv);
526  });
527  } // end profile
528  // *********************************************************************
529 
530  Box bx_shrunk_in_k = bx;
531  int klo = tbz.smallEnd(2);
532  int khi = tbz.bigEnd(2);
533  bx_shrunk_in_k.setSmall(2,klo+1);
534  bx_shrunk_in_k.setBig(2,khi-1);
535 
536  // Note that the notes use "g" to mean the magnitude of gravity, so it is positive
537  // We set grav_gpu[2] to be the vector component which is negative
538  // We define halfg to match the notes (which is why we take the absolute value)
539  Real halfg = std::abs(myhalf * grav_gpu[2]);
540 
541  {
542  BL_PROFILE("fast_loop_on_shrunk_t");
543  //Note we don't act on the bottom or top boundaries of the domain
544  ParallelFor(bx_shrunk_in_k, [=] AMREX_GPU_DEVICE (int i, int j, int k)
545  {
546  Real coeff_P = coeffP_a(i,j,k);
547  Real coeff_Q = coeffQ_a(i,j,k);
548 
549  Real theta_t_lo = myhalf * ( prim(i,j,k-2,PrimTheta_comp) + prim(i,j,k-1,PrimTheta_comp) );
550  Real theta_t_mid = myhalf * ( prim(i,j,k-1,PrimTheta_comp) + prim(i,j,k ,PrimTheta_comp) );
551  Real theta_t_hi = myhalf * ( prim(i,j,k ,PrimTheta_comp) + prim(i,j,k+1,PrimTheta_comp) );
552 
553  // line 2 last two terms (order dtau)
554  Real R0_tmp = -halfg * old_drho(i,j,k ) + coeff_P * old_drho_theta(i,j,k )
555  -halfg * old_drho(i,j,k-1) + coeff_Q * old_drho_theta(i,j,k-1);
556 
557  // line 3 residuals (order dtau^2) one <-> beta_2
558  Real R1_tmp = -halfg * ( slow_rhs_cons(i,j,k ,Rho_comp) + slow_rhs_cons(i,j,k-1,Rho_comp) );
559 
560  R1_tmp += coeff_P * slow_rhs_cons(i,j,k ,RhoTheta_comp)
561  + coeff_Q * slow_rhs_cons(i,j,k-1,RhoTheta_comp);
562 
563  Real Omega_kp1 = omega_arr(i,j,k+1);
564  Real Omega_k = omega_arr(i,j,k );
565  Real Omega_km1 = omega_arr(i,j,k-1);
566 
567  Real detJdiff = (detJ(i,j,k) - detJ(i,j,k-1)) / (detJ(i,j,k)*detJ(i,j,k-1));
568 
569  // consolidate lines 4&5 (order dtau^2)
570  R1_tmp += halfg * ( beta_1 * dzi * (Omega_kp1/detJ(i,j,k) + detJdiff*Omega_k - Omega_km1/detJ(i,j,k-1))
571  + 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) );
572 
573  // consolidate lines 6&7 (order dtau^2)
574  R1_tmp += -( coeff_P/detJ(i,j,k ) * ( beta_1 * dzi * (Omega_kp1*theta_t_hi - Omega_k*theta_t_mid) + temp_rhs_arr(i,j,k ,RhoTheta_comp) )
575  + coeff_Q/detJ(i,j,k-1) * ( beta_1 * dzi * (Omega_k*theta_t_mid - Omega_km1*theta_t_lo) + temp_rhs_arr(i,j,k-1,RhoTheta_comp) ) );
576 
577  // line 1
578  RHS_a(i,j,k) = old_drho_w(i,j,k) + dtau * (slow_rhs_rho_w(i,j,k) + zmom_src_arr(i,j,k) + R0_tmp + dtau*beta_2*R1_tmp);
579 
580  // We cannot use omega_arr here since that was built with old_rho_u and old_rho_v ...
581  RHS_a(i,j,k) += OmegaFromW(i,j,k,zero,
582  new_drho_u,new_drho_v,
583  mf_ux,mf_vy,z_nd,dxInv);
584  });
585  } // end profile
586 
587  Box b2d = tbz; // Copy constructor
588  b2d.setRange(2,0);
589 
590  auto const lo = lbound(bx);
591  auto const hi = ubound(bx);
592 
593  {
594  BL_PROFILE("substep_b2d_loop_t");
595 #ifdef AMREX_USE_GPU
596  ParallelFor(b2d, [=] AMREX_GPU_DEVICE (int i, int j, int)
597  {
598  // w_klo, w_khi given by specified Dirichlet values
599  RHS_a(i,j,lo.z ) = dtau * (slow_rhs_rho_w(i,j,lo.z) + zmom_src_arr(i,j,lo.z));
600  RHS_a(i,j,hi.z+1) = dtau * (slow_rhs_rho_w(i,j,hi.z+1) + zmom_src_arr(i,j,hi.z+1));
601 
602  // w = specified Dirichlet value at k = lo.z
603  soln_a(i,j,lo.z) = RHS_a(i,j,lo.z) * inv_coeffB_a(i,j,lo.z);
604 
605  // Transform the RHS from r_i -> rho_i
606  for (int k = lo.z+1; k <= hi.z+1; k++) {
607  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);
608  }
609 
610  cur_zmom(i,j,lo.z ) = stage_zmom(i,j,lo.z ) + soln_a(i,j,lo.z );
611  cur_zmom(i,j,hi.z+1) = stage_zmom(i,j,hi.z+1) + soln_a(i,j,hi.z+1);
612 
613  // Back sweep to obtain the solution
614  for (int k = hi.z; k >= lo.z; k--) {
615  soln_a(i,j,k) -= ( coeffC_a(i,j,k) * inv_coeffB_a(i,j,k) ) *soln_a(i,j,k+1);
616  }
617  });
618 #else
619  for (int j = lo.y; j <= hi.y; ++j) {
620  AMREX_PRAGMA_SIMD
621  for (int i = lo.x; i <= hi.x; ++i)
622  {
623  RHS_a(i,j,lo.z) = dtau * (slow_rhs_rho_w(i,j,lo.z) + zmom_src_arr(i,j,lo.z));
624  soln_a(i,j,lo.z) = RHS_a(i,j,lo.z) * inv_coeffB_a(i,j,lo.z);
625  }
626 
627  AMREX_PRAGMA_SIMD
628  for (int i = lo.x; i <= hi.x; ++i)
629  {
630  RHS_a(i,j,hi.z+1) = dtau * (slow_rhs_rho_w(i,j,hi.z+1) + zmom_src_arr(i,j,hi.z+1));
631  soln_a(i,j,hi.z+1) = RHS_a(i,j,hi.z+1) * inv_coeffB_a(i,j,hi.z+1);
632  }
633  }
634 
635  for (int k = lo.z+1; k <= hi.z; ++k) {
636  for (int j = lo.y; j <= hi.y; ++j) {
637  AMREX_PRAGMA_SIMD
638  for (int i = lo.x; i <= hi.x; ++i) {
639  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);
640  }
641  }
642  }
643  for (int k = hi.z; k > lo.z; --k) {
644  for (int j = lo.y; j <= hi.y; ++j) {
645  AMREX_PRAGMA_SIMD
646  for (int i = lo.x; i <= hi.x; ++i) {
647  soln_a(i,j,k) -= (coeffC_a(i,j,k) * inv_coeffB_a(i,j,k)) * soln_a(i,j,k+1);
648  }
649  }
650  }
651  if (hi.z == domhi.z) {
652  for (int j = lo.y; j <= hi.y; ++j) {
653  AMREX_PRAGMA_SIMD
654  for (int i = lo.x; i <= hi.x; ++i) {
655  cur_zmom(i,j,hi.z+1) = stage_zmom(i,j,hi.z+1) + soln_a(i,j,hi.z+1);
656  }
657  }
658  }
659 #endif
660  } // end profile
661 
662  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
663  {
664  cur_zmom(i,j,k) = stage_zmom(i,j,k);
665  });
666 
667  if (lo.z == domlo.z) {
668  tbz.setSmall(2,domlo.z+1);
669  }
670  if (hi.z == domhi.z) {
671  tbz.setBig(2,domhi.z);
672  }
673  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
674  {
675  Real wpp = WFromOmega(i,j,k,soln_a(i,j,k),
676  new_drho_u,new_drho_v,
677  mf_ux,mf_vy,z_nd,dxInv);
678 
679  cur_zmom(i,j,k) += wpp;
680 
681  if (l_rayleigh_impl_for_w) {
682  Real damping_coeff = l_damp_coef * dtau * sinesq_stag_d[k];
683  cur_zmom(i,j,k) /= (one + damping_coeff);
684  }
685  });
686 
687  // **************************************************************************
688  // Define updates in the RHS of rho and (rho theta)
689  // **************************************************************************
690  {
691  BL_PROFILE("fast_rho_final_update");
692  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
693  {
694  Real zflux_lo = beta_2 * soln_a(i,j,k ) + beta_1 * omega_arr(i,j,k);
695  Real zflux_hi = beta_2 * soln_a(i,j,k+1) + beta_1 * omega_arr(i,j,k+1);
696 
697  // Note that in the solve we effectively impose new_drho_w(i,j,vbx_hi.z+1)=0
698  // so we don't update avg_zmom at k=vbx_hi.z+1
699  avg_zmom_arr(i,j,k) += facinv*zflux_lo / (mf_mx(i,j,0) * mf_my(i,j,0));
700  if (l_reflux) {
701  (flx_arr[2])(i,j,k,0) = zflux_lo / (mf_mx(i,j,0) * mf_my(i,j,0));
702  }
703 
704  if (k == vbx_hi.z) {
705  avg_zmom_arr(i,j,k+1) += facinv * zflux_hi / (mf_mx(i,j,0) * mf_my(i,j,0));
706  if (l_reflux) {
707  (flx_arr[2])(i,j,k+1,0) = zflux_hi / (mf_mx(i,j,0) * mf_my(i,j,0));
708  (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));
709  }
710  }
711 
712  Real fast_rhs_rho = -(temp_rhs_arr(i,j,k,0) + ( zflux_hi - zflux_lo ) * dzi) / detJ(i,j,k);
713 
714  cur_cons(i,j,k,0) += dtau * (slow_rhs_cons(i,j,k,0) + fast_rhs_rho);
715 
716  Real fast_rhs_rhotheta = -( temp_rhs_arr(i,j,k,1) + myhalf *
717  ( zflux_hi * (prim(i,j,k) + prim(i,j,k+1)) -
718  zflux_lo * (prim(i,j,k) + prim(i,j,k-1)) ) * dzi ) / detJ(i,j,k);
719 
720  cur_cons(i,j,k,1) += dtau * (slow_rhs_cons(i,j,k,1) + fast_rhs_rhotheta);
721 
722  if (l_reflux) {
723  (flx_arr[2])(i,j,k,1) = (flx_arr[2])(i,j,k,0) * myhalf * (prim(i,j,k) + prim(i,j,k-1));
724  }
725 
726  // add in source terms for cell-centered conserved variables
727  cur_cons(i,j,k,Rho_comp) += dtau * cc_src_arr(i,j,k,Rho_comp);
728  cur_cons(i,j,k,RhoTheta_comp) += dtau * cc_src_arr(i,j,k,RhoTheta_comp);
729  });
730  } // end profile
731 
732  // We only add to the flux registers in the final RK step
733  if (l_reflux) {
734  int strt_comp_reflux = 0;
735  // For now we don't reflux (rho theta) because it seems to create issues at c/f boundaries
736  int num_comp_reflux = 1;
737  if (level < finest_level) {
738  fr_as_crse->CrseAdd(mfi,
739  {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
740  dx, dtau, strt_comp_reflux, strt_comp_reflux, num_comp_reflux, RunOn::Device);
741  }
742  if (level > 0) {
743  fr_as_fine->FineAdd(mfi,
744  {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
745  dx, dtau, strt_comp_reflux, strt_comp_reflux, num_comp_reflux, RunOn::Device);
746  }
747 
748  // This is necessary here so we don't go on to the next FArrayBox without
749  // having finished copying the fluxes into the FluxRegisters (since the fluxes
750  // are stored in temporary FArrayBox's)
751  Gpu::streamSynchronize();
752 
753  } // two-way coupling
754  } // mfi
755  } // OMP
756 }
constexpr amrex::Real R_v
Definition: ERF_Constants.H:48
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real fourth
Definition: ERF_Constants.H:14
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
constexpr amrex::Real R_d
Definition: ERF_Constants.H:47
constexpr amrex::Real Gamma
Definition: ERF_Constants.H:62
@ v_x
Definition: ERF_DataStruct.H:24
@ u_y
Definition: ERF_DataStruct.H:25
@ v_y
Definition: ERF_DataStruct.H:25
@ m_y
Definition: ERF_DataStruct.H:25
@ u_x
Definition: ERF_DataStruct.H:24
@ m_x
Definition: ERF_DataStruct.H:24
#define PrimQ1_comp
Definition: ERF_IndexDefines.H:58
#define Rho_comp
Definition: ERF_IndexDefines.H:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define PrimTheta_comp
Definition: ERF_IndexDefines.H:55
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:17
const Real dx
Definition: ERF_InitCustomPert_ABL.H:23
const int khi
Definition: ERF_InitCustomPert_Bubble.H:21
ParallelFor(grown_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
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:414
AMREX_GPU_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:117
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:104
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:144
AMREX_GPU_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:170
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real WFromOmega(int &i, int &j, int &k, amrex::Real omega, 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:464
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ gpy
Definition: ERF_IndexDefines.H:186
@ gpx
Definition: ERF_IndexDefines.H:185
@ ymom
Definition: ERF_IndexDefines.H:195
@ cons
Definition: ERF_IndexDefines.H:193
@ zmom
Definition: ERF_IndexDefines.H:196
@ xmom
Definition: ERF_IndexDefines.H:194
@ qt
Definition: ERF_Kessler.H:29
@ qv
Definition: ERF_Kessler.H:30
@ q
Definition: ERF_WSM6.H:182
Here is the call graph for this function: