@@ -6,39 +6,39 @@ using OrdinaryDiffEqSDIRK
6
6
# Test implicit Euler using ImplicitDiscreteProblem
7
7
@testset " Implicit Euler" begin
8
8
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 ]]
10
10
end
11
11
12
12
function f! (resid, u_next, u, p, t)
13
13
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 ]
16
16
nothing
17
17
end
18
- u0 = [1. , 1. ]
19
- tspan = (0. , 0.5 )
18
+ u0 = [1.0 , 1.0 ]
19
+ tspan = (0.0 , 0.5 )
20
20
21
21
idprob = ImplicitDiscreteProblem (f!, u0, tspan, [])
22
22
idsol = solve (idprob, SimpleIDSolve (), dt = 0.01 )
23
23
24
24
oprob = ODEProblem (lotkavolterra, u0, tspan)
25
25
osol = solve (oprob, ImplicitEuler ())
26
26
27
- @test isapprox (idsol[end - 1 ], osol[end ], atol = 0.1 )
27
+ @test isapprox (idsol[end - 1 ], osol[end ], atol = 0.1 )
28
28
29
29
# ## free-fall
30
30
# y, dy
31
- function ff (u, p, t)
31
+ function ff (u, p, t)
32
32
[u[2 ], - 9.8 ]
33
33
end
34
34
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 ]
39
39
nothing
40
40
end
41
- u0 = [10. , 0. ]
41
+ u0 = [10.0 , 0.0 ]
42
42
tspan = (0 , 0.5 )
43
43
44
44
idprob = ImplicitDiscreteProblem (g!, u0, tspan, [])
@@ -47,17 +47,17 @@ using OrdinaryDiffEqSDIRK
47
47
oprob = ODEProblem (ff, u0, tspan)
48
48
osol = solve (oprob, ImplicitEuler ())
49
49
50
- @test isapprox (idsol[end - 1 ], osol[end ], atol = 0.1 )
50
+ @test isapprox (idsol[end - 1 ], osol[end ], atol = 0.1 )
51
51
end
52
52
53
53
@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
57
57
end
58
58
59
59
tsteps = 15
60
- u0 = [1. , 3. ]
60
+ u0 = [1.0 , 3.0 ]
61
61
idprob = ImplicitDiscreteProblem (periodic!, u0, (0 , tsteps), [])
62
62
initsol, initfail = DiffEqBase. __init (idprob, SimpleIDSolve ())
63
63
@test initsol. u[1 ]^ 2 + initsol. u[2 ]^ 2 ≈ 16
0 commit comments