Function for computing the slow RHS for the evolution equations for the density, potential temperature and momentum.
79 BL_PROFILE_REGION(
"erf_make_mom_sources()");
81 Real time =
static_cast<Real
>(time_d);
83 Box domain(geom.Domain());
84 const GpuArray<Real, AMREX_SPACEDIM>
dxInv = geom.InvCellSizeArray();
99 bool use_canopy_fast = solverChoice.
forest_fast(level);
120 if (solverChoice.
terrain_type == TerrainType::ImmersedForcing) {
122 amrex::Error(
" Currently forest canopy cannot be used with immersed forcing");
132 auto cosphi = solverChoice.
cosphi;
133 auto sinphi = solverChoice.
sinphi;
164 Real rhoUA_target{0};
165 Real rhoVA_target{0};
171 Real massflux_area_x{0};
172 Real massflux_area_y{0};
177 Table1D<Real> dptr_r_plane, dptr_u_plane, dptr_v_plane;
178 TableData<Real, 1> r_plane_tab, u_plane_tab, v_plane_tab;
180 if (is_slow_step && (dptr_wbar_sub ||
183 enforce_massflux_x || enforce_massflux_y))
188 const bool planar_averages_valid =
189 solverChoice.
mesh_type != MeshType::VariableDz ||
192 planar_averages_valid,
193 "Fixed-index planar averages require a non-variable-dz mesh or "
194 "a validated flat fitted mesh (erf.flat_terrain = true).");
197 const int u_offset = 1;
198 const int v_offset = 1;
207 r_ave.compute_averages(
ZDir(), r_ave.field());
209 int ncell = r_ave.ncell_line();
210 Gpu::HostVector< Real> r_plane_h(ncell);
211 Gpu::DeviceVector< Real> r_plane_d(ncell);
213 r_ave.line_average(
Rho_comp, r_plane_h);
215 Gpu::copyAsync(Gpu::hostToDevice, r_plane_h.begin(), r_plane_h.end(), r_plane_d.begin());
217 Real* dptr_r = r_plane_d.data();
219 Box tdomain = domain; tdomain.grow(2,ng_c[2]);
220 r_plane_tab.resize({tdomain.smallEnd(2)}, {tdomain.bigEnd(2)});
222 dptr_r_plane = r_plane_tab.table();
223 ParallelFor(ncell, [=] AMREX_GPU_DEVICE (
int k) noexcept
225 dptr_r_plane(k-
offset) = dptr_r[k];
229 IntVect ng_u = S_data[
IntVars::xmom].nGrowVect(); ng_u[2] = u_offset;
232 IntVect ng_v = S_data[
IntVars::ymom].nGrowVect(); ng_v[2] = v_offset;
235 u_ave.compute_averages(
ZDir(), u_ave.field());
236 v_ave.compute_averages(
ZDir(), v_ave.field());
238 int u_ncell = u_ave.ncell_line();
239 int v_ncell = v_ave.ncell_line();
240 Gpu::HostVector< Real> u_plane_h(u_ncell), v_plane_h(v_ncell);
241 Gpu::DeviceVector< Real> u_plane_d(u_ncell), v_plane_d(v_ncell);
243 u_ave.line_average(0, u_plane_h);
244 v_ave.line_average(0, v_plane_h);
246 Gpu::copyAsync(Gpu::hostToDevice, u_plane_h.begin(), u_plane_h.end(), u_plane_d.begin());
247 Gpu::copyAsync(Gpu::hostToDevice, v_plane_h.begin(), v_plane_h.end(), v_plane_d.begin());
249 Real* dptr_u = u_plane_d.data();
250 Real* dptr_v = v_plane_d.data();
252 Box udomain = domain; udomain.grow(2,ng_u[2]);
253 Box vdomain = domain; vdomain.grow(2,ng_v[2]);
254 u_plane_tab.resize({udomain.smallEnd(2)}, {udomain.bigEnd(2)});
255 v_plane_tab.resize({vdomain.smallEnd(2)}, {vdomain.bigEnd(2)});
257 dptr_u_plane = u_plane_tab.table();
258 ParallelFor(u_ncell, [=] AMREX_GPU_DEVICE (
int k) noexcept
260 dptr_u_plane(k-u_offset) = dptr_u[k];
263 dptr_v_plane = v_plane_tab.table();
264 ParallelFor(v_ncell, [=] AMREX_GPU_DEVICE (
int k) noexcept
266 dptr_v_plane(k-v_offset) = dptr_v[k];
270 if (enforce_massflux_x || enforce_massflux_y) {
271 Real Lx = geom.ProbHi(0) - geom.ProbLo(0);
272 Real Ly = geom.ProbHi(1) - geom.ProbLo(1);
274 if (solverChoice.
mesh_type == MeshType::ConstantDz) {
276 rhoUA = std::accumulate(u_plane_h.begin() + u_offset + massflux_klo,
277 u_plane_h.begin() + u_offset + massflux_khi+1,
zero);
278 rhoVA = std::accumulate(v_plane_h.begin() + v_offset + massflux_klo,
279 v_plane_h.begin() + v_offset + massflux_khi+1,
zero);
280 rhoUA_target = std::accumulate(r_plane_h.begin() +
offset + massflux_klo,
281 r_plane_h.begin() +
offset + massflux_khi+1,
zero);
282 rhoVA_target = rhoUA_target;
284 rhoUA *= geom.CellSize(2) * Ly;
285 rhoVA *= geom.CellSize(2) * Lx;
286 rhoUA_target *= geom.CellSize(2) * Ly;
287 rhoVA_target *= geom.CellSize(2) * Lx;
289 const Real
H = geom.CellSize(2) *
static_cast<Real
>(massflux_khi - massflux_klo + 1);
290 massflux_area_x =
H * Ly;
291 massflux_area_y =
H * Lx;
293 }
else if (solverChoice.
mesh_type == MeshType::StretchedDz) {
296 for (
int k=massflux_klo; k < massflux_khi; ++k) {
297 rhoUA += u_plane_h[k + u_offset] * stretched_dz_h[k];
298 rhoVA += v_plane_h[k + v_offset] * stretched_dz_h[k];
299 rhoUA_target += r_plane_h[k +
offset] * stretched_dz_h[k];
300 H += stretched_dz_h[k];
302 rhoVA_target = rhoUA_target;
309 massflux_area_x =
H * Ly;
310 massflux_area_y =
H * Lx;
314 rhoUA_target *= U_target;
315 rhoVA_target *= V_target;
317 Print() <<
"Integrated mass flux : " << rhoUA <<
" " << rhoVA
318 <<
" (target: " << rhoUA_target <<
" " << rhoVA_target <<
")"
326 for ( MFIter mfi(S_data[
IntVars::cons]); mfi.isValid(); ++mfi)
328 Box tbx = mfi.nodaltilebox(0);
329 Box tby = mfi.nodaltilebox(1);
330 Box tbz = mfi.nodaltilebox(2);
331 if (tbz.bigEnd(2) == domain.bigEnd(2)+1) tbz.growHi(2,-1);
333 const Array4<const Real>& cell_data = S_data[
IntVars::cons].array(mfi);
334 const Array4<const Real>& rho_u = S_data[
IntVars::xmom].array(mfi);
335 const Array4<const Real>& rho_v = S_data[
IntVars::ymom].array(mfi);
336 const Array4<const Real>& rho_w = S_data[
IntVars::zmom].array(mfi);
338 const Array4<const Real>& u =
xvel.array(mfi);
339 const Array4<const Real>& v =
yvel.array(mfi);
340 const Array4<const Real>& w = wvel.array(mfi);
342 const Array4< Real>& xmom_src_arr = xmom_src.array(mfi);
343 const Array4< Real>& ymom_src_arr = ymom_src.array(mfi);
344 const Array4< Real>& zmom_src_arr = zmom_src.array(mfi);
346 const Array4<const Real>&
r0 = r_hse.const_array(mfi);
348 const Array4<const Real>& f_drag_arr = (forest_drag) ? forest_drag->const_array(mfi) :
349 Array4<const Real>{};
350 const Array4<const Real>& t_blank_arr = (terrain_blank) ? terrain_blank->const_array(mfi) :
351 Array4<const Real>{};
352 const Array4<const Real>& t_blank_xface_arr = (terrain_blank_xface) ? terrain_blank_xface->const_array(mfi) :
353 Array4<const Real>{};
354 const Array4<const Real>& t_blank_yface_arr = (terrain_blank_yface) ? terrain_blank_yface->const_array(mfi) :
355 Array4<const Real>{};
356 const Array4<const Real>& t_blank_zface_arr = (terrain_blank_zface) ? terrain_blank_zface->const_array(mfi) :
357 Array4<const Real>{};
359 const Array4<const Real>& cphi_arr = (cosPhi_mf) ? cosPhi_mf->const_array(mfi) :
360 Array4<const Real>{};
361 const Array4<const Real>& sphi_arr = (sinPhi_mf) ? sinPhi_mf->const_array(mfi) :
362 Array4<const Real>{};
364 const Array4<const Real>& z_nd_arr = z_phys_nd->const_array(mfi);
365 const Array4<const Real>& z_cc_arr = z_phys_cc->const_array(mfi);
371 if (use_coriolis && is_slow_step) {
374 if (solverChoice.
init_type == InitType::HindCast && forecast_state_at_lev !=
nullptr) {
375 const Array4<const Real>& latlon_arr = (*forecast_state_at_lev)[4].const_array(mfi);
377 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
380 Real v_loc =
fourth * (v(i,j+1,k) + v(i,j,k) + v(i-1,j+1,k) + v(i-1,j,k));
381 Real w_loc =
fourth * (w(i,j,k+1) + w(i,j,k) + w(i-1,j,k+1) + w(i-1,j,k));
382 Real latitude = latlon_arr(i,j,k,0);
383 Real sphi_loc = std::sin(latitude*
PI/Real(180.0));
384 Real cphi_loc = std::cos(latitude*
PI/Real(180.0));
385 xmom_src_arr(i, j, k) += coriolis_factor * rho_on_u_face * (v_loc * sphi_loc - w_loc * cphi_loc);
387 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
389 Real u_loc =
fourth * (u(i+1,j,k) + u(i,j,k) + u(i+1,j-1,k) + u(i,j-1,k));
390 Real latitude = latlon_arr(i,j,k,0);
391 Real sphi_loc = std::sin(latitude*
PI/Real(180.0));
392 ymom_src_arr(i, j, k) += -coriolis_factor * rho_on_v_face * u_loc * sphi_loc;
394 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
396 Real u_loc =
fourth * (u(i+1,j,k) + u(i,j,k) + u(i+1,j,k-1) + u(i,j,k-1));
397 Real latitude = latlon_arr(i,j,k,0);
398 Real cphi_loc = std::cos(latitude*
PI/Real(180.0));
399 zmom_src_arr(i, j, k) += coriolis_factor * rho_on_w_face * u_loc * cphi_loc;
402 else if (var_coriolis && (sinPhi_mf) && (cosPhi_mf)) {
404 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
407 Real v_loc =
fourth * (v(i,j+1,k) + v(i,j,k) + v(i-1,j+1,k) + v(i-1,j,k));
408 Real w_loc =
fourth * (w(i,j,k+1) + w(i,j,k) + w(i-1,j,k+1) + w(i-1,j,k));
409 Real sphi_loc =
myhalf * (sphi_arr(i,j,0) + sphi_arr(i-1,j,0));
410 Real cphi_loc =
myhalf * (cphi_arr(i,j,0) + cphi_arr(i-1,j,0));
411 xmom_src_arr(i, j, k) += coriolis_factor * rho_on_u_face * (v_loc * sphi_loc - w_loc * cphi_loc);
413 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
415 Real u_loc =
fourth * (u(i+1,j,k) + u(i,j,k) + u(i+1,j-1,k) + u(i,j-1,k));
416 Real sphi_loc =
myhalf * (sphi_arr(i,j,0) + sphi_arr(i,j-1,0));
417 ymom_src_arr(i, j, k) += -coriolis_factor * rho_on_v_face * u_loc * sphi_loc;
419 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
421 Real u_loc =
fourth * (u(i+1,j,k) + u(i,j,k) + u(i+1,j,k-1) + u(i,j,k-1));
422 zmom_src_arr(i, j, k) += coriolis_factor * rho_on_w_face * u_loc * cphi_arr(i,j,0);
426 Array4<const Real> u_volfrac = (ebfact.
get_u_const_factory())->getVolFrac().const_array(mfi);
427 Array4<const Real> v_volfrac = (ebfact.
get_v_const_factory())->getVolFrac().const_array(mfi);
428 Array4<const Real> w_volfrac = (ebfact.
get_w_const_factory())->getVolFrac().const_array(mfi);
429 ParallelFor(tbx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
432 Real v_vol = v_volfrac(i,j+1,k) + v_volfrac(i,j,k) + v_volfrac(i-1,j+1,k) + v_volfrac(i-1,j,k);
433 Real w_vol = w_volfrac(i,j,k+1) + w_volfrac(i,j,k) + w_volfrac(i-1,j,k+1) + w_volfrac(i-1,j,k);
436 v_loc = ( v_volfrac(i ,j+1,k) * v(i ,j+1,k) + v_volfrac(i ,j,k) * v(i ,j,k)
437 + v_volfrac(i-1,j+1,k) * v(i-1,j+1,k) + v_volfrac(i-1,j,k) * v(i-1,j,k)) / v_vol;
440 w_loc = ( w_volfrac(i ,j,k+1) * w(i ,j,k+1) + w_volfrac(i ,j,k) * w(i ,j,k)
441 + w_volfrac(i-1,j,k+1) * w(i-1,j,k+1) + w_volfrac(i-1,j,k) * w(i-1,j,k)) / w_vol;
443 xmom_src_arr(i, j, k) += coriolis_factor * rho_on_u_face * (v_loc * sinphi - w_loc * cosphi);
445 ParallelFor(tby, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
447 Real u_vol = u_volfrac(i+1,j,k) + u_volfrac(i,j,k) + u_volfrac(i+1,j-1,k) + u_volfrac(i,j-1,k);
450 u_loc = ( u_volfrac(i+1,j ,k) * u(i+1,j ,k) + u_volfrac(i,j ,k) * u(i,j ,k)
451 + u_volfrac(i+1,j-1,k) * u(i+1,j-1,k) + u_volfrac(i,j-1,k) * u(i,j-1,k)) / u_vol;
453 ymom_src_arr(i, j, k) += -coriolis_factor * rho_on_v_face * u_loc * sinphi;
455 ParallelFor(tbz, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
457 Real u_vol = u_volfrac(i+1,j,k) + u_volfrac(i,j,k) + u_volfrac(i+1,j,k-1) + u_volfrac(i,j,k-1);
460 u_loc = ( u_volfrac(i+1,j,k ) * u(i+1,j,k ) + u_volfrac(i,j,k) * u(i,j,k )
461 + u_volfrac(i+1,j,k-1) * u(i+1,j,k-1) + u_volfrac(i,j,k-1) * u(i,j,k-1)) / u_vol;
463 zmom_src_arr(i, j, k) += coriolis_factor * rho_on_w_face * u_loc * cosphi;
467 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
469 Real v_loc =
fourth * (v(i,j+1,k) + v(i,j,k) + v(i-1,j+1,k) + v(i-1,j,k));
470 Real w_loc =
fourth * (w(i,j,k+1) + w(i,j,k) + w(i-1,j,k+1) + w(i-1,j,k));
472 xmom_src_arr(i, j, k) += rho_on_u_face * ( coriolis_factor * (v_loc * sinphi - w_loc * cosphi) );
474 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
476 Real u_loc =
fourth * (u(i+1,j,k) + u(i,j,k) + u(i+1,j-1,k) + u(i,j-1,k));
477 ymom_src_arr(i, j, k) += rho_on_v_face * ( -coriolis_factor * u_loc * sinphi );
479 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
480 Real u_loc =
fourth * (u(i+1,j,k) + u(i,j,k) + u(i+1,j,k-1) + u(i,j,k-1));
482 zmom_src_arr(i, j, k) += rho_on_w_face * ( coriolis_factor * u_loc * cosphi );
493 if ( (is_slow_step && !use_Rayleigh_fast_uv) || (!is_slow_step && use_Rayleigh_fast_uv)) {
494 if (rayleigh_damp_U) {
495 ParallelFor(tbx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
498 Real uu = rho_u(i,j,k) / rho_on_u_face;
499 Real sinesq = d_sinesq_at_lev[k];
500 xmom_src_arr(i, j, k) -= dampcoef*sinesq * (uu -
ubar[k]) * rho_on_u_face;
504 if (rayleigh_damp_V) {
505 ParallelFor(tby, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
508 Real vv = rho_v(i,j,k) / rho_on_v_face;
509 Real sinesq = d_sinesq_at_lev[k];
510 ymom_src_arr(i, j, k) -= dampcoef*sinesq * (vv -
vbar[k]) * rho_on_v_face;
517 if ( (is_slow_step && !use_Rayleigh_fast_w && !use_Rayleigh_impl_w) ||
518 (!is_slow_step && use_Rayleigh_fast_w) ) {
519 if (rayleigh_damp_W) {
520 ParallelFor(tbz, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
523 Real
ww = rho_w(i,j,k) / rho_on_w_face;
524 Real sinesq = d_sinesq_stag_at_lev[k];
525 zmom_src_arr(i, j, k) -= dampcoef*sinesq * (
ww -
wbar[k]) * rho_on_w_face;
535 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
538 xmom_src_arr(i, j, k) += rho_on_u_face * abl_geo_forcing[0];
540 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
543 ymom_src_arr(i, j, k) += rho_on_v_face * abl_geo_forcing[1];
545 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
548 zmom_src_arr(i, j, k) += rho_on_w_face * abl_geo_forcing[2];
555 if (geo_wind_profile && is_slow_step) {
558 const bool geo_hindcast_lat = (solverChoice.
init_type == InitType::HindCast) &&
559 (forecast_state_at_lev !=
nullptr);
560 const bool geo_var_sinphi = !geo_hindcast_lat && var_coriolis && (sinPhi_mf !=
nullptr);
561 const Array4<const Real> geo_latlon_arr = (geo_hindcast_lat) ?
562 (*forecast_state_at_lev)[4].const_array(mfi) : Array4<const Real>{};
564 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
566 Real sphi_loc = (geo_hindcast_lat) ? std::sin(geo_latlon_arr(i,j,k,0)*
PI/Real(180.0)) :
567 (geo_var_sinphi) ?
myhalf * (sphi_arr(i,j,0) + sphi_arr(i-1,j,0)) : sinphi;
569 xmom_src_arr(i, j, k) -= coriolis_factor * rho_on_u_face * dptr_v_geos[k] * sphi_loc;
571 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
573 Real sphi_loc = (geo_hindcast_lat) ? std::sin(geo_latlon_arr(i,j,k,0)*
PI/Real(180.0)) :
574 (geo_var_sinphi) ?
myhalf * (sphi_arr(i,j,0) + sphi_arr(i,j-1,0)) : sinphi;
576 ymom_src_arr(i, j, k) += coriolis_factor * rho_on_v_face * dptr_u_geos[k] * sphi_loc;
588 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
592 Real z_xf_lo =
fourth * ( z_nd_arr(i,j,k ) + z_nd_arr(i,j+1,k )
593 + z_nd_arr(i,j,k-1) + z_nd_arr(i,j+1,k-1) );
594 Real z_xf_hi =
fourth * ( z_nd_arr(i,j,k+1) + z_nd_arr(i,j+1,k+1)
595 + z_nd_arr(i,j,k+2) + z_nd_arr(i,j+1,k+2) );
596 dzInv =
one / (z_xf_hi - z_xf_lo);
598 Real rho_on_u_face =
myhalf * ( cell_data(i,j,k,
nr) + cell_data(i-1,j,k,
nr) );
599 Real U_hi = dptr_u_plane(k+1) / dptr_r_plane(k+1);
600 Real U_lo = dptr_u_plane(k-1) / dptr_r_plane(k-1);
601 Real wbar_xf =
myhalf * (dptr_wbar_sub[k] + dptr_wbar_sub[k+1]);
602 xmom_src_arr(i, j, k) -= rho_on_u_face * wbar_xf * (U_hi - U_lo) * dzInv;
604 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
608 Real z_yf_lo =
fourth * ( z_nd_arr(i,j,k ) + z_nd_arr(i+1,j,k )
609 + z_nd_arr(i,j,k-1) + z_nd_arr(i+1,j,k-1) );
610 Real z_yf_hi =
fourth * ( z_nd_arr(i,j,k+1) + z_nd_arr(i+1,j,k+1)
611 + z_nd_arr(i,j,k+2) + z_nd_arr(i+1,j,k+2) );
612 dzInv =
one / (z_yf_hi - z_yf_lo);
614 Real rho_on_v_face =
myhalf * ( cell_data(i,j,k,
nr) + cell_data(i,j-1,k,
nr) );
615 Real V_hi = dptr_v_plane(k+1) / dptr_r_plane(k+1);
616 Real V_lo = dptr_v_plane(k-1) / dptr_r_plane(k-1);
617 Real wbar_yf =
myhalf * (dptr_wbar_sub[k] + dptr_wbar_sub[k+1]);
618 ymom_src_arr(i, j, k) -= rho_on_v_face * wbar_yf * (V_hi - V_lo) * dzInv;
625 auto lsf_arr = lsf_tendencies->const_array(mfi);
627 const int kmin = domain.smallEnd(2) + 1;
628 const int kmax = domain.bigEnd(2) - 1;
630 ParallelFor(tbx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
632 if (k >= kmin && k <= kmax) {
634 if (lsf_arr(i, j, k, 2) >= 0.0)
644 Real dzInv =
dxInv[2];
646 Real z_uf_1 =
fourth * ( z_nd_arr(i,j,
k1 ) + z_nd_arr(i,j+1,
k1 )
647 + z_nd_arr(i,j,
k1+1) + z_nd_arr(i,j+1,
k1+1) );
648 Real z_uf_2 =
fourth * ( z_nd_arr(i,j,k2 ) + z_nd_arr(i,j+1,k2 )
649 + z_nd_arr(i,j,k2+1) + z_nd_arr(i,j+1,k2+1) );
650 dzInv =
one / (z_uf_1 - z_uf_2);
653 amrex::Real utend = -(dzInv * lsf_arr(i, j, k, 2)) * ( u(i, j,
k1) - u(i, j, k2) );
654 xmom_src_arr(i, j, k) += utend * rho_on_u_face;
658 ParallelFor(tby, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
660 if (k >= kmin && k <= kmax) {
662 if (lsf_arr(i, j, k, 2) >= 0.0)
672 Real dzInv =
dxInv[2];
674 Real z_vf_1 =
fourth * ( z_nd_arr(i,j,
k1 ) + z_nd_arr(i+1,j,
k1 )
675 + z_nd_arr(i,j,
k1+1) + z_nd_arr(i+1,j,
k1+1) );
676 Real z_vf_2 =
fourth * ( z_nd_arr(i,j,k2 ) + z_nd_arr(i+1,j,k2 )
677 + z_nd_arr(i,j,k2+1) + z_nd_arr(i+1,j,k2+1) );
678 dzInv =
one / (z_vf_1 - z_vf_2);
680 Real rho_on_v_face = 0.5 * ( cell_data(i,j,k,
Rho_comp) + cell_data(i,j-1,k,
Rho_comp) );
681 amrex::Real vtend = -(dzInv * lsf_arr(i, j, k, 2)) * ( v(i, j,
k1) - v(i, j, k2) );
682 ymom_src_arr(i, j, k) += vtend * rho_on_v_face;
700 Real uv_coeff_n = 1.0;
701 Real uv_coeff_np1 = 0.0;
702 Real tau = Real(1.0) / input_sounding_data.
tau_nudging;
703 const Real *u_nudge_n, *u_nudge_np1, *v_nudge_n, *v_nudge_np1;
710 for (
int nt = 1; nt < n_sounding_times; nt++) {
713 if (itime_n == n_sounding_times-1) {
716 itime_np1 = itime_n+1;
719 uv_coeff_n = Real(1.0) - uv_coeff_np1;
721 u_nudge_n = input_sounding_data.
U_inp_sound_d[itime_n].dataPtr() + 1;
722 u_nudge_np1 = input_sounding_data.
U_inp_sound_d[itime_np1].dataPtr() + 1;
723 v_nudge_n = input_sounding_data.
V_inp_sound_d[itime_n].dataPtr() + 1;
724 v_nudge_np1 = input_sounding_data.
V_inp_sound_d[itime_np1].dataPtr() + 1;
733 u_nudge_n = lsf_data.
u_int_lsf_d[itime_curr].dataPtr();
734 u_nudge_np1 = lsf_data.
u_int_lsf_d[itime_next].dataPtr();
735 v_nudge_n = lsf_data.
v_int_lsf_d[itime_curr].dataPtr();
736 v_nudge_np1 = lsf_data.
v_int_lsf_d[itime_next].dataPtr();
739 ParallelFor(tbx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
741 Real
z = z_cc_arr(i,j,k);
742 if (l_lsf || (z >= u_z1 && z <= u_z2)) {
743 Real unudge = -((dptr_u_plane(k)/dptr_r_plane(k)) - (uv_coeff_n*u_nudge_n[k] + uv_coeff_np1*u_nudge_np1[k]));
744 xmom_src_arr(i, j, k) += tau * unudge * dptr_r_plane(k);
748 ParallelFor(tby, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
750 Real
z = z_cc_arr(i,j,k);
751 if (l_lsf || (z >= u_z1 && z <= u_z2)) {
752 Real vnudge = -((dptr_v_plane(k)/dptr_r_plane(k)) - (uv_coeff_n*v_nudge_n[k] + uv_coeff_np1*v_nudge_np1[k]));
753 ymom_src_arr(i, j, k) += tau * vnudge * dptr_r_plane(k);
763 const Array4<const Real>& mf_ux = mapfac[
MapFacType::u_x]->const_array(mfi);
764 const Array4<const Real>& mf_uy = mapfac[
MapFacType::u_y]->const_array(mfi);
765 const Array4<const Real>& mf_vx = mapfac[
MapFacType::v_x]->const_array(mfi);
766 const Array4<const Real>& mf_vy = mapfac[
MapFacType::v_y]->const_array(mfi);
768 u, cell_data, xmom_src_arr, mf_ux, mf_uy);
770 v, cell_data, ymom_src_arr, mf_vx, mf_vy);
781 z_cc_arr, xmom_src_arr, ymom_src_arr,
782 rho_u, rho_v, d_sponge_ptrs_at_lev);
787 xmom_src_arr, ymom_src_arr, zmom_src_arr, rho_u, rho_v, rho_w,
788 r0, z_nd_arr, z_cc_arr);
793 const Array4<const Real>& rho_u_forecast_state = (*forecast_state_at_lev)[
IntVars::xmom].array(mfi);
794 const Array4<const Real>& rho_v_forecast_state = (*forecast_state_at_lev)[
IntVars::ymom].array(mfi);
795 const Array4<const Real>& rho_w_forecast_state = (*forecast_state_at_lev)[
IntVars::zmom].array(mfi);
796 const Array4<const Real>& cons_forecast_state = (*forecast_state_at_lev)[
IntVars::cons].array(mfi);
798 xmom_src_arr, ymom_src_arr, zmom_src_arr,
800 rho_u_forecast_state, rho_v_forecast_state, rho_w_forecast_state,
801 cons_forecast_state);
814 ((is_slow_step && !use_canopy_fast) || (!is_slow_step && use_canopy_fast))) {
816 [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
818 const Real ux = u(i, j, k);
819 const Real uy =
fourth * ( v(i, j , k ) + v(i-1, j , k )
820 + v(i, j+1, k ) + v(i-1, j+1, k ) );
821 const Real uz =
fourth * ( w(i, j , k ) + w(i-1, j , k )
822 + w(i, j , k+1) + w(i-1, j , k+1) );
823 const Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
824 const Real f_drag =
myhalf * (f_drag_arr(i, j, k) + f_drag_arr(i-1, j, k));
826 xmom_src_arr(i, j, k) -= rho_on_u_face * f_drag * ux * windspeed;
828 [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
830 const Real ux =
fourth * ( u(i , j , k ) + u(i , j-1, k )
831 + u(i+1, j , k ) + u(i+1, j-1, k ) );
832 const Real uy = v(i, j, k);
833 const Real uz =
fourth * ( w(i , j , k ) + w(i , j-1, k )
834 + w(i , j , k+1) + w(i , j-1, k+1) );
835 const amrex::Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
836 const Real f_drag =
myhalf * (f_drag_arr(i, j, k) + f_drag_arr(i, j-1, k));
838 ymom_src_arr(i, j, k) -= rho_on_v_face * f_drag * uy * windspeed;
840 [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
842 const amrex::Real ux =
fourth * ( u(i , j , k ) + u(i+1, j , k )
843 + u(i , j , k-1) + u(i+1, j , k-1) );
844 const amrex::Real uy =
fourth * ( v(i , j , k ) + v(i , j+1, k )
845 + v(i , j , k-1) + v(i , j+1, k-1) );
846 const amrex::Real uz = w(i, j, k);
847 const amrex::Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
848 const Real f_drag =
myhalf * (f_drag_arr(i, j, k) + f_drag_arr(i, j, k-1));
850 zmom_src_arr(i, j, k) -= rho_on_w_face * f_drag * uz * windspeed;
859 if (solverChoice.
terrain_type == TerrainType::ImmersedForcing &&
860 ((is_slow_step && !use_ImmersedForcing_fast) || (!is_slow_step && use_ImmersedForcing_fast))) {
864 xmom_src_arr, geom, solverChoice, dt, time, l_if_drag_in_projection);
866 ymom_src_arr, geom, solverChoice, dt, time, l_if_drag_in_projection);
869 z_cc_arr, xmom_src_arr, geom, solverChoice, dt, l_if_drag_in_projection);
871 z_cc_arr, ymom_src_arr, geom, solverChoice, dt, l_if_drag_in_projection);
874 z_cc_arr, zmom_src_arr, geom, solverChoice, dt, l_if_drag_in_projection);
881 ((is_slow_step && !use_ImmersedForcing_fast) || (!is_slow_step && use_ImmersedForcing_fast))) {
884 z_cc_arr, xmom_src_arr, geom, solverChoice, dt, is_slow_step, l_if_drag_in_projection);
886 z_cc_arr, ymom_src_arr, geom, solverChoice, dt, is_slow_step, l_if_drag_in_projection);
888 z_cc_arr, zmom_src_arr, geom, solverChoice, dt, is_slow_step, l_if_drag_in_projection);
894 if (is_slow_step && (enforce_massflux_x || enforce_massflux_y)) {
901 constexpr Real tiny_area = std::numeric_limits<Real>::min();
902 Real dRUA = (massflux_area_x >
zero) ? (rhoUA_target - rhoUA) / amrex::max(massflux_area_x, tiny_area) :
zero;
903 Real dRVA = (massflux_area_y >
zero) ? (rhoVA_target - rhoVA) / amrex::max(massflux_area_y, tiny_area) :
zero;
907 if (enforce_massflux_x) {
908 ParallelFor(tbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept {
909 xmom_src_arr(i, j, k) += tau_inv * dRUA;
912 if (enforce_massflux_y) {
913 ParallelFor(tby, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept {
914 ymom_src_arr(i, j, k) += tau_inv * dRVA;
void ApplyBndryForcing_Forecast(const SolverChoice &solverChoice, const Geometry geom, const Box &tbx, const Box &tby, const Box &tbz, const Array4< const Real > &z_phys_nd, const Array4< Real > &rho_u_rhs, const Array4< Real > &rho_v_rhs, const Array4< Real > &rho_w_rhs, const Array4< const Real > &rho_u, const Array4< const Real > &rho_v, const Array4< const Real > &rho_w, const Array4< const Real > &rho_u_initial_state, const Array4< const Real > &rho_v_initial_state, const Array4< const Real > &rho_w_initial_state, const Array4< const Real > &cons_initial_state)
Definition: ERF_ApplyBndryForcing_Forecast.cpp:8
void ApplySpongeZoneBCsForMom(const SpongeChoice &spongeChoice, const Geometry geom, const Box &tbx, const Box &tby, const Box &tbz, const Array4< Real > &rho_u_rhs, const Array4< Real > &rho_v_rhs, const Array4< Real > &rho_w_rhs, const Array4< const Real > &rho_u, const Array4< const Real > &rho_v, const Array4< const Real > &rho_w, const Array4< const Real > &r0, const Array4< const Real > &z_phys_nd, const Array4< const Real > &z_phys_cc)
Apply sponge zone damping to momentum variables.
Definition: ERF_ApplySpongeZoneBCs.cpp:211
void ApplySpongeZoneBCsForMom_ReadFromFile(const SpongeChoice &spongeChoice, const Geometry geom, const Box &tbx, const Box &tby, const Array4< const Real > &cell_data, const Array4< const Real > &z_phys_cc, const Array4< Real > &rho_u_rhs, const Array4< Real > &rho_v_rhs, const Array4< const Real > &rho_u, const Array4< const Real > &rho_v, const Vector< Real * > d_sponge_ptrs_at_lev)
Definition: ERF_ApplySpongeZoneBCs_ReadFromFile.cpp:23
@ ubar
Definition: ERF_DataStruct.H:235
@ wbar
Definition: ERF_DataStruct.H:235
@ vbar
Definition: ERF_DataStruct.H:235
@ v_x
Definition: ERF_DataStruct.H:40
@ u_y
Definition: ERF_DataStruct.H:41
@ v_y
Definition: ERF_DataStruct.H:41
@ u_x
Definition: ERF_DataStruct.H:40
DirectionSelector< 2 > ZDir
Definition: ERF_DirectionSelector.H:55
void ImmersedForcingTerrain_Ymom_FractionStress(const Box &tby, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_yface_arr, const Array4< Real > &ymom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, const Real time, const bool l_drag_in_projection)
Definition: ERF_ImmersedForcing.cpp:511
void ImmersedForcingTerrain_Ymom(const Box &tby, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_yface_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &ymom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, const bool l_drag_in_projection)
Definition: ERF_ImmersedForcing.cpp:209
void ImmersedForcingBuildings_Ymom(const Box &tby, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_yface_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &ymom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, bool is_slow_step, const bool l_drag_in_projection)
Definition: ERF_ImmersedForcing.cpp:904
void ImmersedForcingBuildings_Xmom(const Box &tbx, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_xface_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &xmom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, bool is_slow_step, const bool l_drag_in_projection)
Definition: ERF_ImmersedForcing.cpp:701
void ImmersedForcingBuildings_Zmom(const Box &tbz, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_zface_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &zmom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, bool is_slow_step, const bool l_drag_in_projection)
Definition: ERF_ImmersedForcing.cpp:1105
void ImmersedForcingTerrain_Zmom(const Box &tbz, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_zface_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &zmom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, const bool l_drag_in_projection)
Definition: ERF_ImmersedForcing.cpp:637
void ImmersedForcingTerrain_Xmom(const Box &tbx, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_xface_arr, const Array4< const Real > &z_cc_arr, const Array4< Real > &xmom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, const bool l_drag_in_projection)
Definition: ERF_ImmersedForcing.cpp:83
void ImmersedForcingTerrain_Xmom_FractionStress(const Box &tbx, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< const Real > &cell_data, const Array4< const Real > &t_blank_arr, const Array4< const Real > &t_blank_xface_arr, const Array4< Real > &xmom_src_arr, const Geometry &geom, const SolverChoice &solverChoice, const Real fac, const Real time, const bool l_drag_in_projection)
Definition: ERF_ImmersedForcing.cpp:493
#define Rho_comp
Definition: ERF_IndexDefines.H:61
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
Real H
Definition: ERF_InitCustomPert_MovingTerrain.H:8
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
constexpr amrex::Real PI
Definition: ERF_NumericalConstants.H:46
void NumericalDiffusion_Ymom(const Box &bx, const double dt, const Real num_diff_coeff, const Array4< const Real > &prim_data, const Array4< const Real > &cell_data, const Array4< Real > &rhs, const Array4< const Real > &mfx_arr, const Array4< const Real > &mfy_arr)
Definition: ERF_NumericalDiffusion.cpp:151
void NumericalDiffusion_Xmom(const Box &bx, const double dt, const Real num_diff_coeff, const Array4< const Real > &prim_data, const Array4< const Real > &cell_data, const Array4< Real > &rhs, const Array4< const Real > &mfx_arr, const Array4< const Real > &mfy_arr)
Definition: ERF_NumericalDiffusion.cpp:85
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:36
Definition: ERF_PlaneAverage.H:14
amrex::EBFArrayBoxFactory const * get_w_const_factory() const noexcept
Return the native AMReX z-face EB factory.
Definition: ERF_EB.H:136
amrex::EBFArrayBoxFactory const * get_u_const_factory() const noexcept
Return the native AMReX x-face EB factory.
Definition: ERF_EB.H:132
amrex::EBFArrayBoxFactory const * get_v_const_factory() const noexcept
Return the native AMReX y-face EB factory.
Definition: ERF_EB.H:134
@ r0_comp
Definition: ERF_IndexDefines.H:109
@ ymom
Definition: ERF_IndexDefines.H:251
@ cons
Definition: ERF_IndexDefines.H:249
@ zmom
Definition: ERF_IndexDefines.H:252
@ xmom
Definition: ERF_IndexDefines.H:250
@ nr
Definition: ERF_Morrison.H:48
@ xvel
Definition: ERF_IndexDefines.H:232
@ cons
Definition: ERF_IndexDefines.H:231
@ yvel
Definition: ERF_IndexDefines.H:233
@ ww
Definition: ERF_AdvanceWSM6.cpp:107
real(c_double), private k1
Definition: ERF_module_mp_morr_two_moment.F90:213
real(kind=kind_phys), parameter, private r0
Definition: ERF_module_mp_wdm6.F90:75
amrex::Real rayleigh_dampcoef
Rayleigh damping inverse time scale [1/s].
Definition: ERF_DampingStruct.H:103
bool rayleigh_damp_U
Whether Rayleigh damping is applied to x-momentum.
Definition: ERF_DampingStruct.H:99
bool rayleigh_damp_V
Whether Rayleigh damping is applied to y-momentum.
Definition: ERF_DampingStruct.H:100
bool rayleigh_damp_W
Whether Rayleigh damping is applied to vertical momentum.
Definition: ERF_DampingStruct.H:101
void get_forcing_time_coeffs(const amrex::Real &time, int &curr, int &next, amrex::Real &coeff_curr, amrex::Real &coeff_next) const
Determine interpolation coefficients to apply tendencies for the given time.
Definition: ERF_LargeScaleForcingData.H:337
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > v_int_lsf_d
Definition: ERF_LargeScaleForcingData.H:459
amrex::Real tau_lsf
Definition: ERF_LargeScaleForcingData.H:409
amrex::Vector< amrex::Gpu::DeviceVector< amrex::Real > > u_int_lsf_d
Definition: ERF_LargeScaleForcingData.H:459
amrex::Real const_massflux_v
Target constant mass flux in the y direction.
Definition: ERF_DataStruct.H:3552
static InitType init_type
Initial-condition source selected for the run.
Definition: ERF_DataStruct.H:2983
amrex::Real coriolis_factor
Twice the planetary rotation rate used for Coriolis forcing.
Definition: ERF_DataStruct.H:3157
bool if_drag_in_projection(int lev) const noexcept
Definition: ERF_DataStruct.H:3223
static bool flat_terrain
Permit fixed-index planar averages after validating a flat fitted mesh.
Definition: ERF_DataStruct.H:2992
bool if_fraction_stress
erf.if_wall_form = fraction_stress: the wall stress of ERF_ImmersedWallCell.H in the wall cell of eac...
Definition: ERF_DataStruct.H:3126
bool rayleigh_fast_uvT(int lev) const noexcept
Definition: ERF_DataStruct.H:3248
bool variable_coriolis
Whether spatially varying Coriolis forcing is enabled.
Definition: ERF_DataStruct.H:3499
int ave_plane
Averaging plane index used by diagnostics.
Definition: ERF_DataStruct.H:3501
amrex::Real const_massflux_u
Target constant mass flux in the x direction.
Definition: ERF_DataStruct.H:3551
bool forest_fast(int lev) const noexcept
Definition: ERF_DataStruct.H:3297
bool use_building_immersed_forcing(const amrex::Geometry &geom) const noexcept
Definition: ERF_DataStruct.H:3231
bool rayleigh_implicit_w(int lev) const noexcept
Definition: ERF_DataStruct.H:3277
amrex::Real num_diff_coeff
Numerical diffusion coefficient after input scaling.
Definition: ERF_DataStruct.H:3430
bool hindcast_lateral_forcing
Whether hindcast lateral forcing is enabled.
Definition: ERF_DataStruct.H:3561
amrex::Real nudging_u_z2
Definition: ERF_DataStruct.H:3181
bool use_coriolis
Whether Coriolis forcing is enabled.
Definition: ERF_DataStruct.H:3096
static MeshType mesh_type
Vertical mesh representation.
Definition: ERF_DataStruct.H:3004
SpongeChoice spongeChoice
Sponge-layer options.
Definition: ERF_DataStruct.H:3019
bool have_geo_wind_profile
Whether a geostrophic wind profile has been configured.
Definition: ERF_DataStruct.H:3497
DampingChoice dampingChoice
Damping-related options.
Definition: ERF_DataStruct.H:3018
amrex::Real nudging_u_z1
Definition: ERF_DataStruct.H:3180
bool do_forest_drag
Whether forest canopy drag is enabled.
Definition: ERF_DataStruct.H:3541
int massflux_khi
Upper vertical index for constant-mass-flux forcing.
Definition: ERF_DataStruct.H:3557
bool large_scale_forcing
Definition: ERF_DataStruct.H:3191
static TerrainType terrain_type
Terrain or immersed-boundary representation.
Definition: ERF_DataStruct.H:2989
amrex::Real cosphi
Cosine of the latitude used for Coriolis forcing.
Definition: ERF_DataStruct.H:3158
bool immersed_forcing_fast(int lev) const noexcept
Definition: ERF_DataStruct.H:3303
bool rayleigh_fast_w(int lev) const noexcept
Definition: ERF_DataStruct.H:3256
int massflux_klo
Lower vertical index for constant-mass-flux forcing.
Definition: ERF_DataStruct.H:3556
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > abl_geo_forcing
Applied geostrophic-wind forcing vector.
Definition: ERF_DataStruct.H:3495
bool custom_w_subsidence
Whether custom vertical subsidence is enabled.
Definition: ERF_DataStruct.H:3164
bool rayleigh_slow_implicit_w(int lev) const noexcept
Definition: ERF_DataStruct.H:3288
amrex::Real const_massflux_tau
Relaxation time scale for constant-mass-flux forcing.
Definition: ERF_DataStruct.H:3553
amrex::Real sinphi
Sine of the latitude used for Coriolis forcing.
Definition: ERF_DataStruct.H:3159
bool do_mom_advection
Whether custom vertical subsidence is applied to momentum.
Definition: ERF_DataStruct.H:3166
bool nudging_u
Definition: ERF_DataStruct.H:3187
bool nudging_from_input_sounding
Whether solution fields are nudged toward input sounding data.
Definition: ERF_DataStruct.H:3174
static SpongeType sponge_type
Selected sponge damping model.
Definition: ERF_SpongeStruct.H:100