clsSubbasin.h
Go to the documentation of this file.
1/*!
2 * \file clsSubbasin.h
3 * \brief Class for managing subbasin data
4 * \author Junzhi Liu, Liang-Jun Zhu
5 * \date Aug., 2022
6 */
7#ifndef SEIMS_SUBBASIN_CLS_H
8#define SEIMS_SUBBASIN_CLS_H
9
10#include "basic.h"
11#include "db_mongoc.h"
12#include "data_raster.hpp"
13
14#include "seims.h"
15
16using namespace ccgl;
17
18/*!
19 * \class Subbasin
20 * \ingroup data
21 * \brief Subbasin related parameters and methods.
22 *
23 * Changelog:
24 * - 1. Remove isOutput, since the output is handled in printInfo class
25 * - 2. Add soil water balance related. 2016-7-28
26 */
28public:
29 /*!
30 * \brief Constructor
31 * \param [in] id Subbasin ID
32 */
33 explicit Subbasin(int id);
34
35 //! Destructor
37
38 //! Check input size
39 bool CheckInputSize(int n);
40
41 // Set functions
42
43 //! Set cell index list, as well as subbasin area
44 void SetCellList(int n_cells, int* cells);
45
46 //! area of subbasin
47 void SetArea(const FLTPT area) { area_ = area; }
48
49 //! average slope (%)
50 void SetSlope(const FLTPT slp) { slope_ = slp; }
51
52 //! Set slope of current subbasin as the average of all cells
53 void SetSlope(FLTPT* slope);
54
55 //! Set slope correction factor of current subbasin
56 void SetSlopeCoefofBasin(const FLTPT slope_basin) { slope_coef_ = slope_basin; }
57
58 //! pet
59 void SetPet(const FLTPT pet) { pet_ = pet; }
60
61 //! Set average percolation (mm)
62 void SetPerco(const FLTPT perco) { perco_ = perco; }
63
64 //! Set average deep percolation (mm)
65 void SetPerde(const FLTPT perde) { deep_perco_ = perde; }
66
67 //! groundwater revaporization
68 void SetEg(const FLTPT eg) { revap_ = eg; }
69
70 //! Set groundwater storage
71 void SetGw(const FLTPT gw) { gw_ = gw; }
72
73 //! Set groundwater discharge
74 void SetQg(const FLTPT qg) { qg_ = qg; }
75
76 //! Set groundwater runoff
77 void SetRg(const FLTPT rg) { rg_ = rg; }
78
79 //! Is revap changed
80 void SetIsRevapChanged(const bool isrevap) { revap_changed_ = isrevap; }
81
82 // Get functions
83
84 //! Get subbasin ID
85 int GetId() { return subbsn_id_; }
86
87 //! Get valid cells number
88 int GetCellCount() { return n_cells_; }
89
90 //! Get index of valid cells
91 int* GetCells() { return cells_; }
92
93 //! Get the output flag (true mean output), the function will be deprecated. By LJ
94 bool GetIsOutput() { return output_; }
95
96 //! area of subbasin
97 FLTPT GetArea() { return area_; }
98
99 //! Get the Revap change flat (true mean changed from last time step)
100 bool GetIsRevapChanged() { return revap_changed_; }
101
102 //! Get average PET
103 FLTPT GetPet() { return pet_; }
104
105 //! Get average percolation (mm)
106 FLTPT GetPerco() { return perco_; }
107
108 //! Get average deep percolation (mm)
109 FLTPT GetPerde() { return deep_perco_; }
110
111 //! Get average slope (%)
112 FLTPT GetSlope() { return slope_; }
113
114 //! Get slope coefficient of basin
115 FLTPT GetSlopeCoef() { return slope_coef_; }
116
117 //! groundwater revaporization
118 FLTPT GetEg() { return revap_; }
119
120 //! Get groundwater storage
121 FLTPT GetGw() { return gw_; }
122
123 //! Get groundwater discharge
124 FLTPT GetQg() { return qg_; }
125
126 //! Get groundwater runoff
127 FLTPT GetRg() { return rg_; }
128private:
129 //! Subbasin ID
130 int subbsn_id_;
131 //! valid cells number
132 int n_cells_;
133 //! index of valid cells
134 int* cells_;
135 FLTPT cell_area_; ///< area of the cell(s)
136 ///< todo This should be float* when irregular polygon is supported. By lj.
137 //! area of current Subbasin
138 FLTPT area_;
139
140 //! PET
141 FLTPT pet_;
142 //! average percolation (mm) of each valid cells
143 FLTPT perco_;
144
145 // Subbasin scale parameters' mean value
146
147 // 1. Soil water balance related parameters
148
149 //! precipitation
150 FLTPT pcp_;
151 //! interception loss
152 FLTPT intercep_;
153 //! ET from interception storage
154 FLTPT intercep_et_;
155 //! depression evaporation
156 FLTPT depression_et_;
157 //! infiltration loss
158 FLTPT infil_;
159 //! soil et
160 FLTPT soil_et_;
161 //! total ET
162 FLTPT total_et_;
163 //! net percolation
164 FLTPT net_perco_;
165 //! surface runoff generated (mm)
166 FLTPT runoff_;
167 //! subsurface (interflow) runoff
168 FLTPT interflow_;
169 //! soil moisture (mm)
170 FLTPT soil_wtr_;
171 //! net precipitation
172 FLTPT net_pcp_;
173 //! mean temperature
174 FLTPT mean_tmp_;
175 //! soil temperature
176 FLTPT soil_tmp_;
177 // 2. Groundwater related parameters
178
179 //! maximum groundwater storage
180 FLTPT gwmax_;
181 //! baseflow recession coefficient
182 FLTPT kg_;
183 //! groundwater revaporization coefficient
184 FLTPT revap_coef_;
185 //! baseflow recession exponent
186 FLTPT base_ex_;
187 //! convert coefficient from mm to m3/s
188 FLTPT qg_cvt_;
189 //! slope correction factor of current subbasin
190 FLTPT slope_coef_;
191 //! average slope of the subbasin
192 FLTPT slope_;
193 //! revaporization from groundwater
194 FLTPT revap_;
195 //! initial groundwater or time (t-1)
196 FLTPT gw_;
197 //! deep percolation
198 FLTPT deep_perco_;
199 //! groundwater discharge (m3/s)
200 FLTPT qg_;
201 //! groundwater runoff (mm)
202 FLTPT rg_;
203 //! Is output defined by file.out or not
204 bool output_;
205 //! Is the revap (m_EG) is different from last time step
206 bool revap_changed_;
207};
208
209/*!
210 * \class clsSubbasins
211 * \ingroup data
212 * \brief Manager all Subbasin related parameters and methods.
213 */
215public:
216 /*!
217 * \brief Constructor
218 *
219 * Query and constructor basic subbasin's information from MongoDB
220 *
221 * \param[in] rs_map Map of rasters that have been loaded
222 * \param[in] rs_int_map Map of integer rasters that have been loaded
223 * \param[in] prefix_id subbasin ID as prefix in MongoDB
224 */
225 clsSubbasins(map<string, IntRaster*>& rs_int_map,
226 map<string, FloatRaster *>& rs_map, int prefix_id);
227 /*!
228 * \brief Check input parameters to ensure the successful constructor
229 */
230 static clsSubbasins* Init(map<string, IntRaster*>& rs_int_map,
231 map<string, FloatRaster *>& rs_map, int prefix_id);
232 /// Destructor
234
235 /// Get single reach information by subbasin ID
236 Subbasin* GetSubbasinByID(const int id) { return subbasin_objs_.at(id); }
237
238 /// Get subbasin number
239 int GetSubbasinNumber() { return n_subbasins_; }
240
241 /// Get subbasin IDs
242 vector<int>& GetSubbasinIDs() { return subbasin_ids_; }
243
244 /// Get map of subbasin objects
245 map<int, Subbasin *>& GetSubbasinObjects() { return subbasin_objs_; }
246
247 /*!
248 * \brief Set slope coefficient for each subbasin according to the basin slope
249 * \todo This function will set slope_coef_ to 1.f in MPI version.
250 * Currently, the real slope_coef_ is calculated in `seims_mpi/CalculateProcess.cpp/line 77~`.
251 * In the future, we should think of an elegant way to deal with this issue. By lj. 06/28/18
252 */
253 void SetSlopeCoefficient(FLTPT* rs_slope);
254
255 /*!
256 * \brief Get basin (watershed) scale variable (key) value
257 * \param [in] key Variable name which is defined in text.h
258 */
259 FLTPT Subbasin2Basin(const string& key);
260
261private:
262 /// Subbasins number
263 int n_subbasins_;
264 /// Subbasin IDs
265 vector<int> subbasin_ids_;
266 /*!
267 * Map container to store all Subbasins information
268 * key: Subbasin ID
269 * value: Subbasin instance (pointer)
270 */
271 map<int, Subbasin *> subbasin_objs_;
272};
273#endif /* SEIMS_SUBBASIN_CLS_H */
Basic definitions.
Base type of all interfaces.
Definition: basic.h:407
Simple wrappers of the API of MongoDB C driver mongo-c-driver, see MongoDB C Driver for more informat...
map< int, Subbasin * > & GetSubbasinObjects()
Get map of subbasin objects.
Definition: clsSubbasin.h:245
Subbasin(int id)
Constructor.
FLTPT GetPerde()
Get average deep percolation (mm)
Definition: clsSubbasin.h:109
void SetCellList(int n_cells, int *cells)
Set cell index list, as well as subbasin area.
~clsSubbasins()
Destructor.
FLTPT GetPet()
Get average PET.
Definition: clsSubbasin.h:103
clsSubbasins(map< string, IntRaster * > &rs_int_map, map< string, FloatRaster * > &rs_map, int prefix_id)
Constructor.
bool GetIsOutput()
Get the output flag (true mean output), the function will be deprecated. By LJ.
Definition: clsSubbasin.h:94
void SetSlopeCoefofBasin(const FLTPT slope_basin)
Set slope correction factor of current subbasin.
Definition: clsSubbasin.h:56
int * GetCells()
Get index of valid cells.
Definition: clsSubbasin.h:91
FLTPT GetArea()
area of subbasin
Definition: clsSubbasin.h:97
FLTPT GetSlopeCoef()
Get slope coefficient of basin.
Definition: clsSubbasin.h:115
FLTPT Subbasin2Basin(const string &key)
Get basin (watershed) scale variable (key) value.
int GetId()
Get subbasin ID.
Definition: clsSubbasin.h:85
void SetQg(const FLTPT qg)
Set groundwater discharge.
Definition: clsSubbasin.h:74
Subbasin * GetSubbasinByID(const int id)
Get single reach information by subbasin ID.
Definition: clsSubbasin.h:236
FLTPT GetSlope()
Get average slope (%)
Definition: clsSubbasin.h:112
~Subbasin()
Destructor.
void SetEg(const FLTPT eg)
groundwater revaporization
Definition: clsSubbasin.h:68
void SetPerde(const FLTPT perde)
Set average deep percolation (mm)
Definition: clsSubbasin.h:65
void SetSlope(FLTPT *slope)
Set slope of current subbasin as the average of all cells.
int GetSubbasinNumber()
Get subbasin number.
Definition: clsSubbasin.h:239
void SetRg(const FLTPT rg)
Set groundwater runoff.
Definition: clsSubbasin.h:77
FLTPT GetPerco()
Get average percolation (mm)
Definition: clsSubbasin.h:106
void SetSlope(const FLTPT slp)
average slope (%)
Definition: clsSubbasin.h:50
FLTPT GetGw()
Get groundwater storage.
Definition: clsSubbasin.h:121
void SetPet(const FLTPT pet)
pet
Definition: clsSubbasin.h:59
int GetCellCount()
Get valid cells number.
Definition: clsSubbasin.h:88
FLTPT GetEg()
groundwater revaporization
Definition: clsSubbasin.h:118
FLTPT GetQg()
Get groundwater discharge.
Definition: clsSubbasin.h:124
vector< int > & GetSubbasinIDs()
Get subbasin IDs.
Definition: clsSubbasin.h:242
void SetGw(const FLTPT gw)
Set groundwater storage.
Definition: clsSubbasin.h:71
void SetPerco(const FLTPT perco)
Set average percolation (mm)
Definition: clsSubbasin.h:62
bool CheckInputSize(int n)
Check input size.
void SetIsRevapChanged(const bool isrevap)
Is revap changed.
Definition: clsSubbasin.h:80
void SetSlopeCoefficient(FLTPT *rs_slope)
Set slope coefficient for each subbasin according to the basin slope.
FLTPT GetRg()
Get groundwater runoff.
Definition: clsSubbasin.h:127
static clsSubbasins * Init(map< string, IntRaster * > &rs_int_map, map< string, FloatRaster * > &rs_map, int prefix_id)
Check input parameters to ensure the successful constructor.
bool GetIsRevapChanged()
Get the Revap change flat (true mean changed from last time step)
Definition: clsSubbasin.h:100
void SetArea(const FLTPT area)
area of subbasin
Definition: clsSubbasin.h:47
Subbasin related parameters and methods.
Definition: clsSubbasin.h:27
Manager all Subbasin related parameters and methods.
Definition: clsSubbasin.h:214
Common Cross-platform Geographic Library (CCGL)
The SEIMS related definitions and utilities header.