Skip to content

Commit f151e42

Browse files
committed
Clarify documentation for SCC
1 parent a6f781d commit f151e42

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/systems/callbacks.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,26 @@ By default `affect_neg = affect`; to only get rising edges specify `affect_neg =
145145
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`.
146146
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))`.
147147
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+
148151
Inter-sample condition activation is not guaranteed; for example if we use the dirac delta function as `c` to insert a
149152
sharp discontinuity between integrator steps (which in this example would not normally be identified by adaptivity) then the condition is not
150153
guaranteed to be triggered.
151154
152155
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.
159168
160169
Affects (i.e. `affect` and `affect_neg`) can be specified as either:
161170
* 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

Comments
 (0)