Skip to content

Commit 791f175

Browse files
Merge pull request SciML#2948 from ChrisRackauckas-Claude/fix-dprkn5-coefficients
Fix DPRKN5 CompiledFloats coefficients for proper 5th order convergence
2 parents 6b07741 + ebf91fe commit 791f175

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

lib/OrdinaryDiffEqRKN/src/rkn_tableaus.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,9 @@ function DPRKN5ConstantCache(T::Type{<:CompiledFloats}, T2::Type{<:CompiledFloat
936936
a32 = convert(T, 1 // 48)
937937
a41 = convert(T, 1 // 24)
938938
a43 = convert(T, 1 // 12)
939-
a51 = convert(T, 7 // 90)
940-
a53 = convert(T, 4 // 15)
941-
a54 = convert(T, 1 // 15)
939+
a51 = convert(T, 0.0703125) # 9/128
940+
a53 = convert(T, 0.140625) # 9/64
941+
a54 = convert(T, 0.0703125) # 9/128
942942
a61 = convert(T, 0.07777777777777778)
943943
a63 = convert(T, 0.26666666666666666)
944944
a64 = convert(T, 0.06666666666666667)

lib/OrdinaryDiffEqRKN/test/nystrom_convergence_tests.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,36 @@ sim = test_convergence(dts, prob_big, ERKN7(), dense_errors = true)
4747
@test sim.𝒪est[:l2]7 rtol=1e-1
4848
@test sim.𝒪est[:L2]4 rtol=1e-1
4949

50+
# Float64 convergence tests for DPRKN methods
51+
# These tests ensure the CompiledFloats coefficients match the rational coefficients
52+
# (Regression test for https://github.com/SciML/OrdinaryDiffEq.jl/issues/1938)
53+
@testset "Float64 DPRKN convergence" begin
54+
# Use longer integration time to keep errors above machine precision
55+
prob_f64 = DynamicalODEProblem(ff_harmonic, ones(2), fill(0.0, 2), (0.0, 20.0))
56+
dts_f64 = 1.0 ./ 2.0 .^ (2:5)
57+
58+
sim = test_convergence(dts_f64, prob_f64, DPRKN4())
59+
@test sim.𝒪est[:l2]4 rtol=1e-1
60+
61+
sim = test_convergence(dts_f64, prob_f64, DPRKN5())
62+
@test sim.𝒪est[:l2]5 rtol=1e-1
63+
64+
sim = test_convergence(dts_f64, prob_f64, DPRKN6())
65+
@test sim.𝒪est[:l2]6 rtol=1e-1
66+
67+
sim = test_convergence(dts_f64, prob_f64, DPRKN6FM())
68+
@test sim.𝒪est[:l2]6 rtol=1e-1
69+
70+
# DPRKN8 needs larger timesteps and longer integration to avoid hitting machine precision
71+
prob_f64_long = DynamicalODEProblem(ff_harmonic, ones(2), fill(0.0, 2), (0.0, 50.0))
72+
dts_f64_large = [1.0, 0.5, 0.25, 0.125]
73+
sim = test_convergence(dts_f64_large, prob_f64_long, DPRKN8())
74+
@test sim.𝒪est[:l2]8 rtol=1e-1
75+
76+
# DPRKN12 is too accurate for Float64 convergence testing (hits machine precision
77+
# even at dt=1.0), so we only test it with BigFloat (see tests above)
78+
end
79+
5080
sol = solve(prob, Nystrom4(), dt = 1 / 1000)
5181

5282
# Nyström method

0 commit comments

Comments
 (0)