Skip to content

Commit 510a81e

Browse files
Fix test groupings and test setup
1 parent 3b4fb73 commit 510a81e

File tree

88 files changed

+1139
-988
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1139
-988
lines changed

docs/make.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mathengine = MathJax3(Dict(:loader => Dict("load" => ["[tex]/require", "[tex]/ma
1616
"ams",
1717
"autoload",
1818
"mathtools",
19-
"require",
19+
"require"
2020
])))
2121

2222
makedocs(sitename = "ModelingToolkit.jl",

docs/pages.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ pages = [
1010
"tutorials/parameter_identifiability.md",
1111
"tutorials/bifurcation_diagram_computation.md",
1212
"tutorials/domain_connections.md"],
13-
"Examples" => Any["Basic Examples" => Any["examples/higher_order.md",
13+
"Examples" => Any[
14+
"Basic Examples" => Any["examples/higher_order.md",
1415
"examples/spring_mass.md",
1516
"examples/modelingtoolkitize_index_reduction.md",
1617
"examples/parsing.md"],
@@ -34,5 +35,5 @@ pages = [
3435
"systems/OptimizationSystem.md",
3536
"systems/PDESystem.md"],
3637
"comparison.md",
37-
"internals.md",
38+
"internals.md"
3839
]

docs/src/basics/Composition.md

+22-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function decay(; name)
2222
@variables x(t) f(t)
2323
D = Differential(t)
2424
ODESystem([
25-
D(x) ~ -a * x + f,
25+
D(x) ~ -a * x + f
2626
];
2727
name = name)
2828
end
@@ -32,8 +32,9 @@ end
3232
3333
@parameters t
3434
D = Differential(t)
35-
connected = compose(ODESystem([decay2.f ~ decay1.x
36-
D(decay1.f) ~ 0], t; name = :connected), decay1, decay2)
35+
connected = compose(
36+
ODESystem([decay2.f ~ decay1.x
37+
D(decay1.f) ~ 0], t; name = :connected), decay1, decay2)
3738
3839
equations(connected)
3940
@@ -52,10 +53,10 @@ Now we can solve the system:
5253

5354
```@example composition
5455
x0 = [decay1.x => 1.0
55-
decay1.f => 0.0
56-
decay2.x => 1.0]
56+
decay1.f => 0.0
57+
decay2.x => 1.0]
5758
p = [decay1.a => 0.1
58-
decay2.a => 0.2]
59+
decay2.a => 0.2]
5960
6061
using DifferentialEquations
6162
prob = ODEProblem(simplified_sys, x0, (0.0, 100.0), p)
@@ -96,7 +97,7 @@ in their namespaced form. For example:
9697

9798
```julia
9899
u0 = [x => 2.0
99-
subsys.x => 2.0]
100+
subsys.x => 2.0]
100101
```
101102

102103
Note that any default values within the given subcomponent will be
@@ -210,19 +211,27 @@ N = S + I + R
210211
@named ieqn = ODESystem([D(I) ~ β * S * I / N - γ * I])
211212
@named reqn = ODESystem([D(R) ~ γ * I])
212213
213-
sir = compose(ODESystem([
214+
sir = compose(
215+
ODESystem(
216+
[
214217
S ~ ieqn.S,
215218
I ~ seqn.I,
216219
R ~ ieqn.R,
217220
ieqn.S ~ seqn.S,
218221
seqn.I ~ ieqn.I,
219222
seqn.R ~ reqn.R,
220223
ieqn.R ~ reqn.R,
221-
reqn.I ~ ieqn.I], t, [S, I, R], [β, γ],
224+
reqn.I ~ ieqn.I],
225+
t,
226+
[S, I, R],
227+
[β, γ],
222228
defaults = [seqn.β => β
223-
ieqn.β => β
224-
ieqn.γ => γ
225-
reqn.γ => γ], name = :sir), seqn, ieqn, reqn)
229+
ieqn.β => β
230+
ieqn.γ => γ
231+
reqn.γ => γ], name = :sir),
232+
seqn,
233+
ieqn,
234+
reqn)
226235
```
227236

228237
Note that the unknowns are forwarded by an equality relationship, while
@@ -244,7 +253,7 @@ u0 = [seqn.S => 990.0,
244253
reqn.R => 0.0]
245254
246255
p = [β => 0.5
247-
γ => 0.25]
256+
γ => 0.25]
248257
249258
tspan = (0.0, 40.0)
250259
prob = ODEProblem(sireqn_simple, u0, tspan, p, jac = true)

docs/src/basics/Events.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function UnitMassWithFriction(k; name)
6969
@variables t x(t)=0 v(t)=0
7070
D = Differential(t)
7171
eqs = [D(x) ~ v
72-
D(v) ~ sin(t) - k * sign(v)]
72+
D(v) ~ sin(t) - k * sign(v)]
7373
ODESystem(eqs, t; continuous_events = [v ~ 0], name) # when v = 0 there is a discontinuity
7474
end
7575
@mtkbuild m = UnitMassWithFriction(0.7)
@@ -94,7 +94,7 @@ 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
9595
9696
@mtkbuild ball = ODESystem([D(x) ~ v
97-
D(v) ~ -9.8], t; continuous_events = root_eqs => affect) # equation => affect
97+
D(v) ~ -9.8], t; continuous_events = root_eqs => affect) # equation => affect
9898
9999
tspan = (0.0, 5.0)
100100
prob = ODEProblem(ball, Pair[], tspan)
@@ -112,13 +112,14 @@ Multiple events? No problem! This example models a bouncing ball in 2D that is e
112112
D = Differential(t)
113113
114114
continuous_events = [[x ~ 0] => [vx ~ -vx]
115-
[y ~ -1.5, y ~ 1.5] => [vy ~ -vy]]
115+
[y ~ -1.5, y ~ 1.5] => [vy ~ -vy]]
116116
117-
@mtkbuild ball = ODESystem([
117+
@mtkbuild ball = ODESystem(
118+
[
118119
D(x) ~ vx,
119120
D(y) ~ vy,
120121
D(vx) ~ -9.8 - 0.1vx, # gravity + some small air resistance
121-
D(vy) ~ -0.1vy,
122+
D(vy) ~ -0.1vy
122123
], t; continuous_events)
123124
124125
tspan = (0.0, 10.0)
@@ -185,7 +186,7 @@ affect interface:
185186
sts = @variables x(t), v(t)
186187
par = @parameters g = 9.8
187188
bb_eqs = [D(x) ~ v
188-
D(v) ~ -g]
189+
D(v) ~ -g]
189190
190191
function bb_affect!(integ, u, p, ctx)
191192
integ.u[u.v] = -integ.u[u.v]

docs/src/basics/Linearization.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ using ModelingToolkit
2626
D = Differential(t)
2727
2828
eqs = [u ~ kp * (r - y) # P controller
29-
D(x) ~ -x + u # First-order plant
30-
y ~ x] # Output equation
29+
D(x) ~ -x + u # First-order plant
30+
y ~ x] # Output equation
3131
3232
@named sys = ODESystem(eqs, t)
3333
matrices, simplified_sys = linearize(sys, [r], [y]) # Linearize from r to y

docs/src/basics/Validation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Units may be assigned with the following syntax.
1010
using ModelingToolkit, Unitful
1111
@variables t [unit = u"s"] x(t) [unit = u"m"] g(t) w(t) [unit = "Hz"]
1212
13-
@variables(t, [unit = u"s"], x(t), [unit = u"m"], g(t), w(t), [unit = "Hz"])
13+
@variables(t, [unit = u"s"], x(t), [unit = u"m"], g(t), w(t),[unit = "Hz"])
1414
1515
@variables(begin
1616
t, [unit = u"s"],

docs/src/basics/Variable_metadata.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Dₜ = Differential(t)
142142
@parameters T [tunable = true, bounds = (0, Inf)]
143143
@parameters k [tunable = true, bounds = (0, Inf)]
144144
eqs = [Dₜ(x) ~ (-x + k * u) / T # A first-order system with time constant T and gain k
145-
y ~ x]
145+
y ~ x]
146146
sys = ODESystem(eqs, t, name = :tunable_first_order)
147147
```
148148

docs/src/examples/parsing.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ symbolic forms from that? For example, say we had the following system we wanted
77

88
```@example parsing
99
ex = [:(y ~ x)
10-
:(y ~ -2x + 3 / z)
11-
:(z ~ 2)]
10+
:(y ~ -2x + 3 / z)
11+
:(z ~ 2)]
1212
```
1313

1414
We can use the function `parse_expr_to_symbolic` from Symbolics.jl to generate the symbolic

docs/src/examples/spring_mass.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ end
2626
2727
function connect_spring(spring, a, b)
2828
[spring.x ~ norm(scalarize(a .- b))
29-
scalarize(spring.dir .~ scalarize(a .- b))]
29+
scalarize(spring.dir .~ scalarize(a .- b))]
3030
end
3131
3232
function spring_force(spring)
@@ -43,7 +43,7 @@ g = [0.0, -9.81]
4343
@named spring = Spring(k = k, l = l)
4444
4545
eqs = [connect_spring(spring, mass.pos, center)
46-
scalarize(D.(mass.v) .~ spring_force(spring) / mass.m .+ g)]
46+
scalarize(D.(mass.v) .~ spring_force(spring) / mass.m .+ g)]
4747
4848
@named _model = ODESystem(eqs, t, [spring.x; spring.dir; mass.pos], [])
4949
@named model = compose(_model, mass, spring)
@@ -96,7 +96,7 @@ We now define functions that help construct the equations for a mass-spring syst
9696
```@example component
9797
function connect_spring(spring, a, b)
9898
[spring.x ~ norm(scalarize(a .- b))
99-
scalarize(spring.dir .~ scalarize(a .- b))]
99+
scalarize(spring.dir .~ scalarize(a .- b))]
100100
end
101101
```
102102

@@ -125,7 +125,7 @@ We can now create the equations describing this system, by connecting `spring` t
125125

126126
```@example component
127127
eqs = [connect_spring(spring, mass.pos, center)
128-
scalarize(D.(mass.v) .~ spring_force(spring) / mass.m .+ g)]
128+
scalarize(D.(mass.v) .~ spring_force(spring) / mass.m .+ g)]
129129
```
130130

131131
Finally, we can build the model using these equations and components.

docs/src/examples/tearing_parallelism.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function ConstantVoltage(; name, V = 1.0)
3232
@named n = Pin()
3333
@parameters V = V
3434
eqs = [V ~ p.v - n.v
35-
0 ~ p.i + n.i]
35+
0 ~ p.i + n.i]
3636
compose(ODESystem(eqs, t, [], [V], name = name), p, n)
3737
end
3838
@@ -48,10 +48,10 @@ function HeatingResistor(; name, R = 1.0, TAmbient = 293.15, alpha = 1.0)
4848
@variables v(t) RTherm(t)
4949
@parameters R=R TAmbient=TAmbient alpha=alpha
5050
eqs = [RTherm ~ R * (1 + alpha * (h.T - TAmbient))
51-
v ~ p.i * RTherm
52-
h.Q_flow ~ -v * p.i # -LossPower
53-
v ~ p.v - n.v
54-
0 ~ p.i + n.i]
51+
v ~ p.i * RTherm
52+
h.Q_flow ~ -v * p.i # -LossPower
53+
v ~ p.v - n.v
54+
0 ~ p.i + n.i]
5555
compose(ODESystem(eqs, t, [v, RTherm], [R, TAmbient, alpha],
5656
name = name), p, n, h)
5757
end
@@ -61,7 +61,7 @@ function HeatCapacitor(; name, rho = 8050, V = 1, cp = 460, TAmbient = 293.15)
6161
C = rho * V * cp
6262
@named h = HeatPort()
6363
eqs = [
64-
D(h.T) ~ h.Q_flow / C,
64+
D(h.T) ~ h.Q_flow / C
6565
]
6666
compose(ODESystem(eqs, t, [], [rho, V, cp],
6767
name = name), h)
@@ -73,8 +73,8 @@ function Capacitor(; name, C = 1.0)
7373
@variables v(t) = 0.0
7474
@parameters C = C
7575
eqs = [v ~ p.v - n.v
76-
0 ~ p.i + n.i
77-
D(v) ~ p.i / C]
76+
0 ~ p.i + n.i
77+
D(v) ~ p.i / C]
7878
compose(ODESystem(eqs, t, [v], [C],
7979
name = name), p, n)
8080
end
@@ -85,9 +85,9 @@ function parallel_rc_model(i; name, source, ground, R, C)
8585
heat_capacitor = HeatCapacitor(name = Symbol(:heat_capacitor, i))
8686
8787
rc_eqs = [connect(source.p, resistor.p)
88-
connect(resistor.n, capacitor.p)
89-
connect(capacitor.n, source.n, ground.g)
90-
connect(resistor.h, heat_capacitor.h)]
88+
connect(resistor.n, capacitor.p)
89+
connect(capacitor.n, source.n, ground.g)
90+
connect(resistor.h, heat_capacitor.h)]
9191
9292
compose(ODESystem(rc_eqs, t, name = Symbol(name, i)),
9393
[resistor, capacitor, source, ground, heat_capacitor])
@@ -113,7 +113,7 @@ end;
113113
@variables E(t) = 0.0
114114
eqs = [
115115
D(E) ~ sum(((i, sys),) -> getproperty(sys, Symbol(:resistor, i)).h.Q_flow,
116-
enumerate(rc_systems)),
116+
enumerate(rc_systems))
117117
]
118118
@named _big_rc = ODESystem(eqs, t, [E], [])
119119
@named big_rc = compose(_big_rc, rc_systems)
@@ -155,7 +155,8 @@ ts = TearingState(expand_connections(big_rc))
155155
inc_org = BipartiteGraphs.incidence_matrix(ts.structure.graph)
156156
blt_org = StructuralTransformations.sorted_incidence_matrix(ts, only_algeqs = true,
157157
only_algvars = true)
158-
blt_reduced = StructuralTransformations.sorted_incidence_matrix(ModelingToolkit.get_tearing_state(sys),
158+
blt_reduced = StructuralTransformations.sorted_incidence_matrix(
159+
ModelingToolkit.get_tearing_state(sys),
159160
only_algeqs = true,
160161
only_algvars = true)
161162
```

docs/src/tutorials/acausal_components.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ end
102102
103103
@mtkbuild rc_model = RCModel(resistor.R = 2.0)
104104
u0 = [
105-
rc_model.capacitor.v => 0.0,
105+
rc_model.capacitor.v => 0.0
106106
]
107107
prob = ODEProblem(rc_model, u0, (0, 10.0))
108108
sol = solve(prob)
@@ -316,7 +316,7 @@ This is done as follows:
316316

317317
```@example acausal
318318
u0 = [rc_model.capacitor.v => 0.0
319-
rc_model.capacitor.p.i => 0.0]
319+
rc_model.capacitor.p.i => 0.0]
320320
321321
prob = ODEProblem(rc_model, u0, (0, 10.0))
322322
sol = solve(prob)

0 commit comments

Comments
 (0)