-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathhbv_model.h
executable file
·178 lines (145 loc) · 4.66 KB
/
hbv_model.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
Copyright (C) 2010-2015 Matteo Giuliani, Josh Kollat, Jon Herman, and others.
HBV is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
HBV is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with HBV. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __hbv_h
#define __hbv_h
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <cstdlib>
namespace std{
#define ROUNDINT(x) int(x + 0.5)
#define ROUNDDOUBLE(x) double(int(x + 0.5))
struct hbv_parameters
{
// User-specified parameters
double hl1; // L - the storage capacity of the middle/shallow layer [mm]
double ck0; // K0 - overflow from shallow layer
double ck1;
double ck2;
double perc; // [L/T] rate of perc from upper to lower box
double lp; // evap something or other (unitless)
double fcap; // surface soil storage [mm]
double beta; // surface storage exponent
int maxbas; // routing coeff [d]
double ttlim; // (TTH, degC)
double degd; // (DDF - mm/(degC-D))
double degw; // (TB, degC)
};
struct hbv_states
{
double *sowat; //[20][200]; //Soil water storate
double *sdep; //[20][200]; //Snow store
double *ldep; //Depth of liquid in snow store
double *stw1; //[20]; soil storage - shallow layer
double *stw2; //[20]; soil storage - deep layer
};
struct hbv_fluxes
{
double *Qrouting; // Maxbas - routing Q's
double *Qsim; // array of outflow Q's for simulation
double *actualET;
};
struct HamonEvap
{
int day;
double P;
double dayLength;
double eStar;
double *PE;
};
struct MyData
{
string ID; // watershed name
double gageLat; // latitude (decimal degrees)
double gageLong; // longitude (decimal degrees)
double DA; // drainage area
int nDays; // Number of days of data
int tempData; // Type of temperature data (1=daily average, 2=min and max)
//Starting and ending dates of data to read
int *dateStart;
int *dateEnd;
int **date; //Date of data [year, month, day]
double *precip; //Mean areal precipitation (mm)
double *evap; //Climatic potential evaporation (mm)
double *flow; //Streamflow discharge (mm)
double *maxTemp; //Maximum air temperature (Celsius) (should be daily)
double *minTemp; //Minimum air temperature (Celsius) (should be daily)
double *avgTemp; //Average air temperature (Celsius) (should be daily)
//double *peAdjust; //PE adjustment factors for each month
};
class hbv_model {
public:
/**
* default constructor/destructor
*/
hbv_model();
virtual ~hbv_model();
/**
* hbv_model constructor with parameters (namefile with the data)
*/
hbv_model(string dataFile);
/**
* clear hbv_model structures
*/
void hbv_delete(int nDays);
/**
* evaluation of HBV model with parameters passed as input
*/
void calc_HBV(double *parameters);
/**
* get-functions for protected data
**/
MyData getData();
hbv_fluxes getFluxes();
protected:
/**
* Initialization of HBV model:
* - allocation structures
* - loading of data
* - computation of PE
* - setting of HBV parameters
* - re-initialization to zero
*/
void hbv_allocate(int nDays);
void readData(string filename);
void calculateHamonPE(int dataIndex, int nDays, int startDay);
void setParameters(double* parameters);
void reinitStateFluxes();
/**
* rainfall-runoff processes
*/
// Effective precipitation
double snow(int modelDay);
// Soil moisture
void soil(double eff_precip, int modelDay);
// Basin discharge
double discharge(int modelDay);
// Discharge routing
void routing(double Qall, int modelDay);
// Routing update/reinitialization
void backflow();
void reinitForMaxBas();
int dayStartIndex;
int startingIndex;
double tst; // time-step
MyData data;
HamonEvap evap;
hbv_parameters params;
hbv_states states;
hbv_fluxes fluxes;
};
}
#endif