hydrobricks
Loading...
Searching...
No Matches
FormulasGR4J.h
1#ifndef HYDROBRICKS_GR4J_FORMULAS_H
2#define HYDROBRICKS_GR4J_FORMULAS_H
3
4#include <algorithm>
5#include <cmath>
6
15namespace gr4j {
16
17// 13 is the value at which tanh(WS) is numerically indistinguishable from 1.
18constexpr double kTanhCap = 13.0;
19// (9/4)^4 = 25.62890625, the percolation denominator constant.
20constexpr double kPercDenom = 25.62890625;
21
26inline double Infiltration(double S, double Pn, double X1) {
27 if (Pn <= 0.0 || X1 <= 0.0) {
28 return 0.0;
29 }
30 double Sr = S / X1;
31 double tws = std::tanh(std::min(Pn / X1, kTanhCap));
32 return X1 * (1.0 - Sr * Sr) * tws / (1.0 + Sr * tws);
33}
34
39inline double Evaporation(double S, double En, double X1) {
40 if (En <= 0.0 || X1 <= 0.0) {
41 return 0.0;
42 }
43 double Sr = S / X1;
44 double tws = std::tanh(std::min(En / X1, kTanhCap));
45 return S * (2.0 - Sr) * tws / (1.0 + (1.0 - Sr) * tws);
46}
47
51inline double Percolation(double S, double X1) {
52 if (X1 <= 0.0) {
53 return 0.0;
54 }
55 double ratio = S / X1;
56 return S * (1.0 - std::pow(1.0 + (ratio * ratio * ratio * ratio) / kPercDenom, -0.25));
57}
58
59} // namespace gr4j
60
61#endif // HYDROBRICKS_GR4J_FORMULAS_H
Definition FormulasGR4J.h:15
double Infiltration(double S, double Pn, double X1)
Definition FormulasGR4J.h:26
double Percolation(double S, double X1)
Definition FormulasGR4J.h:51
double Evaporation(double S, double En, double X1)
Definition FormulasGR4J.h:39