ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SEBSoilInit.H
Go to the documentation of this file.
1 #ifndef ERF_SEB_SOIL_INIT_H_
2 #define ERF_SEB_SOIL_INIT_H_
3 
4 #include <limits>
5 
6 #include <AMReX_INT.H>
7 #include <AMReX_MultiFab.H>
8 #include <AMReX_REAL.H>
9 #include <AMReX_Vector.H>
10 #include <AMReX_iMultiFab.H>
11 
12 /**
13  * @file ERF_SEBSoilInit.H
14  * @brief The first soil water of the two-stream force-restore balance from the soil
15  * moisture profile of the initial file (SMOIS of a wrfinput file, with the layer
16  * thicknesses DZS), with erf.radiation.seb_init_soil_moisture_from_file.
17  *
18  * The balance holds two water contents per column [m^3/m^3]: q_s, the mean of the top
19  * d_1 = erf.radiation.seb_moisture_layer_depth_m of soil, and q_deep, the mean of the soil
20  * column d_2 = erf.radiation.seb_deep_layer_depth_m deep, which contains the top layer.
21  * The file gives the water content of N layers, the top one first, with thicknesses
22  * dz_n. The mean over the depth d is
23  *
24  * q(d) = sum_n w_n SMOIS_n, w_n = overlap([z_{n-1}, z_n], [0, d]) / sum of overlaps,
25  *
26  * with z_0 = 0 and z_n = z_{n-1} + dz_n. The mean lies between the smallest and the
27  * largest layer value, so it adds no water content the file does not hold; the copy holds
28  * the rounded sum to that interval, so a uniform profile gives exactly its value.
29  *
30  * Without the input every column starts at erf.radiation.seb_q_sfc_default and
31  * seb_q_deep_default. With it a land column starts at the file's means. A water column
32  * keeps the defaults: the balance does not run there.
33  */
34 
35 /**
36  * @brief Relative shortfall of the file's soil depth that seb_soil_layer_weights accepts:
37  * the thicknesses are single-precision in the file, so layers that reach exactly the depth
38  * asked for can sum to a little less in double precision.
39  */
40 constexpr amrex::Real seb_soil_depth_rel_tol = amrex::Real(1.0e-5);
41 
42 /**
43  * @brief Relative distance outside [q_lo, q_hi] at which seb_init_soil_moisture_from_file
44  * still takes a mean, and then stores the bound: the file's water contents are
45  * single-precision, so a soil that the file holds exactly at a bound (saturated at the
46  * porosity 0.439, say) reads back up to 6e-8 of the value away from the bound in double
47  * precision. The 1e-6 is for that rounding of the file, not for the working precision: it
48  * is 4.5e9 double epsilons but only 8 single ones, so a single-precision build takes ten
49  * of its own epsilons (1.2e-6) instead.
50  */
51 constexpr amrex::Real seb_soil_value_rel_tol =
52  (amrex::Real(1.0e-6) > amrex::Real(10.0) * std::numeric_limits<amrex::Real>::epsilon())
53  ? amrex::Real(1.0e-6)
54  : amrex::Real(10.0) * std::numeric_limits<amrex::Real>::epsilon();
55 
56 /**
57  * @brief The weights w_n of the mean over the top @p depth [m] of soil layers with
58  * thicknesses @p thickness [m], top layer first.
59  *
60  * @param[in] thickness layer thicknesses, each finite and > 0
61  * @param[in] depth averaging depth, finite and > 0
62  * @param[out] weights one weight per layer, >= 0, summing to 1; layers below the depth
63  * get 0 (to round-off of the layer bottoms). Left empty when the
64  * function returns false.
65  * @return false when there is no layer, a thickness or the depth is not finite and
66  * positive, or the layers together are shallower than
67  * @p depth (1 - seb_soil_depth_rel_tol): the mean would then need water content the
68  * file does not hold.
69  */
70 [[nodiscard]] bool
71 seb_soil_layer_weights (const amrex::Vector<amrex::Real>& thickness, amrex::Real depth,
72  amrex::Vector<amrex::Real>& weights);
73 
74 /** @brief What seb_init_soil_moisture_from_file did on the boxes of this rank. */
76 {
77  amrex::Long n_set = 0; //!< land columns that took the file's mean
78  amrex::Long n_refused = 0; //!< land columns whose mean is not usable (left as they were)
79  amrex::Real q_min = 0; //!< lowest value set [m^3/m^3]; meaningful when n_set > 0
80  amrex::Real q_max = 0; //!< highest value set [m^3/m^3]; meaningful when n_set > 0
81  //! highest finite refused mean; the lowest Real when no refused mean is finite
82  amrex::Real q_refused_max = 0;
83 };
84 
85 /**
86  * @brief Write sum_n weights[n] file_moisture(n) into the land columns of @p q, valid
87  * columns only.
88  *
89  * A column whose mean is not finite or lies outside [@p q_lo, @p q_hi] by more than the
90  * relative seb_soil_value_rel_tol is refused: it is left as it was and counted. A mean
91  * inside that allowance is stored as the bound.
92  *
93  * @param[in,out] q a water content of the balance on one level (one component)
94  * @param[in] file_moisture the file's soil moisture on the same grids, one component
95  * per layer, top layer first
96  * @param[in] weights one weight per layer (seb_soil_layer_weights)
97  * @param[in] land_mask ERF::lmask_lev of the level (0 is water); nullptr means all land
98  * @param[in] q_lo lowest usable value
99  * @param[in] q_hi highest usable value
100  * @return the counts and range of this rank. The caller sums them over the ranks, stops
101  * when a column was refused, and fills the ghost columns of @p q.
102  */
103 [[nodiscard]] SEBSoilInitReport
104 seb_init_soil_moisture_from_file (amrex::MultiFab& q, const amrex::MultiFab& file_moisture,
105  const amrex::Vector<amrex::Real>& weights,
106  const amrex::iMultiFab* land_mask,
107  amrex::Real q_lo, amrex::Real q_hi);
108 
109 #endif
constexpr amrex::Real seb_soil_depth_rel_tol
Relative shortfall of the file's soil depth that seb_soil_layer_weights accepts: the thicknesses are ...
Definition: ERF_SEBSoilInit.H:40
bool seb_soil_layer_weights(const amrex::Vector< amrex::Real > &thickness, amrex::Real depth, amrex::Vector< amrex::Real > &weights)
The weights w_n of the mean over the top depth [m] of soil layers with thicknesses thickness [m],...
constexpr amrex::Real seb_soil_value_rel_tol
Relative distance outside [q_lo, q_hi] at which seb_init_soil_moisture_from_file still takes a mean,...
Definition: ERF_SEBSoilInit.H:51
SEBSoilInitReport seb_init_soil_moisture_from_file(amrex::MultiFab &q, const amrex::MultiFab &file_moisture, const amrex::Vector< amrex::Real > &weights, const amrex::iMultiFab *land_mask, amrex::Real q_lo, amrex::Real q_hi)
Write sum_n weights[n] file_moisture(n) into the land columns of q, valid columns only.
@ q
Definition: ERF_WSM6.H:296
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
What seb_init_soil_moisture_from_file did on the boxes of this rank.
Definition: ERF_SEBSoilInit.H:76
amrex::Real q_min
lowest value set [m^3/m^3]; meaningful when n_set > 0
Definition: ERF_SEBSoilInit.H:79
amrex::Real q_refused_max
highest finite refused mean; the lowest Real when no refused mean is finite
Definition: ERF_SEBSoilInit.H:82
amrex::Long n_refused
land columns whose mean is not usable (left as they were)
Definition: ERF_SEBSoilInit.H:78
amrex::Long n_set
land columns that took the file's mean
Definition: ERF_SEBSoilInit.H:77
amrex::Real q_max
Definition: ERF_SEBSoilInit.H:80