Ariadne.jl
Newton Method using Krylov.jl (montoison-orban-2023)[@cite]
API
Ariadne.newton_krylov! — Function
newton_krylov!(F!, u₀::AbstractArray, p = nothing, M::Int = length(u₀); kwargs...)Takes an in-place residual function F!(res, u, p).
Arguments
F!:F!(res, u, p)solvesres = F(u) = 0u₀: Initial guessp: ParametersM: Length of the output ofF!. Defaults tolength(u₀)
Keyword Arguments
tol_rel: Relative tolerancetol_abs: Absolute tolerancemax_niter: Maximum number of iterationsforcing: Maximum forcing term for inexact Newton. Ifnothingan exact Newton method is used.linesearch!: Line search strategy. Must be a subtype ofAbstractLineSearch.verbose::Int: Verbosity levelM::Union{Nothing, Function}: If provided,M(ws.J)is passed as a keyword argument to the Krylov solver.N::Union{Nothing, Function}: If provided,N(ws.J)is passed as a keyword argument to the Krylov solver.krylov_kwargs: Keyword arguments passed to the Krylov solver.callback: A function called after each Newton iteration with signaturecallback(u, res, norm_res).
newton_krylov!(F!, u, p, res; kwargs...)Takes an in-place residual function F!(res, u, p).
Arguments
F!:F!(res, u, p)solvesres = F(u) = 0u: Initial guess (modified in-place)p: Parametersres: Temporary for residual
Keyword Arguments
tol_rel: Relative tolerancetol_abs: Absolute tolerancemax_niter: Maximum number of iterationsforcing: Maximum forcing term for inexact Newton. Ifnothingan exact Newton method is used.linesearch!: Line search strategy. Must be a subtype ofAbstractLineSearch.verbose::Int: Verbosity levelM::Union{Nothing, Function}: If provided,M(ws.J)is passed as a keyword argument to the Krylov solver.N::Union{Nothing, Function}: If provided,N(ws.J)is passed as a keyword argument to the Krylov solver.krylov_kwargs: Keyword arguments passed to the Krylov solver.callback: A function called after each Newton iteration with signaturecallback(u, res, norm_res).
newton_krylov!(ws::NewtonKrylovWorkspace, u; kwargs...)Updates ws.u with the initial guess u and then calls newton_krylov!(ws; kwargs...).
Arguments
F!:F!(res, u, p)solvesres = F(u) = 0u: Initial guess (must have the same shape asws.u)
Keyword Arguments
tol_rel: Relative tolerancetol_abs: Absolute tolerancemax_niter: Maximum number of iterationsforcing: Maximum forcing term for inexact Newton. Ifnothingan exact Newton method is used.linesearch!: Line search strategy. Must be a subtype ofAbstractLineSearch.verbose::Int: Verbosity levelM::Union{Nothing, Function}: If provided,M(ws.J)is passed as a keyword argument to the Krylov solver.N::Union{Nothing, Function}: If provided,N(ws.J)is passed as a keyword argument to the Krylov solver.krylov_kwargs: Keyword arguments passed to the Krylov solver.callback: A function called after each Newton iteration with signaturecallback(u, res, norm_res).
newton_krylov!(ws; kwargs...)Arguments
ws: Pre-allocatedNewtonKrylovWorkspace
Keyword Arguments
tol_rel: Relative tolerancetol_abs: Absolute tolerancemax_niter: Maximum number of iterationsforcing: Maximum forcing term for inexact Newton. Ifnothingan exact Newton method is used.linesearch!: Line search strategy. Must be a subtype ofAbstractLineSearch.verbose::Int: Verbosity levelM::Union{Nothing, Function}: If provided,M(ws.J)is passed as a keyword argument to the Krylov solver.N::Union{Nothing, Function}: If provided,N(ws.J)is passed as a keyword argument to the Krylov solver.krylov_kwargs: Keyword arguments passed to the Krylov solver.callback: A function called after each Newton iteration with signaturecallback(u, res, norm_res).
Ariadne.newton_krylov — Function
newton_krylov(F, u₀::AbstractArray, p = nothing, M::Int = length(u₀); kwargs...)Takes a out-of-place residual function F(u, p).
Arguments
F:res = F(u₀, p)solvesres = F(u₀) = 0u₀: Initial guessp: ParametersM: Length of the output ofF. Defaults tolength(u₀).
Keyword Arguments
tol_rel: Relative tolerancetol_abs: Absolute tolerancemax_niter: Maximum number of iterationsforcing: Maximum forcing term for inexact Newton. Ifnothingan exact Newton method is used.linesearch!: Line search strategy. Must be a subtype ofAbstractLineSearch.verbose::Int: Verbosity levelM::Union{Nothing, Function}: If provided,M(ws.J)is passed as a keyword argument to the Krylov solver.N::Union{Nothing, Function}: If provided,N(ws.J)is passed as a keyword argument to the Krylov solver.krylov_kwargs: Keyword arguments passed to the Krylov solver.callback: A function called after each Newton iteration with signaturecallback(u, res, norm_res).
Ariadne.NewtonKrylovWorkspace — Type
NewtonKrylovWorkspacePre-allocated workspace for newton_krylov!. Holds the residual buffer, negated-residual buffer, Jacobian operator (with its Enzyme caches), and the Krylov solver workspace so that no intermediate arrays are allocated during the Newton iteration.
To change the parameters p you have to create a new workspace. To change the initial guess u, you can pass it to newton_krylov!(ws, u).
Constructor
NewtonKrylovWorkspace(F!, u, p, res, alg=Val(:gmres); assume_p_const = false)F!: in-place residual functionF!(res, u, p)u: initial-guess array (used as template; the workspace holds a reference to it)p: parametersres: pre-allocated residual bufferalgo: Krylov algorithm symbol (e.g.:gmres,:fgmres) passed as aVal.assume_p_const: passed through toJacobianOperator
Example
ws = NewtonKrylovWorkspace(F!, u, p, res, Val(:gmres))
newton_krylov!(ws)
# To change the initial guess, pass it to newton_krylov!:
newton_krylov!(ws, u_new) Line Searches
Ariadne.LineSearches.AbstractLineSearch — Type
AbstractLineSearchLine search updates ws.u in-place along the Newton direction d and calls evaluate!(ws) to refresh ws.res and obtain the new residual norm.
Implemented variants
Custom line searches
struct CustomLineSearch <: AbstractLineSearch
# parameters for the line search
end
function (ls::CustomLineSearch)(ws, norm_res_prior, d)
# update ws.u
ws.u .+= d # for example, take the full Newton step
return evaluate!(ws)
endAriadne.LineSearches.NoLineSearch — Type
NoLineSearch()A line search that does not perform any line search: it simply takes the full Newton step.
Ariadne.LineSearches.BacktrackingLineSearch — Type
BacktrackingLineSearch(; n_iter_max = 10)References
- Kelley, C. T. (2022). Solving nonlinear equations with iterative methods: Solvers and examples in Julia. Society for Industrial and Applied Mathematics.
- https://github.com/ctkelley/SIAMFANLEquations.jl
Parameters
Ariadne.Forcing — Type
ForcingImplements forcing for inexact Newton-Krylov. The equation $‖F′(u)d + F(u)‖ <= η * ‖F(u)‖$ gives the inexact Newton termination criterion.
Implemented variants
Ariadne.Fixed — Type
Fixed(η = 0.1)Ariadne.EisenstatWalker — Type
EisenstatWalker(η_max = 0.999, γ = 0.9)Internal
Ariadne.JacobianOperator — Type
JacobianOperatorEfficient implementation of J(f,x,p) * v and v * J(f, x,p)'
Ariadne.BatchedJacobianOperator — Type
BatchedJacobianOperator{N}Ariadne.evaluate! — Function
Ariadne.evaluate!(ws::NewtonKrylovWorkspace) -> norm_resEvaluate F!(ws.res, ws.u, ws.p) in-place and return norm(ws.res).
Bibliography
- [1]
- R. E. Bank, W. M. Coughran, W. Fichtner, E. H. Grosse, D. J. Rose and R. K. Smith. Transient simulation of silicon devices and circuits. IEEE Transactions on Electron Devices 32, 1992–2007 (1985).
- [2]
- [3]
- M. E. Hosea and L. F. Shampine. Analysis and implementation of TR-BDF2. Applied Numerical Mathematics 20, 21–37 (1996).