11using ModelingToolkit, OrdinaryDiffEq, RecursiveArrayTools, StochasticDiffEq, Test
2+ using StochasticDiffEq
23using SymbolicIndexingInterface
34using ModelingToolkit: t_nounits as t, D_nounits as D
45using Plots: Plots, plot
@@ -173,7 +174,7 @@ sol10 = sol(0.1, idxs = 2)
173174end
174175
175176@testset " Saved subsystem" begin
176- @testset " Pure ODE" begin
177+ @testset " Purely continuous ODE/DAE/SDE-solutions " begin
177178 @variables x (t) y (t)
178179 @parameters p
179180 @mtkbuild sys = ODESystem ([D (x) ~ x + p * y, D (y) ~ 2 p + x^ 2 ], t)
@@ -190,21 +191,44 @@ end
190191 ss1. state_map == ss2. state_map
191192 end
192193
193- sol = solve (prob, Tsit5 (); save_idxs = xidx)
194+ ode_sol = solve (prob, Tsit5 (); save_idxs = xidx)
194195 subsys = SciMLBase. SavedSubsystem (sys, prob. p, [xidx])
195- xvals = sol[x]
196196 # FIXME : hack for save_idxs
197- SciMLBase. @reset sol. saved_subsystem = subsys
198- @test sol[x] == xvals
199- @test is_parameter (sol, p)
200- @test parameter_index (sol, p) == parameter_index (sys, p)
201- @test isequal (only (parameter_symbols (sol)), p)
202- @test is_independent_variable (sol, t)
203-
204- tmp = copy (prob. u0)
205- tmp[xidx] = xvals[2 ]
206- @test state_values (sol, 2 ) == tmp
207- @test state_values (sol) == [state_values (sol, i) for i in 1 : length (sol)]
197+ SciMLBase. @reset ode_sol. saved_subsystem = subsys
198+
199+ @mtkbuild sys = ODESystem ([D (x) ~ x + p * y, 1 ~ sin (y) + cos (x)], t)
200+ xidx = variable_index (sys, x)
201+ prob = DAEProblem (sys, [D (x) => x + p * y, D (y) => 1 / sqrt (1 - (1 - cos (x))^ 2 )],
202+ [x => 1.0 , y => asin (1 - cos (x))], (0.0 , 1.0 ), [p => 2.0 ])
203+ dae_sol = solve (prob, DFBDF (); save_idxs = xidx)
204+ subsys = SciMLBase. SavedSubsystem (sys, prob. p, [xidx])
205+ # FIXME : hack for save_idxs
206+ SciMLBase. @reset dae_sol. saved_subsystem = subsys
207+
208+ @brownian a b
209+ @mtkbuild sys = System ([D (x) ~ x + p * y + x * a, D (y) ~ 2 p + x^ 2 + y * b], t)
210+ xidx = variable_index (sys, x)
211+ prob = SDEProblem (sys, [x => 1.0 , y => 2.0 ], (0.0 , 1.0 ), [p => 2.0 ])
212+ sde_sol = solve (prob, SOSRI (); save_idxs = xidx)
213+ subsys = SciMLBase. SavedSubsystem (sys, prob. p, [xidx])
214+ # FIXME : hack for save_idxs
215+ SciMLBase. @reset sde_sol. saved_subsystem = subsys
216+
217+ for sol in [ode_sol, dae_sol, sde_sol]
218+ prob = sol. prob
219+ subsys = sol. saved_subsystem
220+ xvals = sol[x]
221+ @test sol[x] == xvals
222+ @test is_parameter (sol, p)
223+ @test parameter_index (sol, p) == parameter_index (sys, p)
224+ @test isequal (only (parameter_symbols (sol)), p)
225+ @test is_independent_variable (sol, t)
226+
227+ tmp = copy (prob. u0)
228+ tmp[xidx] = xvals[2 ]
229+ @test state_values (sol, 2 ) == tmp
230+ @test state_values (sol) == [state_values (sol, i) for i in 1 : length (sol)]
231+ end
208232 end
209233
210234 @testset " ODE with callbacks" begin
0 commit comments