Skip to content

Commit 6bd71c0

Browse files
Fix FIRK addsteps\! to compute Jacobian instead of extracting from cache
For out-of-place (ConstantCache) versions, the Jacobian is not stored in the cache and must be computed fresh each time. Updated all FIRK addsteps\! functions for ConstantCache types to: - Remove J from @unpack statements (as it doesn't exist in ConstantCache) - Compute J using calc_J(integrator, cache) just like perform_step\! does This matches the pattern used in perform_step\! and fixes undefined variable errors. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ebcbfcc commit 6bd71c0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/OrdinaryDiffEqFIRK/src/firk_addsteps.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function _ode_addsteps!(integrator, cache::RadauIIA3ConstantCache)
22
@unpack t, dt, uprev, u, f, p, k = integrator
33
@unpack T11, T12, T21, T22, TI11, TI12, TI21, TI22 = cache.tab
44
@unpack c1, c2, α, β, e1, e2 = cache.tab
5-
@unpack κ, cont1, cont2, J = cache
5+
@unpack κ, cont1, cont2 = cache
66
@unpack internalnorm, abstol, reltol, adaptive = integrator.opts
77
alg = unwrap_alg(integrator, true)
88
@unpack maxiters = alg
@@ -12,6 +12,7 @@ function _ode_addsteps!(integrator, cache::RadauIIA3ConstantCache)
1212
rtol = @. reltol^(3 / 4) / 10
1313
atol = @. rtol * (abstol / reltol)
1414
αdt, βdt = α / dt, β / dt
15+
J = calc_J(integrator, cache)
1516

1617
c1m1 = c1 - 1
1718
if integrator.iter == 1 || integrator.u_modified || alg.extrapolant == :constant
@@ -279,7 +280,7 @@ function _ode_addsteps!(integrator, cache::RadauIIA5ConstantCache,
279280
@unpack T11, T12, T13, T21, T22, T23, T31, TI11, TI12, TI13,
280281
TI21, TI22, TI23, TI31, TI32, TI33 = cache.tab
281282
@unpack c1, c2, γ, α, β, e1, e2, e3 = cache.tab
282-
@unpack κ, cont1, cont2, cont3, J = cache
283+
@unpack κ, cont1, cont2, cont3 = cache
283284
@unpack internalnorm, abstol, reltol, adaptive = integrator.opts
284285
alg = unwrap_alg(integrator, true)
285286
@unpack maxiters = alg
@@ -292,6 +293,7 @@ function _ode_addsteps!(integrator, cache::RadauIIA5ConstantCache,
292293
c2m1 = c2 - 1
293294
c1mc2 = c1 - c2
294295
γdt, αdt, βdt = γ / dt, α / dt, β / dt
296+
J = calc_J(integrator, cache)
295297
if u isa Number
296298
LU1 = -γdt * mass_matrix + J
297299
LU2 = -(αdt + βdt * im) * mass_matrix + J
@@ -633,7 +635,7 @@ function _ode_addsteps!(integrator, cache::RadauIIA9ConstantCache,
633635
TI12, TI13, TI14, TI15, TI21, TI22, TI23, TI24, TI25, TI31, TI32, TI33, TI34,
634636
TI35, TI41, TI42, TI43, TI44, TI45, TI51, TI52, TI53, TI54, TI55 = cache.tab
635637
@unpack c1, c2, c3, c4, γ, α1, β1, α2, β2, e1, e2, e3, e4, e5 = cache.tab
636-
@unpack κ, J = cache
638+
@unpack κ = cache
637639
@unpack internalnorm, abstol, reltol, adaptive = integrator.opts
638640
alg = unwrap_alg(integrator, true)
639641
@unpack maxiters = alg
@@ -654,6 +656,7 @@ function _ode_addsteps!(integrator, cache::RadauIIA9ConstantCache,
654656
c3mc4 = c3 - c4
655657

656658
γdt, α1dt, β1dt, α2dt, β2dt = γ / dt, α1 / dt, β1 / dt, α2 / dt, β2 / dt
659+
J = calc_J(integrator, cache)
657660
if u isa Number
658661
LU1 = -γdt * mass_matrix + J
659662
LU2 = -(α1dt + β1dt * im) * mass_matrix + J
@@ -1150,7 +1153,7 @@ end
11501153

11511154
function _ode_addstep!(integrator, cache::AdaptiveRadauConstantCache, repeat_step = false)
11521155
@unpack t, dt, uprev, u, f, p, k = integrator
1153-
@unpack tabs, num_stages, index, J = cache
1156+
@unpack tabs, num_stages, index = cache
11541157
tab = tabs[index]
11551158
@unpack T, TI, γ, α, β, c, e = tab
11561159
@unpack κ = cache
@@ -1164,6 +1167,7 @@ function _ode_addstep!(integrator, cache::AdaptiveRadauConstantCache, repeat_ste
11641167
atol = @.. rtol*(abstol / reltol)
11651168

11661169
γdt, αdt, βdt = γ / dt, α ./ dt, β ./ dt
1170+
J = calc_J(integrator, cache)
11671171

11681172
if u isa Number
11691173
LU1 = -γdt * mass_matrix + J

0 commit comments

Comments
 (0)