clsReach.h
Go to the documentation of this file.
1/*!
2 * \file clsReach.h
3 * \brief Class to store reach related parameters from REACHES table
4 *
5 * Changelog:
6 * - 1. 2017-05-30 - lj - Update MongoDB functions.
7 * Get 1D arrays of reach properties to keep synchronization among modules.
8 * - 2. 2017-12-26 - lj - Code refactor.
9 * - 3. 2021-04-20 - lj - Add coordinates x and y of reach vertexes for some channel routing module.
10 *
11 * \author Liang-Jun Zhu
12 * \version 1.3
13 */
14#ifndef SEIMS_REACH_CLS_H
15#define SEIMS_REACH_CLS_H
16
17#include <map>
18
19#include "basic.h"
20#include "db_mongoc.h"
21
22#include "seims.h"
23#include "ParamInfo.h"
24
25using namespace ccgl;
26using namespace db_mongoc;
27using std::map;
28
29/*!
30 * \ingroup data
31 * \class clsReach
32 * \brief Class to store reach related parameters from REACHES table
33 */
35public:
36 //! Constructor
37 explicit clsReach(const bson_t*& bson_table);
38
39 //! Destructor
41
42 //! Get parameters by name
43 FLTPT Get(const string& key);
44
45 //! Get group index
46 int GetGroupIndex(const string& method, int size);
47
48 //! Set parameters by name
49 void Set(const string& key, FLTPT value);
50
51 //! Set positions according to MASK data
52 void SetPositions(IntRaster* mask_raster);
53
54 /*!
55 * \brief Calculate derived parameters after updating the input parameters.
56 */
58
59private:
60 int cells_num_; ///< cells (units) number of current reach
61 vector<FLTPT> coor_x_; ///< X coordinates (not cols!)
62 vector<FLTPT> coor_y_; ///< Y coordinates (not rows!)
63 int* positions_; ///< positions (indexes of valid cells/units) of current reach
64 /*!
65 * Map container to store parameters
66 * key: parameter name
67 * value: parameter value
68 */
69 map<string, FLTPT> param_map_;
70 /*!
71 * Group numbers, e.g., [1, 2, 3, 8, 16]
72 */
73 vector<int> group_number_;
74 /*!
75 * Group index if each group number and group method, e.g.,
76 * {'KMETIS': {1: 0, 2: 1, 3: 1, 8: 2, 16: 15}, 'PMETIS': {...}}
77 */
78 map<string, map<int, int> > group_index_;
79};
80
81/*!
82 * \class clsReaches
83 * \ingroup data
84 *
85 * \brief Read and store all reaches information as input parameters
86 *
87 */
89public:
90 /*!
91 * \brief Constructor, query reach table from MongoDB
92 * \param[in] conn MongoClient instance
93 * \param[in] db_name Database name
94 * \param[in] collection_name Reach collection name
95 * \param[in] mtd layering method, the default is UP_DOWN, \sa LayeringMethod
96 */
97 clsReaches(MongoClient* conn, const string& db_name, const string& collection_name, LayeringMethod mtd = UP_DOWN);
98
99 /// Destructor
101
102 /// Get single reach information by subbasin ID (1 ~ N)
104
105 /// Get reach number
106 int GetReachNumber() const { return reach_num_; }
107
108 /*!
109 * \brief Get 1D array of reach property
110 * \param[in] key Parameter name
111 * \param[out] data 1D array with length of N+1, the first element is Reach number.
112 */
113 void GetReachesSingleProperty(const string& key, FLTPT** data);
114
115 /// Get upstream IDs
116 vector<vector<int> >& GetUpStreamIDs() { return reach_up_streams_; }
117
118 /// Get downstream ID
119 map<int, int>& GetDownStreamID() { return reach_down_stream_; }
120
121 /// Get map of reach layers
122 map<int, vector<int> >& GetReachLayers() { return reach_layers_; }
123
124 /*!
125 * \brief Update reach/channel parameters according to calibration settings
126 */
127 void Update(map<string, ParamInfo<FLTPT> *>& caliparams_map, IntRaster* mask_raster);
128
129private:
130 /// reaches number
131 int reach_num_;
132 /*!
133 * Upstream Ids (The value is -1 if there if no upstream reach)
134 * reach_up_streams_.size() = N+1
135 * reach_up_streams_[1] = [2, 3] means Reach 2 and Reach 3 flow into Reach 1.
136 */
137 vector<vector<int> > reach_up_streams_;
138 /*!
139 * Downstream ID, -1 indicates no downstream, i.e., the outlet reach
140 */
141 map<int, int> reach_down_stream_;
142 /*!
143 * Reach layers according to \a LayeringMethod
144 */
145 map<int, vector<int> > reach_layers_;
146 /*!
147 * Map container to store all reaches information
148 * key: reach ID, 1 ~ N
149 * value: clsReach instance (pointer)
150 */
151 map<int, clsReach *> reaches_obj_;
152
153 /*! Map of all reaches properties arranged as 1D array
154 * the first value is reach number
155 */
156 map<string, FLTPT*> reaches_properties_;
157};
158#endif /* SEIMS_REACH_CLS_H */
Class to store parameter item information.
Basic definitions.
Base type of all interfaces.
Definition: basic.h:407
A simple wrapper of the class of MongoDB Client mongoc_client_t.
Definition: db_mongoc.h:46
Simple wrappers of the API of MongoDB C driver mongo-c-driver, see MongoDB C Driver for more informat...
void Update(map< string, ParamInfo< FLTPT > * > &caliparams_map, IntRaster *mask_raster)
Update reach/channel parameters according to calibration settings.
void Set(const string &key, FLTPT value)
Set parameters by name.
int GetGroupIndex(const string &method, int size)
Get group index.
map< int, vector< int > > & GetReachLayers()
Get map of reach layers.
Definition: clsReach.h:122
void DerivedParameters()
Calculate derived parameters after updating the input parameters.
map< int, int > & GetDownStreamID()
Get downstream ID.
Definition: clsReach.h:119
clsReach(const bson_t *&bson_table)
Constructor.
FLTPT Get(const string &key)
Get parameters by name.
clsReaches(MongoClient *conn, const string &db_name, const string &collection_name, LayeringMethod mtd=UP_DOWN)
Constructor, query reach table from MongoDB.
~clsReach()
Destructor.
~clsReaches()
Destructor.
void SetPositions(IntRaster *mask_raster)
Set positions according to MASK data.
void GetReachesSingleProperty(const string &key, FLTPT **data)
Get 1D array of reach property.
int GetReachNumber() const
Get reach number.
Definition: clsReach.h:106
vector< vector< int > > & GetUpStreamIDs()
Get upstream IDs.
Definition: clsReach.h:116
clsReach * GetReachByID(int id)
Get single reach information by subbasin ID (1 ~ N)
Class to store and manage parameter information from the parameter database.
Definition: ParamInfo.h:37
Class to store reach related parameters from REACHES table.
Definition: clsReach.h:34
Read and store all reaches information as input parameters.
Definition: clsReach.h:88
LayeringMethod
Grid layering method for routing and parallel computing.
Definition: seims.h:25
Common Cross-platform Geographic Library (CCGL)
The SEIMS related definitions and utilities header.
#define IntRaster
Integer-typed raster.
Definition: seims.h:126
@ UP_DOWN
layering-from-source method, default
Definition: seims.h:26