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

Functions

void erf_fast_rhs_N (int step, int nrk, 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, const Real dtau, 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_implicit_substepping)
 

Function Documentation

◆ erf_fast_rhs_N()

void erf_fast_rhs_N ( int  step,
int  nrk,
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,
const Real  dtau,
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_implicit_substepping 
)

Function for computing the fast RHS with no 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_previf step == 0, this is S_old, else the previous fast 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]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_implicit_substepping
69 {
70  //
71  // NOTE: for step > 0, S_data and S_prev point to the same MultiFab data!!
72  //
73 
74  BL_PROFILE_REGION("erf_fast_rhs_N()");
75 
76  Real beta_1 = 0.5 * (1.0 - beta_s); // multiplies explicit terms
77  Real beta_2 = 0.5 * (1.0 + beta_s); // multiplies implicit terms
78 
79  // How much do we project forward the (rho theta) that is used in the horizontal momentum equations
80  Real beta_d = 0.1;
81 
82  Real RvOverRd = R_v / R_d;
83 
84  const Real* dx = geom.CellSize();
85  const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
86 
87  Real dxi = dxInv[0];
88  Real dyi = dxInv[1];
89  Real dzi = dxInv[2];
90 
91  const auto& ba = S_stage_data[IntVars::cons].boxArray();
92  const auto& dm = S_stage_data[IntVars::cons].DistributionMap();
93 
94  MultiFab Delta_rho_theta( ba , dm, 1, 1);
95  MultiFab Delta_rho_w (convert(ba,IntVect(0,0,1)), dm, 1, IntVect(1,1,0));
96 
97  MultiFab coeff_A_mf(fast_coeffs, make_alias, 0, 1);
98  MultiFab inv_coeff_B_mf(fast_coeffs, make_alias, 1, 1);
99  MultiFab coeff_C_mf(fast_coeffs, make_alias, 2, 1);
100  MultiFab coeff_P_mf(fast_coeffs, make_alias, 3, 1);
101  MultiFab coeff_Q_mf(fast_coeffs, make_alias, 4, 1);
102 
103  // *************************************************************************
104  // Set gravity as a vector
105  const Array<Real,AMREX_SPACEDIM> grav{0.0, 0.0, -gravity};
106  const GpuArray<Real,AMREX_SPACEDIM> grav_gpu{grav[0], grav[1], grav[2]};
107 
108  // This will hold theta extrapolated forward in time
109  MultiFab extrap(S_data[IntVars::cons].boxArray(),S_data[IntVars::cons].DistributionMap(),1,1);
110 
111  // This will hold the update for (rho) and (rho theta)
112  MultiFab temp_rhs(S_stage_data[IntVars::zmom].boxArray(),S_stage_data[IntVars::zmom].DistributionMap(),2,0);
113 
114  // This will hold the new x- and y-momenta temporarily (so that we don't overwrite values we need when tiling)
115  MultiFab temp_cur_xmom(S_stage_data[IntVars::xmom].boxArray(),S_stage_data[IntVars::xmom].DistributionMap(),1,0);
116  MultiFab temp_cur_ymom(S_stage_data[IntVars::ymom].boxArray(),S_stage_data[IntVars::ymom].DistributionMap(),1,0);
117 
118  // We assume that in the first step (nrk == 0) we are only doing one substep.
119  AMREX_ALWAYS_ASSERT(nrk > 0 || step == 0);
120 
121  // *************************************************************************
122  // First set up some arrays we'll need
123  // *************************************************************************
124 
125 #ifdef _OPENMP
126 #pragma omp parallel if (Gpu::notInLaunchRegion())
127 #endif
128  for ( MFIter mfi(S_stage_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi)
129  {
130  const Array4<const Real>& prev_cons = S_prev[IntVars::cons].const_array(mfi);
131  const Array4<const Real>& prev_zmom = S_prev[IntVars::zmom].const_array(mfi);
132 
133  const Array4<const Real>& stage_cons = S_stage_data[IntVars::cons].const_array(mfi);
134  const Array4<const Real>& stage_zmom = S_stage_data[IntVars::zmom].const_array(mfi);
135 
136  const Array4<Real>& prev_drho_w = Delta_rho_w.array(mfi);
137  const Array4<Real>& prev_drho_theta = Delta_rho_theta.array(mfi);
138  const Array4<Real>& lagged_arr = lagged_delta_rt.array(mfi);
139  const Array4<Real>& theta_extrap = extrap.array(mfi);
140  const Array4<const Real>& prim = S_stage_prim.const_array(mfi);
141 
142  Box gbx = mfi.growntilebox(1);
143  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
144  {
145  prev_drho_theta(i,j,k) = prev_cons(i,j,k,RhoTheta_comp) - stage_cons(i,j,k,RhoTheta_comp);
146 
147  if (step == 0) {
148  theta_extrap(i,j,k) = prev_drho_theta(i,j,k);
149  } else {
150  theta_extrap(i,j,k) = prev_drho_theta(i,j,k) + beta_d *
151  ( prev_drho_theta(i,j,k) - lagged_arr(i,j,k) );
152  }
153 
154  // NOTE: qv is not changing over the fast steps so we use the stage data
155  Real qv = (l_use_moisture) ? prim(i,j,k,PrimQ1_comp) : 0.0;
156  theta_extrap(i,j,k) *= (1.0 + RvOverRd*qv);
157 
158  // We define lagged_delta_rt for our next step as the current delta_rt
159  // (after using it above to extrapolate theta for this step)
160  lagged_arr(i,j,k) = prev_drho_theta(i,j,k);
161  });
162 
163  // NOTE: We must do this here because for step > 0, prev_zmom and cur_zmom both point to the same data,
164  // so by the time we would use prev_zmom to define zflux, it would have already been over-written.
165  Box gtbz = mfi.nodaltilebox(2);
166  gtbz.grow(IntVect(1,1,0));
167  ParallelFor(gtbz, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
168  prev_drho_w(i,j,k) = prev_zmom(i,j,k) - stage_zmom(i,j,k);
169  });
170  } // mfi
171 
172  // *************************************************************************
173  // Define updates in the current RK stage
174  // *************************************************************************
175 
176 #ifdef _OPENMP
177 #pragma omp parallel if (Gpu::notInLaunchRegion())
178 #endif
179  for ( MFIter mfi(S_stage_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi)
180  {
181  Box tbx = mfi.nodaltilebox(0);
182  Box tby = mfi.nodaltilebox(1);
183 
184  const Array4<Real const>& xmom_src_arr = xmom_src.const_array(mfi);
185  const Array4<Real const>& ymom_src_arr = ymom_src.const_array(mfi);
186 
187  const Array4<const Real> & stage_xmom = S_stage_data[IntVars::xmom].const_array(mfi);
188  const Array4<const Real> & stage_ymom = S_stage_data[IntVars::ymom].const_array(mfi);
189  const Array4<const Real> & qt_arr = qt.const_array(mfi);
190 
191  const Array4<const Real>& slow_rhs_rho_u = S_slow_rhs[IntVars::xmom].const_array(mfi);
192  const Array4<const Real>& slow_rhs_rho_v = S_slow_rhs[IntVars::ymom].const_array(mfi);
193 
194  const Array4<Real>& temp_cur_xmom_arr = temp_cur_xmom.array(mfi);
195  const Array4<Real>& temp_cur_ymom_arr = temp_cur_ymom.array(mfi);
196 
197  const Array4<const Real>& prev_xmom = S_prev[IntVars::xmom].const_array(mfi);
198  const Array4<const Real>& prev_ymom = S_prev[IntVars::ymom].const_array(mfi);
199 
200  // These store the advection momenta which we will use to update the slow variables
201  const Array4< Real>& avg_xmom_arr = avg_xmom.array(mfi);
202  const Array4< Real>& avg_ymom_arr = avg_ymom.array(mfi);
203 
204  const Array4<const Real>& pi_stage_ca = pi_stage.const_array(mfi);
205 
206  const Array4<Real>& theta_extrap = extrap.array(mfi);
207 
208  // Map factors
209  const Array4<const Real>& mf_ux = mapfac[MapFacType::u_x]->const_array(mfi);
210  const Array4<const Real>& mf_vy = mapfac[MapFacType::v_y]->const_array(mfi);
211 
212  // *********************************************************************
213  // Define updates in the RHS of {x, y, z}-momentum equations
214  // *********************************************************************
215  if (nrk == 0 and step == 0) { // prev == stage
216  ParallelFor(tbx, tby,
217  [=] AMREX_GPU_DEVICE (int i, int j, int k)
218  {
219  Real new_drho_u = dtau * slow_rhs_rho_u(i,j,k) + dtau * xmom_src_arr(i,j,k);;
220  avg_xmom_arr(i,j,k) += facinv*new_drho_u;
221  temp_cur_xmom_arr(i,j,k) = stage_xmom(i,j,k) + new_drho_u;
222  },
223  [=] AMREX_GPU_DEVICE (int i, int j, int k)
224  {
225  Real new_drho_v = dtau * slow_rhs_rho_v(i,j,k) + dtau * ymom_src_arr(i,j,k);
226  avg_ymom_arr(i,j,k) += facinv*new_drho_v;
227  temp_cur_ymom_arr(i,j,k) = stage_ymom(i,j,k) + new_drho_v;
228  });
229  } else {
230  ParallelFor(tbx, tby,
231  [=] AMREX_GPU_DEVICE (int i, int j, int k)
232  {
233  // Add (negative) gradient of (rho theta) multiplied by lagged "pi"
234  Real gpx = (theta_extrap(i,j,k) - theta_extrap(i-1,j,k))*dxi;
235  gpx *= mf_ux(i,j,0);
236 
237  Real q = (l_use_moisture) ? 0.5 * (qt_arr(i,j,k) + qt_arr(i-1,j,k)) : 0.0;
238 
239  Real pi_c = 0.5 * (pi_stage_ca(i-1,j,k,0) + pi_stage_ca(i,j,k,0));
240  Real fast_rhs_rho_u = -Gamma * R_d * pi_c * gpx / (1.0 + q);
241 
242  Real new_drho_u = prev_xmom(i,j,k) - stage_xmom(i,j,k)
243  + dtau * fast_rhs_rho_u + dtau * slow_rhs_rho_u(i,j,k)
244  + dtau * xmom_src_arr(i,j,k);
245 
246  avg_xmom_arr(i,j,k) += facinv*new_drho_u;
247 
248  temp_cur_xmom_arr(i,j,k) = stage_xmom(i,j,k) + new_drho_u;
249  },
250  [=] AMREX_GPU_DEVICE (int i, int j, int k)
251  {
252  // Add (negative) gradient of (rho theta) multiplied by lagged "pi"
253  Real gpy = (theta_extrap(i,j,k) - theta_extrap(i,j-1,k))*dyi;
254  gpy *= mf_vy(i,j,0);
255 
256  Real q = (l_use_moisture) ? 0.5 * (qt_arr(i,j,k) + qt_arr(i,j-1,k)) : 0.0;
257 
258  Real pi_c = 0.5 * (pi_stage_ca(i,j-1,k,0) + pi_stage_ca(i,j,k,0));
259  Real fast_rhs_rho_v = -Gamma * R_d * pi_c * gpy / (1.0 + q);
260 
261  Real new_drho_v = prev_ymom(i,j,k) - stage_ymom(i,j,k)
262  + dtau * fast_rhs_rho_v + dtau * slow_rhs_rho_v(i,j,k)
263  + dtau * ymom_src_arr(i,j,k);
264 
265  avg_ymom_arr(i,j,k) += facinv*new_drho_v;
266 
267  temp_cur_ymom_arr(i,j,k) = stage_ymom(i,j,k) + new_drho_v;
268  });
269  } // nrk > 0 and/or step > 0
270  } //mfi
271 
272 #ifdef _OPENMP
273 #pragma omp parallel if (Gpu::notInLaunchRegion())
274 #endif
275  {
276  std::array<FArrayBox,AMREX_SPACEDIM> flux;
277  for ( MFIter mfi(S_stage_data[IntVars::cons],TileNoZ()); mfi.isValid(); ++mfi)
278  {
279  Box bx = mfi.tilebox();
280  Box tbz = surroundingNodes(bx,2);
281 
282  Box vbx = mfi.validbox();
283  const auto& vbx_hi = ubound(vbx);
284 
285  const Array4<Real const>& zmom_src_arr = zmom_src.const_array(mfi);
286 
287  const Array4<const Real>& stage_xmom = S_stage_data[IntVars::xmom].const_array(mfi);
288  const Array4<const Real>& stage_ymom = S_stage_data[IntVars::ymom].const_array(mfi);
289  const Array4<const Real>& stage_zmom = S_stage_data[IntVars::zmom].const_array(mfi);
290  const Array4<const Real> & prim = S_stage_prim.const_array(mfi);
291  const Array4<const Real> & qt_arr = qt.const_array(mfi);
292 
293  const Array4<const Real>& prev_drho_theta = Delta_rho_theta.array(mfi);
294 
295  const Array4<const Real>& prev_cons = S_prev[IntVars::cons].const_array(mfi);
296  const Array4<const Real>& stage_cons = S_stage_data[IntVars::cons].const_array(mfi);
297 
298  const Array4<const Real>& slow_rhs_cons = S_slow_rhs[IntVars::cons].const_array(mfi);
299  const Array4<const Real>& slow_rhs_rho_w = S_slow_rhs[IntVars::zmom].const_array(mfi);
300 
301  const Array4<const Real>& prev_zmom = S_prev[IntVars::zmom].const_array(mfi);
302  const Array4< Real>& cur_zmom = S_data[IntVars::zmom].array(mfi);
303 
304  const Array4<Real>& temp_cur_xmom_arr = temp_cur_xmom.array(mfi);
305  const Array4<Real>& temp_cur_ymom_arr = temp_cur_ymom.array(mfi);
306 
307  // These store the advection momenta which we will use to update the slow variables
308  const Array4< Real>& avg_zmom_arr = avg_zmom.array(mfi);
309 
310  // Map factors
311  const Array4<const Real>& mf_mx = mapfac[MapFacType::m_x]->const_array(mfi);
312  const Array4<const Real>& mf_my = mapfac[MapFacType::m_y]->const_array(mfi);
313  const Array4<const Real>& mf_uy = mapfac[MapFacType::u_y]->const_array(mfi);
314  const Array4<const Real>& mf_vx = mapfac[MapFacType::v_x]->const_array(mfi);
315 
316  FArrayBox RHS_fab;
317  RHS_fab.resize(tbz,1, The_Async_Arena());
318 
319  FArrayBox soln_fab;
320  soln_fab.resize(tbz,1, The_Async_Arena());
321 
322  auto const& RHS_a = RHS_fab.array();
323  auto const& soln_a = soln_fab.array();
324 
325  auto const& temp_rhs_arr = temp_rhs.array(mfi);
326 
327  auto const& coeffA_a = coeff_A_mf.array(mfi);
328  auto const& inv_coeffB_a = inv_coeff_B_mf.array(mfi);
329  auto const& coeffC_a = coeff_C_mf.array(mfi);
330  auto const& coeffP_a = coeff_P_mf.array(mfi);
331  auto const& coeffQ_a = coeff_Q_mf.array(mfi);
332 
333  // *************************************************************************
334  // Define flux arrays for use in advection
335  // *************************************************************************
336  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
337  flux[dir].resize(surroundingNodes(bx,dir),2);
338  flux[dir].setVal<RunOn::Device>(0.);
339  }
340  const GpuArray<const Array4<Real>, AMREX_SPACEDIM>
341  flx_arr{{AMREX_D_DECL(flux[0].array(), flux[1].array(), flux[2].array())}};
342 
343  // *********************************************************************
344  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
345  Real xflux_lo = (temp_cur_xmom_arr(i ,j,k) - stage_xmom(i ,j,k)) / mf_uy(i ,j,0);
346  Real xflux_hi = (temp_cur_xmom_arr(i+1,j,k) - stage_xmom(i+1,j,k)) / mf_uy(i+1,j,0);
347  Real yflux_lo = (temp_cur_ymom_arr(i,j ,k) - stage_ymom(i,j ,k)) / mf_vx(i,j ,0);
348  Real yflux_hi = (temp_cur_ymom_arr(i,j+1,k) - stage_ymom(i,j+1,k)) / mf_vx(i,j+1,0);
349 
350  Real mfsq = mf_mx(i,j,0) * mf_my(i,j,0);
351 
352  temp_rhs_arr(i,j,k,Rho_comp ) = ( xflux_hi - xflux_lo ) * dxi * mfsq
353  + ( yflux_hi - yflux_lo ) * dyi * mfsq;
354  temp_rhs_arr(i,j,k,RhoTheta_comp) = (( xflux_hi * (prim(i,j,k,0) + prim(i+1,j,k,0)) -
355  xflux_lo * (prim(i,j,k,0) + prim(i-1,j,k,0)) ) * dxi * mfsq +
356  ( yflux_hi * (prim(i,j,k,0) + prim(i,j+1,k,0)) -
357  yflux_lo * (prim(i,j,k,0) + prim(i,j-1,k,0)) ) * dyi * mfsq) * 0.5;
358 
359  if (l_reflux) {
360  (flx_arr[0])(i,j,k,0) = xflux_lo;
361  (flx_arr[0])(i,j,k,1) = (flx_arr[0])(i ,j,k,0) * 0.5 * (prim(i,j,k,0) + prim(i-1,j,k,0));
362 
363  (flx_arr[1])(i,j,k,0) = yflux_lo;
364  (flx_arr[1])(i,j,k,1) = (flx_arr[1])(i,j ,k,0) * 0.5 * (prim(i,j,k,0) + prim(i,j-1,k,0));
365 
366  if (i == vbx_hi.x) {
367  (flx_arr[0])(i+1,j,k,0) = xflux_hi;
368  (flx_arr[0])(i+1,j,k,1) = (flx_arr[0])(i+1,j,k,0) * 0.5 * (prim(i,j,k,0) + prim(i+1,j,k,0));
369  }
370  if (j == vbx_hi.y) {
371  (flx_arr[1])(i,j+1,k,0) = yflux_hi;
372  (flx_arr[1])(i,j+1,k,1) = (flx_arr[1])(i,j+1,k,0) * 0.5 * (prim(i,j,k,0) + prim(i,j+1,k,0));
373  }
374  }
375  });
376 
377  Box bx_shrunk_in_k = bx;
378  int klo = tbz.smallEnd(2);
379  int khi = tbz.bigEnd(2);
380  bx_shrunk_in_k.setSmall(2,klo+1);
381  bx_shrunk_in_k.setBig(2,khi-1);
382 
383  // Note that the notes use "g" to mean the magnitude of gravity, so it is positive
384  // We set grav_gpu[2] to be the vector component which is negative
385  // We define halfg to match the notes (which is why we take the absolute value)
386  Real halfg = std::abs(0.5 * grav_gpu[2]);
387 
388  // *********************************************************************
389  // fast_loop_on_shrunk
390  // *********************************************************************
391  //Note we don't act on the bottom or top boundaries of the domain
392  ParallelFor(bx_shrunk_in_k, [=] AMREX_GPU_DEVICE (int i, int j, int k)
393  {
394  Real q = (l_use_moisture) ? 0.5 * (qt_arr(i,j,k) + qt_arr(i,j,k-1)) : 0.0;
395 
396  Real coeff_P = coeffP_a(i,j,k) / (1.0 + q);
397  Real coeff_Q = coeffQ_a(i,j,k) / (1.0 + q);
398 
399  Real theta_t_lo = 0.5 * ( prim(i,j,k-2,PrimTheta_comp) + prim(i,j,k-1,PrimTheta_comp) );
400  Real theta_t_mid = 0.5 * ( prim(i,j,k-1,PrimTheta_comp) + prim(i,j,k ,PrimTheta_comp) );
401  Real theta_t_hi = 0.5 * ( prim(i,j,k ,PrimTheta_comp) + prim(i,j,k+1,PrimTheta_comp) );
402 
403  Real Omega_kp1 = prev_zmom(i,j,k+1) - stage_zmom(i,j,k+1);
404  Real Omega_k = prev_zmom(i,j,k ) - stage_zmom(i,j,k );
405  Real Omega_km1 = prev_zmom(i,j,k-1) - stage_zmom(i,j,k-1);
406 
407  // line 2 last two terms (order dtau)
408  Real old_drho_k = prev_cons(i,j,k ,Rho_comp) - stage_cons(i,j,k ,Rho_comp);
409  Real old_drho_km1 = prev_cons(i,j,k-1,Rho_comp) - stage_cons(i,j,k-1,Rho_comp);
410  Real R0_tmp = coeff_P * prev_drho_theta(i,j,k) + coeff_Q * prev_drho_theta(i,j,k-1)
411  - halfg * ( old_drho_k + old_drho_km1 );
412 
413  // lines 3-5 residuals (order dtau^2) 1.0 <-> beta_2
414  Real R1_tmp = halfg * (-slow_rhs_cons(i,j,k ,Rho_comp)
415  -slow_rhs_cons(i,j,k-1,Rho_comp)
416  +temp_rhs_arr(i,j,k,0) + temp_rhs_arr(i,j,k-1) )
417  + ( coeff_P * (slow_rhs_cons(i,j,k ,RhoTheta_comp) - temp_rhs_arr(i,j,k ,RhoTheta_comp)) +
418  coeff_Q * (slow_rhs_cons(i,j,k-1,RhoTheta_comp) - temp_rhs_arr(i,j,k-1,RhoTheta_comp)) );
419 
420  // lines 6&7 consolidated (reuse Omega & metrics) (order dtau^2)
421  R1_tmp += beta_1 * dzi * ( (Omega_kp1 - Omega_km1) * halfg
422  -(Omega_kp1*theta_t_hi - Omega_k *theta_t_mid) * coeff_P
423  -(Omega_k *theta_t_mid - Omega_km1*theta_t_lo ) * coeff_Q );
424 
425  // line 1
426  RHS_a(i,j,k) = Omega_k + dtau * (slow_rhs_rho_w(i,j,k) + R0_tmp + dtau * beta_2 * R1_tmp + zmom_src_arr(i,j,k));
427 
428  }); // bx_shrunk_in_k
429 
430  Box b2d = tbz; // Copy constructor
431  b2d.setRange(2,0);
432 
433  auto const lo = lbound(bx);
434  auto const hi = ubound(bx);
435 
436  ParallelFor(b2d, [=] AMREX_GPU_DEVICE (int i, int j, int)
437  {
438  // w at bottom boundary of grid is 0 if at domain boundary, otherwise w = w_old + dtau * slow_rhs
439  RHS_a (i,j,lo.z) = prev_zmom(i,j,lo.z) - stage_zmom(i,j,lo.z)
440  + dtau * slow_rhs_rho_w(i,j,lo.z)
441  + dtau * zmom_src_arr(i,j,lo.z);
442 
443  // w at top boundary of grid is 0 if at domain boundary, otherwise w = w_old + dtau * slow_rhs
444  RHS_a (i,j,hi.z+1) = prev_zmom(i,j,hi.z+1) - stage_zmom(i,j,hi.z+1)
445  + dtau * slow_rhs_rho_w(i,j,hi.z+1)
446  + dtau * zmom_src_arr(i,j,hi.z+1);
447  }); // b2d
448 
449 #ifdef AMREX_USE_GPU
450  if (l_implicit_substepping) {
451 
452  ParallelFor(b2d, [=] AMREX_GPU_DEVICE (int i, int j, int)
453  {
454  // w = specified Dirichlet value at k = lo.z
455  soln_a(i,j,lo.z) = RHS_a(i,j,lo.z) * inv_coeffB_a(i,j,lo.z);
456  cur_zmom(i,j,lo.z) = stage_zmom(i,j,lo.z) + soln_a(i,j,lo.z);
457 
458  for (int k = lo.z+1; k <= hi.z+1; k++) {
459  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);
460  }
461 
462  cur_zmom(i,j,hi.z+1) = stage_zmom(i,j,hi.z+1) + soln_a(i,j,hi.z+1);
463 
464  for (int k = hi.z; k >= lo.z; k--) {
465  soln_a(i,j,k) -= ( coeffC_a(i,j,k) * inv_coeffB_a(i,j,k) ) *soln_a(i,j,k+1);
466  cur_zmom(i,j,k) = stage_zmom(i,j,k) + soln_a(i,j,k);
467  }
468  }); // b2d
469 
470  } else { // explicit substepping (beta_1 = 1; beta_2 = 0)
471 
472  ParallelFor(b2d, [=] AMREX_GPU_DEVICE (int i, int j, int)
473  {
474  for (int k = lo.z; k <= hi.z+1; k++) {
475  soln_a(i,j,k) = RHS_a(i,j,k);
476  cur_zmom(i,j,k) = stage_zmom(i,j,k) + soln_a(i,j,k);
477  }
478  }); // b2d
479  } // end of explicit substepping
480 #else
481  if (l_implicit_substepping) {
482 
483  for (int j = lo.y; j <= hi.y; ++j) {
484  AMREX_PRAGMA_SIMD
485  for (int i = lo.x; i <= hi.x; ++i) {
486  soln_a(i,j,lo.z) = RHS_a(i,j,lo.z) * inv_coeffB_a(i,j,lo.z);
487  }
488  }
489  for (int k = lo.z+1; k <= hi.z+1; ++k) {
490  for (int j = lo.y; j <= hi.y; ++j) {
491  AMREX_PRAGMA_SIMD
492  for (int i = lo.x; i <= hi.x; ++i) {
493  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);
494  }
495  }
496  }
497  for (int j = lo.y; j <= hi.y; ++j) {
498  AMREX_PRAGMA_SIMD
499  for (int i = lo.x; i <= hi.x; ++i) {
500  cur_zmom(i,j,hi.z+1) = stage_zmom(i,j,hi.z+1) + soln_a(i,j,hi.z+1);
501  }
502  }
503  for (int k = hi.z; k >= lo.z; --k) {
504  for (int j = lo.y; j <= hi.y; ++j) {
505  AMREX_PRAGMA_SIMD
506  for (int i = lo.x; i <= hi.x; ++i) {
507  soln_a(i,j,k) -= ( coeffC_a(i,j,k) * inv_coeffB_a(i,j,k) ) * soln_a(i,j,k+1);
508  cur_zmom(i,j,k) = stage_zmom(i,j,k) + soln_a(i,j,k);
509  }
510  }
511  }
512  } else { // explicit substepping (beta_1 = 1; beta_2 = 0)
513 
514  for (int k = lo.z; k <= hi.z+1; ++k) {
515  for (int j = lo.y; j <= hi.y; ++j) {
516  AMREX_PRAGMA_SIMD
517  for (int i = lo.x; i <= hi.x; ++i) {
518 
519  soln_a(i,j,k) = RHS_a(i,j,k);
520 
521  cur_zmom(i,j,k) = stage_zmom(i,j,k) + soln_a(i,j,k);
522  }
523  }
524  }
525 
526  } // end of explicit substepping
527 #endif
528 
529  // **************************************************************************
530  // Define updates in the RHS of rho and (rho theta)
531  // **************************************************************************
532  const Array4<Real>& prev_drho_w = Delta_rho_w.array(mfi);
533  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
534  {
535  Real zflux_lo = beta_2 * soln_a(i,j,k ) + beta_1 * prev_drho_w(i,j,k );
536  Real zflux_hi = beta_2 * soln_a(i,j,k+1) + beta_1 * prev_drho_w(i,j,k+1);
537 
538  avg_zmom_arr(i,j,k) += facinv*zflux_lo / (mf_mx(i,j,0) * mf_my(i,j,0));
539  if (l_reflux) {
540  (flx_arr[2])(i,j,k,0) = zflux_lo / (mf_mx(i,j,0) * mf_my(i,j,0));
541  (flx_arr[2])(i,j,k,1) = (flx_arr[2])(i,j,k,0) * 0.5 * (prim(i,j,k) + prim(i,j,k-1));
542  }
543 
544  if (k == vbx_hi.z) {
545  avg_zmom_arr(i,j,k+1) += facinv * zflux_hi / (mf_mx(i,j,0) * mf_my(i,j,0));
546  if (l_reflux) {
547  (flx_arr[2])(i,j,k+1,0) = zflux_hi / (mf_mx(i,j,0) * mf_my(i,j,0));
548  (flx_arr[2])(i,j,k+1,1) = (flx_arr[2])(i,j,k+1,0) * 0.5 * (prim(i,j,k) + prim(i,j,k+1));
549  }
550  }
551 
552  temp_rhs_arr(i,j,k,Rho_comp ) += dzi * ( zflux_hi - zflux_lo );
553  temp_rhs_arr(i,j,k,RhoTheta_comp) += 0.5 * dzi * ( zflux_hi * (prim(i,j,k) + prim(i,j,k+1))
554  - zflux_lo * (prim(i,j,k) + prim(i,j,k-1)) );
555  });
556 
557  // We only add to the flux registers in the final RK step
558  if (l_reflux) {
559  int strt_comp_reflux = 0;
560  // For now we don't reflux (rho theta) because it seems to create issues at c/f boundaries
561  int num_comp_reflux = 1;
562  if (level < finest_level) {
563  fr_as_crse->CrseAdd(mfi,
564  {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
565  dx, dtau, strt_comp_reflux, strt_comp_reflux, num_comp_reflux, RunOn::Device);
566  }
567  if (level > 0) {
568  fr_as_fine->FineAdd(mfi,
569  {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
570  dx, dtau, strt_comp_reflux, strt_comp_reflux, num_comp_reflux, RunOn::Device);
571  }
572 
573  // This is necessary here so we don't go on to the next FArrayBox without
574  // having finished copying the fluxes into the FluxRegisters (since the fluxes
575  // are stored in temporary FArrayBox's)
576  Gpu::streamSynchronize();
577 
578  } // two-way coupling
579  } // mfi
580  } // OMP
581 
582 #ifdef _OPENMP
583 #pragma omp parallel if (Gpu::notInLaunchRegion())
584 #endif
585  for ( MFIter mfi(S_stage_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi)
586  {
587  const Box& bx = mfi.tilebox();
588 
589  const Array4< Real>& cur_cons = S_data[IntVars::cons].array(mfi);
590  const Array4<const Real>& prev_cons = S_prev[IntVars::cons].const_array(mfi);
591  auto const& temp_rhs_arr = temp_rhs.const_array(mfi);
592  auto const& slow_rhs_cons = S_slow_rhs[IntVars::cons].const_array(mfi);
593  const Array4<Real const>& cc_src_arr = cc_src.const_array(mfi);
594 
595  if (step == 0) {
596  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
597  {
598  cur_cons(i,j,k,Rho_comp) = prev_cons(i,j,k,Rho_comp) +
599  dtau * (slow_rhs_cons(i,j,k,Rho_comp) - temp_rhs_arr(i,j,k,Rho_comp));
600  cur_cons(i,j,k,RhoTheta_comp) = prev_cons(i,j,k,RhoTheta_comp) +
601  dtau * (slow_rhs_cons(i,j,k,RhoTheta_comp) - temp_rhs_arr(i,j,k,RhoTheta_comp));
602 
603  // add in source terms for cell-centered conserved variables
604  cur_cons(i,j,k,Rho_comp) += dtau * cc_src_arr(i,j,k,Rho_comp);
605  cur_cons(i,j,k,RhoTheta_comp) += dtau * cc_src_arr(i,j,k,RhoTheta_comp);
606  });
607  } else {
608  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
609  {
610  //
611  // We didn't need to set cur_cons = prev_cons above because they point to the same data for step > 0
612  //
613  cur_cons(i,j,k,Rho_comp) += dtau * (slow_rhs_cons(i,j,k,Rho_comp) - temp_rhs_arr(i,j,k,Rho_comp));
614  cur_cons(i,j,k,RhoTheta_comp) += dtau * (slow_rhs_cons(i,j,k,RhoTheta_comp) - temp_rhs_arr(i,j,k,RhoTheta_comp));
615 
616  // add in source terms for cell-centered conserved variables
617  cur_cons(i,j,k,Rho_comp) += dtau * cc_src_arr(i,j,k,Rho_comp);
618  cur_cons(i,j,k,RhoTheta_comp) += dtau * cc_src_arr(i,j,k,RhoTheta_comp);
619  });
620  } // step = 0
621 
622  const Array4<Real>& cur_xmom = S_data[IntVars::xmom].array(mfi);
623  const Array4<Real>& cur_ymom = S_data[IntVars::ymom].array(mfi);
624 
625  const Array4<Real const>& temp_cur_xmom_arr = temp_cur_xmom.const_array(mfi);
626  const Array4<Real const>& temp_cur_ymom_arr = temp_cur_ymom.const_array(mfi);
627 
628  Box tbx = surroundingNodes(bx,0);
629  Box tby = surroundingNodes(bx,1);
630 
631  ParallelFor(tbx, tby,
632  [=] AMREX_GPU_DEVICE (int i, int j, int k)
633  {
634  cur_xmom(i,j,k) = temp_cur_xmom_arr(i,j,k);
635  },
636  [=] AMREX_GPU_DEVICE (int i, int j, int k)
637  {
638  cur_ymom(i,j,k) = temp_cur_ymom_arr(i,j,k);
639  });
640 
641  } // mfi
642 }
constexpr amrex::Real R_v
Definition: ERF_Constants.H:11
constexpr amrex::Real R_d
Definition: ERF_Constants.H:10
constexpr amrex::Real Gamma
Definition: ERF_Constants.H:19
@ v_x
Definition: ERF_DataStruct.H:22
@ u_y
Definition: ERF_DataStruct.H:23
@ v_y
Definition: ERF_DataStruct.H:23
@ m_y
Definition: ERF_DataStruct.H:23
@ u_x
Definition: ERF_DataStruct.H:22
@ m_x
Definition: ERF_DataStruct.H:22
#define PrimQ1_comp
Definition: ERF_IndexDefines.H:53
#define Rho_comp
Definition: ERF_IndexDefines.H:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define PrimTheta_comp
Definition: ERF_IndexDefines.H:50
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ gpy
Definition: ERF_IndexDefines.H:151
@ gpx
Definition: ERF_IndexDefines.H:150
@ ymom
Definition: ERF_IndexDefines.H:160
@ cons
Definition: ERF_IndexDefines.H:158
@ zmom
Definition: ERF_IndexDefines.H:161
@ xmom
Definition: ERF_IndexDefines.H:159
@ qt
Definition: ERF_Kessler.H:27
@ qv
Definition: ERF_Kessler.H:28
Here is the call graph for this function: