diff --git a/core/src/solve.jl b/core/src/solve.jl index 23614a073..845b67754 100644 --- a/core/src/solve.jl +++ b/core/src/solve.jl @@ -53,7 +53,12 @@ end """ Store the connectivity information -graph_flow, graph_control: directed graph with vertices equal to ids +graph: a directed metagraph with data of nodes (NodeMetadata): + - Node type (snake case) + - Allocation network ID + and data of edges (EdgeMetadata): + - Edge ID (EdgeID) + - type (flow/control) flow: store the flow on every flow edge edge_ids_flow, edge_ids_control: get the external edge id from (src, dst) edge_connection_type_flow, edge_connection_types_control: get (src_node_type, dst_node_type) from edge id @@ -744,8 +749,7 @@ function continuous_control!( if controls_pump for id in outneighbor_labels_type(graph, controlled_node_id, EdgeType.flow) if id in fractional_flow.node_id - after_ff_id = - only(outneighbor_labels_type(graph_flow, id, EdgeType.flow)) + after_ff_id = only(outneighbor_labels_type(graph, id, EdgeType.flow)) ff_idx = findsorted(fractional_flow, id) flow_rate_fraction = fractional_flow.fraction[ff_idx] * flow_rate flow[id, after_ff_id] = flow_rate_fraction diff --git a/core/src/validation.jl b/core/src/validation.jl index 29bf65dc0..d58025454 100644 --- a/core/src/validation.jl +++ b/core/src/validation.jl @@ -571,7 +571,7 @@ Check that nodes that have fractional flow outneighbors do not have any other ty outneighbor, that the fractions leaving a node add up to ≈1 and that the fractions are non-negative. """ function valid_fractional_flow( - graph_flow::MetaGraph, + graph::MetaGraph, node_id::Vector{NodeID}, control_mapping::Dict{Tuple{NodeID, String}, NamedTuple}, )::Bool @@ -581,14 +581,14 @@ function valid_fractional_flow( src_ids = Set{NodeID}() for id in node_id - union!(src_ids, inneighbor_labels(graph_flow, id)) + union!(src_ids, inneighbor_labels(graph, id)) end node_id_set = Set{NodeID}(node_id) control_states = Set{String}([key[2] for key in keys(control_mapping)]) for src_id in src_ids - src_outneighbor_ids = Set(outneighbor_labels(graph_flow, src_id)) + src_outneighbor_ids = Set(outneighbor_labels(graph, src_id)) if src_outneighbor_ids ⊈ node_id errors = true @error( diff --git a/core/test/validation_test.jl b/core/test/validation_test.jl index deea526ea..9d16ac4f3 100644 --- a/core/test/validation_test.jl +++ b/core/test/validation_test.jl @@ -49,6 +49,7 @@ end end @testitem "Neighbor count validation" begin + using MetaGraphsNext: MetaGraph using Graphs: DiGraph using Logging @@ -135,6 +136,7 @@ end end @testitem "PidControl connectivity validation" begin + using MetaGraphsNext: MetaGraph using Graphs: DiGraph using Dictionaries: Indices using Logging @@ -209,7 +211,7 @@ end logger = TestLogger() with_logger(logger) do @test !Ribasim.valid_fractional_flow( - connectivity.graph_flow, + connectivity.graph, fractional_flow.node_id, fractional_flow.control_mapping, ) @@ -222,13 +224,13 @@ end @test logger.logs[2].level == Error @test logger.logs[2].message == "Fractional flow nodes must have non-negative fractions." - @test logger.logs[2].kwargs[:node_id] == 3 + @test logger.logs[2].kwargs[:node_id].value == 3 @test logger.logs[2].kwargs[:fraction] ≈ -0.1 @test logger.logs[2].kwargs[:control_state] == "" @test logger.logs[3].level == Error @test logger.logs[3].message == "The sum of fractional flow fractions leaving a node must be ≈1." - @test logger.logs[3].kwargs[:node_id] == 7 + @test logger.logs[3].kwargs[:node_id].value == 7 @test logger.logs[3].kwargs[:fraction_sum] ≈ 0.4 @test logger.logs[3].kwargs[:control_state] == "" end