Skip to content

Commit 3045cb1

Browse files
remove t and D definitions
1 parent 4cd7d1b commit 3045cb1

16 files changed

+44
-69
lines changed

docs/src/basics/Composition.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ using ModelingToolkit: t_nounits as t, D_nounits as D
2121
function decay(; name)
2222
@parameters a
2323
@variables x(t) f(t)
24-
D = Differential(t)
2524
ODESystem([
2625
D(x) ~ -a * x + f
2726
], t;
@@ -31,7 +30,6 @@ end
3130
@named decay1 = decay()
3231
@named decay2 = decay()
3332
34-
D = Differential(t)
3533
connected = compose(
3634
ODESystem([decay2.f ~ decay1.x
3735
D(decay1.f) ~ 0], t; name = :connected), decay1, decay2)

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/Variable_metadata.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

docs/src/examples/higher_order.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ 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,

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

0 commit comments

Comments
 (0)