Skip to content

Commit 00a736c

Browse files
committed
docs: fix more doc examples
1 parent b28b416 commit 00a736c

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

docs/src/basics/Events.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ event time, the event condition now returns false. Here we used logical and,
330330
cannot be used within symbolic expressions.
331331

332332
Let's now also add a drug at time `tkill` that turns off production of new
333-
cells, modeled by setting `α = 0.0`
333+
cells, modeled by setting `α = 0.0`. Since this is a parameter we must explicitly
334+
set it as `discrete_parameters`.
334335

335336
```@example events
336337
@parameters tkill
@@ -339,7 +340,8 @@ cells, modeled by setting `α = 0.0`
339340
injection = (t == tinject) => [N ~ Pre(N) + M]
340341
341342
# at time tkill we turn off production of cells
342-
killing = (t == tkill) => [α ~ 0.0]
343+
killing = ModelingToolkit.SymbolicDiscreteCallback(
344+
(t == tkill) => [α ~ 0.0]; discrete_parameters = α, iv = t)
343345
344346
tspan = (0.0, 30.0)
345347
p = [α => 100.0, tinject => 10.0, M => 50, tkill => 20.0]
@@ -368,7 +370,8 @@ As such, our last example with treatment and killing could instead be modeled by
368370

369371
```@example events
370372
injection = [10.0] => [N ~ Pre(N) + M]
371-
killing = [20.0] => [α ~ 0.0]
373+
killing = ModelingToolkit.SymbolicDiscreteCallback(
374+
[20.0] => [α ~ 0.0], discrete_parameters = α, iv = t)
372375
373376
p = [α => 100.0, M => 50]
374377
@mtkbuild osys = ODESystem(eqs, t, [N], [α, M];
@@ -409,7 +412,8 @@ example:
409412
@variables x(t)
410413
@parameters c(t)
411414
412-
ev = ModelingToolkit.SymbolicDiscreteCallback(1.0 => [c ~ Pre(c) + 1], discrete_parameters = c, iv = t)
415+
ev = ModelingToolkit.SymbolicDiscreteCallback(
416+
1.0 => [c ~ Pre(c) + 1], discrete_parameters = c, iv = t)
413417
@mtkbuild sys = ODESystem(
414418
D(x) ~ c * cos(x), t, [x], [c]; discrete_events = [ev])
415419
@@ -424,7 +428,7 @@ The solution object can also be interpolated with the discrete variables
424428
sol([1.0, 2.0], idxs = [c, c * cos(x)])
425429
```
426430

427-
Note that only time-dependent parameters that are explicitly passed as `discrete_parameters`
431+
Note that only time-dependent parameters that are explicitly passed as `discrete_parameters`
428432
will be saved. If we repeat the above example with `c` not a `discrete_parameter`:
429433

430434
```@example events

docs/src/tutorials/fmi.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ we will create a model from a CoSimulation FMU.
9494
```@example fmi
9595
fmu = loadFMU("SpringPendulum1D", "Dymola", "2023x", "3.0"; type = :CS)
9696
@named inner = ModelingToolkit.FMIComponent(
97-
Val(3); fmu, communication_step_size = 0.001, type = :CS)
97+
Val(3); fmu, communication_step_size = 0.001, type = :CS,
98+
reinitializealg = BrownFullBasicInit())
9899
```
99100

100101
This FMU has fewer equations, partly due to missing aliasing variables and partly due to being a CS FMU.
@@ -170,7 +171,8 @@ end
170171
`a` and `b` are inputs, `c` is a state, and `out` and `out2` are outputs of the component.
171172

172173
```@repl fmi
173-
@named adder = ModelingToolkit.FMIComponent(Val(2); fmu, type = :ME);
174+
@named adder = ModelingToolkit.FMIComponent(
175+
Val(2); fmu, type = :ME, reinitializealg = SciMLBase.BrownFullBasicInit());
174176
isinput(adder.a)
175177
isinput(adder.b)
176178
isoutput(adder.out)
@@ -214,7 +216,7 @@ fmu = loadFMU(
214216
type = :CS)
215217
@named adder = ModelingToolkit.FMIComponent(
216218
Val(2); fmu, type = :CS, communication_step_size = 1e-3,
217-
reinitializealg = BrownFullBasicInit())
219+
reinitializealg = SciMLBase.BrownFullBasicInit())
218220
@mtkbuild sys = ODESystem(
219221
[adder.a ~ a, adder.b ~ b, D(a) ~ t,
220222
D(b) ~ adder.out + adder.c, c^2 ~ adder.out + adder.value],

ext/MTKFMIExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ with the name `namespace__variable`.
9393
- `name`: The name of the system.
9494
"""
9595
function MTK.FMIComponent(::Val{Ver}; fmu = nothing, tolerance = 1e-6,
96-
communication_step_size = nothing, type, name, reinitializealg = nothing) where {Ver}
96+
communication_step_size = nothing, reinitializealg = nothing, type, name) where {Ver}
9797
if Ver != 2 && Ver != 3
9898
throw(ArgumentError("FMI Version must be `2` or `3`"))
9999
end

0 commit comments

Comments
 (0)