This class is used to delay a CRHM HRU variable in a user module using a time shift and a storage term. Clark's Method is used and is implemented using the following code.
ClassClark *OurDelays;
OurDelays = new ClassClark(const float* inVar, float* outVar, const float*
kstorage, const float* lag);
where:
inVar[HRU] is the input variable to be processed,
outVar[HRU] is the destination for the delayed output variable,
kstorage[HRU] is the desired storage constant (days) and
lag[HRU] is the desired time shift (hours). The resolution is equal to the observation interval.
To generated the delay after every module HRU so that it can be used for a downstream HRU in the same module use:
OurDelays->DoClark(hru);// note hru in the range (0 to
HRUmax-1).
If delayed and lagged output is not used in the same module then all HRUs can be processed at once using:
OurDelays->DoClark();
The class is destroyed using,
delete OurDelays;
To determine the quantity still in storage before destroying the storage object use:
float residual = OurDelays->Left(hru); // note hru in the
range (0 to HRUmax-1).
Sample Application of ClassClark.
class Classdelay : public ClassModule {
public:
Classdelay(string Name = "Qdelay", String Version =
"undefined") : ClassModule(Name, Version){};
long nhru;
// declared variables
float *Tdelay; // °C
ClassClark *OurDelays;
// declared parameters
const float *Kstorage;
const float *Lag;
// declared observations
const float *t;
// procedures
void decl(void);
void init(void);
void run(void);
void finish(bool good);
};
void Classdelay::decl(void) {
declvar("Tdelay", NHRU, "delayed
temperature", "(°C)", &Tdelay);
declparam("Kstorage", NHRU, "[0]",
"0", "20", "Air Temperature Storage", "()",
&Kstorage);
declparam("Lag", NHRU, "[1]",
"0", "96", "lag delay", "(hour)", &Lag);
declreadobs("t", NOBS, "air temperature",
"(°C)", &t);
}
void Classdelay::init(void) {
nhru = getdim(NHRU);
for(int hh = 0; hh < nhru; hh+) Tdelay[hh] = 0.0; //
initial value
OurDelays = new ClassClark(t, Tdelay, Kstorage, Lag);
}
void Classdelay::run(void) {
OurDelays->DoClark();
}
void Classdelay::finish(bool good) {
delete OurDelays;
}