Skip to content

Commit

Permalink
Merge branch 'main' into discrete_control_with_discrete_callback
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Apr 17, 2024
2 parents f2517ed + f6108a0 commit 3c7a52b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions core/src/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ end
function apply_discrete_control!(u, t, integrator)::Nothing
(; p) = integrator
(; discrete_control) = p
condition_idx = 0

discrete_control_condition!(u, t, integrator)

Expand Down
16 changes: 16 additions & 0 deletions core/src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -709,3 +709,19 @@ function get_influx(basin::Basin, basin_idx::Int)::Float64
return precipitation[basin_idx] - evaporation[basin_idx] + drainage[basin_idx] -
infiltration[basin_idx]
end

function get_discrete_control_indices(discrete_control::DiscreteControl, condition_idx::Int)
(; greater_than) = discrete_control
condition_idx_now = 1

for (compound_variable_idx, vec) in enumerate(greater_than)
l = length(vec)

if condition_idx_now + l > condition_idx
greater_than_idx = condition_idx - condition_idx_now + 1
return compound_variable_idx, greater_than_idx
end

condition_idx_now += l
end
end
2 changes: 0 additions & 2 deletions core/src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,6 @@ function valid_discrete_control(p::Parameters, config::Config)::Bool
for (Δt, var, node_id) in zip(look_aheads, variables, listen_node_ids)
if !iszero(Δt)
node_type = node_id.type
# TODO: If more transient listen variables must be supported, this validation must be more specific
# (e.g. for some node some variables are transient, some not).
if node_type [NodeType.FlowBoundary, NodeType.LevelBoundary]
errors = true
@error "Look ahead supplied for non-timeseries listen variable '$var' from listen node $node_id."
Expand Down
4 changes: 2 additions & 2 deletions docs/core/usage.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ which can be for instance an average or a difference of variables. If a variable
column | type | unit | restriction
-------------------- | -------- | ------- | -----------
node_id | Int32 | - | sorted
compound_variable_id | String | - | sorted per node_id
compound_variable_id | Int32 | - | 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 @@ -648,7 +648,7 @@ look_ahead | Float64 | $s$ | Only on transient boundary condition

## DiscreteControl / condition

The condition schema defines conditions of the form 'the `discrete_control` node with this `node_id`listens to whether the variable given by the `node_id` and `compound_variable_id` is greater than `greater_than`'. If the condition variable comes from a time-series, a look ahead $\Delta t$ can be supplied. Multiple conditions with different `greater_than` values can be defined on the same compound_variable.
The condition schema defines conditions of the form 'the `discrete_control` node with this `node_id`listens to whether the variable given by the `node_id` and `compound_variable_id` is greater than `greater_than`'. Multiple conditions with different `greater_than` values can be defined on the same compound_variable.

column | type | unit | restriction
-------------------- | -------- | ------- | -----------
Expand Down

0 comments on commit 3c7a52b

Please sign in to comment.