From 026492030f422435905c45862e0f77137ed7051d Mon Sep 17 00:00:00 2001 From: Bart de Koning Date: Tue, 23 Apr 2024 14:15:33 +0200 Subject: [PATCH] FlowBoundary is flow direction constraining (cherry picked from commit e84ae3a180136a394965a2de87ab9728883f868f) --- core/src/allocation_init.jl | 3 ++- core/src/allocation_optim.jl | 4 +++- core/src/util.jl | 11 +++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/src/allocation_init.jl b/core/src/allocation_init.jl index aea5afe44..2d406b439 100644 --- a/core/src/allocation_init.jl +++ b/core/src/allocation_init.jl @@ -7,7 +7,8 @@ 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) || + (graph[node_id, outflow_id].subnetwork_id_source == 1) main_network_source_edges = get_main_network_connections(p, graph[outflow_id].subnetwork_id) edge = (node_id, outflow_id) diff --git a/core/src/allocation_optim.jl b/core/src/allocation_optim.jl index 75dc66c12..d3c94f262 100644 --- a/core/src/allocation_optim.jl +++ b/core/src/allocation_optim.jl @@ -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 diff --git a/core/src/util.jl b/core/src/util.jl index ee7191142..a52bdb277 100644 --- a/core/src/util.jl +++ b/core/src/util.jl @@ -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