Skip to content

Commit 066ef50

Browse files
Harsh SinghHarsh Singh
authored andcommitted
Fix two CI failures in unified RosenbrockCache
1. strip_cache override: the generic implementation calls constructorof(cache)(nothing × 29) which fails for RosenbrockCache because dense/ks/dtC/dtd require Vector/Matrix types and interp_order requires Int. Add an explicit override that constructs a Nothing-typed cache. 2. Val{1} interpolants: all four _ode_interpolant derivative functions were missing the interp_order == -1 branch. When Rosenbrock23/32 (which have empty H → interp_order = -1) hit the else branch it accessed k[3] but only 2 k-vectors exist, causing a BoundsError. Add the Hermite derivative formula as the first branch in each function.
1 parent d638d33 commit 066ef50

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_caches.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,30 @@ function get_fsalfirstlast(
247247
return (cache.fsalfirst, cache.fsallast)
248248
end
249249

250+
function OrdinaryDiffEqCore.strip_cache(cache::RosenbrockCache)
251+
return RosenbrockCache{
252+
Nothing, Nothing, Nothing, Nothing, Nothing, Nothing,
253+
Nothing, Nothing, Nothing, Nothing, Nothing, Nothing,
254+
Nothing, Nothing, Nothing, Nothing,
255+
}(
256+
nothing, nothing,
257+
Vector{Nothing}(undef, 0),
258+
nothing, nothing, nothing,
259+
Matrix{Nothing}(undef, 0, 0),
260+
Vector{Nothing}(undef, 0),
261+
Vector{Nothing}(undef, 0),
262+
nothing, nothing, nothing,
263+
nothing, nothing,
264+
nothing, nothing, nothing,
265+
nothing, nothing, nothing,
266+
nothing, nothing,
267+
nothing, nothing,
268+
nothing, nothing,
269+
nothing, nothing,
270+
0,
271+
)
272+
end
273+
250274
################################################################################
251275

252276
### Tsit5DA - hybrid explicit/linear-implicit method for DAEs

lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_interpolants.jl

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,14 @@ end
145145
},
146146
idxs::Nothing, T::Type{Val{1}}, differential_vars
147147
)
148-
if !hasproperty(cache, :interp_order) || cache.interp_order == 2
148+
if hasproperty(cache, :interp_order) && cache.interp_order == -1
149+
# Hermite derivative: d/dt of Θ1*y₀ + Θ*y₁ + Θ*(Θ-1)*[(1-2Θ)*(y₁-y₀) + (Θ-1)*dt*k[1] + Θ*dt*k[2]]
150+
@.. (
151+
(-y₀ + y₁) +
152+
(2Θ - 1) * ((1 - 2Θ) * (y₁ - y₀) +- 1) * dt * k[1] + Θ * dt * k[2]) +
153+
Θ *- 1) * (-2 * (y₁ - y₀) + dt * (k[1] + k[2]))
154+
) / dt
155+
elseif !hasproperty(cache, :interp_order) || cache.interp_order == 2
149156
@.. (k[1] + Θ * (-2 * k[1] + 2 * k[2] - 3 * k[2] * Θ) - y₀ + y₁) / dt
150157
elseif cache.interp_order == 4
151158
@.. (
@@ -177,7 +184,16 @@ end
177184
},
178185
idxs, T::Type{Val{1}}, differential_vars
179186
)
180-
if !hasproperty(cache, :interp_order) || cache.interp_order == 2
187+
if hasproperty(cache, :interp_order) && cache.interp_order == -1
188+
@views @.. (
189+
(-y₀[idxs] + y₁[idxs]) +
190+
(2Θ - 1) * (
191+
(1 - 2Θ) * (y₁[idxs] - y₀[idxs]) +- 1) * dt * k[1][idxs] +
192+
Θ * dt * k[2][idxs]
193+
) +
194+
Θ *- 1) * (-2 * (y₁[idxs] - y₀[idxs]) + dt * (k[1][idxs] + k[2][idxs]))
195+
) / dt
196+
elseif !hasproperty(cache, :interp_order) || cache.interp_order == 2
181197
@views @.. (
182198
k[1][idxs] +
183199
Θ * (-2 * k[1][idxs] + 2 * k[2][idxs] - 3 * k[2][idxs] * Θ) -
@@ -215,7 +231,13 @@ end
215231
},
216232
idxs::Nothing, T::Type{Val{1}}, differential_vars
217233
)
218-
if !hasproperty(cache, :interp_order) || cache.interp_order == 2
234+
if hasproperty(cache, :interp_order) && cache.interp_order == -1
235+
@.. out = (
236+
(-y₀ + y₁) +
237+
(2Θ - 1) * ((1 - 2Θ) * (y₁ - y₀) +- 1) * dt * k[1] + Θ * dt * k[2]) +
238+
Θ *- 1) * (-2 * (y₁ - y₀) + dt * (k[1] + k[2]))
239+
) / dt
240+
elseif !hasproperty(cache, :interp_order) || cache.interp_order == 2
219241
@.. out = (k[1] + Θ * (-2 * k[1] + 2 * k[2] - 3 * k[2] * Θ) - y₀ + y₁) / dt
220242
elseif cache.interp_order == 4
221243
@.. out = (
@@ -249,7 +271,16 @@ end
249271
},
250272
idxs, T::Type{Val{1}}, differential_vars
251273
)
252-
if !hasproperty(cache, :interp_order) || cache.interp_order == 2
274+
if hasproperty(cache, :interp_order) && cache.interp_order == -1
275+
@views @.. out = (
276+
(-y₀[idxs] + y₁[idxs]) +
277+
(2Θ - 1) * (
278+
(1 - 2Θ) * (y₁[idxs] - y₀[idxs]) +- 1) * dt * k[1][idxs] +
279+
Θ * dt * k[2][idxs]
280+
) +
281+
Θ *- 1) * (-2 * (y₁[idxs] - y₀[idxs]) + dt * (k[1][idxs] + k[2][idxs]))
282+
) / dt
283+
elseif !hasproperty(cache, :interp_order) || cache.interp_order == 2
253284
@views @.. out = (
254285
k[1][idxs] +
255286
Θ *

0 commit comments

Comments
 (0)