196 using namespace amrex;
198 if (alfg <= Real(0.0)) {
return; }
199 if (feedback <= Real(0.0)) {
return; }
202 constexpr Real Cp_fire =
Cp_d;
205 constexpr Real L_V =
L_v;
213 const Box& domain = geom_atm.Domain();
214 int klo = domain.smallEnd(2);
215 int khi = domain.bigEnd(2);
216 const auto&
dx = geom_atm.CellSize();
219 const bool has_latent_global = (Q_lat_atm !=
nullptr) && has_moisture;
222 const bool have_open = (open_frac_atm !=
nullptr) && (roof_h_atm !=
nullptr);
223 const bool use_open = have_open && use_open_weights;
229 tend_dbg.define(cc_source.boxArray(), cc_source.DistributionMap(), 1, 0);
230 tend_dbg.setVal(0.0);
238 cc_source.setVal(0.0,
RhoTheta_comp, 1, cc_source.nGrowVect());
239 if (has_latent_global) {
240 cc_source.setVal(0.0,
RhoQ1_comp, 1, cc_source.nGrowVect());
252 const BoxArray& cba = cc_source.boxArray();
253 bool same_layout = open_frac_atm->DistributionMap() == cc_source.DistributionMap() &&
254 roof_h_atm->DistributionMap() == cc_source.DistributionMap() &&
255 open_frac_atm->boxArray().size() == cba.size() &&
256 roof_h_atm->boxArray().size() == cba.size();
257 for (
int ib = 0; same_layout && ib < cba.size(); ++ib) {
258 const Box slab = makeSlab(cba[ib], 2,
klo);
259 same_layout = (open_frac_atm->boxArray()[ib] == slab) && (roof_h_atm->boxArray()[ib] == slab);
262 "[FIRE] the engine's heat_open_fraction_atm and roof_height_atm must hold one k = 0 slab "
263 "per box of the fire grid's level, in its box order and on its DistributionMapping");
267 norm_mf.define(open_frac_atm->boxArray(), cc_source.DistributionMap(), 1, 0);
268 for (MFIter mfi(norm_mf); mfi.isValid(); ++mfi) {
269 auto const& norm_a = norm_mf.array(mfi);
270 auto const& open_arr = open_frac_atm->const_array(mfi);
271 auto const& roof_arr = roof_h_atm->const_array(mfi);
272 auto const& z_cc_a = z_phys_cc.const_array(mfi);
273 const bool has_nd = (z_phys_nd !=
nullptr);
274 Array4<Real const> z_nd_a;
275 if (has_nd) { z_nd_a = z_phys_nd->const_array(mfi); }
276 amrex::ParallelFor(mfi.validbox(), [=] AMREX_GPU_DEVICE (
int i,
int j,
int ) noexcept {
277 const Real f_open = open_arr(i, j, 0);
278 const Real h_roof = roof_arr(i, j, 0);
279 const Real z_sfc = z_cc_a(i, j,
klo);
280 const Real ground =
fire_cell_face(z_nd_a, z_cc_a, has_nd, dz_avg, i, j,
klo, 0);
281 Real norm = Real(0.0);
282 for (
int kk =
klo; kk <=
khi; ++kk) {
283 const Real zz = z_cc_a(i, j, kk) - z_sfc;
284 const Real zzp1 = (kk <
khi) ? (z_cc_a(i, j, kk + 1) - z_sfc) : (zz + dz_avg);
286 if (h_roof > Real(0.0)) {
287 const Real zlo2 =
fire_cell_face(z_nd_a, z_cc_a, has_nd, dz_avg, i, j, kk, 0) - ground;
288 const Real zhi2 =
fire_cell_face(z_nd_a, z_cc_a, has_nd, dz_avg, i, j, kk, 1) - ground;
290 if (zhi2 <= h_roof) { s = f_open; }
291 else if (zlo2 < h_roof) { s = f_open + (Real(1.0) - f_open) * (zhi2 - h_roof) / dzz; }
293 norm += (std::exp(-zz / alfg) - std::exp(-zzp1 / alfg)) * s;
295 norm_a(i, j,
klo) = norm;
300 for (MFIter mfi(cc_source, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
301 auto const& cc_src_a = cc_source.array(mfi);
302 auto const& q_atm_a = Q_atm.array(mfi);
303 auto const& z_cc_a = z_phys_cc.array(mfi);
304 auto const& s_old_a = S_old.array(mfi);
307 const bool has_nd = (z_phys_nd !=
nullptr);
308 Array4<Real const> z_nd_a;
309 if (has_nd) { z_nd_a = z_phys_nd->const_array(mfi); }
311 const Box& bx = mfi.tilebox();
313 const bool has_latent = has_latent_global;
314 Array4<Real const> q_lat_arr;
316 q_lat_arr = Q_lat_atm->const_array(mfi);
318 Array4<Real const> open_arr, roof_arr;
320 open_arr = open_frac_atm->const_array(mfi);
321 roof_arr = roof_h_atm->const_array(mfi);
323 Array4<Real> dbg_arr;
324 if (fire_debug) { dbg_arr = tend_dbg.array(mfi); }
328 Array4<Real const> norm_arr;
329 if (use_open) { norm_arr = norm_mf.const_array(mfi); }
336 Real q_sfc_sensible = feedback * q_atm_a(i, j, 0);
337 Real q_sfc_latent = Real(0.0);
339 q_sfc_latent = feedback * q_lat_arr(i, j, 0);
342 Real z_sfc = z_cc_a(i, j,
klo);
343 Real z_k = z_cc_a(i, j, k) - z_sfc;
344 Real exp_k = std::exp(-z_k / alfg);
346 Real z_kp1 = (k <
khi) ? (z_cc_a(i, j, k + 1) - z_sfc) : (z_k + dz_avg);
347 Real exp_kp1 = std::exp(-z_kp1 / alfg);
354 const Real z_lo =
fire_cell_face(z_nd_a, z_cc_a, has_nd, dz_avg, i, j, k, 0);
355 const Real z_hi =
fire_cell_face(z_nd_a, z_cc_a, has_nd, dz_avg, i, j, k, 1);
359 if (
rho <= Real(0.0)) {
rho = Real(1.2); }
368 const Real mass_fac = density_factor ?
rho : Real(1.0);
369 Real heat_fac = mass_fac;
371 const Real rhotheta = amrex::max(s_old_a(i, j, k,
RhoTheta_comp), Real(1.0e-10));
373 const Real
qv = has_moisture ? amrex::max(s_old_a(i, j, k,
RhoQ1_comp), Real(0.0)) /
rho : Real(0.0);
375 const Real exner = std::pow(
p /
p_0,
rdOcp);
376 heat_fac /= amrex::max(exner, Real(1.0e-6));
386 Real w_k = exp_k - exp_kp1;
389 if (bottom_cell) { w_k = (k ==
klo) ? Real(1.0) : Real(0.0); }
391 const Real f_open = open_arr(i, j, 0);
392 const Real h_roof = roof_arr(i, j, 0);
396 Real share = Real(1.0);
397 if (h_roof > Real(0.0)) {
398 const Real ground =
fire_cell_face(z_nd_a, z_cc_a, has_nd, dz_avg, i, j,
klo, 0);
399 const Real zlo_g = z_lo - ground;
400 const Real zhi_g = z_hi - ground;
401 if (zhi_g <= h_roof) { share = f_open; }
402 else if (zlo_g < h_roof) { share = f_open + (Real(1.0) - f_open) * (zhi_g - h_roof) /
dz; }
406 const Real norm = norm_arr(i, j,
klo);
409 const Real z_top = (z_cc_a(i, j,
khi) - z_sfc) + dz_avg;
410 const Real legacy = Real(1.0) - std::exp(-z_top / alfg);
411 w_k = (norm > Real(1.0e-30)) ? w_k * share * legacy / amrex::max(norm, Real(1.0e-30)) : Real(0.0);
416 Real theta_tend, q_tend = Real(0.0);
417 if (use_open || bottom_cell) {
418 theta_tend = heat_fac * (q_sfc_sensible / Cp_fire) * w_k /
dz;
419 if (has_latent) { q_tend = mass_fac * (q_sfc_latent / L_V) * w_k /
dz; }
421 Real hfx_k = (q_sfc_sensible / Cp_fire) * exp_k;
422 Real hfx_kp1 = (q_sfc_sensible / Cp_fire) * exp_kp1;
423 theta_tend = -heat_fac * (hfx_kp1 - hfx_k) /
dz;
425 Real qfx_k = (q_sfc_latent / L_V) * exp_k;
426 Real qfx_kp1 = (q_sfc_latent / L_V) * exp_kp1;
427 q_tend = -mass_fac * (qfx_kp1 - qfx_k) /
dz;
445 if (dbg_arr) { dbg_arr(i, j, k) = theta_tend * (z_hi - z_lo); }
454 Real Q_max = Q_atm.max(0);
457 Real expected_max = feedback * Q_max / Cp_fire
458 * (Real(1.0) - std::exp(-dz_avg / alfg)) / dz_avg;
459 amrex::Print() <<
"[FIRE COUPLING] Q_atm_max=" << Q_max
460 <<
" W/m2 alfg=" << alfg <<
" m\n"
461 <<
"[FIRE COUPLING] RhoTheta tendency"
462 <<
" sum=" << rt_tend_sum
463 <<
" max=" << rt_tend_max
464 <<
" expected_surface_max=" << expected_max
465 <<
" [kg K m^-3 s^-1]\n";
475 const Real area =
dx[0] *
dx[1];
476 const Real e_out = Cp_fire * tend_dbg.sum(0) * area;
477 const Real e_in = feedback * Q_atm.sum(0) * area;
488 Real below_roof_max = -Real(1.0), theta_blocked_max = -Real(1.0);
490 MultiFab col(open_frac_atm->boxArray(), open_frac_atm->DistributionMap(), 1, 0);
491 MultiFab thb(tend_dbg.boxArray(), tend_dbg.DistributionMap(), 1, 0);
492 col.setVal(0.0); thb.setVal(0.0);
493 for (MFIter mfi(col, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
494 const Box& bx2 = mfi.tilebox();
495 auto const& c = col.array(mfi);
496 auto const&
t = tend_dbg.const_array(mfi);
497 auto const&
z = z_phys_cc.const_array(mfi);
498 auto const& ofrac = open_frac_atm->const_array(mfi);
499 auto const& hr = roof_h_atm->const_array(mfi);
500 const bool has_nd = (z_phys_nd !=
nullptr);
501 Array4<Real const> znd;
502 if (has_nd) { znd = z_phys_nd->const_array(mfi); }
504 const Real f = ofrac(i, j, 0);
505 if (f <= Real(1.0e-6) || f >= Real(1.0) - Real(1.0e-6)) {
return; }
507 Real below = Real(0.0),
total = Real(0.0);
508 for (
int kk =
klo; kk <=
khi; ++kk) {
509 const Real zk =
z(i, j, kk) - ground;
511 if (zk < hr(i, j, 0)) { below +=
t(i, j, kk); }
513 c(i, j, 0) = (
total > Real(1.0e-30)) ? below / amrex::max(
total, Real(1.0e-30)) : Real(0.0);
516 for (MFIter mfi(thb, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
517 const Box& bx = mfi.tilebox();
518 auto const& b = thb.array(mfi);
519 auto const&
z = z_phys_cc.const_array(mfi);
520 auto const& so = S_old.const_array(mfi);
521 auto const& ofrac = open_frac_atm->const_array(mfi);
522 auto const& hr = roof_h_atm->const_array(mfi);
523 const bool has_nd = (z_phys_nd !=
nullptr);
524 Array4<Real const> znd;
525 if (has_nd) { znd = z_phys_nd->const_array(mfi); }
528 if (ofrac(i, j, 0) < Real(1.0) - Real(1.0e-6) && zk < hr(i, j, 0)) {
533 below_roof_max = col.max(0);
534 theta_blocked_max = thb.max(0);
541 amrex::Print() <<
"[FIRE COUPLING] energy_in=" << e_in <<
" W energy_out=" << e_out
542 <<
" W ratio=" << ((e_in > 0.0) ? e_out / amrex::max(e_in, std::numeric_limits<Real>::min()) : 0.0)
543 <<
" below_roof_share_max=" << below_roof_max
544 <<
" theta_blocked_max=" << theta_blocked_max <<
"\n";
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:51
constexpr amrex::Real p_0
Definition: ERF_Constants.H:69
constexpr amrex::Real R_d
Definition: ERF_Constants.H:49
constexpr amrex::Real L_v
Definition: ERF_Constants.H:67
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:81
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real fire_cell_thickness(amrex::Real z_lo, amrex::Real z_hi, amrex::Real dz_avg) noexcept
Definition: ERF_FireAtmCoupling.H:150
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real fire_cell_face(amrex::Array4< amrex::Real const > const &z_nd, amrex::Array4< amrex::Real const > const &z_cc, bool has_nd, amrex::Real dz_avg, int i, int j, int k, int upper) noexcept
Definition: ERF_FireAtmCoupling.H:131
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:78
const Real rdOcp
Definition: ERF_InitCustomPert_ABL.H:128
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
const int klo
Definition: ERF_InitCustomPert_KE.H:9
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
@ rho
Definition: ERF_Kessler.H:25
@ qv
Definition: ERF_Kessler.H:31
@ total
Definition: ERF_NOAHMP_Fields.H:137
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
@ t
Definition: ERF_WSM6.H:295
@ p
Definition: ERF_WSM6.H:303
Definition: ERF_ConsoleIO.cpp:17