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}(2.168579147435665e-5,3.051758529387333e-5,2.0203911739265703e-5), Dual{Nothing}(3.0517585293877254e-5,2.8627375179145664e-5,3.051758529383635e-5)], ForwardDiff.Dual{Nothing, Float64, 2}[Dual{Nothing}(0.0009553098332088527,3.051758525174931e-5,0.0009364663835268099), Dual{Nothing}(3.0517585252869435e-5,0.001179212933443071,3.051758524374665e-5)])), [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