ModelingToolkit.jl
ModelingToolkit.jl copied to clipboard
WIP: introduce time-domain operators
This PR introduces the operators
Sample, Hold, Shift
as well as functions to query their presence in expressions and equations.
For background, see discussion in
- https://github.com/SciML/ModelingToolkit.jl/issues/1307
The intention is for this to serve as a foundation to improve the semantics of hybrid systems, systems with both continuous and discrete-time signals, similar to the Modelica Synchronous/Clocked module.
The Sample
and Hold
operators define the interface between the continuous domain and the discrete domain, while Shift
is the time-shift operator that fills the same role for discrete systems as Differential
does for continuous systems.
This PR depends on
- https://github.com/JuliaSymbolics/Symbolics.jl/pull/454
And supersedes
- https://github.com/SciML/ModelingToolkit.jl/pull/1381
Future work:
- Classify signals (states) as either continuous or discrete.
- Check that time domains only mix through the interface
Sample/Hold
. Implicit sample and hold may be implemented at a later stage if the sample time can be inferred unambiguously.
I don't quite understand the purpose of the Hold operator. Wouldn't it be better to just have the interpretation that x(t+dt/n) == x(t)
for discrete processes with steps dt
? That would be equivalent, match the way the plots are drawn, require less machinery, and be more explicit about the definition of the discrete values when used in a continuous context?
The hold operator is not required for DiscreteSystem
s, it's only intended to define the interface from discrete to continuous time in hybrid systems. The modelica reference defines the hold
operator as
A discrete-time signal (such as ud) is converted to a continuous-time signal with the hold(..) operator.
The requirement for hold
comes from discrete variables in modelica only being defined at discrete time points, and the hold operator extends the discrete time point to the interval between the point and the next time point. The diagram on p197 illustrates how it works in modelica
https://modelica.org/documents/ModelicaSpec34.pdf
But you can already put discrete update operators in continuous ODESystems, and it has the interpretation that would match the hold operator, so that makes it seem redundant?
But you can already put discrete update operators in continuous ODESystems, and it has the interpretation that would match the hold operator, so that makes it seem redundant?
The DiscreteUpdate
operator of MTK only have the hold behavior if you have an additional equation that sets the derivative of the state you're holding to zero. Inbetween the "discrete updates", the variable may have any dynamics in general. This can certainly be useful at times, but it's not really the typical operator you'd use to model discrete systems.