From c3140bb0062f7905edfd14f7e9f79be6cbe3eccf Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Mon, 11 Sep 2023 21:27:36 +0200 Subject: [PATCH] add reduction_factor to TabulatedRatingCurve If the rating curve prescribes large Q even when the upstream Basin is nearly empty, this leads to an incorrect water balance. --- core/src/solve.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/solve.jl b/core/src/solve.jl index 52f57ffee..febdaf195 100644 --- a/core/src/solve.jl +++ b/core/src/solve.jl @@ -748,7 +748,13 @@ function formulate_flow!( downstream_ids = outneighbors(graph_flow, id) if active[i] - q = tables[i](get_level(p, upstream_basin_id, current_level, t)) + hasindex, basin_idx = id_index(basin.node_id, upstream_basin_id) + @assert hasindex "TabulatedRatingCurve must be downstream of a Basin" + s = storage[basin_idx] + reduction_factor = clamp(s, 0.0, 10.0) / 10.0 + q = + reduction_factor * + tables[i](get_level(p, upstream_basin_id, current_level, t)) else q = 0.0 end