@@ -3,6 +3,7 @@ using Test
33using ImplicitDiscreteSolve
44using OrdinaryDiffEqCore
55using OrdinaryDiffEqSDIRK
6+ using SciMLBase
67
78# Test implicit Euler using ImplicitDiscreteProblem
89@testset " Implicit Euler" begin
@@ -20,7 +21,7 @@ using OrdinaryDiffEqSDIRK
2021 tspan = (0. , 0.5 )
2122
2223 idprob = ImplicitDiscreteProblem (f!, u0, tspan, []; dt = 0.01 )
23- idsol = solve (idprob, SimpleIDSolve ())
24+ idsol = solve (idprob, IDSolve ())
2425
2526 oprob = ODEProblem (lotkavolterra, u0, tspan)
2627 osol = solve (oprob, ImplicitEuler ())
@@ -43,7 +44,7 @@ using OrdinaryDiffEqSDIRK
4344 tspan = (0 , 0.2 )
4445
4546 idprob = ImplicitDiscreteProblem (g!, u0, tspan, []; dt = 0.01 )
46- idsol = solve (idprob, SimpleIDSolve ())
47+ idsol = solve (idprob, IDSolve ())
4748
4849 oprob = ODEProblem (ff, u0, tspan)
4950 osol = solve (oprob, ImplicitEuler ())
6061 tsteps = 15
6162 u0 = [1. , 3. ]
6263 idprob = ImplicitDiscreteProblem (periodic!, u0, (0 , tsteps), [])
63- integ = init (idprob, SimpleIDSolve ())
64+ integ = init (idprob, IDSolve ())
6465 @test integ. u[1 ]^ 2 + integ. u[2 ]^ 2 ≈ 16
6566
6667 for ts in 1 : tsteps
7778 tsteps = 5
7879 u0 = nothing
7980 idprob = ImplicitDiscreteProblem (empty, u0, (0 , tsteps), [])
80- @test_nowarn integ = init (idprob, SimpleIDSolve ())
81+ @test_nowarn integ = init (idprob, IDSolve ())
82+ end
83+
84+ @testset " Create NonlinearLeastSquaresProblem" begin
85+ function over (u_next, u, p, t)
86+ [u_next[1 ] - 1 , u_next[2 ] - 1 , u_next[1 ] - u_next[2 ]]
87+ end
88+
89+ tsteps = 5
90+ u0 = [1. , 1. ]
91+ idprob = ImplicitDiscreteProblem (ImplicitDiscreteFunction (over, resid_prototype = zeros (3 )), u0, (0 , tsteps), [])
92+ integ = init (idprob, IDSolve ())
93+ @test integ. cache. prob isa NonlinearLeastSquaresProblem
94+
95+ function under (u_next, u, p, t)
96+ [u_next[1 ] - u_next[2 ] - 1 ]
97+ end
98+ idprob = ImplicitDiscreteProblem (ImplicitDiscreteFunction (under; resid_prototype = zeros (1 )), u0, (0 , tsteps), [])
99+ integ = init (idprob, IDSolve ())
100+ @test integ. cache. prob isa NonlinearLeastSquaresProblem
101+
102+ function full (u_next, u, p, t)
103+ [u_next[1 ]^ 2 - 3 , u_next[2 ] - u[1 ]]
104+ end
105+ idprob = ImplicitDiscreteProblem (ImplicitDiscreteFunction (full; resid_prototype = zeros (2 )), u0, (0 , tsteps), [])
106+ integ = init (idprob, IDSolve ())
107+ @test integ. cache. prob isa NonlinearProblem
108+ end
109+
110+ @testset " InitialFailure thrown" begin
111+ function bad (u_next, u, p, t)
112+ [u_next[1 ] - u_next[2 ], u_next[1 ] - 3 , u_next[2 ] - 4 ]
113+ end
114+
115+ u0 = [3. , 4. ]
116+ idprob = ImplicitDiscreteProblem (bad, u0, (0 , 0 ), [])
117+ integ = init (idprob, IDSolve ())
118+ @test check_error (integ) == ReturnCode. InitialFailure
119+ sol = solve (idprob, IDSolve ())
120+ @test length (sol. u) == 1
81121end
0 commit comments