ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ForceRestoreHydrology Class Reference

The per-level state of the force-restore hydrology (ERF_ForceRestoreHydrology.H): the running totals that close each column's water budget. More...

#include <ERF_ForceRestoreHydrologyState.H>

Collaboration diagram for ForceRestoreHydrology:

Classes

struct  StepSums
 Domain sums of one step on one level (rank-reduced), for the log. More...
 

Public Types

enum  Total : int {
  Rain = 0 , Runoff , Drainage , Deficit ,
  NumTotals
}
 Components of totals(lev), each a running total [kg/m^2] since the start. More...
 

Public Member Functions

void resize (int nlevs_max)
 
void define_level (int lev, const RadChoice &rc, const amrex::BoxArray &ba2d, const amrex::DistributionMapping &dm, const amrex::IntVect &ng)
 Allocate the level's fields; a no-op unless the hydrology is enabled. More...
 
bool defined (int lev) const noexcept
 True once define_level allocated lev. More...
 
StepSums step (int lev, const amrex::MultiFab &t_s, amrex::MultiFab &q_s, amrex::MultiFab &q_deep, amrex::MultiFab &t_deep, const amrex::MultiFab &lh, const amrex::MultiFab *footprint, amrex::Real dt, const ForceRestoreHydrologyParams &prm, const ForceRestorePrecipInput &rain, const amrex::MultiFab *snow_water=nullptr, const amrex::iMultiFab *land_mask=nullptr)
 One hydrology step on every open column of lev, after the balance has updated T_s and q_s. A footprint cell (footprint > 0.5) and a water column (land_mask 0) keep their state and are left out of the sums. More...
 
amrex::MultiFab * totals (int lev) noexcept
 The running totals (Total components) [kg/m^2], or nullptr. More...
 
void write_checkpoint (int lev, const std::string &checkpointname) const
 
void read_checkpoint (int lev, const std::string &restart_chkfile, const amrex::Periodicity &period)
 

Static Public Member Functions

static ForceRestoreHydrologyParams params (const RadChoice &rc)
 The parameters of one step, from the erf.radiation.seb_* inputs. More...
 

Private Attributes

amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_totals
 Total components. More...
 

Detailed Description

The per-level state of the force-restore hydrology (ERF_ForceRestoreHydrology.H): the running totals that close each column's water budget.

Owned by TwoStreamRadiation, which keeps the force-restore state itself (q_s, q_deep, T_deep) and the rain rate of the step (ERF_ForceRestorePrecipRate.H). step(...) at the force-restore update after the dycore applies one hydrology step to every open column and adds to the running totals. The totals are checkpointed, and TwoStreamRadiation lists them with its prognostic fields for regrid, coarse-fine filling and averaging down.

Member Enumeration Documentation

◆ Total

Components of totals(lev), each a running total [kg/m^2] since the start.

Enumerator
Rain 
Runoff 
Drainage 
Deficit 
NumTotals 
51 : int { Rain = 0, Runoff, Drainage, Deficit, NumTotals };
@ NumTotals
Definition: ERF_ForceRestoreHydrologyState.H:51
@ Drainage
Definition: ERF_ForceRestoreHydrologyState.H:51
@ Runoff
Definition: ERF_ForceRestoreHydrologyState.H:51
@ Rain
Definition: ERF_ForceRestoreHydrologyState.H:51
@ Deficit
Definition: ERF_ForceRestoreHydrologyState.H:51

Member Function Documentation

◆ define_level()

void ForceRestoreHydrology::define_level ( int  lev,
const RadChoice &  rc,
const amrex::BoxArray &  ba2d,
const amrex::DistributionMapping &  dm,
const amrex::IntVect &  ng 
)

Allocate the level's fields; a no-op unless the hydrology is enabled.

47 {
48  if (!rc.seb_hydrology_enabled()) { return; }
49  m_totals[lev] = std::make_unique<MultiFab>(ba2d, dm, NumTotals, ng);
50  m_totals[lev]->setVal(0.0);
51 }
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_totals
Total components.
Definition: ERF_ForceRestoreHydrologyState.H:118
@ ng
Definition: ERF_Morrison.H:51
constexpr std::array< amrex::Real, num_veg_params > rc
Definition: ERF_SLM_DefaultParams.H:22

◆ defined()

bool ForceRestoreHydrology::defined ( int  lev) const
inlinenoexcept

True once define_level allocated lev.

74  {
75  return lev >= 0 && lev < static_cast<int>(m_totals.size()) && m_totals[lev] != nullptr;
76  }

Referenced by read_checkpoint(), totals(), and write_checkpoint().

Here is the caller graph for this function:

◆ params()

ForceRestoreHydrologyParams ForceRestoreHydrology::params ( const RadChoice &  rc)
static

The parameters of one step, from the erf.radiation.seb_* inputs.

21 {
23  p.rain = rc.seb_precipitation_source != SEBPrecipitationSource::None;
24  p.deep = rc.seb_deep_prognostic_enable;
25  p.drain = rc.seb_drainage_enable;
26  p.d_s = rc.seb_moisture_layer_depth_m;
27  p.d_2 = rc.seb_deep_layer_depth_m;
28  p.tau = rc.seb_restore_timescale_s;
29  p.w_fc = rc.seb_soil_moisture_fc;
30  p.w_sat = rc.seb_soil_porosity;
31  // MN96 Eq. (16): C_3 scales as 1/d_2; Table 1 gives C_3 d_2 [m].
32  p.c3 = p.drain ? rc.seb_drainage_c3_m / rc.seb_deep_layer_depth_m : Real(0.0);
33  p.q_min = rc.seb_prognostic_q_min;
34  p.q_max = rc.seb_prognostic_q_max;
35  return p;
36 }
@ None
Definition: ERF_LSM_Types.H:6
@ p
Definition: ERF_WSM6.H:303
Definition: ERF_ForceRestoreHydrology.H:75

Referenced by TwoStreamRadiation::advance().

Here is the caller graph for this function:

◆ read_checkpoint()

void ForceRestoreHydrology::read_checkpoint ( int  lev,
const std::string &  restart_chkfile,
const amrex::Periodicity &  period 
)
160 {
161  if (!defined(lev)) { return; }
162  const std::string name =
163  MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "TwoStream_HydrologyTotals");
164  // A checkpoint written without the hydrology has no totals: they restart from zero.
165  if (!amrex::FileExists(name + "_H")) {
166  // Once, not per level.
167  if (lev == 0) {
168  amrex::Print() << "NOTE: the checkpoint has no force-restore hydrology totals; "
169  << "seb_rain_total, seb_runoff_total, seb_drainage_total and "
170  << "seb_deficit_total restart from zero.\n";
171  }
172  return;
173  }
175  m_totals[lev]->nGrowVect(), true, period);
176 }
GpuArray< Real, AMREX_SPACEDIM > period
Definition: ERF_ActuatorSpreading.cpp:131
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
bool defined(int lev) const noexcept
True once define_level allocated lev.
Definition: ERF_ForceRestoreHydrologyState.H:74
void read_checkpoint_multifab(amrex::MultiFab &dst, const std::string &mf_name, int scomp, int dcomp, int ncomp, const amrex::IntVect &dst_ghosts, bool src_ghosts, const amrex::Periodicity &period)
Definition: ERF_ReadCheckpointMF.H:92
Here is the call graph for this function:

◆ resize()

void ForceRestoreHydrology::resize ( int  nlevs_max)
40 {
41  m_totals.resize(nlevs_max);
42 }

◆ step()

ForceRestoreHydrology::StepSums ForceRestoreHydrology::step ( int  lev,
const amrex::MultiFab &  t_s,
amrex::MultiFab &  q_s,
amrex::MultiFab &  q_deep,
amrex::MultiFab &  t_deep,
const amrex::MultiFab &  lh,
const amrex::MultiFab *  footprint,
amrex::Real  dt,
const ForceRestoreHydrologyParams &  prm,
const ForceRestorePrecipInput &  rain,
const amrex::MultiFab *  snow_water = nullptr,
const amrex::iMultiFab *  land_mask = nullptr 
)

One hydrology step on every open column of lev, after the balance has updated T_s and q_s. A footprint cell (footprint > 0.5) and a water column (land_mask 0) keep their state and are left out of the sums.

Parameters
t_ssurface temperature after the update [K]
q_ssurface water content [m^3/m^3], updated
q_deepcolumn water content [m^3/m^3], updated with the deep reservoir
t_deepdeep temperature [K], updated with the deep reservoir
lhlatent heat flux the balance used [W/m^2]; E = LH / L_v
footprintbuilding footprints, or nullptr
dtthe step [s]
prmparams(rc)
rainthe rain of the step (ForceRestorePrecipRate::rain); used only with prm.rain
snow_waterwater the snow layer hands the soil this step [kg/m^2], or nullptr (ERF_ForceRestoreSnowState.H): it enters as rain does, and is not part of the Rain total. It needs prm.rain (the soil takes no water otherwise), which the step asserts
land_maskthe level's land mask (0 water), or nullptr: every column is land
Returns
the step's domain sums, reduced over ranks
61 {
62  StepSums sums;
63  if (!defined(lev)) { return sums; }
64  seb_assert_land_mask_layout(land_mask, q_s, "ForceRestoreHydrology::step");
65 
66  // The soil takes water only with prm.rain: the snow layer's water would otherwise leave
67  // the column unseen.
68  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(snow_water == nullptr || prm.rain,
69  "ForceRestoreHydrology::step: the snow layer's water (snow_water) needs "
70  "erf.radiation.seb_precipitation_source, which lets the soil take water");
71 
72  // The rain of the step: the rate times its scale (ERF_ForceRestorePrecipRate.H).
73  const bool has_rain = prm.rain && rain.rate != nullptr;
74  const Real rain_scale = rain.scale;
75  const int rain_comp = rain.comp;
76 
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;
81 
82  // Untiled, on the valid boxes: the update is in place.
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>{};
96  // A water column is not soil: no rain, runoff or drainage is booked on it.
97  const SEBLandMaskView mask = seb_land_mask_view(land_mask, mfi);
98 
99  reduce_op.eval(bx, reduce_data,
100  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept -> ReduceTuple
101  {
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)};
104  }
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); }
109 
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);
112  // The snow layer's water (melt, and the sublimation the balance took from the
113  // soil) enters as rain does; the Rain total keeps the rain alone.
114  const Real p_rain = p;
115  if (has_snow) { p += sw(i, j, k) / dt; }
117  force_restore_hydrology_step(qs_c, qd_c, td_c, ts(i, j, k), p, e, dt, prm);
118  qs(i, j, k) = qs_c;
119  if (prm.deep) { qd(i, j, k) = qd_c; td(i, j, k) = td_c; }
120 
121  tot(i, j, k, Rain) += p_rain * dt;
122  tot(i, j, k, Runoff) += f.runoff;
123  tot(i, j, k, Drainage) += f.drainage;
124  tot(i, j, k, Deficit) += f.deficit;
125 
126  // The column's water budget, which closes to round-off with the deep reservoir.
127  Real residual = Real(0.0);
128  if (prm.deep) {
129  residual = amrex::Math::abs(rhor * prm.d_2 * (qd_c - qd_old)
130  - ((p - e) * dt - f.drainage - f.runoff + f.deficit));
131  }
132  return {p_rain * dt, e * dt, f.runoff, f.drainage, f.deficit, residual, Long(1)};
133  });
134  }
135 
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),
138  amrex::get<4>(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;
146  return sums;
147 }
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
Here is the call graph for this function:

◆ totals()

amrex::MultiFab* ForceRestoreHydrology::totals ( int  lev)
inlinenoexcept

The running totals (Total components) [kg/m^2], or nullptr.

109  {
110  return defined(lev) ? m_totals[lev].get() : nullptr;
111  }

Referenced by TwoStreamRadiation::hydrology_totals().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_checkpoint()

void ForceRestoreHydrology::write_checkpoint ( int  lev,
const std::string &  checkpointname 
) const
151 {
152  if (!defined(lev)) { return; }
153  VisMF::Write(*m_totals[lev],
154  MultiFabFileFullPrefix(lev, checkpointname, "Level_", "TwoStream_HydrologyTotals"));
155 }
Here is the call graph for this function:

Member Data Documentation

◆ m_totals

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ForceRestoreHydrology::m_totals
private

Total components.

Referenced by defined(), read_checkpoint(), totals(), and write_checkpoint().


The documentation for this class was generated from the following files: