63 if (!
defined(lev)) {
return sums; }
69 "ForceRestoreHydrology::step: the snow layer's water (snow_water) needs "
70 "erf.radiation.seb_precipitation_source, which lets the soil take water");
73 const bool has_rain = prm.
rain &&
rain.rate !=
nullptr;
74 const Real rain_scale =
rain.scale;
75 const int rain_comp =
rain.comp;
77 ReduceOps<ReduceOpSum, ReduceOpSum, ReduceOpSum, ReduceOpSum, ReduceOpSum, ReduceOpMax,
78 ReduceOpSum> reduce_op;
79 ReduceData<Real, Real, Real, Real, Real, Real, Long> reduce_data(reduce_op);
80 using ReduceTuple =
typename decltype(reduce_data)::Type;
83 for (MFIter mfi(q_s,
false); mfi.isValid(); ++mfi) {
84 const Box& bx = mfi.validbox();
85 Array4<const Real> ts = t_s.const_array(mfi);
86 Array4<Real>
qs = q_s.array(mfi);
87 Array4<Real> qd = q_deep.array(mfi);
88 Array4<Real> td = t_deep.array(mfi);
89 Array4<const Real> le = lh.const_array(mfi);
90 Array4<const Real> pr = has_rain ?
rain.rate->const_array(mfi) : Array4<const Real>{};
91 Array4<Real> tot =
m_totals[lev]->array(mfi);
92 const bool has_foot = footprint !=
nullptr;
93 Array4<const Real> foot = has_foot ? footprint->const_array(mfi) : Array4<const Real>{};
94 const bool has_snow = snow_water !=
nullptr;
95 Array4<const Real> sw = has_snow ? snow_water->const_array(mfi) : Array4<const Real>{};
99 reduce_op.eval(bx, reduce_data,
100 [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept -> ReduceTuple
102 if ((has_foot && foot(i, j, k) > Real(0.5)) || mask.
water(i, j)) {
103 return {Real(0.), Real(0.), Real(0.), Real(0.), Real(0.), Real(0.), Long(0)};
105 Real
p = has_rain ? pr(i, j, k, rain_comp) * rain_scale : Real(0.0);
106 if (!amrex::Math::isfinite(
p)) {
p = Real(0.0); }
107 Real e = le(i, j, k) /
L_v;
108 if (!amrex::Math::isfinite(e)) { e = Real(0.0); }
110 const Real qd_old = qd(i, j, k);
111 Real qs_c =
qs(i, j, k), qd_c = qd_old, td_c = td(i, j, k);
114 const Real p_rain =
p;
115 if (has_snow) {
p += sw(i, j, k) / dt; }
119 if (prm.
deep) { qd(i, j, k) = qd_c; td(i, j, k) = td_c; }
121 tot(i, j, k,
Rain) += p_rain * dt;
127 Real residual = Real(0.0);
129 residual = amrex::Math::abs(
rhor * prm.
d_2 * (qd_c - qd_old)
136 ReduceTuple h = reduce_data.value(reduce_op);
137 Real s[5] = {amrex::get<0>(h), amrex::get<1>(h), amrex::get<2>(h), amrex::get<3>(h),
139 Real rmax = amrex::get<5>(h);
140 Long n = amrex::get<6>(h);
141 ParallelDescriptor::ReduceRealSum(s, 5);
142 ParallelDescriptor::ReduceRealMax(rmax);
143 ParallelDescriptor::ReduceLongSum(n);
144 sums.rain = s[0]; sums.evaporation = s[1]; sums.runoff = s[2];
145 sums.drainage = s[3]; sums.deficit = s[4]; sums.max_residual = rmax; sums.columns = n;
constexpr amrex::Real L_v
Definition: ERF_Constants.H:67
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ForceRestoreHydrologyFluxes force_restore_hydrology_step(amrex::Real &q_s, amrex::Real &q_deep, amrex::Real &t_deep, amrex::Real t_s, amrex::Real p, amrex::Real e, amrex::Real dt, const ForceRestoreHydrologyParams &prm) noexcept
One step of the force-restore hydrology for one column, after the balance has updated T_s and q_s (pr...
Definition: ERF_ForceRestoreHydrology.H:144
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
constexpr amrex::Real rhor
Definition: ERF_MicrophysicsConstants.H:39
SEBLandMaskView seb_land_mask_view(const amrex::iMultiFab *mask, const amrex::MFIter &mfi)
The view of mask on the box of mfi; off when mask is nullptr.
Definition: ERF_SEBLandMask.H:54
void seb_assert_land_mask_layout(const amrex::iMultiFab *mask, const amrex::FabArrayBase &field, const char *who)
Stop when mask is given and is not on the grids of field.
Definition: ERF_SEBLandMask.H:43
@ qs
Definition: ERF_Morrison.H:113
@ rain
Definition: ERF_NOAHMP_Fields.H:138
Water that left a column during one step [kg/m^2].
Definition: ERF_ForceRestoreHydrology.H:93
amrex::Real deficit
Water the column lacked when evaporation would take q_deep below 0.
Definition: ERF_ForceRestoreHydrology.H:96
amrex::Real runoff
Above-porosity water that left the column: rain that did not infiltrate, and column excess.
Definition: ERF_ForceRestoreHydrology.H:94
amrex::Real drainage
Gravitational drainage out of the column bottom.
Definition: ERF_ForceRestoreHydrology.H:95
bool rain
seb_precipitation_source != none
Definition: ERF_ForceRestoreHydrology.H:84
bool deep
seb_deep_prognostic_enable
Definition: ERF_ForceRestoreHydrology.H:85
amrex::Real d_2
Column depth d_2 [m] (seb_deep_layer_depth_m)
Definition: ERF_ForceRestoreHydrology.H:77
The land mask of one box, for a device kernel. Captured by value.
Definition: ERF_SEBLandMask.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool water(int i, int j) const noexcept
True when the balance does not run on column (i, j).
Definition: ERF_SEBLandMask.H:35