Function for computing the slow RHS for the evolution equations for the density, potential temperature and momentum.
70 BL_PROFILE_REGION(
"erf_make_mom_sources()");
72 Box domain(geom.Domain());
73 const GpuArray<Real, AMREX_SPACEDIM>
dxInv = geom.InvCellSizeArray();
107 if (solverChoice.
terrain_type == TerrainType::ImmersedForcing) {
109 amrex::Error(
" Currently forest canopy cannot be used with immersed forcing");
119 auto cosphi = solverChoice.
cosphi;
120 auto sinphi = solverChoice.
sinphi;
151 Real rhoUA_target{0};
152 Real rhoVA_target{0};
159 Table1D<Real> dptr_r_plane, dptr_u_plane, dptr_v_plane;
160 TableData<Real, 1> r_plane_tab, u_plane_tab, v_plane_tab;
163 enforce_massflux_x || enforce_massflux_y))
169 const int u_offset = 1;
170 const int v_offset = 1;
179 r_ave.compute_averages(
ZDir(), r_ave.field());
181 int ncell = r_ave.ncell_line();
182 Gpu::HostVector< Real> r_plane_h(ncell);
183 Gpu::DeviceVector< Real> r_plane_d(ncell);
185 r_ave.line_average(
Rho_comp, r_plane_h);
187 Gpu::copyAsync(Gpu::hostToDevice, r_plane_h.begin(), r_plane_h.end(), r_plane_d.begin());
189 Real* dptr_r = r_plane_d.data();
191 Box tdomain = domain; tdomain.grow(2,ng_c[2]);
192 r_plane_tab.resize({tdomain.smallEnd(2)}, {tdomain.bigEnd(2)});
194 dptr_r_plane = r_plane_tab.table();
195 ParallelFor(ncell, [=] AMREX_GPU_DEVICE (
int k) noexcept
197 dptr_r_plane(k-
offset) = dptr_r[k];
201 IntVect ng_u = S_data[
IntVars::xmom].nGrowVect(); ng_u[2] = u_offset;
204 IntVect ng_v = S_data[
IntVars::ymom].nGrowVect(); ng_v[2] = v_offset;
207 u_ave.compute_averages(
ZDir(), u_ave.field());
208 v_ave.compute_averages(
ZDir(), v_ave.field());
210 int u_ncell = u_ave.ncell_line();
211 int v_ncell = v_ave.ncell_line();
212 Gpu::HostVector< Real> u_plane_h(u_ncell), v_plane_h(v_ncell);
213 Gpu::DeviceVector< Real> u_plane_d(u_ncell), v_plane_d(v_ncell);
215 u_ave.line_average(0, u_plane_h);
216 v_ave.line_average(0, v_plane_h);
218 Gpu::copyAsync(Gpu::hostToDevice, u_plane_h.begin(), u_plane_h.end(), u_plane_d.begin());
219 Gpu::copyAsync(Gpu::hostToDevice, v_plane_h.begin(), v_plane_h.end(), v_plane_d.begin());
221 Real* dptr_u = u_plane_d.data();
222 Real* dptr_v = v_plane_d.data();
224 Box udomain = domain; udomain.grow(2,ng_u[2]);
225 Box vdomain = domain; vdomain.grow(2,ng_v[2]);
226 u_plane_tab.resize({udomain.smallEnd(2)}, {udomain.bigEnd(2)});
227 v_plane_tab.resize({vdomain.smallEnd(2)}, {vdomain.bigEnd(2)});
229 dptr_u_plane = u_plane_tab.table();
230 ParallelFor(u_ncell, [=] AMREX_GPU_DEVICE (
int k) noexcept
232 dptr_u_plane(k-u_offset) = dptr_u[k];
235 dptr_v_plane = v_plane_tab.table();
236 ParallelFor(v_ncell, [=] AMREX_GPU_DEVICE (
int k) noexcept
238 dptr_v_plane(k-v_offset) = dptr_v[k];
242 if (enforce_massflux_x || enforce_massflux_y) {
243 Real Lx = geom.ProbHi(0) - geom.ProbLo(0);
244 Real Ly = geom.ProbHi(1) - geom.ProbLo(1);
246 if (solverChoice.
mesh_type == MeshType::ConstantDz) {
248 rhoUA = std::accumulate(u_plane_h.begin() + u_offset + massflux_klo,
249 u_plane_h.begin() + u_offset + massflux_khi+1,
zero);
250 rhoVA = std::accumulate(v_plane_h.begin() + v_offset + massflux_klo,
251 v_plane_h.begin() + v_offset + massflux_khi+1,
zero);
252 rhoUA_target = std::accumulate(r_plane_h.begin() +
offset + massflux_klo,
253 r_plane_h.begin() +
offset + massflux_khi+1,
zero);
254 rhoVA_target = rhoUA_target;
256 rhoUA *= geom.CellSize(2) * Ly;
257 rhoVA *= geom.CellSize(2) * Lx;
258 rhoUA_target *= geom.CellSize(2) * Ly;
259 rhoVA_target *= geom.CellSize(2) * Lx;
261 }
else if (solverChoice.
mesh_type == MeshType::StretchedDz) {
263 for (
int k=massflux_klo; k < massflux_khi; ++k) {
264 rhoUA += u_plane_h[k + u_offset] * stretched_dz_h[k];
265 rhoVA += v_plane_h[k + v_offset] * stretched_dz_h[k];
266 rhoUA_target += r_plane_h[k +
offset] * stretched_dz_h[k];
268 rhoVA_target = rhoUA_target;
277 rhoUA_target *= U_target;
278 rhoVA_target *= V_target;
280 Print() <<
"Integrated mass flux : " << rhoUA <<
" " << rhoVA
281 <<
" (target: " << rhoUA_target <<
" " << rhoVA_target <<
")"
289 for ( MFIter mfi(S_data[
IntVars::cons]); mfi.isValid(); ++mfi)
291 Box tbx = mfi.nodaltilebox(0);
292 Box tby = mfi.nodaltilebox(1);
293 Box tbz = mfi.nodaltilebox(2);
294 if (tbz.bigEnd(2) == domain.bigEnd(2)+1) tbz.growHi(2,-1);
296 const Array4<const Real>& cell_data = S_data[
IntVars::cons].array(mfi);
297 const Array4<const Real>& rho_u = S_data[
IntVars::xmom].array(mfi);
298 const Array4<const Real>& rho_v = S_data[
IntVars::ymom].array(mfi);
299 const Array4<const Real>& rho_w = S_data[
IntVars::zmom].array(mfi);
301 const Array4<const Real>& u =
xvel.array(mfi);
302 const Array4<const Real>& v =
yvel.array(mfi);
303 const Array4<const Real>& w = wvel.array(mfi);
305 const Array4< Real>& xmom_src_arr = xmom_src.array(mfi);
306 const Array4< Real>& ymom_src_arr = ymom_src.array(mfi);
307 const Array4< Real>& zmom_src_arr = zmom_src.array(mfi);
309 const Array4<const Real>&
r0 = r_hse.const_array(mfi);
311 const Array4<const Real>& f_drag_arr = (forest_drag) ? forest_drag->const_array(mfi) :
312 Array4<const Real>{};
313 const Array4<const Real>& t_blank_arr = (terrain_blank) ? terrain_blank->const_array(mfi) :
314 Array4<const Real>{};
316 const Array4<const Real>& cphi_arr = (cosPhi_mf) ? cosPhi_mf->const_array(mfi) :
317 Array4<const Real>{};
318 const Array4<const Real>& sphi_arr = (sinPhi_mf) ? sinPhi_mf->const_array(mfi) :
319 Array4<const Real>{};
321 const Array4<const Real>& z_nd_arr = z_phys_nd->const_array(mfi);
322 const Array4<const Real>& z_cc_arr = z_phys_cc->const_array(mfi);
328 if (use_coriolis && is_slow_step) {
329 if(solverChoice.
init_type == InitType::HindCast) {
330 const Array4<const Real>& latlon_arr = (*forecast_state_at_lev)[4].array(mfi);
332 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
334 Real rho_v_loc =
fourth * (rho_v(i,j+1,k) + rho_v(i,j,k) + rho_v(i-1,j+1,k) + rho_v(i-1,j,k));
335 Real rho_w_loc =
fourth * (rho_w(i,j,k+1) + rho_w(i,j,k) + rho_w(i,j-1,k+1) + rho_w(i,j-1,k));
336 Real latitude = latlon_arr(i,j,k,0);
337 Real sphi_loc = std::sin(latitude*
PI/
Real(180.0));
338 Real cphi_loc = std::cos(latitude*
PI/
Real(180.0));
339 xmom_src_arr(i, j, k) += coriolis_factor * (rho_v_loc * sphi_loc - rho_w_loc * cphi_loc);
341 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
342 Real rho_u_loc =
fourth * (rho_u(i+1,j,k) + rho_u(i,j,k) + rho_u(i+1,j-1,k) + rho_u(i,j-1,k));
343 Real latitude = latlon_arr(i,j,k,0);
344 Real sphi_loc = std::sin(latitude*
PI/
Real(180.0));
345 ymom_src_arr(i, j, k) += -coriolis_factor * rho_u_loc * sphi_loc;
347 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
348 Real rho_u_loc =
fourth * (rho_u(i+1,j,k) + rho_u(i,j,k) + rho_u(i+1,j,k-1) + rho_u(i,j,k-1));
349 Real latitude = latlon_arr(i,j,k,0);
350 Real cphi_loc = std::cos(latitude*
PI/
Real(180.0));
351 zmom_src_arr(i, j, k) += coriolis_factor * rho_u_loc * cphi_loc;
354 else if (var_coriolis && (sinPhi_mf) && (cosPhi_mf)) {
356 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
358 Real rho_v_loc =
fourth * (rho_v(i,j+1,k) + rho_v(i,j,k) + rho_v(i-1,j+1,k) + rho_v(i-1,j,k));
359 Real rho_w_loc =
fourth * (rho_w(i,j,k+1) + rho_w(i,j,k) + rho_w(i-1,j,k+1) + rho_w(i-1,j,k));
360 Real sphi_loc =
myhalf * (sphi_arr(i,j,0) + sphi_arr(i-1,j,0));
361 Real cphi_loc =
myhalf * (cphi_arr(i,j,0) + cphi_arr(i-1,j,0));
362 xmom_src_arr(i, j, k) += coriolis_factor * (rho_v_loc * sphi_loc - rho_w_loc * cphi_loc);
364 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
365 Real rho_u_loc =
fourth * (rho_u(i+1,j,k) + rho_u(i,j,k) + rho_u(i+1,j-1,k) + rho_u(i,j-1,k));
366 Real sphi_loc =
myhalf * (sphi_arr(i,j,0) + sphi_arr(i,j-1,0));
367 ymom_src_arr(i, j, k) += -coriolis_factor * rho_u_loc * sphi_loc;
369 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
370 Real rho_u_loc =
fourth * (rho_u(i+1,j,k) + rho_u(i,j,k) + rho_u(i+1,j,k-1) + rho_u(i,j,k-1));
371 zmom_src_arr(i, j, k) += coriolis_factor * rho_u_loc * cphi_arr(i,j,0);
375 Array4<const Real> u_volfrac = (ebfact.
get_u_const_factory())->getVolFrac().const_array(mfi);
376 Array4<const Real> v_volfrac = (ebfact.
get_v_const_factory())->getVolFrac().const_array(mfi);
377 Array4<const Real> w_volfrac = (ebfact.
get_w_const_factory())->getVolFrac().const_array(mfi);
378 ParallelFor(tbx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
379 Real rho_v_loc = 0.0;
380 Real rho_w_loc = 0.0;
381 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);
382 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);
384 rho_v_loc = ( v_volfrac(i,j+1,k) * rho_v(i,j+1,k) + v_volfrac(i,j,k) * rho_v(i,j,k)
385 + v_volfrac(i-1,j+1,k) * rho_v(i-1,j+1,k) + v_volfrac(i-1,j,k) * rho_v(i-1,j,k)) / v_vol;
388 rho_w_loc = ( w_volfrac(i,j,k+1) * rho_w(i,j,k+1) + w_volfrac(i,j,k) * rho_w(i,j,k)
389 + w_volfrac(i-1,j,k+1) * rho_w(i-1,j,k+1) + w_volfrac(i-1,j,k) * rho_w(i-1,j,k)) / w_vol;
391 xmom_src_arr(i, j, k) += coriolis_factor * (rho_v_loc * sinphi - rho_w_loc * cosphi);
393 ParallelFor(tby, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
394 Real rho_u_loc = 0.0;
395 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);
397 rho_u_loc = ( u_volfrac(i+1,j,k) * rho_u(i+1,j,k) + u_volfrac(i,j,k) * rho_u(i,j,k)
398 + u_volfrac(i+1,j-1,k) * rho_u(i+1,j-1,k) + u_volfrac(i,j-1,k) * rho_u(i,j-1,k)) / u_vol;
400 ymom_src_arr(i, j, k) += -coriolis_factor * rho_u_loc * sinphi;
402 ParallelFor(tbz, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
403 Real rho_u_loc = 0.0;
404 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);
406 rho_u_loc = ( u_volfrac(i+1,j,k) * rho_u(i+1,j,k) + u_volfrac(i,j,k) * rho_u(i,j,k)
407 + u_volfrac(i+1,j,k-1) * rho_u(i+1,j,k-1) + u_volfrac(i,j,k-1) * rho_u(i,j,k-1)) / u_vol;
409 zmom_src_arr(i, j, k) += coriolis_factor * rho_u_loc * cosphi;
413 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
415 Real rho_v_loc =
fourth * (rho_v(i,j+1,k) + rho_v(i,j,k) + rho_v(i-1,j+1,k) + rho_v(i-1,j,k));
416 Real rho_w_loc =
fourth * (rho_w(i,j,k+1) + rho_w(i,j,k) + rho_w(i-1,j,k+1) + rho_w(i-1,j,k));
417 xmom_src_arr(i, j, k) += coriolis_factor * (rho_v_loc * sinphi - rho_w_loc * cosphi);
419 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
420 Real rho_u_loc =
fourth * (rho_u(i+1,j,k) + rho_u(i,j,k) + rho_u(i+1,j-1,k) + rho_u(i,j-1,k));
421 ymom_src_arr(i, j, k) += -coriolis_factor * rho_u_loc * sinphi;
423 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) {
424 Real rho_u_loc =
fourth * (rho_u(i+1,j,k) + rho_u(i,j,k) + rho_u(i+1,j,k-1) + rho_u(i,j,k-1));
425 zmom_src_arr(i, j, k) += coriolis_factor * rho_u_loc * cosphi;
436 if ( (is_slow_step && !use_Rayleigh_fast_uv) || (!is_slow_step && use_Rayleigh_fast_uv)) {
437 if (rayleigh_damp_U) {
438 ParallelFor(tbx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
441 Real uu = rho_u(i,j,k) / rho_on_u_face;
442 Real sinesq = d_sinesq_at_lev[k];
443 xmom_src_arr(i, j, k) -= dampcoef*sinesq * (uu -
ubar[k]) * rho_on_u_face;
447 if (rayleigh_damp_V) {
448 ParallelFor(tby, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
451 Real vv = rho_v(i,j,k) / rho_on_v_face;
452 Real sinesq = d_sinesq_at_lev[k];
453 ymom_src_arr(i, j, k) -= dampcoef*sinesq * (vv -
vbar[k]) * rho_on_v_face;
458 if ( (is_slow_step && !use_Rayleigh_fast_w) || (!is_slow_step && use_Rayleigh_fast_w)) {
459 if (rayleigh_damp_W) {
460 ParallelFor(tbz, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
463 Real ww = rho_w(i,j,k) / rho_on_w_face;
464 Real sinesq = d_sinesq_stag_at_lev[k];
465 zmom_src_arr(i, j, k) -= dampcoef*sinesq * (
ww -
wbar[k]) * rho_on_w_face;
475 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
478 xmom_src_arr(i, j, k) += rho_on_u_face * abl_geo_forcing[0];
480 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
483 ymom_src_arr(i, j, k) += rho_on_v_face * abl_geo_forcing[1];
485 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
488 zmom_src_arr(i, j, k) += rho_on_w_face * abl_geo_forcing[2];
495 if (geo_wind_profile && is_slow_step) {
497 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
500 xmom_src_arr(i, j, k) -= coriolis_factor * rho_on_u_face * dptr_v_geos[k] * sinphi;
502 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
505 ymom_src_arr(i, j, k) += coriolis_factor * rho_on_v_face * dptr_u_geos[k] * sinphi;
516 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
520 Real z_xf_lo =
fourth * ( z_nd_arr(i,j,k ) + z_nd_arr(i,j+1,k )
521 + z_nd_arr(i,j,k-1) + z_nd_arr(i,j+1,k-1) );
522 Real z_xf_hi =
fourth * ( z_nd_arr(i,j,k+1) + z_nd_arr(i,j+1,k+1)
523 + z_nd_arr(i,j,k+2) + z_nd_arr(i,j+1,k+2) );
524 dzInv =
one / (z_xf_hi - z_xf_lo);
526 Real rho_on_u_face =
myhalf * ( cell_data(i,j,k,
nr) + cell_data(i-1,j,k,
nr) );
527 Real U_hi = dptr_u_plane(k+1) / dptr_r_plane(k+1);
528 Real U_lo = dptr_u_plane(k-1) / dptr_r_plane(k-1);
529 Real wbar_xf =
myhalf * (dptr_wbar_sub[k] + dptr_wbar_sub[k+1]);
530 xmom_src_arr(i, j, k) -= rho_on_u_face * wbar_xf * (U_hi - U_lo) * dzInv;
532 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
536 Real z_yf_lo =
fourth * ( z_nd_arr(i,j,k ) + z_nd_arr(i+1,j,k )
537 + z_nd_arr(i,j,k-1) + z_nd_arr(i+1,j,k-1) );
538 Real z_yf_hi =
fourth * ( z_nd_arr(i,j,k+1) + z_nd_arr(i+1,j,k+1)
539 + z_nd_arr(i,j,k+2) + z_nd_arr(i+1,j,k+2) );
540 dzInv =
one / (z_yf_hi - z_yf_lo);
542 Real rho_on_v_face =
myhalf * ( cell_data(i,j,k,
nr) + cell_data(i,j-1,k,
nr) );
543 Real V_hi = dptr_v_plane(k+1) / dptr_r_plane(k+1);
544 Real V_lo = dptr_v_plane(k-1) / dptr_r_plane(k-1);
545 Real wbar_yf =
myhalf * (dptr_wbar_sub[k] + dptr_wbar_sub[k+1]);
546 ymom_src_arr(i, j, k) -= rho_on_v_face * wbar_yf * (V_hi - V_lo) * dzInv;
550 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
554 Real z_xf_lo =
fourth * ( z_nd_arr(i,j,k ) + z_nd_arr(i,j+1,k )
555 + z_nd_arr(i,j,k-1) + z_nd_arr(i,j+1,k-1) );
556 Real z_xf_hi =
fourth * ( z_nd_arr(i,j,k+1) + z_nd_arr(i,j+1,k+1)
557 + z_nd_arr(i,j,k+2) + z_nd_arr(i,j+1,k+2) );
558 dzInv =
one / (z_xf_hi - z_xf_lo);
560 Real U_hi = dptr_u_plane(k+1) / dptr_r_plane(k+1);
561 Real U_lo = dptr_u_plane(k-1) / dptr_r_plane(k-1);
562 Real wbar_xf =
myhalf * (dptr_wbar_sub[k] + dptr_wbar_sub[k+1]);
563 xmom_src_arr(i, j, k) -= wbar_xf * (U_hi - U_lo) * dzInv;
565 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
569 Real z_yf_lo =
fourth * ( z_nd_arr(i,j,k ) + z_nd_arr(i+1,j,k )
570 + z_nd_arr(i,j,k-1) + z_nd_arr(i+1,j,k-1) );
571 Real z_yf_hi =
fourth * ( z_nd_arr(i,j,k+1) + z_nd_arr(i+1,j,k+1)
572 + z_nd_arr(i,j,k+2) + z_nd_arr(i+1,j,k+2) );
573 dzInv =
one / (z_yf_hi - z_yf_lo);
575 Real V_hi = dptr_v_plane(k+1) / dptr_r_plane(k+1);
576 Real V_lo = dptr_v_plane(k-1) / dptr_r_plane(k-1);
577 Real wbar_yf =
myhalf * (dptr_wbar_sub[k] + dptr_wbar_sub[k+1]);
578 ymom_src_arr(i, j, k) -= wbar_yf * (V_hi - V_lo) * dzInv;
597 for (
int nt = 1; nt < n_sounding_times; nt++) {
600 if (itime_n == n_sounding_times-1) {
603 itime_np1 = itime_n+1;
606 coeff_n =
one - coeff_np1;
611 const Real* u_inp_sound_n = input_sounding_data.
U_inp_sound_d[itime_n].dataPtr();
612 const Real* u_inp_sound_np1 = input_sounding_data.
U_inp_sound_d[itime_np1].dataPtr();
613 const Real* v_inp_sound_n = input_sounding_data.
V_inp_sound_d[itime_n].dataPtr();
614 const Real* v_inp_sound_np1 = input_sounding_data.
V_inp_sound_d[itime_np1].dataPtr();
616 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
618 Real nudge_u = (coeff_n*u_inp_sound_n[k] + coeff_np1*u_inp_sound_np1[k]) - (dptr_u_plane(k)/dptr_r_plane(k));
620 xmom_src_arr(i, j, k) += cell_data(i, j, k,
nr) * nudge_u;
622 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
624 Real nudge_v = (coeff_n*v_inp_sound_n[k] + coeff_np1*v_inp_sound_np1[k]) - (dptr_v_plane(k)/dptr_r_plane(k));
626 ymom_src_arr(i, j, k) += cell_data(i, j, k,
nr) * nudge_v;
635 const Array4<const Real>& mf_ux = mapfac[MapFac::ux]->const_array(mfi);
636 const Array4<const Real>& mf_uy = mapfac[MapFac::uy]->const_array(mfi);
637 const Array4<const Real>& mf_vx = mapfac[MapFac::vx]->const_array(mfi);
638 const Array4<const Real>& mf_vy = mapfac[MapFac::vy]->const_array(mfi);
640 u, cell_data, xmom_src_arr, mf_ux, mf_uy);
642 v, cell_data, ymom_src_arr, mf_vx, mf_vy);
653 z_cc_arr, xmom_src_arr, ymom_src_arr,
654 rho_u, rho_v, d_sponge_ptrs_at_lev);
659 xmom_src_arr, ymom_src_arr, zmom_src_arr, rho_u, rho_v, rho_w,
660 r0, z_nd_arr, z_cc_arr);
665 const Array4<const Real>& rho_u_forecast_state = (*forecast_state_at_lev)[
IntVars::xmom].array(mfi);
666 const Array4<const Real>& rho_v_forecast_state = (*forecast_state_at_lev)[
IntVars::ymom].array(mfi);
667 const Array4<const Real>& rho_w_forecast_state = (*forecast_state_at_lev)[
IntVars::zmom].array(mfi);
668 const Array4<const Real>& cons_forecast_state = (*forecast_state_at_lev)[
IntVars::cons].array(mfi);
670 xmom_src_arr, ymom_src_arr, zmom_src_arr,
672 rho_u_forecast_state, rho_v_forecast_state, rho_w_forecast_state,
673 cons_forecast_state);
676 const Array4<const Real>& surface_state_arr = (*surface_state_at_lev).array(mfi);
678 xmom_src_arr, ymom_src_arr,
689 ((is_slow_step && !use_canopy_fast) || (!is_slow_step && use_canopy_fast))) {
691 [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
693 const Real ux = u(i, j, k);
694 const Real uy =
fourth * ( v(i, j , k ) + v(i-1, j , k )
695 + v(i, j+1, k ) + v(i-1, j+1, k ) );
696 const Real uz =
fourth * ( w(i, j , k ) + w(i-1, j , k )
697 + w(i, j , k+1) + w(i-1, j , k+1) );
698 const Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
699 const Real f_drag =
myhalf * (f_drag_arr(i, j, k) + f_drag_arr(i-1, j, k));
700 xmom_src_arr(i, j, k) -= f_drag * ux * windspeed;
702 [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
704 const Real ux =
fourth * ( u(i , j , k ) + u(i , j-1, k )
705 + u(i+1, j , k ) + u(i+1, j-1, k ) );
706 const Real uy = v(i, j, k);
707 const Real uz =
fourth * ( w(i , j , k ) + w(i , j-1, k )
708 + w(i , j , k+1) + w(i , j-1, k+1) );
709 const amrex::Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
710 const Real f_drag =
myhalf * (f_drag_arr(i, j, k) + f_drag_arr(i, j-1, k));
711 ymom_src_arr(i, j, k) -= f_drag * uy * windspeed;
713 [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
716 + u(i , j , k-1) + u(i+1, j , k-1) );
718 + v(i , j , k-1) + v(i , j+1, k-1) );
720 const amrex::Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
721 const Real f_drag =
myhalf * (f_drag_arr(i, j, k) + f_drag_arr(i, j, k-1));
722 zmom_src_arr(i, j, k) -= f_drag * uz * windspeed;
728 if (solverChoice.
terrain_type == TerrainType::ImmersedForcing &&
729 ((is_slow_step && !use_ImmersedForcing_fast) || (!is_slow_step && use_ImmersedForcing_fast))) {
731 const Real* dx_arr = geom.CellSize();
732 const Real dx_x = dx_arr[0];
733 const Real dx_y = dx_arr[1];
734 const Real dx_z = dx_arr[2];
737 const Real drag_coefficient = alpha_m / std::pow(dx_x*dx_y*dx_z,
one/
three);
750 ParallelFor(tbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
752 const Real ux = u(i, j, k);
753 const Real uy =
fourth * ( v(i, j , k ) + v(i-1, j , k )
754 + v(i, j+1, k ) + v(i-1, j+1, k ) );
755 const Real uz =
fourth * ( w(i, j , k ) + w(i-1, j , k )
756 + w(i, j , k+1) + w(i-1, j , k+1) );
757 const Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
758 const Real t_blank =
myhalf * (t_blank_arr(i, j, k) + t_blank_arr(i-1, j, k));
759 const Real t_blank_above =
myhalf * (t_blank_arr(i, j, k+1) + t_blank_arr(i-1, j, k+1));
760 const Real CdM = std::min(drag_coefficient / (windspeed + tiny),
Real(1000.0));
763 if ((t_blank > 0 && (t_blank_above ==
zero)) && l_use_most) {
765 const Real ux2r = u(i, j, k+1) ;
766 const Real uy2r =
fourth * ( v(i, j , k+1) + v(i-1, j , k+1)
767 + v(i, j+1, k+1) + v(i-1, j+1, k+1) ) ;
768 const Real h_windspeed2r = std::sqrt(ux2r * ux2r + uy2r * uy2r);
774 const Real theta_surf = theta_xface_below;
778 Real ustar = h_windspeed2r * kappa / (std::log(
Real(1.5) * dx_z /
z0) - psi_m);
779 Real tflux = (tflux_in !=
Real(1e-8)) ? tflux_in : -(theta_xface - theta_surf) * ustar * kappa / (std::log(
Real(1.5) * dx_z /
z0) - psi_h);
780 Real Olen = (Olen_in !=
Real(1e-8)) ? Olen_in : -ustar * ustar * ustar * theta_xface / (kappa * ggg * tflux + tiny);
781 Real zeta =
Real(1.5) * dx_z / Olen;
786 ustar = h_windspeed2r * kappa / (std::log(
Real(1.5) * dx_z /
z0) - psi_m);
789 if (!(ustar >
zero && !std::isnan(ustar))) { ustar =
zero; }
790 if (!(ustar <
two && !std::isnan(ustar))) { ustar =
two; }
791 if (psi_m > std::log(
myhalf * dx_z /
z0)) { psi_m = std::log(
myhalf * dx_z /
z0); }
794 const Real uTarget = ustar / kappa * (std::log(
myhalf * dx_z /
z0) - psi_m);
795 Real uxTarget = uTarget * ux2r / (tiny + h_windspeed2r);
796 const Real bc_forcing_x = -(uxTarget - ux);
797 xmom_src_arr(i, j, k) -= (1-t_blank) * rho_xface * CdM * U_s * bc_forcing_x;
799 xmom_src_arr(i, j, k) -= t_blank * rho_xface * CdM * ux * windspeed;
802 ParallelFor(tby, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
804 const Real ux =
fourth * ( u(i , j , k ) + u(i , j-1, k )
805 + u(i+1, j , k ) + u(i+1, j-1, k ) );
806 const Real uy = v(i, j, k);
807 const Real uz =
fourth * ( w(i , j , k ) + w(i , j-1, k )
808 + w(i , j , k+1) + w(i , j-1, k+1) );
809 const Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
810 const Real t_blank =
myhalf * (t_blank_arr(i, j, k) + t_blank_arr(i, j-1, k));
811 const Real t_blank_above =
myhalf * (t_blank_arr(i, j, k+1) + t_blank_arr(i, j-1, k+1));
812 const Real CdM = std::min(drag_coefficient / (windspeed + tiny),
Real(1000.0));
815 if ((t_blank > 0 && (t_blank_above ==
zero)) && l_use_most) {
817 const Real ux2r =
fourth * ( u(i , j , k+1) + u(i , j-1, k+1)
818 + u(i+1, j , k+1) + u(i+1, j-1, k+1) );
819 const Real uy2r = v(i, j, k+1) ;
820 const Real h_windspeed2r = std::sqrt(ux2r * ux2r + uy2r * uy2r);
826 const Real theta_surf = theta_yface_below;
830 Real ustar = h_windspeed2r * kappa / (std::log(
Real(1.5) * dx_z /
z0) - psi_m);
831 Real tflux = (tflux_in !=
Real(1e-8)) ? tflux_in : -(theta_yface - theta_surf) * ustar * kappa / (std::log(
Real(1.5) * dx_z /
z0) - psi_h);
832 Real Olen = (Olen_in !=
Real(1e-8)) ? Olen_in : -ustar * ustar * ustar * theta_yface / (kappa * ggg * tflux + tiny);
833 Real zeta =
Real(1.5) * dx_z / Olen;
838 ustar = h_windspeed2r * kappa / (std::log(
Real(1.5) * dx_z /
z0) - psi_m);
841 if (!(ustar >
zero && !std::isnan(ustar))) { ustar =
zero; }
842 if (!(ustar <
two && !std::isnan(ustar))) { ustar =
two; }
843 if (psi_m > std::log(
myhalf * dx_z /
z0)) { psi_m = std::log(
myhalf * dx_z /
z0); }
846 const Real uTarget = ustar / kappa * (std::log(
myhalf * dx_z /
z0) - psi_m);
847 Real uyTarget = uTarget * uy2r / (tiny + h_windspeed2r);
848 const Real bc_forcing_y = -(uyTarget - uy);
849 ymom_src_arr(i, j, k) -= (1 - t_blank) * rho_yface * CdM * U_s * bc_forcing_y;
851 ymom_src_arr(i, j, k) -= t_blank * rho_yface * CdM * uy * windspeed;
854 ParallelFor(tbz, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
856 const Real ux =
fourth * ( u(i , j , k ) + u(i+1, j , k )
857 + u(i , j , k-1) + u(i+1, j , k-1) );
858 const Real uy =
fourth * ( v(i , j , k ) + v(i , j+1, k )
859 + v(i , j , k-1) + v(i , j+1, k-1) );
860 const Real uz = w(i, j, k);
861 const Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
862 const Real t_blank =
myhalf * (t_blank_arr(i, j, k) + t_blank_arr(i, j, k-1));
863 const Real CdM = std::min(drag_coefficient / (windspeed + tiny),
Real(1000.0));
865 zmom_src_arr(i, j, k) -= t_blank * rho_zface * CdM * uz * windspeed;
872 if ((solverChoice.
buildings_type == BuildingsType::ImmersedForcing ) &&
873 ((is_slow_step && !use_ImmersedForcing_fast) || (!is_slow_step && use_ImmersedForcing_fast)))
876 const Real* dx_arr = geom.CellSize();
877 const Real dx_x = dx_arr[0];
878 const Real dx_y = dx_arr[1];
882 const Real min_t_blank =
Real(0.005);
884 ParallelFor(tbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
886 const Real ux = u(i, j, k);
887 const Real uy =
fourth * ( v(i, j , k ) + v(i-1, j , k )
888 + v(i, j+1, k ) + v(i-1, j+1, k ) );
889 const Real uz =
fourth * ( w(i, j , k ) + w(i-1, j , k )
890 + w(i, j , k+1) + w(i-1, j , k+1) );
891 const Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
893 Real t_blank =
myhalf * (t_blank_arr(i, j, k) + t_blank_arr(i-1, j, k));
894 if (t_blank < min_t_blank) { t_blank =
zero; }
895 const Real dx_z = (z_cc_arr) ? (z_cc_arr(i,j,k) - z_cc_arr(i,j,k-1)) : dx_arr[2];
896 const Real drag_coefficient = alpha_m / std::pow(dx_x*dx_y*dx_z,
one/
three);
897 const Real CdM = std::min(drag_coefficient / (windspeed + tiny),
Real(1000.0));
899 xmom_src_arr(i, j, k) -= t_blank * rho_xface * CdM * ux * windspeed;
901 ParallelFor(tby, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
903 const Real ux =
fourth * ( u(i , j , k ) + u(i , j-1, k )
904 + u(i+1, j , k ) + u(i+1, j-1, k ) );
905 const Real uy = v(i, j, k);
906 const Real uz =
fourth * ( w(i , j , k ) + w(i , j-1, k )
907 + w(i , j , k+1) + w(i , j-1, k+1) );
908 const Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
910 Real t_blank =
myhalf * (t_blank_arr(i, j, k) + t_blank_arr(i, j-1, k));
911 if (t_blank < min_t_blank) { t_blank =
zero; }
912 const Real dx_z = (z_cc_arr) ? (z_cc_arr(i,j,k) - z_cc_arr(i,j,k-1)) : dx_arr[2];
913 const Real drag_coefficient = alpha_m / std::pow(dx_x*dx_y*dx_z,
one/
three);
914 const Real CdM = std::min(drag_coefficient / (windspeed + tiny),
Real(1000.0));
916 ymom_src_arr(i, j, k) -= t_blank * rho_yface * CdM * uy * windspeed;
918 ParallelFor(tbz, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
920 const Real ux =
fourth * ( u(i , j , k ) + u(i+1, j , k )
921 + u(i , j , k-1) + u(i+1, j , k-1) );
922 const Real uy =
fourth * ( v(i , j , k ) + v(i , j+1, k )
923 + v(i , j , k-1) + v(i , j+1, k-1) );
924 const Real uz = w(i, j, k);
925 const Real windspeed = std::sqrt(ux * ux + uy * uy + uz * uz);
927 Real t_blank =
myhalf * (t_blank_arr(i, j, k) + t_blank_arr(i, j, k-1));
928 if (t_blank < min_t_blank) { t_blank =
zero; }
929 const Real dx_z = (z_nd_arr) ? (z_nd_arr(i,j,k) - z_nd_arr(i,j,k-1)) : dx_arr[2];
930 const Real drag_coefficient = alpha_m / std::pow(dx_x*dx_y*dx_z,
one/
three);
931 const Real CdM = std::min(drag_coefficient / (windspeed + tiny),
Real(1000.0));
933 zmom_src_arr(i, j, k) -= t_blank * rho_zface * CdM * uz * windspeed;
940 if (is_slow_step && (enforce_massflux_x || enforce_massflux_y)) {
944 [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept {
945 xmom_src_arr(i, j, k) += tau_inv * (rhoUA_target - rhoUA);
947 [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept {
948 ymom_src_arr(i, j, k) += tau_inv * (rhoVA_target - rhoVA);
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)
Definition: ERF_ApplySpongeZoneBCs.cpp:169
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:8
void ApplySurfaceTreatment_BulkCoeff_Mom(const Box &tbx, const Box &tby, 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 Array4< const Real > &cons_state, const Array4< const Real > &z_phys_nd, const Array4< const Real > &surface_state_arr)
Definition: ERF_ApplySurfaceTreatment_BulkCoeff.cpp:8
constexpr amrex::Real three
Definition: ERF_Constants.H:9
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:39
constexpr amrex::Real two
Definition: ERF_Constants.H:8
constexpr amrex::Real one
Definition: ERF_Constants.H:7
constexpr amrex::Real fourth
Definition: ERF_Constants.H:12
constexpr amrex::Real zero
Definition: ERF_Constants.H:6
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:11
constexpr amrex::Real PI
Definition: ERF_Constants.H:24
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:40
@ ubar
Definition: ERF_DataStruct.H:98
@ wbar
Definition: ERF_DataStruct.H:98
@ vbar
Definition: ERF_DataStruct.H:98
DirectionSelector< 2 > ZDir
Definition: ERF_DirectionSelector.H:38
#define Rho_comp
Definition: ERF_IndexDefines.H:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:17
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:8
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
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);})
void NumericalDiffusion_Ymom(const Box &bx, const Real 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 Real 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:28
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_PlaneAverage.H:14
eb_aux_ const * get_w_const_factory() const noexcept
Definition: ERF_EB.H:52
eb_aux_ const * get_v_const_factory() const noexcept
Definition: ERF_EB.H:51
eb_aux_ const * get_u_const_factory() const noexcept
Definition: ERF_EB.H:50
@ r0_comp
Definition: ERF_IndexDefines.H:73
@ ymom
Definition: ERF_IndexDefines.H:194
@ cons
Definition: ERF_IndexDefines.H:192
@ zmom
Definition: ERF_IndexDefines.H:195
@ xmom
Definition: ERF_IndexDefines.H:193
@ nr
Definition: ERF_Morrison.H:45
@ xvel
Definition: ERF_IndexDefines.H:175
@ cons
Definition: ERF_IndexDefines.H:174
@ yvel
Definition: ERF_IndexDefines.H:176
@ ww
Definition: ERF_AdvanceWSM6.cpp:105
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
real(kind=kind_phys), parameter, private r0
Definition: ERF_module_mp_wsm6.F90:21
bool rayleigh_damp_V
Definition: ERF_DampingStruct.H:85
amrex::Real rayleigh_dampcoef
Definition: ERF_DampingStruct.H:88
bool rayleigh_damp_W
Definition: ERF_DampingStruct.H:86
RayleighDampingType rayleigh_damping_type
Definition: ERF_DampingStruct.H:101
bool rayleigh_damp_U
Definition: ERF_DampingStruct.H:84
bool do_mom_advection
Definition: ERF_DataStruct.H:1239
amrex::Real coriolis_factor
Definition: ERF_DataStruct.H:1230
static MeshType mesh_type
Definition: ERF_DataStruct.H:1134
amrex::Real if_surf_temp_flux
Definition: ERF_DataStruct.H:1207
bool if_use_most
Definition: ERF_DataStruct.H:1211
DampingChoice dampingChoice
Definition: ERF_DataStruct.H:1144
amrex::Real const_massflux_v
Definition: ERF_DataStruct.H:1335
amrex::Real if_z0
Definition: ERF_DataStruct.H:1206
amrex::Real cosphi
Definition: ERF_DataStruct.H:1231
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > abl_geo_forcing
Definition: ERF_DataStruct.H:1307
bool hindcast_lateral_forcing
Definition: ERF_DataStruct.H:1344
int massflux_klo
Definition: ERF_DataStruct.H:1339
bool custom_w_subsidence
Definition: ERF_DataStruct.H:1237
bool nudging_from_input_sounding
Definition: ERF_DataStruct.H:1247
bool immersed_forcing_substep
Definition: ERF_DataStruct.H:1199
amrex::Real sinphi
Definition: ERF_DataStruct.H:1232
bool have_geo_wind_profile
Definition: ERF_DataStruct.H:1309
amrex::Real const_massflux_u
Definition: ERF_DataStruct.H:1334
amrex::Real if_Olen_in
Definition: ERF_DataStruct.H:1210
bool use_coriolis
Definition: ERF_DataStruct.H:1193
amrex::Real num_diff_coeff
Definition: ERF_DataStruct.H:1296
bool variable_coriolis
Definition: ERF_DataStruct.H:1311
amrex::Real if_Cd_momentum
Definition: ERF_DataStruct.H:1204
bool custom_forcing_prim_vars
Definition: ERF_DataStruct.H:1241
static BuildingsType buildings_type
Definition: ERF_DataStruct.H:1128
static TerrainType terrain_type
Definition: ERF_DataStruct.H:1125
SpongeChoice spongeChoice
Definition: ERF_DataStruct.H:1145
static InitType init_type
Definition: ERF_DataStruct.H:1119
bool hindcast_surface_bcs
Definition: ERF_DataStruct.H:1345
bool do_forest_drag
Definition: ERF_DataStruct.H:1331
amrex::Real const_massflux_tau
Definition: ERF_DataStruct.H:1336
int massflux_khi
Definition: ERF_DataStruct.H:1340
bool forest_substep
Definition: ERF_DataStruct.H:1200
int ave_plane
Definition: ERF_DataStruct.H:1313
static SpongeType sponge_type
Definition: ERF_SpongeStruct.H:81
Definition: ERF_MOSTStress.H:40
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_psi_m(amrex::Real zeta) const
Definition: ERF_MOSTStress.H:90
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_psi_h(amrex::Real zeta) const
Definition: ERF_MOSTStress.H:104