Skip to content

Commit aac3d1f

Browse files
Merge pull request #2478 from SciML/ChrisRackauckas-patch-5
Fix and update documentation for v9
2 parents 6558b25 + 6606f7a commit aac3d1f

18 files changed

+62
-90
lines changed

docs/src/basics/Composition.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@ of `decay2` is the value of the unknown variable `x`.
1616

1717
```@example composition
1818
using ModelingToolkit
19+
using ModelingToolkit: t_nounits as t, D_nounits as D
1920
2021
function decay(; name)
21-
@parameters t a
22+
@parameters a
2223
@variables x(t) f(t)
23-
D = Differential(t)
2424
ODESystem([
2525
D(x) ~ -a * x + f
26-
];
26+
], t;
2727
name = name)
2828
end
2929
3030
@named decay1 = decay()
3131
@named decay2 = decay()
3232
33-
@parameters t
34-
D = Differential(t)
3533
connected = compose(
3634
ODESystem([decay2.f ~ decay1.x
3735
D(decay1.f) ~ 0], t; name = :connected), decay1, decay2)
@@ -137,7 +135,7 @@ sys.y = u * 1.1
137135
In a hierarchical system, variables of the subsystem get namespaced by the name of the system they are in. This prevents naming clashes, but also enforces that every unknown and parameter is local to the subsystem it is used in. In some cases it might be desirable to have variables and parameters that are shared between subsystems, or even global. This can be accomplished as follows.
138136

139137
```julia
140-
@parameters t a b c d e f
138+
@parameters a b c d e f
141139

142140
# a is a local variable
143141
b = ParentScope(b) # b is a variable that belongs to one level up in the hierarchy
@@ -197,19 +195,16 @@ higher level system:
197195

198196
```@example compose
199197
using ModelingToolkit, OrdinaryDiffEq, Plots
198+
using ModelingToolkit: t_nounits as t, D_nounits as D
200199
201200
## Library code
202-
203-
@parameters t
204-
D = Differential(t)
205-
206201
@variables S(t), I(t), R(t)
207202
N = S + I + R
208203
@parameters β, γ
209204
210-
@named seqn = ODESystem([D(S) ~ -β * S * I / N])
211-
@named ieqn = ODESystem([D(I) ~ β * S * I / N - γ * I])
212-
@named reqn = ODESystem([D(R) ~ γ * I])
205+
@named seqn = ODESystem([D(S) ~ -β * S * I / N], t)
206+
@named ieqn = ODESystem([D(I) ~ β * S * I / N - γ * I], t)
207+
@named reqn = ODESystem([D(R) ~ γ * I],t )
213208
214209
sir = compose(
215210
ODESystem(

docs/src/basics/Events.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ friction
6565

6666
```@example events
6767
using ModelingToolkit, OrdinaryDiffEq, Plots
68+
using ModelingToolkit: t_nounits as t, D_nounits as D
69+
6870
function UnitMassWithFriction(k; name)
69-
@variables t x(t)=0 v(t)=0
70-
D = Differential(t)
71+
@variables x(t)=0 v(t)=0
7172
eqs = [D(x) ~ v
7273
D(v) ~ sin(t) - k * sign(v)]
7374
ODESystem(eqs, t; continuous_events = [v ~ 0], name) # when v = 0 there is a discontinuity
@@ -87,8 +88,7 @@ an `affect!` on the state. We can model the same system using ModelingToolkit
8788
like this
8889

8990
```@example events
90-
@variables t x(t)=1 v(t)=0
91-
D = Differential(t)
91+
@variables x(t)=1 v(t)=0
9292
9393
root_eqs = [x ~ 0] # the event happens at the ground x(t) = 0
9494
affect = [v ~ -v] # the effect is that the velocity changes sign
@@ -108,8 +108,7 @@ plot(sol)
108108
Multiple events? No problem! This example models a bouncing ball in 2D that is enclosed by two walls at $y = \pm 1.5$.
109109

110110
```@example events
111-
@variables t x(t)=1 y(t)=0 vx(t)=0 vy(t)=2
112-
D = Differential(t)
111+
@variables x(t)=1 y(t)=0 vx(t)=0 vy(t)=2
113112
114113
continuous_events = [[x ~ 0] => [vx ~ -vx]
115114
[y ~ -1.5, y ~ 1.5] => [vy ~ -vy]]
@@ -229,7 +228,7 @@ Suppose we have a population of `N(t)` cells that can grow and die, and at time
229228

230229
```@example events
231230
@parameters M tinject α
232-
@variables t N(t)
231+
@variables N(t)
233232
Dₜ = Differential(t)
234233
eqs = [Dₜ(N) ~ α - N]
235234

docs/src/basics/FAQ.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ end
102102
This error can come up after running `structural_simplify` on a system that generates dummy derivatives (i.e. variables with `ˍt`). For example, here even though all the variables are defined with initial values, the `ODEProblem` generation will throw an error that defaults are missing from the variable map.
103103

104104
```
105-
@variables t
105+
using ModelingToolkit
106+
using ModelingToolkit: t_nounits as t, D_nounits as D
107+
106108
sts = @variables x1(t)=0.0 x2(t)=0.0 x3(t)=0.0 x4(t)=0.0
107-
D = Differential(t)
108109
eqs = [x1 + x2 + 1 ~ 0
109110
x1 + x2 + x3 + 2 ~ 0
110111
x1 + D(x3) + x4 + 3 ~ 0
@@ -137,9 +138,9 @@ container type. For example:
137138

138139
```
139140
using ModelingToolkit, StaticArrays
140-
@variables t
141+
using ModelingToolkit: t_nounits as t, D_nounits as D
142+
141143
sts = @variables x1(t)=0.0
142-
D = Differential(t)
143144
eqs = [D(x1) ~ 1.1 * x1]
144145
@mtkbuild sys = ODESystem(eqs, t)
145146
prob = ODEProblem{false}(sys, [], (0,1); u0_constructor = x->SVector(x...))

docs/src/basics/Linearization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ The `linearize` function expects the user to specify the inputs ``u`` and the ou
2121

2222
```@example LINEARIZE
2323
using ModelingToolkit
24-
@variables t x(t)=0 y(t)=0 u(t)=0 r(t)=0
24+
using ModelingToolkit: t_nounits as t, D_nounits as D
25+
@variables x(t)=0 y(t)=0 u(t)=0 r(t)=0
2526
@parameters kp = 1
26-
D = Differential(t)
2727
2828
eqs = [u ~ kp * (r - y) # P controller
2929
D(x) ~ -x + u # First-order plant

docs/src/basics/Validation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ second argument.
8383
```@example validation2
8484
using ModelingToolkit, Unitful
8585
# Composite type parameter in registered function
86-
@parameters t
86+
@variables t
8787
D = Differential(t)
8888
struct NewType
8989
f::Any

docs/src/basics/Variable_metadata.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ Descriptive strings can be attached to variables using the `[description = "desc
1010

1111
```@example metadata
1212
using ModelingToolkit
13+
using ModelingToolkit: t_nounits as t, D_nounits as D
1314
@variables u [description = "This is my input"]
1415
getdescription(u)
1516
```
1617

1718
When variables with descriptions are present in systems, they will be printed when the system is shown in the terminal:
1819

1920
```@example metadata
20-
@parameters t
2121
@variables u(t) [description = "A short description of u"]
2222
@parameters p [description = "A description of p"]
2323
@named sys = ODESystem([u ~ p], t)
@@ -50,8 +50,9 @@ current in a resistor. These variables sum up to zero in connections.
5050

5151
```@example connect
5252
using ModelingToolkit
53+
using ModelingToolkit: t_nounits as t, D_nounits as D
5354
54-
@variables t, i(t) [connect = Flow]
55+
@variables i(t) [connect = Flow]
5556
@variables k(t) [connect = Stream]
5657
```
5758

@@ -61,6 +62,8 @@ Designate a variable as either an input or an output using the following
6162

6263
```@example metadata
6364
using ModelingToolkit
65+
using ModelingToolkit: t_nounits as t, D_nounits as D
66+
6467
@variables u [input = true]
6568
isinput(u)
6669
```
@@ -136,8 +139,6 @@ For systems that contain parameters with metadata like described above, have som
136139
In the example below, we define a system with tunable parameters and extract bounds vectors
137140

138141
```@example metadata
139-
@parameters t
140-
Dₜ = Differential(t)
141142
@variables x(t)=0 u(t)=0 [input = true] y(t)=0 [output = true]
142143
@parameters T [tunable = true, bounds = (0, Inf)]
143144
@parameters k [tunable = true, bounds = (0, Inf)]

docs/src/examples/higher_order.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ We utilize the derivative operator twice here to define the second order:
1313

1414
```@example orderlowering
1515
using ModelingToolkit, OrdinaryDiffEq
16+
using ModelingToolkit: t_nounits as t, D_nounits as D
1617
1718
@parameters σ ρ β
18-
@variables t x(t) y(t) z(t)
19-
D = Differential(t)
19+
@variables x(t) y(t) z(t)
2020
2121
eqs = [D(D(x)) ~ σ * (y - x),
2222
D(y) ~ x * (ρ - z) - y,
2323
D(z) ~ x * y - β * z]
2424
25-
@named sys = ODESystem(eqs)
25+
@named sys = ODESystem(eqs,t)
2626
```
2727

2828
Note that we could've used an alternative syntax for 2nd order, i.e.

docs/src/examples/modelingtoolkitize_index_reduction.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pendulum_prob = ODEProblem(pendulum_fun!, u0, tspan, p)
3131
traced_sys = modelingtoolkitize(pendulum_prob)
3232
pendulum_sys = structural_simplify(dae_index_lowering(traced_sys))
3333
prob = ODEProblem(pendulum_sys, [], tspan)
34-
sol = solve(prob, Tsit5(), abstol = 1e-8, reltol = 1e-8)
34+
sol = solve(prob, Rodas5P(), abstol = 1e-8, reltol = 1e-8)
3535
plot(sol, idxs = unknowns(traced_sys))
3636
```
3737

@@ -71,7 +71,7 @@ u0 = [1.0, 0, 0, 0, 0];
7171
p = [9.8, 1];
7272
tspan = (0, 10.0);
7373
pendulum_prob = ODEProblem(pendulum_fun!, u0, tspan, p)
74-
solve(pendulum_prob, Rodas4())
74+
solve(pendulum_prob, Rodas5P())
7575
```
7676

7777
However, one will quickly be greeted with the unfortunate message:
@@ -151,7 +151,7 @@ numerical solver. Let's try that out:
151151
traced_sys = modelingtoolkitize(pendulum_prob)
152152
pendulum_sys = structural_simplify(dae_index_lowering(traced_sys))
153153
prob = ODEProblem(pendulum_sys, Pair[], tspan)
154-
sol = solve(prob, Rodas4())
154+
sol = solve(prob, Rodas5P())
155155
156156
using Plots
157157
plot(sol, idxs = unknowns(traced_sys))

docs/src/examples/perturbation.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ As the first ODE example, we have chosen a simple and well-behaved problem, whic
4545
with the initial conditions $x(0) = 0$, and $\dot{x}(0) = 1$. Note that for $\epsilon = 0$, this equation transforms back to the standard one. Let's start with defining the variables
4646

4747
```julia
48+
using ModelingToolkit: t_nounits as t, D_nounits as D
4849
n = 3
49-
@variables ϵ t y[1:n](t) ∂∂y[1:n](t)
50+
@variables ϵ y[1:n](t) ∂∂y[1:n](t)
5051
```
5152

5253
Next, we define $x$.
@@ -82,7 +83,6 @@ vals = solve_coef(eqs, ∂∂y)
8283
Our system of ODEs is forming. Now is the time to convert `∂∂`s to the correct **Symbolics.jl** form by substitution:
8384

8485
```julia
85-
D = Differential(t)
8686
subs = Dict(∂∂y[i] => D(D(y[i])) for i in eachindex(y))
8787
eqs = [substitute(first(v), subs) ~ substitute(last(v), subs) for v in vals]
8888
```
@@ -147,7 +147,6 @@ vals = solve_coef(eqs, ∂∂y)
147147
Next, we need to replace ``s and `∂∂`s with their **Symbolics.jl** counterparts:
148148

149149
```julia
150-
D = Differential(t)
151150
subs1 = Dict(∂y[i] => D(y[i]) for i in eachindex(y))
152151
subs2 = Dict(∂∂y[i] => D(D(y[i])) for i in eachindex(y))
153152
subs = subs1 subs2

docs/src/examples/spring_mass.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ In this tutorial, we will build a simple component-based model of a spring-mass
66

77
```@example component
88
using ModelingToolkit, Plots, DifferentialEquations, LinearAlgebra
9+
using ModelingToolkit: t_nounits as t, D_nounits as D
910
using Symbolics: scalarize
1011
11-
@variables t
12-
D = Differential(t)
13-
1412
function Mass(; name, m = 1.0, xy = [0.0, 0.0], u = [0.0, 0.0])
1513
ps = @parameters m = m
1614
sts = @variables pos(t)[1:2]=xy v(t)[1:2]=u

docs/src/examples/tearing_parallelism.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ electrical circuits:
1111

1212
```@example tearing
1313
using ModelingToolkit, OrdinaryDiffEq
14+
using ModelingToolkit: t_nounits as t, D_nounits as D
1415
1516
# Basic electric components
16-
@variables t
17-
const D = Differential(t)
1817
@connector function Pin(; name)
1918
@variables v(t)=1.0 i(t)=1.0 [connect = Flow]
2019
ODESystem(Equation[], t, [v, i], [], name = name)

docs/src/tutorials/acausal_components.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ equalities before solving. Let's see this in action.
2121

2222
```@example acausal
2323
using ModelingToolkit, Plots, DifferentialEquations
24+
using ModelingToolkit: t_nounits as t, D_nounits as D
2425
25-
@variables t
2626
@connector Pin begin
2727
v(t)
2828
i(t), [connect = Flow]
@@ -63,8 +63,6 @@ end
6363
end
6464
end
6565
66-
D = Differential(t)
67-
6866
@mtkmodel Capacitor begin
6967
@extend OnePort()
7068
@parameters begin
@@ -213,8 +211,6 @@ equations and unknowns and extend them with a new equation. Note that `v`, `i` a
213211
Using our knowledge of circuits, we similarly construct the `Capacitor`:
214212

215213
```@example acausal
216-
D = Differential(t)
217-
218214
@mtkmodel Capacitor begin
219215
@extend OnePort()
220216
@parameters begin

docs/src/tutorials/bifurcation_diagram_computation.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Let us first consider a simple `NonlinearSystem`:
88

99
```@example Bif1
1010
using ModelingToolkit
11-
@variables t x(t) y(t)
11+
using ModelingToolkit: t_nounits as t, D_nounits as D
12+
13+
@variables x(t) y(t)
1214
@parameters μ α
1315
eqs = [0 ~ μ * x - x^3 + α * y,
1416
0 ~ -y]
@@ -87,10 +89,10 @@ It is also possible to use `ODESystem`s (rather than `NonlinearSystem`s) as inpu
8789

8890
```@example Bif2
8991
using BifurcationKit, ModelingToolkit, Plots
92+
using ModelingToolkit: t_nounits as t, D_nounits as D
9093
91-
@variables t x(t) y(t)
94+
@variables x(t) y(t)
9295
@parameters μ
93-
D = Differential(t)
9496
eqs = [D(x) ~ μ * x - y - x * (x^2 + y^2),
9597
D(y) ~ x + μ * y - y * (x^2 + y^2)]
9698
@mtkbuild osys = ODESystem(eqs, t)

docs/src/tutorials/domain_connections.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ A domain in ModelingToolkit.jl is a network of connected components that share p
66

77
```@example domain
88
using ModelingToolkit
9-
10-
@parameters t
11-
D = Differential(t)
9+
using ModelingToolkit: t_nounits as t, D_nounits as D
1210
1311
@connector function HydraulicPort(; p_int, name)
1412
pars = @parameters begin

0 commit comments

Comments
 (0)