I am trying to solve a system of three nonlinear equations and would like to use the termination conditions provided by DiffEqBase.NLSolveTerminationCondition (see the documentation of NonlinearSolve.jl.
The function definitions in my problem are of the form
f!(r,param,a) = eq_bin!(r, param, kappa, gamma, a; verbose = verbose::Bool)
J!(J,param,a) = eq_bin_jac!(J, param, kappa, gamma, a, v)
function Jv!(Jv,vec,param,a)
eq_bin_jac!(J, param, kappa, gamma, a, v)
mul!(Jv,J,vec)
return nothing
end
function Jvt!(Jv,vec,param,a)
eq_bin_jac!(J, param, kappa, gamma, a, v)
mul!(Jv,J',vec)
return nothing
end
NF = NonlinearFunction{true, specialize}(f!;
jac = J!,
jvp = Jv!,
vjp = Jvt!,
jac_prototype = jp
)
which I want to solve using
probN = NonlinearProblem(NF, x_init, a)
sol = solve(probN, method, reltol = reltol, abstol = abstol, maxiters = maxiters)
Now it sometimes happens with unfortunate starting values, that my system blows up, or that I do not get an improvement over a series of iterations of my system. Hence, I would like to use
NLSolveTerminationCondition(NLSolveTerminationMode.AbsSafeBest)
.
However, I do not understand where I should put this termination condtion in my solver setup. solve does not have an obvious suitable kwarg and nor does NonlinearProblem from what I saw.
Any help as to how to use the termination condition funcitonality is greatly appreciated.