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
- Raises compat from `ModelingToolkit` v10 to v11. MTK v11 split into `ModelingToolkitBase` (MIT-licensed) and `ModelingToolkit` (AGPL-licensed); NetworkDynamics.jl now only requires the MIT-licensed `ModelingToolkitBase` as a direct dependency, dropping the AGPL dependency.
@@ -15,6 +15,7 @@
15
15
- The default initial state for fixpoint search now applies guesses and formulas automatically (`guess=true, apply_formulas=true`).
16
16
-**`NWState` constructor** gains `guess`, `apply_formulas`, and `verbose` keyword arguments. With `default=true` (the default), values are filled in order: defaults/inits → `InitFormula`s → guesses (if `guess=true`) → `GuessFormula`s. `apply_formulas=true` by default; `guess=false` by default.
17
17
-`doctor` check: added smoketest for the observable function (`obsf`) of each component.
18
+
-`SciMLBase@3` and `OrdinaryDfifEq@7` compat. Most notably, upstream `DiffEq` changed its default `initializealg` to *check* rather than *reinit* inconsistent initial conditions. To preserve the previous behavior, the `ODEProblem(nw::Network, ...)` constructor now defaults to `initializealg=BrownFullBasicInit()` (deliberately differing from the OrdinaryDiffEq default). Pass `initializealg=...` to the constructor to override. Also, the interface of the `VectorContinuousComponentCallback` changed to fit that of `VectorContinuousCallback`: the affect now receives a buffer with per-element up or down crossing information rather than a single event idx.
Copy file name to clipboardExpand all lines: docs/src/callbacks.md
+11-7Lines changed: 11 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ The main entry points are the types [`ContinuousComponentCallback`](@ref),
28
28
[`VectorContinuousComponentCallback`](@ref) and [`DiscreteComponentCallback`](@ref). All of those objects combine a [`ComponentCondition`](@ref) with an [`ComponentAffect`](@ref).
29
29
30
30
The "normal" [`ContinuousComponentCallback`](@ref) and [`DiscreteComponentCallback`](@ref) have a condition which returns a single value. The corresponding affect is triggered when the return value hits zero.
31
-
In contrast, the "vector" version has an in-place condition which writes `len` outputs. When any of those outputs hits zero, the affect is triggered with an additional argument `event_idx` which tells the effect which dimension encountered the zerocrossing.
31
+
In contrast, the "vector" version has an in-place condition which writes `len` outputs. When any of those outputs hits zero, the affect is triggered once with an additional argument `event_signs`: a length-`len` vector where entry `i` is `0` (no crossing), `+1` (upcrossing) or `-1` (downcrossing) for the `i`-th output. The affect resolves the crossing direction (and any simultaneous crossings) itself. This mirrors the `affect!(integrator, event_signs)` interface of the underlying [`VectorContinuousCallback`](@extref SciMLBase.VectorContinuousCallback).
32
32
33
33
There is a special type [`PresetTimeComponentCallback`](@ref) which has no explicit condition and triggers the affect at given times.
34
34
This internally generates a [`PresetTimeCallback`](@extref DiffEqCallbacks.PresetTimeCallback) object from `DiffEqCallbacks.jl`.
@@ -64,11 +64,15 @@ affect = ComponentAffect([:u], [:p]) do u, p, ctx
64
64
obs =NWState(ctx.integrator)[VIndex(ctx.vidx, :obs)] # extract some observed state from context
65
65
println("Trigger affect at t=$t")
66
66
end
67
-
vectoraffect =ComponentAffect([:u], [:p]) do u, p, event_idx, ctx
68
-
if event_idx ==1
69
-
u[:u] =0# change state
70
-
else
71
-
u[:p] =0# change parameter
67
+
vectoraffect =ComponentAffect([:u], [:p]) do u, p, event_signs, ctx
68
+
for i ineachindex(event_signs)
69
+
event_signs[i] ==0&&continue# skip outputs that did not cross
70
+
if i ==1
71
+
u[:u] =0# first output crossed: change state
72
+
else
73
+
u[:p] =0# second output crossed: change parameter
74
+
end
75
+
# event_signs[i] is +1 for an upcrossing and -1 for a downcrossing
72
76
end
73
77
end
74
78
```
@@ -78,7 +82,7 @@ However the affect gets passed a `ctx` "context" object, which is a named tuple
78
82
Lastly we need to define the actual callback object using [`ContinuousComponentCallback`](@ref)/[`VectorContinuousComponentCallback`](@ref):
0 commit comments