@@ -125,7 +125,7 @@ struct ForwardDiffStepSize3 <: ForwardDiffStepSize end
125125Computes the Jacobian-vector product `j(x[n]) * Δx[n]` for a Newton-Krylov
126126method without directly using the Jacobian `j(x[n])`, and instead only using
127127`x[n]`, `f(x[n])`, and other function evaluations `f(x′)`. This is done by
128- calling `run !(::JacobianFreeJVP, cache, jΔx, Δx, x, f!, f)`. The `jΔx` passed to
128+ calling `jvp !(::JacobianFreeJVP, cache, jΔx, Δx, x, f!, f)`. The `jΔx` passed to
129129a Jacobian-free JVP is modified in-place. The `cache` can be obtained with
130130`allocate_cache(::JacobianFreeJVP, x_prototype)`, where `x_prototype` is
131131`similar` to `x` (and also to `Δx` and `f`).
146146
147147allocate_cache (:: ForwardDiffJVP , x_prototype) = (; x2 = similar (x_prototype), f2 = similar (x_prototype))
148148
149- function run ! (alg:: ForwardDiffJVP , cache, jΔx, Δx, x, f!, f)
149+ function jvp ! (alg:: ForwardDiffJVP , cache, jΔx, Δx, x, f!, f)
150150 (; default_step, step_adjustment) = alg
151151 (; x2, f2) = cache
152152 FT = eltype (x)
160160 ForcingTerm
161161
162162Computes the value of `rtol[n]` for a Newton-Krylov method. This is done by
163- calling `run !(::ForcingTerm, cache, f, n)`, which returns `rtol[n]`. The `cache`
163+ calling `get_rtol !(::ForcingTerm, cache, f, n)`, which returns `rtol[n]`. The `cache`
164164can be obtained with `allocate_cache(::ForcingTerm, x_prototype)`, where
165165`x_prototype` is `similar` to `f`.
166166
188188
189189allocate_cache (:: ConstantForcing , x_prototype) = (;)
190190
191- function run ! (alg:: ConstantForcing , cache, f, n)
191+ function get_rtol ! (alg:: ConstantForcing , cache, f, n)
192192 FT = eltype (f)
193193 return FT (alg. rtol)
194194end
@@ -230,7 +230,7 @@ function allocate_cache(::EisenstatWalkerForcing, x_prototype)
230230 return (; prev_norm_f = Ref {FT} (), prev_rtol = Ref {FT} ())
231231end
232232
233- function run ! (alg:: EisenstatWalkerForcing , cache, f, n)
233+ function get_rtol ! (alg:: EisenstatWalkerForcing , cache, f, n)
234234 (; initial_rtol, γ, α, min_rtol_threshold, max_rtol) = alg
235235 (; prev_norm_f, prev_rtol) = cache
236236 FT = eltype (f)
256256
257257Prints information about the Jacobian matrix `j` and the preconditioner `M` (if
258258it is available) that are passed to a Krylov method. This is done by calling
259- `run !(::KrylovMethodDebugger, cache, j, M)`. The `cache` can be obtained with
259+ `print_debug !(::KrylovMethodDebugger, cache, j, M)`. The `cache` can be obtained with
260260`allocate_cache(::KrylovMethodDebugger, x_prototype)`, where `x_prototype` is
261261`similar` to `x`.
262262"""
@@ -284,7 +284,9 @@ function allocate_cache(::PrintConditionNumber, x_prototype)
284284 )
285285end
286286
287- function run! (:: PrintConditionNumber , cache, j, M)
287+ print_debug! (:: Nothing , cache, j, M) = nothing
288+
289+ function print_debug! (:: PrintConditionNumber , cache, j, M)
288290 (; dense_vector, dense_j, dense_inv_M, dense_inv_M_j) = cache
289291 dense_matrix_from_operator! (dense_j, dense_vector, j)
290292 if M === I
335337Finds an approximation `Δx[n] ≈ j(x[n]) \\ f(x[n])` for Newton's method such
336338that `‖f(x[n]) - j(x[n]) * Δx[n]‖ ≤ rtol[n] * ‖f(x[n])‖`, where `rtol[n]` is the
337339value of the forcing term on iteration `n`. This is done by calling
338- `run !(::KrylovMethod, cache, Δx, x, f!, f, n, j = nothing)`, where `f` is
340+ `solve_krylov !(::KrylovMethod, cache, Δx, x, f!, f, n, j = nothing)`, where `f` is
339341`f(x[n])` and, if it is specified, `j` is either `j(x[n])` or an approximation
340342of `j(x[n])`. The `Δx` passed to a Krylov method is modified in-place. The
341343`cache` can be obtained with `allocate_cache(::KrylovMethod, x_prototype)`,
@@ -347,7 +349,7 @@ This is primarily a wrapper for a `Krylov.KrylovSolver` from `Krylov.jl`. In
347349`l = length(x_prototype)` and `Krylov.ktypeof(x_prototype)` is a subtype of
348350`DenseVector` that can be used to store `x_prototype`. By default, the solver
349351is a `Krylov.GmresSolver` with a Krylov subspace size of 20 (the default Krylov
350- subspace size for this solver in `Krylov.jl`). In `run !`, the solver is run with
352+ subspace size for this solver in `Krylov.jl`). In `solve_krylov !`, the solver is run with
351353`Krylov.solve!(solver, opj, f; M, ldiv, atol, rtol, verbose, solve_kwargs...)`.
352354The solver's type can be changed by specifying a different value for `type`,
353355though this value has to be wrapped in a `Val` to avoid runtime compilation.
@@ -419,20 +421,20 @@ function allocate_cache(alg::KrylovMethod, x_prototype)
419421 )
420422end
421423
422- function run ! (alg:: KrylovMethod , cache, Δx, x, f!, f, n, j = nothing )
424+ function solve_krylov ! (alg:: KrylovMethod , cache, Δx, x, f!, f, n, j = nothing )
423425 (; jacobian_free_jvp, forcing_term, solve_kwargs) = alg
424426 (; disable_preconditioner, verbose, debugger) = alg
425427 type = solver_type (alg)
426428 (; jacobian_free_jvp_cache, forcing_term_cache, solver, debugger_cache) = cache
427429 jΔx! (jΔx, Δx) =
428430 isnothing (jacobian_free_jvp) ? mul! (jΔx, j, Δx) :
429- run ! (jacobian_free_jvp, jacobian_free_jvp_cache, jΔx, Δx, x, f!, f)
431+ jvp ! (jacobian_free_jvp, jacobian_free_jvp_cache, jΔx, Δx, x, f!, f)
430432 opj = LinearOperator (eltype (x), length (x), length (x), false , false , jΔx!)
431433 M = disable_preconditioner || isnothing (j) || isnothing (jacobian_free_jvp) ? I : j
432- run ! (debugger, debugger_cache, opj, M)
434+ print_debug ! (debugger, debugger_cache, opj, M)
433435 ldiv = true
434436 atol = zero (eltype (Δx))
435- rtol = run ! (forcing_term, forcing_term_cache, f, n)
437+ rtol = get_rtol ! (forcing_term, forcing_term_cache, f, n)
436438 verbose = Int (verbose)
437439 Krylov. solve! (solver, opj, f; M, ldiv, atol, rtol, verbose, solve_kwargs... )
438440 iter = solver. stats. niter
466468
467469Solves the equation `f(x) = 0`, using the Jacobian (or an approximation of the
468470Jacobian) `j(x) = f'(x)` if it is available. This is done by calling
469- `run !(::NewtonsMethod, cache, x, f!, j! = nothing)`, where `f!(f, x)` is a
471+ `solve_newton !(::NewtonsMethod, cache, x, f!, j! = nothing)`, where `f!(f, x)` is a
470472function that sets `f(x)` in-place and, if it is specified, `j!(j, x)` is a
471473function that sets `j(x)` in-place. The `x` passed to Newton's method is
472474modified in-place, and its initial value is used as a starting guess for the
@@ -508,7 +510,7 @@ If `j(x)` changes sufficiently slowly, `update_j` may be changed from
508510`UpdateEvery(NewNewtonIteration)` to some other `UpdateSignalHandler` that
509511gets triggered less frequently, such as `UpdateEvery(NewNewtonSolve)`. This
510512can be used to make the approximation `j(x[n]) ≈ j(x₀)`, where `x₀` is a
511- previous value of `x[n]` (possibly even a value from a previous `run !` of
513+ previous value of `x[n]` (possibly even a value from a previous `solve_newton !` of
512514Newton's method). When Newton's method uses such an approximation, it is called
513515the "chord method".
514516
@@ -558,7 +560,7 @@ function allocate_cache(alg::NewtonsMethod, x_prototype, j_prototype = nothing)
558560 )
559561end
560562
561- function run ! (alg:: NewtonsMethod , cache, x, f!, j! = nothing )
563+ function solve_newton ! (alg:: NewtonsMethod , cache, x, f!, j! = nothing )
562564 (; max_iters, update_j, krylov_method, convergence_checker, verbose) = alg
563565 (; update_j_cache, krylov_method_cache, convergence_checker_cache) = cache
564566 (; Δx, f, j) = cache
@@ -581,13 +583,13 @@ function run!(alg::NewtonsMethod, cache, x, f!, j! = nothing)
581583 ldiv! (Δx, j, f)
582584 end
583585 else
584- run ! (krylov_method, krylov_method_cache, Δx, x, f!, f, n, j)
586+ solve_krylov ! (krylov_method, krylov_method_cache, Δx, x, f!, f, n, j)
585587 end
586588 verbose && @info " Newton iteration $n : ‖x‖ = $(norm (x)) , ‖Δx‖ = $(norm (Δx)) "
587589
588590 # Check for convergence if necessary.
589591 if ! isnothing (convergence_checker)
590- run ! (convergence_checker, convergence_checker_cache, x, Δx, n) && break
592+ check_convergence ! (convergence_checker, convergence_checker_cache, x, Δx, n) && break
591593 n == max_iters && @warn " Newton's method did not converge within $n iterations"
592594 end
593595 end
0 commit comments