Skip to content

Commit

Permalink
update sorting and schema explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Apr 11, 2024
1 parent 3144ef1 commit e842bdf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions core/src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ sort_by_id_state_level(row) = (row.node_id, row.control_state, row.level)
sort_by_priority(row) = (row.node_id, row.priority)
sort_by_priority_time(row) = (row.node_id, row.priority, row.time)
sort_by_subgrid_level(row) = (row.subgrid_id, row.basin_level)
sort_by_id_name(row) = (row.node_id, row.name)

# get the right sort by function given the Schema, with sort_by_id as the default
sort_by_function(table::StructVector{<:Legolas.AbstractRecord}) = sort_by_id
Expand All @@ -110,6 +111,7 @@ sort_by_function(table::StructVector{BasinProfileV1}) = sort_by_id_level
sort_by_function(table::StructVector{UserDemandStaticV1}) = sort_by_priority
sort_by_function(table::StructVector{UserDemandTimeV1}) = sort_by_priority_time
sort_by_function(table::StructVector{BasinSubgridV1}) = sort_by_subgrid_level
sort_by_function(table::StructVector{DiscreteControlCompoundvariableV1}) = sort_by_id_name

const TimeSchemas = Union{
BasinTimeV1,
Expand Down
13 changes: 11 additions & 2 deletions docs/core/usage.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,18 @@ DiscreteControl is implemented based on [VectorContinuousCallback](https://docs.

## DiscreteControl / compoundvariable

The compound variable schema defines linear combinations of variables which can be used in conditions. This means that
this schema defines new variables with the given name that look like
$$
\text{weight}_1 * \text{variable}_1 + \text{weight}_2 * \text{variable}_2 + \ldots,
$$

which can be for instance an average or a difference of variables. If a variable comes from a time-series, a look ahead $\Delta t$ can be supplied.

column | type | unit | restriction
----------------- | -------- | ------- | -----------
node_id | Int32 | - | sorted
name | String | - | -
name | String | - | sorted per node_id
listen_node_type | String | - | known node type
listen_node_id | Int32 | - | sorted per node_id
variable | String | - | must be "level" or "flow_rate", sorted per listen_node_id
Expand All @@ -640,7 +648,8 @@ look_ahead | Float64 | $s$ | Only on transient boundary conditions,

## DiscreteControl / condition

The condition schema defines conditions of the form 'the discrete_control node with this node id listens to whether the given variable of the node with the given listen feature id is grater than the given value'. If the condition variable comes from a time-series, a look ahead $\Delta t$ can be supplied.
The condition schema defines conditions of the form 'the discrete_control node with this node id listens to whether the given variable of the node with the given listen node id is greater than the given value'. If the condition variable comes from a time-series, a look ahead $\Delta t$ can be supplied.
Compound variables from the schema above can also be used, in which case the listen node ID and look ahead in this schema are ignored.

column | type | unit | restriction
----------------- | -------- | ------- | -----------
Expand Down
6 changes: 2 additions & 4 deletions python/ribasim/ribasim/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,11 @@ class ManningResistance(MultiNodeModel):
class DiscreteControl(MultiNodeModel):
compoundvariable: TableModel[DiscreteControlCompoundvariableSchema] = Field(
default_factory=TableModel[DiscreteControlCompoundvariableSchema],
json_schema_extra={"sort_keys": ["name"]},
json_schema_extra={"sort_keys": ["node_id", "name"]},
)
condition: TableModel[DiscreteControlConditionSchema] = Field(
default_factory=TableModel[DiscreteControlConditionSchema],
json_schema_extra={
"sort_keys": ["node_id", "listen_node_id", "variable", "greater_than"]
},
json_schema_extra={"sort_keys": ["node_id"]},
)
logic: TableModel[DiscreteControlLogicSchema] = Field(
default_factory=TableModel[DiscreteControlLogicSchema],
Expand Down

0 comments on commit e842bdf

Please sign in to comment.