From bae862579a28ca806c1076c4a73b6c8f897c6708 Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Sun, 28 Apr 2024 21:03:00 +0200 Subject: [PATCH 1/2] Tighten edge validation Since LevelDemand and FlowDemand were not AbstractParameterNodes, their connections were not being validated despite the constraints being set properly. LinearResistance and ManningResistance already required 1 in and 1 outflow, just not in validation. Basin already cannot have outgoing control edges. --- core/src/parameter.jl | 4 ++-- core/src/validation.jl | 6 +++--- docs/contribute/addnode.qmd | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/parameter.jl b/core/src/parameter.jl index d16b793a8..047ddb992 100644 --- a/core/src/parameter.jl +++ b/core/src/parameter.jl @@ -556,14 +556,14 @@ min_level: The minimum target level of the connected basin(s) max_level: The maximum target level of the connected basin(s) priority: If in a shortage state, the priority of the demand of the connected basin(s) """ -struct LevelDemand +struct LevelDemand <: AbstractParameterNode node_id::Vector{NodeID} min_level::Vector{LinearInterpolation} max_level::Vector{LinearInterpolation} priority::Vector{Int32} end -struct FlowDemand +struct FlowDemand <: AbstractParameterNode node_id::Vector{NodeID} demand_itp::Vector{ScalarInterpolation} demand::Vector{Float64} diff --git a/core/src/validation.jl b/core/src/validation.jl index bcdf9eef7..f848be7ee 100644 --- a/core/src/validation.jl +++ b/core/src/validation.jl @@ -47,8 +47,8 @@ end n_neighbor_bounds_flow(nodetype::Symbol) = n_neighbor_bounds_flow(Val(nodetype)) n_neighbor_bounds_flow(::Val{:Basin}) = n_neighbor_bounds(0, typemax(Int), 0, typemax(Int)) -n_neighbor_bounds_flow(::Val{:LinearResistance}) = n_neighbor_bounds(1, 1, 1, typemax(Int)) -n_neighbor_bounds_flow(::Val{:ManningResistance}) = n_neighbor_bounds(1, 1, 1, typemax(Int)) +n_neighbor_bounds_flow(::Val{:LinearResistance}) = n_neighbor_bounds(1, 1, 1, 1) +n_neighbor_bounds_flow(::Val{:ManningResistance}) = n_neighbor_bounds(1, 1, 1, 1) n_neighbor_bounds_flow(::Val{:TabulatedRatingCurve}) = n_neighbor_bounds(1, 1, 1, typemax(Int)) n_neighbor_bounds_flow(::Val{:FractionalFlow}) = n_neighbor_bounds(1, 1, 1, 1) @@ -67,7 +67,7 @@ n_neighbor_bounds_flow(nodetype) = error("'n_neighbor_bounds_flow' not defined for $nodetype.") n_neighbor_bounds_control(nodetype::Symbol) = n_neighbor_bounds_control(Val(nodetype)) -n_neighbor_bounds_control(::Val{:Basin}) = n_neighbor_bounds(0, 1, 0, typemax(Int)) +n_neighbor_bounds_control(::Val{:Basin}) = n_neighbor_bounds(0, 1, 0, 0) n_neighbor_bounds_control(::Val{:LinearResistance}) = n_neighbor_bounds(0, 1, 0, 0) n_neighbor_bounds_control(::Val{:ManningResistance}) = n_neighbor_bounds(0, 1, 0, 0) n_neighbor_bounds_control(::Val{:TabulatedRatingCurve}) = n_neighbor_bounds(0, 1, 0, 0) diff --git a/docs/contribute/addnode.qmd b/docs/contribute/addnode.qmd index 2bc64eace..1bd65f434 100644 --- a/docs/contribute/addnode.qmd +++ b/docs/contribute/addnode.qmd @@ -11,7 +11,7 @@ Several parts of the code have to be made aware of the new node type. In the res The parameters object (defined in `parameter.jl`) passed to the ODE solver must be made aware of the new node type. Therefore define a struct in `parameter.jl` which holds the data for each node of the new node type: ```julia -struct NewNodeType +struct NewNodeType <: AbstractParameterNode node_id::Vector{NodeID} # Other fields end From 4f8a3212eebe65199b81c4c2d32ae1ce59431e99 Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Sun, 28 Apr 2024 21:05:39 +0200 Subject: [PATCH 2/2] Remove outdated comment about ribasim.cmd --- docs/python/examples.ipynb | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/python/examples.ipynb b/docs/python/examples.ipynb index 5b1721bc8..d3a708b79 100644 --- a/docs/python/examples.ipynb +++ b/docs/python/examples.ipynb @@ -397,8 +397,6 @@ "subprocess.run([cli_path, toml_path], check=True)\n", "```\n", "\n", - "Windows users should note that if you put the `ribasim_cli` folder in your Path, `cli_path` needs to have the cmd suffix; `ribasim.cmd`.\n", - "\n", "Or similarly you can from the terminal with:\n", "```bash\n", "ribasim basic/ribasim.toml\n",