You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/tutorials/SampledData.md
+8-8
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ A clock can be seen as an *event source*, i.e., when the clock ticks, an event i
16
16
-[`Hold`](@ref)
17
17
-[`ShiftIndex`](@ref)
18
18
19
-
When a continuous-time variable `x` is sampled using `xd = Sample(x, dt)`, the result is a discrete-time variable `xd` that is defined and updated whenever the clock ticks. `xd` is *only defined when the clock ticks*, which it does with an interval of `dt`. If `dt` is unspecified, the tick rate of the clock associated with `xd` is inferred from the context in which `xd` appears. Any variable taking part in the same equation as `xd` is inferred to belong to the same *discrete partition* as `xd`, i.e., belonging to the same clock. A system may contain multiple different discrete-time partitions, each with a unique clock. This allows for modeling of multi-rate systems and discrete-time processes located on different computers etc.
19
+
When a continuous-time variable `x` is sampled using `xd = Sample(dt)(x)`, the result is a discrete-time variable `xd` that is defined and updated whenever the clock ticks. `xd` is *only defined when the clock ticks*, which it does with an interval of `dt`. If `dt` is unspecified, the tick rate of the clock associated with `xd` is inferred from the context in which `xd` appears. Any variable taking part in the same equation as `xd` is inferred to belong to the same *discrete partition* as `xd`, i.e., belonging to the same clock. A system may contain multiple different discrete-time partitions, each with a unique clock. This allows for modeling of multi-rate systems and discrete-time processes located on different computers etc.
20
20
21
21
To make a discrete-time variable available to the continuous partition, the [`Hold`](@ref) operator is used. `xc = Hold(xd)` creates a continuous-time variable `xc` that is updated whenever the clock associated with `xd` ticks, and holds its value constant between ticks.
22
22
@@ -34,7 +34,7 @@ using ModelingToolkit
34
34
using ModelingToolkit: t_nounits as t
35
35
@variables x(t) y(t) u(t)
36
36
dt = 0.1 # Sample interval
37
-
clock = Clock(t, dt) # A periodic clock with tick rate dt
37
+
clock = Clock(dt) # A periodic clock with tick rate dt
38
38
k = ShiftIndex(clock)
39
39
40
40
eqs = [
@@ -98,7 +98,7 @@ may thus be modeled as
98
98
99
99
```julia
100
100
@variables t y(t) [description ="Output"] u(t) [description ="Input"]
@@ -127,10 +127,10 @@ requires specification of the initial condition for both `x(k-1)` and `x(k-2)`.
127
127
Multi-rate systems are easy to model using multiple different clocks. The following set of equations is valid, and defines *two different discrete-time partitions*, each with its own clock:
128
128
129
129
```julia
130
-
yd1 ~Sample(t, dt1)(y)
131
-
ud1 ~ kp * (Sample(t, dt1)(r) - yd1)
132
-
yd2 ~Sample(t, dt2)(y)
133
-
ud2 ~ kp * (Sample(t, dt2)(r) - yd2)
130
+
yd1 ~Sample(dt1)(y)
131
+
ud1 ~ kp * (Sample(dt1)(r) - yd1)
132
+
yd2 ~Sample(dt2)(y)
133
+
ud2 ~ kp * (Sample(dt2)(r) - yd2)
134
134
```
135
135
136
136
`yd1` and `ud1` belong to the same clock which ticks with an interval of `dt1`, while `yd2` and `ud2` belong to a different clock which ticks with an interval of `dt2`. The two clocks are *not synchronized*, i.e., they are not *guaranteed* to tick at the same point in time, even if one tick interval is a rational multiple of the other. Mechanisms for synchronization of clocks are not yet implemented.
@@ -147,7 +147,7 @@ using ModelingToolkit: t_nounits as t
is_concrete_time_domain(x) = x isa Union{AbstractClock, Continuous}
127
-
128
-
"""
129
-
SolverStepClock <: AbstractClock
130
-
SolverStepClock()
131
-
SolverStepClock(t)
132
-
133
-
A clock that ticks at each solver step (sometimes referred to as "continuous sample time"). This clock **does generally not have equidistant tick intervals**, instead, the tick interval depends on the adaptive step-size selection of the continuous solver, as well as any continuous event handling. If adaptivity of the solver is turned off and there are no continuous events, the tick interval will be given by the fixed solver time step `dt`.
134
-
135
-
Due to possibly non-equidistant tick intervals, this clock should typically not be used with discrete-time systems that assume a fixed sample time, such as PID controllers and digital filters.
0 commit comments