Skip to content
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

FlowBoundary is flow direction constraining #1424

Merged
merged 4 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/allocation_init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function find_subnetwork_connections!(p::Parameters)::Nothing
# destination node subnetwork id ≠1
for node_id in graph[].node_ids[1]
for outflow_id in outflow_ids(graph, node_id)
if graph[outflow_id].subnetwork_id != 1
if (graph[outflow_id].subnetwork_id != 1)
main_network_source_edges =
get_main_network_connections(p, graph[outflow_id].subnetwork_id)
edge = (node_id, outflow_id)
Expand Down
4 changes: 3 additions & 1 deletion core/src/allocation_optim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,9 @@ function save_allocation_flows!(
end

# Check whether the next edge is the current one reversed
if edge_2 == reverse(edge_1)
# and the edge does not have a UserDemand end
if edge_2 == reverse(edge_1) &&
!(edge_1[1].type == NodeType.UserDemand || edge_1[2].type == NodeType.UserDemand)
# If so, these edges are both processed in this iteration
flow_rate += sign_2 * JuMP.value(F[edge_2])
skip = true
Expand Down
11 changes: 9 additions & 2 deletions core/src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,15 @@ is_flow_constraining(node::AbstractParameterNode) = hasfield(typeof(node), :max_

"""Whether the given node is flow direction constraining (only in direction of edges)."""
is_flow_direction_constraining(node::AbstractParameterNode) = (
node isa
Union{Pump, Outlet, TabulatedRatingCurve, FractionalFlow, Terminal, UserDemand}
node isa Union{
Pump,
Outlet,
TabulatedRatingCurve,
FractionalFlow,
Terminal,
UserDemand,
FlowBoundary,
}
)

function has_main_network(allocation::Allocation)::Bool
Expand Down
2 changes: 1 addition & 1 deletion core/test/allocation_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ end
# lower the subnetwork demands
@test subnetwork_demands[(NodeID(:Basin, 2), NodeID(:Pump, 11))] ≈ [3.1, 4.0, 0.0]
@test subnetwork_demands[(NodeID(:Basin, 6), NodeID(:Pump, 24))] ≈ [0.004, 0.0, 0.0]
@test subnetwork_demands[(NodeID(:Basin, 10), NodeID(:Pump, 38))][1:2] ≈ [0.001, 0.002]
@test subnetwork_demands[(NodeID(:Basin, 10), NodeID(:Pump, 38))][1:2] ≈ [0.001, 0.001]
end

@testitem "Allocation level control" begin
Expand Down
Loading