@@ -13,6 +13,12 @@ function test_diffeq_inference(name, de, iv, dvs, ps)
1313 @test Set ([p. name for p ∈ de. ps ]) == Set (ps)
1414 end
1515end
16+ function test_nlsys_inference (name, de, vs, ps)
17+ @testset " NonlinearSystem construction: $name " begin
18+ @test Set (vs) == Set (vs)
19+ @test Set ([p. name for p ∈ de. ps]) == Set (ps)
20+ end
21+ end
1622
1723# Define a differential equation
1824eqs = [D (x) ~ σ* (y- x),
@@ -96,21 +102,14 @@ jac = calculate_jacobian(de)
96102 f = ODEFunction (de)
97103end
98104
99- @test_broken begin
100105# Define a nonlinear system
101106eqs = [0 ~ σ* (y- x),
102107 0 ~ x* (ρ- z)- y,
103108 0 ~ x* y - β* z]
104- ns = NonlinearSystem (eqs,[x,y,z],[t,σ,ρ,β])
105- ns2 = NonlinearSystem (eqs)
106- for el in (:vs , :ps )
107- names2 = sort (collect (var. name for var in getfield (ns2,el)))
108- names = sort (collect (var. name for var in getfield (ns,el)))
109- @test names2 == names
110- end
109+ ns = NonlinearSystem (eqs, [x,y,z])
110+ test_nlsys_inference (" standard" , ns, (x, y, z), (:σ , :ρ , :β ))
111111
112112generate_function (ns, [x,y,z], [σ,ρ,β])
113- end
114113
115114@derivatives D' ~ t
116115@parameters A () B () C ()
@@ -125,16 +124,15 @@ de = ODESystem(eqs)
125124 du ≈ [- 1 , - 1 / 3 ]
126125end
127126
128- @test_broken begin
129127# Now nonlinear system with only variables
130- @variables x y z
128+ @variables x () y () z ()
131129@parameters σ () ρ () β ()
132130
133131# Define a nonlinear system
134132eqs = [0 ~ σ* (y- x),
135133 0 ~ x* (ρ- z)- y,
136134 0 ~ x* y - β* z]
137- ns = NonlinearSystem (eqs, [x,y,z], [σ,ρ,β] )
135+ ns = NonlinearSystem (eqs, [x,y,z])
138136jac = calculate_jacobian (ns)
139137@testset " nlsys jacobian" begin
140138 @test isequal (jac[1 ,1 ], σ * - 1 )
@@ -156,8 +154,7 @@ f = @eval eval(nlsys_func)
156154eqs = [0 ~ σ* a,
157155 0 ~ x* (ρ- z)- y,
158156 0 ~ x* y - β* z]
159- ns = NonlinearSystem (eqs,[x,y,z],[σ,ρ,β ])
157+ ns = NonlinearSystem (eqs, [x,y,z])
160158nlsys_func = generate_function (ns, [x,y,z], [σ,ρ,β])
161159jac = calculate_jacobian (ns)
162160jac = generate_jacobian (ns)
163- end
0 commit comments