ModelingToolkit.jl
ModelingToolkit.jl copied to clipboard
WIP: Add `SampledTime` operator
This PR implements the SampledTime
operator proposed by @jonniedie in https://github.com/SciML/ModelingToolkit.jl/issues/894#issuecomment-805893878
It provides a convenient interface between the continuous and discrete time domains, examplified by
julia> @variables t x(t);
julia> k = SampledTime(t, dt=0.1);
julia> x(k)
Sample(t; dt=0.1)(x(t))
julia> x(k+1)
Shift(t, 1; dt=0.1)(Sample(t; dt=0.1)(x(t)))
i.e., the semantics is that when you call a continuous-time signal with this operator it becomes sampled, and possibly shifted. If the indexed signal is already a discrete-time signal, the Sample
should be a noop.
This PR builds on
- #1382
If x(k)
is the value of x
at the current time step, I think any x(k+n)
with n>0
is not implementable. Modelica only defines the previous(.)
operator
x = A*previous(x) + B*u
.
I think any x(k+n) with n>0 is not implementable
Being able to express a model is not the same as being able to implement or simulate it, I see no reason to limit the expressivity the way modelica does. The model
x(k+1) = x(k)
defines a constant system, which is trivially implementable. In general, for discrete-time systems you may transform all shifted variables by shifting them with the largest shift present and then you have a causal system you can implement, it doesn't matter if the way the model was written was not implementable.
Also, you often want to express non-causal / non-proper models which are later inverted, thus becoming causal/proper. This is common when you design model-based inverse filters for feedforward design.
If x(k) is the value of x at the current time step, I think any x(k+n) with n>0 is not implementable
That could actually be useful for PDE definitions.
If x(k) is the value of x at the current time step, I think any x(k+n) with n>0 is not implementable
That could actually be useful for PDE definitions.
Good point, perhaps SampledTime
is a poor choice of name, maybe it should just be called SampledVar
or something more generic to indicate that the independent variables does not have to be time.