Skip to content

Commit 7590f47

Browse files
Harsh SinghHarsh Singh
authored andcommitted
fix: restore Shampine stiff interpolation via 2-row H matrix
1 parent 92d7262 commit 7590f47

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_tableaus.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ function Rosenbrock23RodasTableau(T, T2)
3838
convert(T, igamma / 6),
3939
]
4040

41-
H = zeros(T, 0, 3)
41+
# Shampine 2nd-order "free" stiff interpolation encoded as a 2-row H matrix
42+
# (interp_order=2) so the standard Rodas 2-vector formula applies:
43+
# p(Θ) = (1-Θ)y₀ + Θ(y₁ + (1-Θ)(K[1] + Θ·K[2]))
44+
# K[1] = -ks[2]/(γ(1-2γ)), K[2] = 0
45+
# Algebraically equals the MATLAB ODE Suite c1·k̃₁ + c2·k̃₂ dense output
46+
# with c1=Θ(1-Θ)/(1-2γ), c2=Θ(Θ-2γ)/(1-2γ); K[2]=0 because the Θ² term
47+
# from c2 is already absorbed into K[1] via the y₁ endpoint.
48+
H = T[zero(T) convert(T, -1/(gamma*(1 - 2*gamma))) zero(T)
49+
zero(T) zero(T) zero(T)]
4250

4351
return RodasTableau(A, C, gamma, c, d, H, b, btilde)
4452
end
@@ -75,7 +83,9 @@ function Rosenbrock32RodasTableau(T, T2)
7583
convert(T, igamma / 6),
7684
]
7785

78-
H = zeros(T, 0, 3)
86+
# Same Shampine interpolation as Rosenbrock23 (identical γ, same stencil)
87+
H = T[zero(T) convert(T, -1/(gamma*(1 - 2*gamma))) zero(T)
88+
zero(T) zero(T) zero(T)]
7989

8090
return RodasTableau(A, C, gamma, c, d, H, b, btilde)
8191
end

test/integrators/resize_tests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ resize!(i, 5)
7878
@test length(i.cache.uprev) == 5
7979
@test length(i.cache.ks) == 3
8080
@test all(length.(i.cache.ks) .== 5)
81+
@test all(length.(i.cache.dense) .== 5)
8182
@test length(i.cache.du1) == 5
8283
@test length(i.cache.du2) == 5
8384
@test length(i.cache.fsalfirst) == 5
@@ -104,6 +105,7 @@ resize!(i, 5)
104105
@test length(i.cache.uprev) == 5
105106
@test length(i.cache.ks) == 3
106107
@test all(length.(i.cache.ks) .== 5)
108+
@test all(length.(i.cache.dense) .== 5)
107109
@test length(i.cache.du1) == 5
108110
@test length(i.cache.du2) == 5
109111
@test length(i.cache.fsalfirst) == 5
@@ -121,6 +123,7 @@ resize!(i, 5)
121123
@test length(i.cache.uprev) == 5
122124
@test length(i.cache.ks) == 3
123125
@test all(length.(i.cache.ks) .== 5)
126+
@test all(length.(i.cache.dense) .== 5)
124127
@test length(i.cache.du1) == 5
125128
@test length(i.cache.du2) == 5
126129
@test length(i.cache.fsalfirst) == 5

0 commit comments

Comments
 (0)