Skip to content

Commit b32d548

Browse files
committed
Add more tests
1 parent 1905833 commit b32d548

File tree

3 files changed

+106
-14
lines changed

3 files changed

+106
-14
lines changed

bench/adaptive_order.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ end
1818
prob = ODEProblem{true, SciMLBase.FullSpecialize}(f, [100.0, 100.0], (0.0, 10.0), nothing)
1919
sol = solve(prob, Vern7(), abstol = 1 / 10^14, reltol = 1 / 10^14);
2020

21+
function f2(du, u, p, t)
22+
t0 = 5.0
23+
δ = 1
24+
κ = 10.0
25+
y = u[1]
26+
ϕ1 = κ / δ / cosh((t - t0) / δ)^2
27+
du[1] = ϕ1 * (y - y^2)
28+
end
29+
30+
prob2 = ODEProblem{true, SciMLBase.FullSpecialize}(f2, [0.5], (0.0, 10.0), nothing)
31+
sol2 = solve(prob2, Vern7(), abstol = 1 / 10^14, reltol = 1 / 10^14);
32+
2133
# Profile
2234
function profile1()
2335
cache1 = init(prob, ExplicitTaylor(order = Val(8)))
@@ -35,6 +47,6 @@ for order in 6:2:12
3547
push!(names, "Taylor $(order)")
3648
push!(setups, Dict(:alg => ExplicitTaylor(order = Val(order + 1))))
3749
end
38-
wp = WorkPrecisionSet([prob], abstols, reltols, setups; names = names, appxsol = [sol],
50+
wp = WorkPrecisionSet([prob2], abstols, reltols, setups; names = names, appxsol = [sol2],
3951
save_everystep = false, numruns = 100, maxiters = 10000)
4052
plot(wp)

bench/non_stiff.jl

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,71 @@
11
using OrdinaryDiffEq, ParameterizedFunctions, DiffEqDevTools, StaticArrays,
22
OrdinaryDiffEqTaylorSeries
3-
using Plots, BenchmarkTools
3+
using Plots, BenchmarkTools, Random, LinearAlgebra
44
gr();
55

6-
abstols = 1.0 ./ 10.0 .^ (6:15)
7-
reltols = 1.0 ./ 10.0 .^ (3:12);
8-
96
function lotka(du, u, p, t)
107
x = u[1]
118
y = u[2]
129
du[1] = p[1] * x - p[2] * x * y
1310
du[2] = -p[3] * y + p[4] * x * y
1411
end
15-
prob = ODEProblem{true, SciMLBase.FullSpecialize}(
12+
prob_lotka = ODEProblem{true, SciMLBase.FullSpecialize}(
1613
lotka, [1.0, 1.0], (0.0, 10.0), [1.5, 1.0, 3.0, 1.0])
17-
sol = solve(prob, Vern7(), abstol = 1 / 10^14, reltol = 1 / 10^14)
14+
sol_lotka = solve(prob_lotka, Vern7(), abstol = 1e-14, reltol = 1e-14);
15+
16+
function fitzhugh(du, u, p, t)
17+
v = u[1]
18+
w = u[2]
19+
a = p[1]
20+
b = p[2]
21+
τinv = p[3]
22+
l = p[4]
23+
du[1] = v - v^3 / 3 - w + l
24+
du[2] = τinv * (v + a - b * w)
25+
end
26+
prob_fitzhugh = ODEProblem{true, SciMLBase.FullSpecialize}(
27+
fitzhugh, [1.0; 1.0], (0.0, 10.0), [0.7, 0.8, 1 / 12.5, 0.5])
28+
sol_fitzhugh = solve(prob_fitzhugh, Vern7(), abstol = 1e-14, reltol = 1e-14);
29+
30+
function rigid(du, u, p, t)
31+
I₁ = p[1]
32+
I₂ = p[2]
33+
I₃ = p[3]
34+
du[1] = I₁ * u[2] * u[3]
35+
du[2] = I₂ * u[1] * u[3]
36+
du[3] = I₃ * u[1] * u[2] + 0.25 * sin(t)^2
37+
end
38+
prob_rigid = ODEProblem{true, SciMLBase.FullSpecialize}(
39+
rigid, [1.0; 0.0; 0.9], (0.0, 10.0), [-2.0, 1.25, -0.5])
40+
sol_rigid = solve(prob_rigid, Vern7(), abstol = 1e-14, reltol = 1e-14);
41+
42+
function make_problem_random_dense(N; seed = 1)
43+
Random.seed!(seed)
44+
λ = -rand(N) .- 1 # eigenvalues in [-2,-1]
45+
D = Diagonal(λ)
46+
Q, _ = qr(randn(N, N)) # random orthogonal matrix
47+
A = Q * D * Q' # similar transformation
48+
f(du, u, p, t) = du .= A * u
49+
u0 = rand(N)
50+
ODEProblem{true, SciMLBase.FullSpecialize}(f, u0, (0.0, 10.0))
51+
end
52+
53+
function make_problem_random_sparse(N; seed = 1, density = 0.1)
54+
Random.seed!(seed)
55+
λ = -rand(N) .- 1 # eigenvalues in [-2,-1]
56+
D = Diagonal(λ)
57+
Q, _ = qr(randn(N, N)) # random orthogonal matrix
58+
A_dense = Q * D * Q' # similar transformation
59+
A_sparse = sparse(A_dense)
60+
A_sparse .= sprand(N, N, density) .* A_sparse # make sparse but keep structure
61+
f(du, u, p, t) = du .= A_sparse * u
62+
u0 = rand(N)
63+
ODEProblem{true, SciMLBase.FullSpecialize}(f, u0, (0.0, 10.0))
64+
end
65+
66+
# prob_dense = make_problem_random_dense(64)
67+
prob_dense = make_problem_poisson(16)
68+
sol_dense = solve(prob_dense, Vern7(), abstol = 1e-14, reltol = 1e-14);
1869

1970
# Make work-precision plot
2071
setups = [Dict(:alg => DP5())
@@ -26,6 +77,17 @@ for order in 6:2:12
2677
push!(names, "Taylor $(order)")
2778
push!(setups, Dict(:alg => ExplicitTaylor(order = Val(order + 1))))
2879
end
29-
wp = WorkPrecisionSet([prob], abstols, reltols, setups; names = names, appxsol = [sol],
30-
save_everystep = false, numruns = 100, maxiters = 10000)
31-
plot(wp)
80+
81+
function make_plot(
82+
prob, sol; numruns = 100, maxiters = 1000, absrange = (-13:-6), relrange = (-10:-3))
83+
abstols = 10.0 .^ absrange
84+
reltols = 10.0 .^ relrange
85+
wp = WorkPrecisionSet([prob], abstols, reltols, setups; names = names, appxsol = [sol],
86+
save_everystep = false, numruns = numruns, maxiters = maxiters)
87+
p = plot(wp)
88+
return p
89+
end
90+
p_lotka = make_plot(prob_lotka, sol_lotka)
91+
p_fitzhugh = make_plot(prob_fitzhugh, sol_fitzhugh)
92+
p_rigid = make_plot(prob_rigid, sol_rigid)
93+
p_dense = make_plot(prob_dense, sol_dense)

bench/threebody.jl

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,30 @@ function py!(q0, J0)
3131
end
3232
q0 = [-0.8, 0.0, 0.0, 0.0]
3333
py!(q0, J0)
34-
tspan = (0.0, 2000.0)
34+
tspan = (0.0, 100.0)
3535
p = SA[μ]
3636
prob = ODEProblem{true, SciMLBase.FullSpecialize}(pcr3bp!, q0, tspan, p)
3737

38-
ref = solve(prob, Vern9(), abstol = 1e-10, reltol = 1e-10)
38+
ref = solve(prob, TaylorMethod(32), abstol = 1e-20)
3939

4040
@benchmark solve($prob, $(TaylorMethod(25)), abstol = 1e-15)
41-
@benchmark solve($prob, $(ExplicitTaylor(order = Val(25))), abstol = 1e-15, reltol = 1e-15)
42-
@benchmark solve($prob, $(Vern9()), abstol = 1e-15, reltol = 1e-15)
41+
@benchmark solve($prob, $(ExplicitTaylor(order = Val(11))), abstol = 1e-10, reltol = 1e-10)
42+
@benchmark solve($prob, $(Vern9()), abstol = 1e-10, reltol = 1e-10)
43+
44+
setups = [Dict(:alg => Vern7())
45+
Dict(:alg => Vern9())
46+
Dict(:alg => ExplicitTaylor(order = Val(13)))
47+
Dict(:alg => ExplicitTaylor(order = Val(17)))
48+
Dict(:alg => ExplicitTaylor(order = Val(21)))
49+
Dict(:alg => ExplicitTaylor(order = Val(25)))
50+
Dict(:alg => TaylorMethod(12))
51+
Dict(:alg => TaylorMethod(16))
52+
Dict(:alg => TaylorMethod(20))
53+
Dict(:alg => TaylorMethod(24))]
54+
abstols = 10.0 .^ (-19:-15)
55+
reltols = 10.0 .^ (-15:-11)
56+
names = ["Vern7", "Vern9", "Taylor12", "Taylor16", "Taylor20", "Taylor24", "TI12", "TI16",
57+
"TI20", "TI24"]
58+
wp = WorkPrecisionSet([prob], abstols, reltols, setups; names = names, appxsol = [ref],
59+
save_everystep = false, numruns = 100)
60+
plot(wp)

0 commit comments

Comments
 (0)