diff --git a/core/src/validation.jl b/core/src/validation.jl index 66427e6bb..d8372e668 100644 --- a/core/src/validation.jl +++ b/core/src/validation.jl @@ -243,27 +243,23 @@ function valid_pid_connectivity( )::Bool errors = false - for (id, listen_id) in zip(pid_control_node_id, pid_control_listen_node_id) + for (pid_control_id, listen_id) in zip(pid_control_node_id, pid_control_listen_node_id) has_index, _ = id_index(basin_node_id, listen_id) if !has_index - @error "Listen node $listen_id of $id is not a Basin" + @error "Listen node $listen_id of $pid_control_id is not a Basin" errors = true end - controlled_id = only(outneighbor_labels_type(graph, id, EdgeType.control)) + controlled_id = + only(outneighbor_labels_type(graph, pid_control_id, EdgeType.control)) + @assert controlled_id.type in [NodeType.Pump, NodeType.Outlet] - if controlled_id in pump_node_id - pump_intake_id = inflow_id(graph, controlled_id) - if pump_intake_id != listen_id - @error "Listen node $listen_id of $id is not upstream of controlled $controlled_id" - errors = true - end - else - outlet_outflow_id = outflow_id(graph, controlled_id) - if outlet_outflow_id != listen_id - @error "Listen node $listen_id of PidControl node $id is not downstream of controlled outlet $controlled_id" - errors = true - end + id_inflow = inflow_id(graph, controlled_id) + id_outflow = outflow_id(graph, controlled_id) + + if listen_id ∉ [id_inflow, id_outflow] + errors = true + @error "PID listened $listen_id is not on either side of controlled $controlled_id." end end diff --git a/core/test/validation_test.jl b/core/test/validation_test.jl index f7231af8a..c8f175741 100644 --- a/core/test/validation_test.jl +++ b/core/test/validation_test.jl @@ -181,6 +181,8 @@ end set_edge_metadata!(NodeID(:Terminal, 3), NodeID(:Pump, 4), EdgeType.flow) set_edge_metadata!(NodeID(:Basin, 7), NodeID(:Pump, 2), EdgeType.flow) + set_edge_metadata!(NodeID(:Pump, 2), NodeID(:Basin, 7), EdgeType.flow) + set_edge_metadata!(NodeID(:Pump, 4), NodeID(:Basin, 7), EdgeType.flow) set_edge_metadata!(NodeID(:PidControl, 1), NodeID(:Pump, 4), EdgeType.control) set_edge_metadata!(NodeID(:PidControl, 6), NodeID(:Pump, 2), EdgeType.control) @@ -204,7 +206,7 @@ end "Listen node Terminal #3 of PidControl #1 is not a Basin" @test logger.logs[2].level == Error @test logger.logs[2].message == - "Listen node Basin #5 of PidControl #6 is not upstream of controlled Pump #2" + "PID listened Basin #5 is not on either side of controlled Pump #2." end @testitem "FractionalFlow validation" begin