@@ -289,7 +289,8 @@ Suppose we have a population of `N(t)` cells that can grow and die, and at time
289289` t1 ` we want to inject ` M ` more cells into the population. We can model this by
290290
291291``` @example events
292- @parameters M tinject α(t)
292+ @parameters M tinject
293+ @discretes α(t)
293294@variables N(t)
294295Dₜ = Differential(t)
295296eqs = [Dₜ(N) ~ α - N]
@@ -411,7 +412,7 @@ example:
411412
412413``` @example events
413414@variables x(t)
414- @parameters c(t)
415+ @discretes c(t)
415416
416417ev = ModelingToolkit.SymbolicDiscreteCallback(
417418 1.0 => [c ~ Pre(c) + 1], discrete_parameters = c, iv = t)
@@ -430,21 +431,9 @@ sol([1.0, 2.0], idxs = [c, c * cos(x)])
430431```
431432
432433Note that only time-dependent parameters that are explicitly passed as ` discrete_parameters `
433- will be saved. If we repeat the above example with ` c ` not a ` discrete_parameter ` :
434-
435- ``` @example events
436- @variables x(t)
437- @parameters c(t)
438-
439- @mtkcompile sys = System(
440- D(x) ~ c * cos(x), t, [x], [c]; discrete_events = [1.0 => [c ~ Pre(c) + 1]])
441-
442- prob = ODEProblem(sys, [x => 0.0, c => 1.0], (0.0, 2pi))
443- sol = solve(prob, Tsit5())
444- sol.ps[c] # sol[c] will error, since `c` is not a timeseries value
445- ```
446-
447- It can be seen that the timeseries for ` c ` is not saved.
434+ will be saved. The ` discrete_parameters ` argument is also required for the callback to compile
435+ successfully - omitting it will result in an error because the equation modifying the discrete
436+ would have no unknowns/observables.
448437
449438## [ (Experimental) Imperative affects] (@id imp_affects)
450439
@@ -464,7 +453,9 @@ Bang-bang control of a heater connected to a leaky plant requires hysteresis in
464453
465454``` @example events
466455@variables temp(t)
467- params = @parameters furnace_on_threshold=0.5 furnace_off_threshold=0.7 furnace_power=1.0 leakage=0.1 furnace_on(t)::Bool=false
456+ @parameters furnace_on_threshold=0.5 furnace_off_threshold=0.7 furnace_power=1.0 leakage=0.1
457+ @discretes furnace_on(t)::Bool = false
458+ params = [furnace_on_threshold, furnace_off_threshold, furnace_power, leakage, furnace_on]
468459eqs = [
469460 D(temp) ~ furnace_on * furnace_power - temp^2 * leakage
470461]
0 commit comments