-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Terminals sometimes "leak" water #1851
Comments
To reproduce, insert the following snippet into for (inflow_edge, outflow_edge) in zip(state_inflow_edge, state_outflow_edge)
from_flow = inflow_edge.edge[1]
to_flow = outflow_edge.edge[2]
if from_flow.type == NodeType.Basin
flow = flow_update_on_edge(integrator, inflow_edge.edge) |
I cannot get your snippet to work. Can you maybe make such a snippet a PR on main that would fail the HWS integration test by checking for negative flows? I tried reproducing by running the HWS model with starttime = 2023-01-20 00:00:00
endtime = 2023-05-30 00:00:00
crs = "EPSG:28992"
input_dir = "."
results_dir = "results"
ribasim_version = "2024.10.0"
[solver]
autodiff = false
saveat=0
water_balance_abstol = 1e30 # optional, default 1e-3
water_balance_reltol = 1e20 # optional, default 1e-2 But I don't find any leaky Terminal nodes: import ribasim
model = ribasim.Model.read(r"d:\repo\ribasim\Ribasim\models\hws\minio\hws.toml")
terminals = model.node_table().df[model.node_table().df.node_type == "Terminal"].index.to_numpy()
flow = pd.read_feather(
r"d:\repo\ribasim\Ribasim\models\hws\minio\results\flow.arrow",
dtype_backend="pyarrow",
)
flow = flow[flow.to_node_id.isin(terminals)]
flow.flow_rate.min() # 0.0
flow.flow_rate.max() # 31.31 |
What about this on main? I'm on HWS version 2024_7_0. diff --git core/src/callback.jl core/src/callback.jl
index 8990d86f..c3bf1d2c 100644
--- core/src/callback.jl
+++ core/src/callback.jl
@@ -92,7 +92,14 @@ Update with the latest timestep:
"""
function update_cumulative_flows!(u, t, integrator)::Nothing
(; p, uprev, tprev, dt) = integrator
- (; basin, user_demand, flow_boundary, allocation) = p
+ (;
+ basin,
+ user_demand,
+ flow_boundary,
+ allocation,
+ state_inflow_edge,
+ state_outflow_edge,
+ ) = p
(; vertical_flux_bmi, vertical_flux_from_input) = basin
# Update tprev
@@ -150,6 +157,25 @@ function update_cumulative_flows!(u, t, integrator)::Nothing
end
end
end
+
+ for (inflow_edge, outflow_edge) in zip(state_inflow_edge, state_outflow_edge)
+ from_flow = inflow_edge.edge[1]
+ to_flow = outflow_edge.edge[2]
+ if from_flow.type == NodeType.Basin
+ flow = flow_update_on_edge(integrator, inflow_edge.edge)
+ if to_flow.type == NodeType.Terminal && flow < 0 && to_flow.value != 0
+ @warn "Unsupported inflow type $(to_flow.type) #$(to_flow.value) with flow $flow"
+ end
+ end
+
+ if to_flow.type == NodeType.Basin
+ flow = flow_update_on_edge(integrator, outflow_edge.edge)
+ if from_flow.type == NodeType.Terminal && flow > 0 && from_flow.value != 0
+ @warn "Unsupported outflow type $(from_flow.type) #$(from_flow.value) with flow $flow"
+ end
+ end
+ end
+
return nothing
end |
Just a thought, it could be my mac here, producing slightly different stuff than linux/windows. Then again seeing |
Earlier I couldn't reproduce just because I didn't run quite long enough to hit the error. |
I hit this during the implementation of #1849, where edges to Terminals have negative flows when checked in
update_cumulative_flows!
using the flow fromflow_update_on_edge
. For example in the HWS model I get the following:This is the Terminal at Herentals in the HWS model with an Outlet(!) before it (the only Terminal one to show such behaviour). I can imagine this happens during smaller timesteps to balance the problem, and you'll never see this on the larger saveat timesteps. Given the rather large flows/timesteps in the above, this should be investigated (could also be a bug in the code to check such flows).
The text was updated successfully, but these errors were encountered: