Nonlinear Solver Iterator Interface
There is an iterator form of the nonlinear solver which somewhat mirrors the DiffEq integrator interface:
using NonlinearSolve
f(u, p) = u .* u .- 2.0
u0 = 1.5
probB = NonlinearProblem(f, u0)
nlcache = init(probB, NewtonRaphson())
GeneralizedFirstOrderAlgorithmCache(
alg = NewtonRaphson(
descent = NewtonDescent(),
autodiff = AutoForwardDiff(),
vjp_autodiff = AutoFiniteDiff(
fdtype = Val{:forward}(),
fdjtype = Val{:forward}(),
fdhtype = Val{:hcentral}(),
dir = true
),
jvp_autodiff = AutoForwardDiff(),
concrete_jac = Val{false}()
),
u = 1.5,
residual = 0.25,
inf-norm(residual) = 0.25,
nsteps = 0,
retcode = Default
)
init
takes the same keyword arguments as solve
, but it returns a cache object that satisfies typeof(nlcache) <: AbstractNonlinearSolveCache
and can be used to iterate the solver.
The iterator interface supports:
CommonSolve.step!
— Methodstep!(
cache::AbstractNonlinearSolveCache;
recompute_jacobian::Union{Nothing, Bool} = nothing
)
Performs one step of the nonlinear solver.
Keyword Arguments
recompute_jacobian
: allows controlling whether the jacobian is recomputed at the current step. Ifnothing
, then the algorithm determines whether to recompute the jacobian. Iftrue
orfalse
, then the jacobian is recomputed or not recomputed, respectively. For algorithms that don't use jacobian information, this keyword is ignored with a one-time warning.
We can perform 10 steps of the Newton-Raphson solver with the following:
for i in 1:10
step!(nlcache)
end
We currently don't implement a Base.iterate
interface but that will be added in the future.