Skip to content

Commit 8b170a2

Browse files
committed
Update tests
1 parent a62167c commit 8b170a2

10 files changed

+33
-26
lines changed

test/abstractsystem.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ using ModelingToolkit
22
using Test
33
MT = ModelingToolkit
44

5-
@variables t x
5+
@parameters t
6+
@variables x
67
struct MyNLS <: MT.AbstractSystem
78
name::Any
89
systems::Any

test/components.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ sol = solve(prob, Tsit5())
304304
Hey there, Pin1!
305305
"""
306306
@connector function Pin1(; name)
307-
@variables t
307+
@parameters t
308308
sts = @variables v(t)=1.0 i(t)=1.0
309309
ODESystem(Equation[], t, sts, []; name = name)
310310
end
@@ -314,7 +314,7 @@ sol = solve(prob, Tsit5())
314314
Hey there, Pin2!
315315
"""
316316
@component function Pin2(; name)
317-
@variables t
317+
@parameters t
318318
sts = @variables v(t)=1.0 i(t)=1.0
319319
ODESystem(Equation[], t, sts, []; name = name)
320320
end

test/constants.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ UMT = ModelingToolkit.UnitfulUnitCheck
66
@constants a = 1
77
@test_throws MT.ArgumentError @constants b
88

9-
@variables t x(t) w(t)
9+
@parameters t
10+
@variables x(t) w(t)
1011
D = Differential(t)
1112
eqs = [D(x) ~ a]
1213
@named sys = ODESystem(eqs, t)
@@ -28,7 +29,8 @@ simp = structural_simplify(sys)
2829
@constants β=1 [unit = u"m/s"]
2930
UMT.get_unit(β)
3031
@test MT.isconstant(β)
31-
@variables t [unit = u"s"] x(t) [unit = u"m"]
32+
@parameters t [unit = u"s"]
33+
@variables x(t) [unit = u"m"]
3234
D = Differential(t)
3335
eqs = [D(x) ~ β]
3436
@named sys = ODESystem(eqs, t)

test/direct.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ reference_jac = sparse(ModelingToolkit.jacobian(du, [x, y, z]))
5959
findnz(reference_jac)[[1, 2]]
6060

6161
let
62-
@variables t x(t) y(t) z(t)
62+
@parameters t
63+
@variables x(t) y(t) z(t)
6364
@test ModelingToolkit.exprs_occur_in([x, y, z], x^2 * y) == [true, true, false]
6465
end
6566

@@ -196,7 +197,7 @@ test_worldage()
196197

197198
let
198199
@register_symbolic foo(x)
199-
@variables t
200+
@parameters t
200201
D = Differential(t)
201202

202203
@test isequal(expand_derivatives(D(foo(t))), D(foo(t)))

test/downstream/linearize.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using ModelingToolkit, Test
22

33
# r is an input, and y is an output.
4-
@variables t x(t)=0 y(t)=0 u(t)=0 r(t)=0
5-
@variables t x(t)=0 y(t)=0 u(t)=0 r(t)=0 [input = true]
4+
@parameters t
5+
@variables x(t)=0 y(t)=0 u(t)=0 r(t)=0
6+
@variables x(t)=0 y(t)=0 u(t)=0 r(t)=0 [input = true]
67
@parameters kp = 1
78
D = Differential(t)
89

test/nonlinearsystem.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ lorenz2 = lorenz(:lorenz2)
115115

116116
# system promotion
117117
using OrdinaryDiffEq
118-
@variables t
118+
@parameters t
119119
D = Differential(t)
120120
@named subsys = convert_system(ODESystem, lorenz1, t)
121121
@named sys = ODESystem([D(subsys.x) ~ subsys.x + subsys.x], t, systems = [subsys])
@@ -178,8 +178,8 @@ end
178178
end
179179

180180
# observed variable handling
181-
@variables t x(t) RHS(t)
182-
@parameters τ
181+
@parameters t τ
182+
@variables x(t) RHS(t)
183183
@named fol = NonlinearSystem([0 ~ (1 - x * h) / τ], [x], [τ];
184184
observed = [RHS ~ (1 - x) / τ])
185185
@test isequal(RHS, @nonamespace fol.RHS)
@@ -188,7 +188,7 @@ RHS2 = RHS
188188
@test isequal(RHS, RHS2)
189189

190190
# issue #1358
191-
@variables t
191+
@parameters t
192192
@variables v1(t) v2(t) i1(t) i2(t)
193193
eq = [v1 ~ sin(2pi * t * h)
194194
v1 - v2 ~ i1

test/sdesystem.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ fdif!(du, u0, p, t)
458458

459459
# issue #819
460460
@testset "Combined system name collisions" begin
461-
@variables t
461+
@parameters t
462462
eqs_short = [D(x) ~ σ * (y - x),
463463
D(y) ~ x *- z) - y
464464
]
@@ -619,8 +619,8 @@ solve(prob, LambaEulerHeun(), seed = 1)
619619

620620
# Test ill-formed due to more equations than states in noise equations
621621

622-
@parameters p d
623-
@variables t X(t)
622+
@parameters t p d
623+
@variables X(t)
624624
eqs = [D(X) ~ p - d * X]
625625
noise_eqs = [sqrt(p), -sqrt(d * X)]
626626
@test_throws ArgumentError SDESystem(eqs, noise_eqs, t, [X], [p, d]; name = :ssys)

test/units.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ using ModelingToolkit, OrdinaryDiffEq, JumpProcesses, Unitful
22
using Test
33
MT = ModelingToolkit
44
UMT = ModelingToolkit.UnitfulUnitCheck
5-
@parameters τ [unit = u"ms"] γ
6-
@variables t [unit = u"ms"] E(t) [unit = u"kJ"] P(t) [unit = u"MW"]
5+
@parameters t [unit = u"ms"] τ [unit = u"ms"] γ
6+
@variables E(t) [unit = u"kJ"] P(t) [unit = u"MW"]
77
D = Differential(t)
88

99
#This is how equivalent works:
@@ -94,8 +94,8 @@ bad_length_eqs = [connect(op, lp)]
9494
@test_throws MT.ValidationError ODESystem(bad_eqs, t, [], []; name = :sys)
9595

9696
# Array variables
97-
@variables t [unit = u"s"] x(t)[1:3] [unit = u"m"]
98-
@parameters v[1:3]=[1, 2, 3] [unit = u"m/s"]
97+
@parameters t [unit = u"s"] v[1:3]=[1, 2, 3] [unit = u"m/s"]
98+
@variables x(t)[1:3] [unit = u"m"]
9999
D = Differential(t)
100100
eqs = D.(x) .~ v
101101
ODESystem(eqs, t, name = :sys)
@@ -109,8 +109,8 @@ eqs = [
109109
@named nls = NonlinearSystem(eqs, [x], [a])
110110

111111
# SDE test w/ noise vector
112-
@parameters τ [unit = u"ms"] Q [unit = u"MW"]
113-
@variables t [unit = u"ms"] E(t) [unit = u"kJ"] P(t) [unit = u"MW"]
112+
@parameters t [unit = u"ms"] τ [unit = u"ms"] Q [unit = u"MW"]
113+
@variables E(t) [unit = u"kJ"] P(t) [unit = u"MW"]
114114
D = Differential(t)
115115
eqs = [D(E) ~ P - E / τ
116116
P ~ Q]
@@ -130,8 +130,8 @@ noiseeqs = [0.1u"MW" 0.1u"MW"
130130
@test !UMT.validate(eqs, noiseeqs)
131131

132132
# Non-trivial simplifications
133-
@variables t [unit = u"s"] V(t) [unit = u"m"^3] L(t) [unit = u"m"]
134-
@parameters v [unit = u"m/s"] r [unit = u"m"^3 / u"s"]
133+
@parameters t [unit = u"s"] v [unit = u"m/s"] r [unit = u"m"^3 / u"s"]
134+
@variables V(t) [unit = u"m"^3] L(t) [unit = u"m"]
135135
D = Differential(t)
136136
eqs = [D(L) ~ v,
137137
V ~ L^3]

test/variable_parsing.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ a = rename(value(x), :a)
115115
@test getmetadata(x, VariableConnectType) == Flow
116116
@test getmetadata(x, VariableUnit) == u
117117

118-
@variables t x(t)=1 [connect = Flow, unit = u]
118+
@parameters t
119+
@variables x(t)=1 [connect = Flow, unit = u]
119120

120121
@test getmetadata(x, VariableDefaultValue) == 1
121122
@test getmetadata(x, VariableConnectType) == Flow

test/variable_utils.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ new = (((1 / β - 1) + δ) / γ)^(1 / (γ - 1))
1818
# Continuous
1919
using ModelingToolkit: isdifferential, vars, collect_differential_variables,
2020
collect_ivs
21-
@variables t u(t) y(t)
21+
@parameters t
22+
@variables u(t) y(t)
2223
D = Differential(t)
2324
eq = D(y) ~ u
2425
v = vars(eq)

0 commit comments

Comments
 (0)