hydrobricks
Loading...
Searching...
No Matches
GR6JFormulas.h
1#ifndef HYDROBRICKS_GR6J_FORMULAS_H
2#define HYDROBRICKS_GR6J_FORMULAS_H
3
4#include <algorithm>
5#include <cmath>
6
14namespace gr6j {
15
23inline double ExponentialStoreOutflow(double Rexp, double X6) {
24 if (X6 <= 0.0) {
25 // Degenerate store: drain whatever positive content is present.
26 return std::max(0.0, Rexp);
27 }
28
29 // ar is clamped to [-33, 33] to keep exp() in a safe numeric range, then the
30 // outflow is computed with a piecewise form that stays accurate at both ends.
31 double ar = std::max(-33.0, std::min(33.0, Rexp / X6));
32 if (ar > 7.0) {
33 return Rexp + X6 / std::exp(ar);
34 }
35 if (ar < -7.0) {
36 return X6 * std::exp(ar);
37 }
38 return X6 * std::log(std::exp(ar) + 1.0);
39}
40
41} // namespace gr6j
42
43#endif // HYDROBRICKS_GR6J_FORMULAS_H
Definition GR6JFormulas.h:14
double ExponentialStoreOutflow(double Rexp, double X6)
Definition GR6JFormulas.h:23