Skip to content

Commit 91fa1e0

Browse files
committed
Added constants to nonlinear systems tests.
1 parent d10d5e1 commit 91fa1e0

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

test/nonlinearsystem.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ canonequal(a, b) = isequal(simplify(a), simplify(b))
88

99
# Define some variables
1010
@parameters t σ ρ β
11+
@constants h=1
1112
@variables x y z
1213

1314
function test_nlsys_inference(name, sys, vs, ps)
@@ -18,7 +19,7 @@ function test_nlsys_inference(name, sys, vs, ps)
1819
end
1920

2021
# Define a nonlinear system
21-
eqs = [0 ~ σ * (y - x),
22+
eqs = [0 ~ σ * (y - x) * h,
2223
0 ~ x *- z) - y,
2324
0 ~ x * y - β * z]
2425
@named ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β], defaults = Dict(x => 2))
@@ -59,7 +60,7 @@ f = @eval eval(nlsys_func)
5960
# Intermediate calculations
6061
a = y - x
6162
# Define a nonlinear system
62-
eqs = [0 ~ σ * a,
63+
eqs = [0 ~ σ * a * h,
6364
0 ~ x *- z) - y,
6465
0 ~ x * y - β * z]
6566
@named ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])
@@ -87,7 +88,7 @@ sol = solve(prob, NewtonRaphson())
8788

8889
@variables u F s a
8990
eqs1 = [
90-
0 ~ σ * (y - x) + F,
91+
0 ~ σ * (y - x) * h + F,
9192
0 ~ x *- z) - u,
9293
0 ~ x * y - β * z,
9394
0 ~ x + y - z - u,
@@ -98,7 +99,7 @@ lorenz1 = lorenz(:lorenz1)
9899
@test_throws ArgumentError NonlinearProblem(lorenz1, zeros(5))
99100
lorenz2 = lorenz(:lorenz2)
100101
@named connected = NonlinearSystem([s ~ a + lorenz1.x
101-
lorenz2.y ~ s
102+
lorenz2.y ~ s * h
102103
lorenz1.F ~ lorenz2.u
103104
lorenz2.F ~ lorenz1.u], [s, a], [],
104105
systems = [lorenz1, lorenz2])
@@ -123,7 +124,7 @@ sol = solve(prob, Rodas5())
123124
# Define a nonlinear system
124125
eqs = [0 ~ σ * (y - x),
125126
0 ~ x *- z) - y,
126-
0 ~ x * y - β * z]
127+
0 ~ x * y - β * z * h]
127128
@named ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])
128129
np = NonlinearProblem(ns, [0, 0, 0], [1, 2, 3], jac = true, sparse = true)
129130
@test calculate_jacobian(ns, sparse = true) isa SparseMatrixCSC
@@ -170,7 +171,7 @@ end
170171
# observed variable handling
171172
@variables t x(t) RHS(t)
172173
@parameters τ
173-
@named fol = NonlinearSystem([0 ~ (1 - x) / τ], [x], [τ]; observed = [RHS ~ (1 - x) / τ])
174+
@named fol = NonlinearSystem([0 ~ (1 - x * h) / τ], [x], [τ]; observed = [RHS ~ (1 - x) / τ])
174175
@test isequal(RHS, @nonamespace fol.RHS)
175176
RHS2 = RHS
176177
@unpack RHS = fol
@@ -179,7 +180,7 @@ RHS2 = RHS
179180
# issue #1358
180181
@variables t
181182
@variables v1(t) v2(t) i1(t) i2(t)
182-
eq = [v1 ~ sin(2pi * t)
183+
eq = [v1 ~ sin(2pi * t * h)
183184
v1 - v2 ~ i1
184185
v2 ~ i2
185186
i1 ~ i2]
@@ -193,7 +194,7 @@ let
193194
eqs = [u[1] ~ 1,
194195
u[2] ~ 1,
195196
u[3] ~ 1,
196-
u[4] ~ 1]
197+
u[4] ~ h]
197198

198199
sys = NonlinearSystem(eqs, collect(u[1:4]), Num[], defaults = Dict([]), name = :test)
199200
prob = NonlinearProblem(sys, ones(length(states(sys))))

0 commit comments

Comments
 (0)