Skip to content

Commit e05ccf8

Browse files
committed
fix oop addsteps
1 parent d76108c commit e05ccf8

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ end
8181
@unpack tstep, invγdt = cache
8282

8383
nlcache = nlsolver.cache.cache
84-
step!(nlcache, recompute_jacobian=false)
84+
step!(nlcache)
8585
nlsolver.ztmp = nlcache.u
8686

8787
ustep = compute_ustep(tmp, γ, z, method)
@@ -103,7 +103,7 @@ end
103103
@unpack tstep, invγdt, atmp, ustep = cache
104104

105105
nlcache = nlsolver.cache.cache
106-
step!(nlcache, recompute_jacobian=false)
106+
step!(nlcache)
107107
@.. broadcast=false ztmp=nlcache.u
108108

109109
ustep = compute_ustep!(ustep, tmp, γ, z, method)

lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,14 +1268,14 @@ end
12681268
end
12691269

12701270
if integrator.opts.calck
1271-
k1 = zero(integrator.k[1])
1272-
k2 = zero(integrator.k[2])
1273-
for i in 1:length(ks)
1274-
k1 = @.. k1 + H[1, i] * ks[i]
1275-
k2 = @.. k2 + H[2, i] * ks[i]
1271+
for j in eachindex(integrator.k)
1272+
integrator.k[j] = zero(integrator.k[1])
1273+
end
1274+
for i in eachindex(ks)
1275+
for j in eachindex(integrator.k)
1276+
integrator.k[j] = @.. integrator.k[j] + H[j, i] * ks[i]
1277+
end
12761278
end
1277-
integrator.k[1] = k1
1278-
integrator.k[2] = k2
12791279
end
12801280

12811281
integrator.u = u
@@ -1369,11 +1369,11 @@ end
13691369
end
13701370

13711371
if integrator.opts.calck
1372-
for j in 1:length(integrator.k)
1372+
for j in eachindex(integrator.k)
13731373
integrator.k[j] .= 0
13741374
end
1375-
for i in 1:length(ks)
1376-
for j in 1:length(integrator.k)
1375+
for i in eachindex(ks)
1376+
for j in eachindex(integrator.k)
13771377
@.. integrator.k[j] += H[j, i] * ks[i]
13781378
end
13791379
end

lib/OrdinaryDiffEqRosenbrock/src/stiff_addsteps.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::Rodas4ConstantCache,
319319
end
320320

321321
num_stages = size(A, 1)
322-
323-
for stage in 1:num_stages
322+
# Last stage doesn't affect ks
323+
for stage in 1:num_stages-1
324324
u = uprev
325325
for i in 1:stage-1
326326
u = @.. u + A[stage, i] * ks[i]
@@ -341,13 +341,14 @@ function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::Rodas4ConstantCache,
341341
end
342342
end
343343

344-
ks[stage] = _reshape(W \ -_vec(linsolve_tmp), axes(uprev))
344+
ks[stage] = _reshape(W \ _vec(linsolve_tmp), axes(uprev))
345345
end
346346

347347
k1 = zero(ks[1])
348348
k2 = zero(ks[1])
349349
H = cache.tab.H
350-
for i in 1:length(ks)
350+
# Last stage doesn't affect ks
351+
for i in 1:length(ks)-1
351352
k1 = @.. k1 + H[1, i] * ks[i]
352353
k2 = @.. k2 + H[2, i] * ks[i]
353354
end
@@ -384,7 +385,8 @@ function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::RosenbrockCache,
384385

385386
linres = dolinsolve(cache, linsolve; A = W, b = _vec(linsolve_tmp), reltol = cache.reltol)
386387
@.. $(_vec(ks[1]))=-linres.u
387-
for stage in 2:length(ks)
388+
# Last stage doesn't affect ks
389+
for stage in 2:length(ks)-1
388390
tmp .= uprev
389391
for i in 1:stage-1
390392
@.. tmp += A[stage, i] * _vec(ks[i])
@@ -411,7 +413,8 @@ function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::RosenbrockCache,
411413

412414
copyat_or_push!(k, 1, zero(du))
413415
copyat_or_push!(k, 2, zero(du))
414-
for i in 1:length(ks)
416+
# Last stage doesn't affect ks
417+
for i in 1:length(ks)-1
415418
@.. k[1] += H[1, i] * _vec(ks[i])
416419
@.. k[2] += H[2, i] * _vec(ks[i])
417420
end

0 commit comments

Comments
 (0)