Skip to content

Commit 26e4842

Browse files
Merge pull request #977 from SciML/defaults
A new round of ODE defaults
2 parents b275fb7 + ab704b1 commit 26e4842

File tree

2 files changed

+25
-46
lines changed

2 files changed

+25
-46
lines changed

src/ode_default_alg.jl

+16-37
Original file line numberDiff line numberDiff line change
@@ -23,67 +23,46 @@ function default_algorithm(prob::DiffEqBase.AbstractODEProblem{uType, tType, inp
2323
elseif typeof(prob.f) <: DynamicalODEFunction
2424
if tol_level == :low_tol || tol_level == :med_tol
2525
alg = Tsit5()
26-
elseif tol_level == :high_tol
27-
alg = Vern7(lazy = !callbacks)
2826
else
29-
alg = Vern9(lazy = !callbacks)
27+
alg = Vern7(lazy = !callbacks)
3028
end
3129
else # Standard ODE
32-
if :nonstiff alg_hints || length(prob.u0) > 10000
30+
if :nonstiff alg_hints
3331
# Don't default to implicit here because of memory requirements
3432
# And because the linear system gets unruly
3533
if (!(uEltype <: Float64) && !(uEltype <: Float32) && !(uEltype <: Complex)) ||
36-
tol_level == :extreme_tol
34+
tol_level == :extreme_tol || tol_level == :low_tol
3735
# Most likely higher precision, so use a higher order method
38-
alg = Vern9(lazy = !callbacks)
39-
elseif tol_level == :low_tol
4036
alg = Vern7(lazy = !callbacks)
41-
elseif tol_level == :med_tol
37+
else
4238
alg = Tsit5()
43-
else # tol_level == :high_tol
44-
alg = BS3()
4539
end
4640
elseif :stiff alg_hints || mm # The problem is stiff
4741
if length(prob.u0) > 500
4842
# Use Krylov method when huge!
49-
if !mm
50-
alg = CVODE_BDF(linear_solver = :GMRES)
51-
elseif mm
52-
alg = Rodas4(autodiff = false, linsolve = LinearSolve.KrylovJL_GMRES())
53-
end
54-
elseif length(prob.u0) > 50
55-
if callbacks && !mm
56-
alg = CVODE_BDF()
57-
elseif !callbacks
58-
alg = QNDF(autodiff = false)
59-
else
60-
alg = Rodas4(autodiff = false)
61-
end
43+
alg = FBDF(autodiff = false, linsolve = LinearSolve.KrylovJL_GMRES())
44+
elseif length(prob.u0) > 500
45+
alg = FBDF(autodiff = false)
6246
elseif tol_level == :high_tol
6347
alg = Rosenbrock23(autodiff = false)
6448
else
65-
alg = Rodas4(autodiff = false)
49+
alg = Rodas5P(autodiff = false)
6650
end
6751
else # :auto ∈ alg_hints
68-
if (!(uEltype <: Float64) && !(uEltype <: Float32)) || tol_level == :extreme_tol
52+
if (!(uEltype <: Float64) && !(uEltype <: Float32)) || tol_level == :extreme_tol ||
53+
tol_level == :low_tol
6954
# Most likely higher precision, so use a higher order method
70-
if length(prob.u0) > 100
71-
alg = AutoVern9(KenCarp47(autodiff = false), lazy = !callbacks)
72-
else
73-
alg = AutoVern9(Rodas5P(autodiff = false), lazy = !callbacks)
74-
end
75-
elseif tol_level == :low_tol
7655
if length(prob.u0) > 500
77-
alg = AutoVern7(Rodas4(autodiff = false,
78-
linsolve = LinearSolve.KrylovJL_GMRES()),
79-
lazy = !callbacks)
56+
alg = AutoVern7(KenCarp47(autodiff = false, linsolve = LinearSolve.KrylovJL_GMRES()), lazy = !callbacks)
8057
elseif length(prob.u0) > 50
81-
alg = AutoVern7(TRBDF2(autodiff = false), lazy = !callbacks)
58+
alg = AutoVern7(KenCarp47(autodiff = false), lazy = !callbacks)
8259
else
83-
alg = AutoVern7(Rodas4(autodiff = false), lazy = !callbacks)
60+
alg = AutoVern7(Rodas5P(autodiff = false), lazy = !callbacks)
8461
end
8562
else # :med or low
86-
if length(prob.u0) > 100
63+
if length(prob.u0) > 500
64+
alg = AutoTsit5(TRBDF2(autodiff = false, linsolve = LinearSolve.KrylovJL_GMRES()))
65+
elseif length(prob.u0) > 50
8766
alg = AutoTsit5(TRBDF2(autodiff = false))
8867
else
8968
alg = AutoTsit5(Rosenbrock23(autodiff = false))

test/default_ode_alg_test.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ sol = solve(prob_ode_2Dlinear; reltol = 1e-1)
2020
sol = solve(prob_ode_2Dlinear; reltol = 1e-7)
2121

2222
@test typeof(sol.alg.algs[1]) <: Vern7
23-
@test typeof(sol.alg.algs[2]) <: Rodas4
23+
@test typeof(sol.alg.algs[2]) <: Rodas5P
2424

2525
sol = solve(prob_ode_2Dlinear; reltol = 1e-10)
2626

27-
@test typeof(sol.alg.algs[1]) <: Vern9
27+
@test typeof(sol.alg.algs[1]) <: Vern7
2828
@test typeof(sol.alg.algs[2]) <: Rodas5P
2929

3030
sol = solve(prob_ode_2Dlinear; alg_hints = [:stiff])
3131

32-
@test typeof(sol.alg) <: Rodas4
32+
@test typeof(sol.alg) <: Rodas5P
3333

3434
sol = solve(prob_ode_2Dlinear; alg_hints = [:stiff], reltol = 1e-1)
3535

@@ -46,18 +46,18 @@ prob_ode_bigfloat2Dlinear = ODEProblem(f, map(BigFloat, rand(4, 2)) .* ones(4, 2
4646
(0.0, 1.0))
4747

4848
sol = solve(prob_ode_bigfloat2Dlinear; dt = 1 // 2^(4))
49-
@test typeof(sol.alg.algs[1]) <: Vern9
49+
@test typeof(sol.alg.algs[1]) <: Vern7
5050
@test typeof(sol.alg.algs[2]) <: Rodas5P
5151

5252
default_algorithm(prob_ode_bigfloat2Dlinear; alg_hints = [:stiff])
5353

5454
sol = solve(prob_ode_bigfloat2Dlinear; alg_hints = [:stiff])
5555

56-
@test typeof(sol.alg) <: Rodas4
56+
@test typeof(sol.alg) <: Rodas5P
5757

5858
sol = solve(prob_ode_bigfloat2Dlinear, nothing; alg_hints = [:stiff])
5959

60-
@test typeof(sol.alg) <: Rodas4
60+
@test typeof(sol.alg) <: Rodas5P
6161

6262
struct FooAlg end
6363

@@ -73,21 +73,21 @@ prob = ODEProblem(f, rand(4, 2) .* ones(4, 2) / 2, (0.0, 1.0))
7373

7474
sol = solve(prob; alg_hints = [:stiff])
7575

76-
@test typeof(sol.alg) <: Rodas4
76+
@test typeof(sol.alg) <: Rodas5P
7777

7878
sol = solve(prob; alg_hints = [:stiff], reltol = 1e-1)
7979

8080
@test typeof(sol.alg) <: Rosenbrock23
8181

8282
sol = solve(prob; alg_hints = [:stiff], callback = CallbackSet())
8383

84-
@test typeof(sol.alg) <: Rodas4
84+
@test typeof(sol.alg) <: Rodas5P
8585

8686
prob = ODEProblem(f, rand(4, 2) .* ones(4, 2) / 2, (0.0, 1.0))
8787

8888
alg, kwargs = default_algorithm(prob; alg_hints = [:stiff])
8989

90-
@test typeof(alg) <: Rodas4
90+
@test typeof(alg) <: Rodas5P
9191

9292
m = 1.0
9393
ω = 1.0

0 commit comments

Comments
 (0)