diff --git a/core/src/solve.jl b/core/src/solve.jl index db3c5c957..90d2cc212 100644 --- a/core/src/solve.jl +++ b/core/src/solve.jl @@ -989,7 +989,10 @@ function formulate_flow!( for (i, id) in enumerate(node_id) downstream_id = only(outneighbors(graph_flow, id)) upstream_id = only(inneighbors(graph_flow, id)) - flow[id, downstream_id] = flow[upstream_id, id] * fraction[i] + # overwrite the inflow such that flow is conserved over the FractionalFlow + outflow = flow[upstream_id, id] * fraction[i] + flow[upstream_id, id] = outflow + flow[id, downstream_id] = outflow end return nothing end diff --git a/core/test/run_models.jl b/core/test/run_models.jl index 69bb3d4ef..893034ae1 100644 --- a/core/test/run_models.jl +++ b/core/test/run_models.jl @@ -55,6 +55,15 @@ end ) # flows are recorded at the end of each period, and are undefined at the start @test unique(table.time) == Ribasim.datetimes(model)[2:end] + + # inflow = outflow over FractionalFlow + t = table.time[1] + @test length(p.fractional_flow.node_id) == 3 + for id in p.fractional_flow.node_id + inflow = only(table.flow[table.to_node_id .== id .&& table.time .== t]) + outflow = only(table.flow[table.from_node_id .== id .&& table.time .== t]) + @test inflow == outflow + end end @testset "basic transient model" begin diff --git a/docs/core/usage.qmd b/docs/core/usage.qmd index a0a5e18bb..b20f4987d 100644 --- a/docs/core/usage.qmd +++ b/docs/core/usage.qmd @@ -506,7 +506,7 @@ node_id | Int | - | sorted active | Bool | - | (optional, default true) length | Float64 | $m$ | positive manning_n | Float64 | $s m^{-\frac{1}{3}}$ | positive -profile_with | Float64 | $m$ | positive +profile_width | Float64 | $m$ | positive profile_slope | Float64 | - | - control_state | String | - | (optional)