Skip to content

Commit

Permalink
Add controllable parameters table (#1584)
Browse files Browse the repository at this point in the history
Fixes #1574.
  • Loading branch information
SouthEndMusic authored Jun 27, 2024
1 parent 12c3f67 commit e4e8848
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ controllablefields(::Val{:FractionalFlow}) = Set((:fraction,))
controllablefields(::Val{:Pump}) = Set((:active, :flow_rate))
controllablefields(::Val{:Outlet}) = Set((:active, :flow_rate))
controllablefields(::Val{:PidControl}) =
Set((:active, :target, :propoertional, :integral, :derivative))
Set((:active, :target, :proportional, :integral, :derivative))
controllablefields(nodetype) = Set{Symbol}()

function variable_names(s::Any)
Expand Down
30 changes: 30 additions & 0 deletions docs/reference/node/discrete-control.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@ title: "DiscreteControl"
---

Set parameters of other nodes based on model state conditions (e.g. Basin level).
The table below shows which parameters are controllable for a given node type.

```{julia}
# | code-fold: true
using Ribasim
using DataFrames: DataFrame
using MarkdownTables
node_names = Symbol[]
controllable_parameters = String[]
for node_type in fieldtypes(Ribasim.Parameters)
if node_type <: Ribasim.AbstractParameterNode
node_name = nameof(node_type)
controllable_fields = Ribasim.controllablefields(node_name)
controllable_fields = sort!(string.(controllable_fields))
if node_name == :TabulatedRatingCurve
controllable_fields = map(s -> replace(s, "table" => "q(h) relationship (given by level, flow_rate)"), controllable_fields)
end
if !isempty(controllable_fields)
push!(node_names, Ribasim.snake_case(node_name))
push!(controllable_parameters, join(controllable_fields, ", "))
end
end
end
df = DataFrame(:node => node_names, :controllable_parameters => controllable_parameters)
markdown_table(df)
```

# Tables

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/validation.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ using Ribasim
using DataFrames: DataFrame
using MarkdownTables
node_names_snake_case = Vector{Symbol}()
node_names_camel_case = Vector{Symbol}()
node_names_snake_case = Symbol[]
node_names_camel_case = Symbol[]
for (node_name, node_type) in zip(fieldnames(Ribasim.Parameters), fieldtypes(Ribasim.Parameters))
if node_type <: Ribasim.AbstractParameterNode
push!(node_names_snake_case, node_name)
Expand Down

0 comments on commit e4e8848

Please sign in to comment.