@@ -73,6 +73,24 @@ discu0 = Dict([u0..., x(k - 1) => 0.0, y(k - 1) => 0.0, z(k - 1) => 0.0])
7373push! (syss, discsys)
7474push! (probs, DiscreteProblem (fn, getindex .((discu0,), unknowns (discsys)), (0 , 10 ), ps))
7575
76+ # TODO : Rewrite this example when the MTK codegen is merged
77+ @named sys1 = NonlinearSystem (
78+ [0 ~ x^ 3 * β + y^ 3 * ρ - σ, 0 ~ x^ 2 + 2 x * y + y^ 2 ], [x, y], [σ, β, ρ])
79+ sys1 = complete (sys1)
80+ @named sys2 = NonlinearSystem ([0 ~ z^ 2 - 4 z + 4 ], [z], [])
81+ sys2 = complete (sys2)
82+ @named fullsys = NonlinearSystem (
83+ [0 ~ x^ 3 * β + y^ 3 * ρ - σ, 0 ~ x^ 2 + 2 x * y + y^ 2 , 0 ~ z^ 2 - 4 z + 4 ],
84+ [x, y, z], [σ, β, ρ])
85+ fullsys = complete (fullsys)
86+
87+ prob1 = NonlinearProblem (sys1, u0, p)
88+ prob2 = NonlinearProblem (sys2, u0, prob1. p)
89+ sccprob = SCCNonlinearProblem (
90+ [prob1, prob2], [Returns (nothing ), Returns (nothing )], fullsys, prob1. p, true )
91+ push! (syss, fullsys)
92+ push! (probs, sccprob)
93+
7694for (sys, prob) in zip (syss, probs)
7795 @test parameter_values (prob) isa ModelingToolkit. MTKParameters
7896
274292 @test_throws SciMLBase. CyclicDependencyError remake (
275293 prob; u0 = [x => 2 y + p, y => q + 3 ], p = [p => x + y, q => p + 3 ])
276294end
295+
296+ @testset " SCCNonlinearProblem" begin
297+ @named sys1 = NonlinearSystem (
298+ [0 ~ x^ 3 * β + y^ 3 * ρ - σ, 0 ~ x^ 2 + 2 x * y + y^ 2 ], [x, y], [σ, β, ρ])
299+ sys1 = complete (sys1)
300+ @named sys2 = NonlinearSystem ([0 ~ z^ 2 - 4 z + 4 ], [z], [])
301+ sys2 = complete (sys2)
302+ @named fullsys = NonlinearSystem (
303+ [0 ~ x^ 3 * β + y^ 3 * ρ - σ, 0 ~ x^ 2 + 2 x * y + y^ 2 , 0 ~ z^ 2 - 4 z + 4 ],
304+ [x, y, z], [σ, β, ρ])
305+ fullsys = complete (fullsys)
306+
307+ u0 = [x => 1.0 ,
308+ y => 0.0 ,
309+ z => 0.0 ]
310+
311+ p = [σ => 28.0 ,
312+ ρ => 10.0 ,
313+ β => 8 / 3 ]
314+
315+ prob1 = NonlinearProblem (sys1, u0, p)
316+ prob2 = NonlinearProblem (sys2, u0, prob1. p)
317+ sccprob = SCCNonlinearProblem (
318+ [prob1, prob2], [Returns (nothing ), Returns (nothing )], fullsys, prob1. p, true )
319+
320+ sccprob2 = remake (sccprob; u0 = 2 ones (3 ))
321+ @test state_values (sccprob2) ≈ 2 ones (3 )
322+ @test sccprob2. probs[1 ]. u0 ≈ 2 ones (2 )
323+ @test sccprob2. probs[2 ]. u0 ≈ 2 ones (1 )
324+
325+ sccprob3 = remake (sccprob; p = [σ => 2.0 ])
326+ @test sccprob3. parameter_object === sccprob3. probs[1 ]. p
327+ @test sccprob3. parameter_object === sccprob3. probs[2 ]. p
328+
329+ @test_throws [" parameters_alias" , " SCCNonlinearProblem" ] remake (
330+ sccprob; parameters_alias = false , p = [σ => 2.0 ])
331+
332+ newp = remake_buffer (sys1, prob1. p, [σ], [3.0 ])
333+ sccprob4 = remake (sccprob; parameters_alias = false , p = newp,
334+ probs = [remake (prob1; p = [σ => 3.0 ]), prob2])
335+ @test ! sccprob4. parameters_alias
336+ @test sccprob4. parameter_object != = sccprob4. probs[1 ]. p
337+ @test sccprob4. parameter_object != = sccprob4. probs[2 ]. p
338+ end
0 commit comments