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/basics/Composition.md
+6-14Lines changed: 6 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -135,42 +135,34 @@ sys.y = u * 1.1
135
135
In a hierarchical system, variables of the subsystem get namespaced by the name of the system they are in. This prevents naming clashes, but also enforces that every unknown and parameter is local to the subsystem it is used in. In some cases it might be desirable to have variables and parameters that are shared between subsystems, or even global. This can be accomplished as follows.
136
136
137
137
```julia
138
-
@parameters a b c d e f
138
+
@parameters a b c d
139
139
140
140
# a is a local variable
141
141
b =ParentScope(b) # b is a variable that belongs to one level up in the hierarchy
142
142
c =ParentScope(ParentScope(c)) # ParentScope can be nested
143
-
d =DelayParentScope(d) # skips one level before applying ParentScope
144
-
e =DelayParentScope(e, 2) # second argument allows skipping N levels
145
-
f =GlobalScope(f)
143
+
d =GlobalScope(d)
146
144
147
-
p = [a, b, c, d, e, f]
145
+
p = [a, b, c, d]
148
146
149
147
level0 =ODESystem(Equation[], t, [], p; name =:level0)
150
148
level1 =ODESystem(Equation[], t, [], []; name =:level1) ∘ level0
151
149
parameters(level1)
152
150
#level0₊a
153
151
#b
154
152
#c
155
-
#level0₊d
156
-
#level0₊e
157
-
#f
153
+
#d
158
154
level2 =ODESystem(Equation[], t, [], []; name =:level2) ∘ level1
159
155
parameters(level2)
160
156
#level1₊level0₊a
161
157
#level1₊b
162
158
#c
163
-
#level0₊d
164
-
#level1₊level0₊e
165
-
#f
159
+
#d
166
160
level3 =ODESystem(Equation[], t, [], []; name =:level3) ∘ level2
Copy file name to clipboardExpand all lines: docs/src/basics/Events.md
+87-21Lines changed: 87 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,67 @@ the event occurs). These can both be specified symbolically, but a more [general
25
25
functional affect](@ref func_affects) representation is also allowed, as described
26
26
below.
27
27
28
+
## Symbolic Callback Semantics
29
+
30
+
In callbacks, there is a distinction between values of the unknowns and parameters
31
+
*before* the callback, and the desired values *after* the callback. In MTK, this
32
+
is provided by the `Pre` operator. For example, if we would like to add 1 to an
33
+
unknown `x` in a callback, the equation would look like the following:
34
+
35
+
```julia
36
+
x ~Pre(x) +1
37
+
```
38
+
39
+
Non `Pre`-d values will be interpreted as values *after* the callback. As such,
40
+
writing
41
+
42
+
```julia
43
+
x ~ x +1
44
+
```
45
+
46
+
will be interpreted as an algebraic equation to be satisfied after the callback.
47
+
Since this equation obviously cannot be satisfied, an error will result.
48
+
49
+
Callbacks must maintain the consistency of DAEs, meaning that they must satisfy
50
+
all the algebraic equations of the system after their update. However, the affect
51
+
equations often do not fully specify which unknowns/parameters should be modified
52
+
to maintain consistency. To make this clear, MTK uses the following rules:
53
+
54
+
1. All unknowns are treated as modifiable by the callback. In order to enforce that an unknown `x` remains the same, one can add `x ~ Pre(x)` to the affect equations.
55
+
2. All parameters are treated as un-modifiable, *unless* they are declared as `discrete_parameters` to the callback. In order to be a discrete parameter, the parameter must be time-dependent (the terminology *discretes* here means [discrete variables](@ref save_discretes)).
56
+
57
+
For example, consider the following system.
58
+
59
+
```julia
60
+
@variablesx(t) y(t)
61
+
@parametersp(t)
62
+
@mtkbuild sys =ODESystem([x * y ~ p, D(x) ~0], t)
63
+
event = [t ==1] => [x ~Pre(x) +1]
64
+
```
65
+
66
+
By default what will happen is that `x` will increase by 1, `p` will remain constant,
67
+
and `y` will change in order to compensate the increase in `x`. But what if we
68
+
wanted to keep `y` constant and change `p` instead? We could use the callback
0 commit comments