@@ -6,39 +6,39 @@ using OrdinaryDiffEqSDIRK
66# Test implicit Euler using ImplicitDiscreteProblem
77@testset " Implicit Euler" begin
88 function lotkavolterra (u, p, t)
9- [1.5 * u[1 ] - u[1 ]* u[2 ], - 3.0 * u[2 ] + u[1 ]* u[2 ]]
9+ [1.5 * u[1 ] - u[1 ] * u[2 ], - 3.0 * u[2 ] + u[1 ] * u[2 ]]
1010 end
1111
1212 function f! (resid, u_next, u, p, t)
1313 lv = lotkavolterra (u_next, p, t)
14- resid[1 ] = u_next[1 ] - u[1 ] - 0.01 * lv[1 ]
15- resid[2 ] = u_next[2 ] - u[2 ] - 0.01 * lv[2 ]
14+ resid[1 ] = u_next[1 ] - u[1 ] - 0.01 * lv[1 ]
15+ resid[2 ] = u_next[2 ] - u[2 ] - 0.01 * lv[2 ]
1616 nothing
1717 end
18- u0 = [1. , 1. ]
19- tspan = (0. , 0.5 )
18+ u0 = [1.0 , 1.0 ]
19+ tspan = (0.0 , 0.5 )
2020
2121 idprob = ImplicitDiscreteProblem (f!, u0, tspan, [])
2222 idsol = solve (idprob, SimpleIDSolve (), dt = 0.01 )
2323
2424 oprob = ODEProblem (lotkavolterra, u0, tspan)
2525 osol = solve (oprob, ImplicitEuler ())
2626
27- @test isapprox (idsol[end - 1 ], osol[end ], atol = 0.1 )
27+ @test isapprox (idsol[end - 1 ], osol[end ], atol = 0.1 )
2828
2929 # ## free-fall
3030 # y, dy
31- function ff (u, p, t)
31+ function ff (u, p, t)
3232 [u[2 ], - 9.8 ]
3333 end
3434
35- function g! (resid, u_next, u, p, t)
36- f = ff (u_next, p, t)
37- resid[1 ] = u_next[1 ] - u[1 ] - 0.01 * f[1 ]
38- resid[2 ] = u_next[2 ] - u[2 ] - 0.01 * f[2 ]
35+ function g! (resid, u_next, u, p, t)
36+ f = ff (u_next, p, t)
37+ resid[1 ] = u_next[1 ] - u[1 ] - 0.01 * f[1 ]
38+ resid[2 ] = u_next[2 ] - u[2 ] - 0.01 * f[2 ]
3939 nothing
4040 end
41- u0 = [10. , 0. ]
41+ u0 = [10.0 , 0.0 ]
4242 tspan = (0 , 0.5 )
4343
4444 idprob = ImplicitDiscreteProblem (g!, u0, tspan, [])
@@ -47,17 +47,17 @@ using OrdinaryDiffEqSDIRK
4747 oprob = ODEProblem (ff, u0, tspan)
4848 osol = solve (oprob, ImplicitEuler ())
4949
50- @test isapprox (idsol[end - 1 ], osol[end ], atol = 0.1 )
50+ @test isapprox (idsol[end - 1 ], osol[end ], atol = 0.1 )
5151end
5252
5353@testset " Solver initializes" begin
54- function periodic! (resid, u_next, u, p, t)
55- resid[1 ] = u_next[1 ] - u[1 ] - sin (t* π / 4 )
56- resid[2 ] = 16 - u_next[2 ]^ 2 - u_next[1 ]^ 2
54+ function periodic! (resid, u_next, u, p, t)
55+ resid[1 ] = u_next[1 ] - u[1 ] - sin (t * π / 4 )
56+ resid[2 ] = 16 - u_next[2 ]^ 2 - u_next[1 ]^ 2
5757 end
5858
5959 tsteps = 15
60- u0 = [1. , 3. ]
60+ u0 = [1.0 , 3.0 ]
6161 idprob = ImplicitDiscreteProblem (periodic!, u0, (0 , tsteps), [])
6262 initsol, initfail = DiffEqBase. __init (idprob, SimpleIDSolve ())
6363 @test initsol. u[1 ]^ 2 + initsol. u[2 ]^ 2 ≈ 16
0 commit comments