Skip to content

Commit f6c8d01

Browse files
AJ0070ChrisRackauckas
authored andcommitted
Fix: reinit! error when using AbsTerminationMode
1 parent 3433c52 commit f6c8d01

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/NonlinearSolveBase/src/termination_conditions.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ function SciMLBase.reinit!(
9898
length(saved_value_prototype) != 0 && (cache.saved_values = saved_value_prototype)
9999

100100
mode = cache.mode
101-
if u isa Number || !ArrayInterface.can_setindex(u)
102-
cache.u = u
103-
else
104-
cache.u .= u
101+
if cache.u !== nothing
102+
if u isa Number || !ArrayInterface.can_setindex(u)
103+
cache.u = u
104+
else
105+
cache.u .= u
106+
end
105107
end
106108
cache.retcode = ReturnCode.Default
107109

lib/NonlinearSolveBase/test/runtests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,20 @@ using InteractiveUtils, Test
3333

3434
@test NonlinearSolveBase.Utils.faster_vcat(b, d) == vcat(sparse(b), d)
3535
end
36+
37+
@testset "Termination Conditions" begin
38+
using NonlinearSolveBase, SciMLBase
39+
@testset "reinit! with AbsTerminationMode" begin
40+
mode = NonlinearSolveBase.AbsTerminationMode()
41+
u_unaliased = nothing
42+
T = Float64
43+
cache = NonlinearSolveBase.NonlinearTerminationModeCache(
44+
u_unaliased, SciMLBase.ReturnCode.Default, 1e-8, 1e-8, Inf, mode,
45+
nothing, nothing, 0, nothing, nothing, nothing, nothing, nothing, false
46+
)
47+
du = [1.0, 1.0]
48+
u = [1.1, 1.1]
49+
@test_nowarn SciMLBase.reinit!(cache, du, u)
50+
end
51+
end
3652
end

0 commit comments

Comments
 (0)