Skip to content

Commit d89e8d7

Browse files
author
Your Name
committed
OOP NSA resize: handle Ref-wrapped W; Runic literal fmt
1 parent 0c7ac6c commit d89e8d7

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,13 +718,25 @@ function Base.resize!(nlcache::NLNewtonCache, ::AbstractNLSolver, integrator, i:
718718
return nothing
719719
end
720720

721+
function _resize_nlsolvealg_W!(nlcache, integrator, i)
722+
W = nlcache.W[]
723+
W isa StaticWOperator && return nothing
724+
if nlcache.J !== nothing && ArrayInterface.can_setindex(nlcache.J)
725+
nlcache.J = similar(nlcache.J, i, i)
726+
end
727+
nlcache.W[] = WOperator{SciMLBase.isinplace(integrator.sol.prob)}(
728+
integrator.f.mass_matrix, integrator.dt, nlcache.J, integrator.u
729+
)
730+
return nothing
731+
end
732+
721733
function Base.resize!(nlcache::NonlinearSolveCache, ::AbstractNLSolver, integrator, i::Int)
722734
nlcache.ustep === nothing || resize!(nlcache.ustep, i)
723735
nlcache.k === nothing || resize!(nlcache.k, i)
724736
nlcache.atmp === nothing || resize!(nlcache.atmp, i)
725737
nlcache.du1 === nothing || resize!(nlcache.du1, i)
726738
nlcache.jac_config === nothing || resize_jac_config!(nlcache, integrator)
727-
nlcache.W === nothing || resize_J_W!(nlcache, integrator, i)
739+
nlcache.W === nothing || _resize_nlsolvealg_W!(nlcache, integrator, i)
728740
nlcache.W_γdt = zero(nlcache.W_γdt)
729741
nlcache.new_W = true
730742
return nothing

lib/OrdinaryDiffEqNonlinearSolve/test/linear_nonlinear_tests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ let
111111
TRBDF2(
112112
nlsolve = NonlinearSolveAlg(NewtonRaphson(; autodiff = AutoForwardDiff())),
113113
concrete_jac = true
114-
); reltol = 1e-8, abstol = 1e-10
114+
); reltol = 1.0e-8, abstol = 1.0e-10
115115
)
116116
@test SciMLBase.successful_retcode(sol.retcode)
117117
@test sol.stats.njacs > 0
@@ -129,7 +129,7 @@ let
129129
TRBDF2(
130130
nlsolve = NonlinearSolveAlg(NewtonRaphson(; autodiff = AutoForwardDiff())),
131131
concrete_jac = true
132-
); reltol = 1e-8, abstol = 1e-10
132+
); reltol = 1.0e-8, abstol = 1.0e-10
133133
)
134134
@test SciMLBase.successful_retcode(sol.retcode)
135135
@test sol.stats.njacs > 0

0 commit comments

Comments
 (0)