Skip to content

Commit

Permalink
Relax PID validation (#1194)
Browse files Browse the repository at this point in the history
Fixes #1114.
  • Loading branch information
SouthEndMusic authored Feb 29, 2024
1 parent e8e7202 commit 9f62534
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
26 changes: 11 additions & 15 deletions core/src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion core/test/validation_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 9f62534

Please sign in to comment.