Ribasim icon indicating copy to clipboard operation
Ribasim copied to clipboard

Add an optional time interval to `DiscreteControl` nodes

Open SouthEndMusic opened this issue 7 months ago • 2 comments

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.

SouthEndMusic avatar Apr 17 '25 10:04 SouthEndMusic

I have some questions:

  • Where should the time interval be in the input? As it is a single value per node the Node table 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 DiscreteControl nodes 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 a FunctionCallingCallback as they are handled now, and the others can be done with a PresetTimeCallback. The latter of course doesn't work when the time interval depends on the simulation itself but we can use tstops on the fly with add_tstop!(integrator,new_t).

SouthEndMusic avatar Apr 22 '25 12:04 SouthEndMusic

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.

visr avatar Apr 22 '25 14:04 visr