Ribasim
Ribasim copied to clipboard
Add an optional time interval to `DiscreteControl` nodes
Currently the DiscreteControl run logic is applied after every solver timestep. However, sometimes it is more realistic human behavior to apply the logic for instance once a day. This interval can be different between different DiscreteControl nodes.
Eventually we also want this update interval to be dependent on the state of the model. This is not necessary for this first implementation, but it could be helpful to keep in mind. This could also be done with DiscreteControl, but that might get a bit meta.
I have some questions:
- Where should the time interval be in the input? As it is a single value per node the
Nodetable makes sense, but maybe we don't want to clog that up with a lot of parameters. @JohnRushKucharski-Deltares also said that in the future this parameter might not be fixed, so we could already keep in mind what the input should look line then. - In terms of implementation: I think we should divide
DiscreteControlnodes in ones whose logic runs after each timestep and ones whose logic runs after its own specific interval. The ones that work as before can then still be handled by aFunctionCallingCallbackas they are handled now, and the others can be done with aPresetTimeCallback. The latter of course doesn't work when the time interval depends on the simulation itself but we can usetstopson the fly withadd_tstop!(integrator,new_t).
I think DiscreteControl / condition would make most sense. That also is already optionally time-dependent via the time column. We could add an optional interval column. We could for now restrict to only having a constant interval per node_id, and then the data model wouldn't change when we start allowing it to change.
https://ribasim.org/reference/node/discrete-control.html#condition
Your implementation suggestion with split callbacks makes sense to me. Also worth considering is adding tstops at the start, keeping one FunctionCallingCallback, and then skipping all controls that don't need to be run at the given t % interval. If that can be done cheaply enough that may be simpler.