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: src/systems/callbacks.jl
+15-6Lines changed: 15 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -145,17 +145,26 @@ By default `affect_neg = affect`; to only get rising edges specify `affect_neg =
145
145
Assume without loss of generality that the equation is of the form `c(u,p,t) ~ 0`; we denote the integrator state as `i.u`.
146
146
For compactness, we define `prev_sign = sign(c(u[t-1], p[t-1], t-1))` and `cur_sign = sign(c(u[t], p[t], t))`.
147
147
A condition edge will be detected and the callback will be invoked iff `prev_sign * cur_sign <= 0`.
148
+
The positive edge `affect` will be triggered iff an edge is detected and if `prev_sign < 0`; similarly, `affect_neg` will be
149
+
triggered iff an edge is detected and `prev_sign > 0`.
150
+
148
151
Inter-sample condition activation is not guaranteed; for example if we use the dirac delta function as `c` to insert a
149
152
sharp discontinuity between integrator steps (which in this example would not normally be identified by adaptivity) then the condition is not
150
153
guaranteed to be triggered.
151
154
152
155
Once detected the integrator will "wind back" through a root-finding process to identify the point when the condition became active; the method used
153
-
is specified by `rootfind` from [`SciMLBase.RootfindOpt`](@ref). Multiple callbacks in the same system with different `rootfind` operations will be resolved
154
-
into separate VectorContinuousCallbacks in the enumeration order of `SciMLBase.RootfindOpt`, which may cause some callbacks to not fire if several become
155
-
active at the same instant. See the `SciMLBase` documentation for more information on the semantic rules.
156
-
157
-
The positive edge `affect` will be triggered iff an edge is detected and if `prev_sign < 0`; similarly, `affect_neg` will be
158
-
triggered iff an edge is detected `prev_sign > 0`.
156
+
is specified by `rootfind` from [`SciMLBase.RootfindOpt`](@ref). If we denote the time when the condition becomes active at tc,
157
+
the value in the integrator after windback will be:
158
+
* `u[tc-epsilon], p[tc-epsilon], tc` if `LeftRootFind` is used,
159
+
* `u[tc+epsilon], p[tc+epsilon], tc` if `RightRootFind` is used,
160
+
* or `u[t], p[t], t` if `NoRootFind` is used.
161
+
For example, if we want to detect when an unknown variable `x` satisfies `x > 0` using the condition `x ~ 0` on a positive edge (that is, `D(x) > 0`),
162
+
then left root finding will get us `x=-epsilon`, right root finding `x=epsilon` and no root finding whatever the next step of the integrator was after
163
+
it passed through 0.
164
+
165
+
Multiple callbacks in the same system with different `rootfind` operations will be grouped
166
+
by their `rootfind` value into separate VectorContinuousCallbacks in the enumeration order of `SciMLBase.RootfindOpt`. This may cause some callbacks to not fire if several become
167
+
active at the same instant. See the `SciMLBase` documentation for more information on the semantic rules.
159
168
160
169
Affects (i.e. `affect` and `affect_neg`) can be specified as either:
161
170
* A list of equations that should be applied when the callback is triggered (e.g. `x ~ 3, y ~ 7`) which must be of the form `unknown ~ observed value` where each `unknown` appears only once. Equations will be applied in the order that they appear in the vector; parameters and state updates will become immediately visible to following equations.
0 commit comments