Solver Status

In SimpleSolvers we can use the SimpleSolvers.NonlinearSolverStatus to provide a diagnostic tool for a NonlinearSolver. We first make an instance of NonlinearSystem:

x = [3., 1.3]
f = x -> tanh.(x)
F!(y, x, params) = y .= f(x)
nls = NonlinearSystem(F!, x, f(x))
NonlinearSystem{Float64, false, typeof(Main.F!), JacobianAutodiff{Float64, typeof(Main.F!), ForwardDiff.JacobianConfig{Nothing, Float64, 2, Tuple{Vector{ForwardDiff.Dual{Nothing, Float64, 2}}, Vector{ForwardDiff.Dual{Nothing, Float64, 2}}}}, Vector{Float64}}, Vector{Float64}, Vector{Float64}, Matrix{Float64}}(Main.F!, JacobianAutodiff{Float64, typeof(Main.F!), ForwardDiff.JacobianConfig{Nothing, Float64, 2, Tuple{Vector{ForwardDiff.Dual{Nothing, Float64, 2}}, Vector{ForwardDiff.Dual{Nothing, Float64, 2}}}}, Vector{Float64}}(Main.F!, ForwardDiff.JacobianConfig{Nothing, Float64, 2, Tuple{Vector{ForwardDiff.Dual{Nothing, Float64, 2}}, Vector{ForwardDiff.Dual{Nothing, Float64, 2}}}}((Partials(1.0, 0.0), Partials(0.0, 1.0)), (ForwardDiff.Dual{Nothing, Float64, 2}[Dual{Nothing}(6.9471170064999e-310,6.94718437048197e-310,6.9471211640979e-310), Dual{Nothing}(6.94712116410184e-310,6.9471214778857e-310,6.9471214778873e-310)], ForwardDiff.Dual{Nothing, Float64, 2}[Dual{Nothing}(6.9471170064999e-310,6.94718437048197e-310,6.9471211640979e-310), Dual{Nothing}(6.94712116410184e-310,6.9471214778857e-310,6.9471214778873e-310)])), [0.0, 0.0]), [NaN, NaN], [NaN NaN; NaN NaN], [NaN, NaN], [NaN, NaN], 0, 0)

We now create an instance of NewtonSolver which also allocates a SimpleSolvers.NonlinearSolverStatus:

solver = NewtonSolver(x, f(x); F = F!)
i=   0,
x= NaN,
f= NaN,
rxₐ= NaN,
rfₐ= NaN

Note that all variables are initialized with NaNs.

For the first step we therefore have to call update![1]:

params = nothing
update!(solver, x, params)
i=   0,
x=3.000000e+00,
f=9.950548e-01,
rxₐ= NaN,
rfₐ=1.316321e+00

Note that the residuals are still NaNs however as we need to perform at least two updates in order to compute them. As a next step we write:

x = [2., 1.2]
update!(solver, x, params)
i=   0,
x=2.000000e+00,
f=9.640276e-01,
rxₐ=1.004988e+00,
rfₐ=1.274492e+00