ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ForceRestoreHydrologyState.H
Go to the documentation of this file.
1 #ifndef ERF_FORCE_RESTORE_HYDROLOGY_STATE_H_
2 #define ERF_FORCE_RESTORE_HYDROLOGY_STATE_H_
3 
4 #include <memory>
5 #include <string>
6 
7 #include <AMReX_MultiFab.H>
8 #include <AMReX_iMultiFab.H>
9 #include <AMReX_Periodicity.H>
10 #include <AMReX_REAL.H>
11 #include <AMReX_Vector.H>
12 
15 
16 struct RadChoice;
17 
18 /**
19  * @brief The force-restore soil of one level, read-only, for a model that reads the ground
20  * (the dust coupling's DustStep::soil). Every pointer is to a 2D field (i, j, k = 0)
21  * on the level's horizontal grids, valid for the duration of the call it is handed to.
22  */
24 {
25  const amrex::MultiFab* q_sfc = nullptr; ///< surface-layer water content [m^3/m^3]
26  const amrex::MultiFab* q_deep = nullptr; ///< column water content [m^3/m^3]; constant in time without the deep reservoir (per column with seb_init_soil_moisture_from_file)
27  const amrex::MultiFab* t_sfc = nullptr; ///< surface temperature [K]
28  const amrex::MultiFab* rain_rate = nullptr; ///< rain of the last step [kg/m^2/s], component 0; nullptr without seb_precipitation_source
29  amrex::Real d_s = 0.0; ///< surface layer depth [m] (seb_moisture_layer_depth_m)
30  amrex::Real d_2 = 0.0; ///< column depth [m] (seb_deep_layer_depth_m); 0 without the deep reservoir
31  amrex::Real porosity = -1.0; ///< [m^3/m^3]; -1 when neither seb_soil_porosity nor seb_soil_type gives one
32  amrex::Real fc = 0.0; ///< field capacity [m^3/m^3] (seb_soil_moisture_fc)
33  amrex::Real wilt = 0.0; ///< wilting point [m^3/m^3] (seb_soil_moisture_wilt)
34  bool deep = false; ///< seb_deep_prognostic_enable
35 };
36 
37 /**
38  * @brief The per-level state of the force-restore hydrology (ERF_ForceRestoreHydrology.H):
39  * the running totals that close each column's water budget.
40  *
41  * Owned by TwoStreamRadiation, which keeps the force-restore state itself (q_s, q_deep,
42  * T_deep) and the rain rate of the step (ERF_ForceRestorePrecipRate.H). step(...) at the
43  * force-restore update after the dycore applies one hydrology step to every open column
44  * and adds to the running totals. The totals are checkpointed, and TwoStreamRadiation lists
45  * them with its prognostic fields for regrid, coarse-fine filling and averaging down.
46  */
48 {
49 public:
50  /** @brief Components of totals(lev), each a running total [kg/m^2] since the start. */
51  enum Total : int { Rain = 0, Runoff, Drainage, Deficit, NumTotals };
52 
53  /** @brief Domain sums of one step on one level (rank-reduced), for the log. */
54  struct StepSums {
55  amrex::Real rain = 0.0; ///< sum of P dt [kg/m^2]
56  amrex::Real evaporation = 0.0; ///< sum of E dt [kg/m^2]
57  amrex::Real runoff = 0.0; ///< [kg/m^2]
58  amrex::Real drainage = 0.0; ///< [kg/m^2]
59  amrex::Real deficit = 0.0; ///< [kg/m^2]
60  amrex::Real max_residual = 0.0; ///< max |column budget residual| [kg/m^2]
61  amrex::Long columns = 0; ///< open columns updated
62  };
63 
64  /** @brief The parameters of one step, from the erf.radiation.seb_* inputs. */
65  [[nodiscard]] static ForceRestoreHydrologyParams params (const RadChoice& rc);
66 
67  void resize (int nlevs_max);
68 
69  /** @brief Allocate the level's fields; a no-op unless the hydrology is enabled. */
70  void define_level (int lev, const RadChoice& rc, const amrex::BoxArray& ba2d,
71  const amrex::DistributionMapping& dm, const amrex::IntVect& ng);
72 
73  /** @brief True once define_level allocated @p lev. */
74  [[nodiscard]] bool defined (int lev) const noexcept {
75  return lev >= 0 && lev < static_cast<int>(m_totals.size()) && m_totals[lev] != nullptr;
76  }
77 
78  /**
79  * @brief One hydrology step on every open column of @p lev, after the balance has
80  * updated T_s and q_s. A footprint cell (footprint > 0.5) and a water column
81  * (land_mask 0) keep their state and are left out of the sums.
82  *
83  * @param t_s surface temperature after the update [K]
84  * @param q_s surface water content [m^3/m^3], updated
85  * @param q_deep column water content [m^3/m^3], updated with the deep reservoir
86  * @param t_deep deep temperature [K], updated with the deep reservoir
87  * @param lh latent heat flux the balance used [W/m^2]; E = LH / L_v
88  * @param footprint building footprints, or nullptr
89  * @param dt the step [s]
90  * @param prm params(rc)
91  * @param rain the rain of the step (ForceRestorePrecipRate::rain); used only with
92  * prm.rain
93  * @param snow_water water the snow layer hands the soil this step [kg/m^2], or nullptr
94  * (ERF_ForceRestoreSnowState.H): it enters as rain does, and is not
95  * part of the Rain total. It needs prm.rain (the soil takes no water
96  * otherwise), which the step asserts
97  * @param land_mask the level's land mask (0 water), or nullptr: every column is land
98  * @return the step's domain sums, reduced over ranks
99  */
100  StepSums step (int lev, const amrex::MultiFab& t_s, amrex::MultiFab& q_s,
101  amrex::MultiFab& q_deep, amrex::MultiFab& t_deep,
102  const amrex::MultiFab& lh, const amrex::MultiFab* footprint,
103  amrex::Real dt, const ForceRestoreHydrologyParams& prm,
105  const amrex::MultiFab* snow_water = nullptr,
106  const amrex::iMultiFab* land_mask = nullptr);
107 
108  /** @brief The running totals (Total components) [kg/m^2], or nullptr. */
109  [[nodiscard]] amrex::MultiFab* totals (int lev) noexcept {
110  return defined(lev) ? m_totals[lev].get() : nullptr;
111  }
112 
113  void write_checkpoint (int lev, const std::string& checkpointname) const;
114  void read_checkpoint (int lev, const std::string& restart_chkfile,
115  const amrex::Periodicity& period);
116 
117 private:
118  amrex::Vector<std::unique_ptr<amrex::MultiFab>> m_totals; ///< Total components
119 };
120 
121 #endif // ERF_FORCE_RESTORE_HYDROLOGY_STATE_H_
GpuArray< Real, AMREX_SPACEDIM > period
Definition: ERF_ActuatorSpreading.cpp:131
Water of the two-stream force-restore surface: rain in, runoff, a prognostic deep reservoir with grav...
The per-level state of the force-restore hydrology (ERF_ForceRestoreHydrology.H): the running totals ...
Definition: ERF_ForceRestoreHydrologyState.H:48
void read_checkpoint(int lev, const std::string &restart_chkfile, const amrex::Periodicity &period)
Definition: ERF_ForceRestoreHydrologyState.cpp:158
amrex::MultiFab * totals(int lev) noexcept
The running totals (Total components) [kg/m^2], or nullptr.
Definition: ERF_ForceRestoreHydrologyState.H:109
void write_checkpoint(int lev, const std::string &checkpointname) const
Definition: ERF_ForceRestoreHydrologyState.cpp:150
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....
Definition: ERF_ForceRestoreHydrologyState.cpp:54
bool defined(int lev) const noexcept
True once define_level allocated lev.
Definition: ERF_ForceRestoreHydrologyState.H:74
static ForceRestoreHydrologyParams params(const RadChoice &rc)
The parameters of one step, from the erf.radiation.seb_* inputs.
Definition: ERF_ForceRestoreHydrologyState.cpp:20
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.
Definition: ERF_ForceRestoreHydrologyState.cpp:45
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_totals
Total components.
Definition: ERF_ForceRestoreHydrologyState.H:118
void resize(int nlevs_max)
Definition: ERF_ForceRestoreHydrologyState.cpp:39
Total
Components of totals(lev), each a running total [kg/m^2] since the start.
Definition: ERF_ForceRestoreHydrologyState.H:51
@ 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
@ ng
Definition: ERF_Morrison.H:51
@ rain
Definition: ERF_NOAHMP_Fields.H:138
constexpr std::array< amrex::Real, num_veg_params > rc
Definition: ERF_SLM_DefaultParams.H:22
Definition: ERF_ForceRestoreHydrology.H:75
Domain sums of one step on one level (rank-reduced), for the log.
Definition: ERF_ForceRestoreHydrologyState.H:54
amrex::Real deficit
[kg/m^2]
Definition: ERF_ForceRestoreHydrologyState.H:59
amrex::Long columns
open columns updated
Definition: ERF_ForceRestoreHydrologyState.H:61
amrex::Real runoff
[kg/m^2]
Definition: ERF_ForceRestoreHydrologyState.H:57
amrex::Real evaporation
sum of E dt [kg/m^2]
Definition: ERF_ForceRestoreHydrologyState.H:56
amrex::Real rain
sum of P dt [kg/m^2]
Definition: ERF_ForceRestoreHydrologyState.H:55
amrex::Real max_residual
max |column budget residual| [kg/m^2]
Definition: ERF_ForceRestoreHydrologyState.H:60
amrex::Real drainage
[kg/m^2]
Definition: ERF_ForceRestoreHydrologyState.H:58
The precipitation one force-restore step takes from a rate field: the rate [kg/m^2/s] in component co...
Definition: ERF_ForceRestorePrecipRate.H:20
The force-restore soil of one level, read-only, for a model that reads the ground (the dust coupling'...
Definition: ERF_ForceRestoreHydrologyState.H:24
const amrex::MultiFab * q_sfc
surface-layer water content [m^3/m^3]
Definition: ERF_ForceRestoreHydrologyState.H:25
amrex::Real d_2
column depth [m] (seb_deep_layer_depth_m); 0 without the deep reservoir
Definition: ERF_ForceRestoreHydrologyState.H:30
amrex::Real porosity
[m^3/m^3]; -1 when neither seb_soil_porosity nor seb_soil_type gives one
Definition: ERF_ForceRestoreHydrologyState.H:31
const amrex::MultiFab * t_sfc
surface temperature [K]
Definition: ERF_ForceRestoreHydrologyState.H:27
bool deep
seb_deep_prognostic_enable
Definition: ERF_ForceRestoreHydrologyState.H:34
const amrex::MultiFab * q_deep
column water content [m^3/m^3]; constant in time without the deep reservoir (per column with seb_init...
Definition: ERF_ForceRestoreHydrologyState.H:26
const amrex::MultiFab * rain_rate
rain of the last step [kg/m^2/s], component 0; nullptr without seb_precipitation_source
Definition: ERF_ForceRestoreHydrologyState.H:28
amrex::Real fc
field capacity [m^3/m^3] (seb_soil_moisture_fc)
Definition: ERF_ForceRestoreHydrologyState.H:32
amrex::Real wilt
wilting point [m^3/m^3] (seb_soil_moisture_wilt)
Definition: ERF_ForceRestoreHydrologyState.H:33
amrex::Real d_s
surface layer depth [m] (seb_moisture_layer_depth_m)
Definition: ERF_ForceRestoreHydrologyState.H:29
Container holding radiation-related choices and parameters.
Definition: ERF_RadStruct.H:142