Skip to content

Commit

Permalink
set FractionalFlow inflow equal to outflow (#736)
Browse files Browse the repository at this point in the history
Fixes #733
  • Loading branch information
visr authored Nov 6, 2023
1 parent 6bd31ba commit d2483a3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion core/src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions core/test/run_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/core/usage.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d2483a3

Please sign in to comment.