@@ -19,6 +19,11 @@ function maybe_duplicated(f, df)
1919 end
2020end
2121
22+ """
23+ JacobianOperator
24+
25+ Efficient implementation of `J(f,x) * v` and `v * J(f, x)'`
26+ """
2227struct JacobianOperator{F, A}
2328 f:: F # F!(res, u)
2429 f_cache:: F
8994# #
9095import Base: @kwdef
9196
97+ """
98+ Forcing
99+
100+ Implements forcing for inexact Newton-Krylov.
101+ The equation ``‖F′(u)d + F(u)‖ <= η * ‖F(u)‖`` gives
102+ the inexact Newton termination criterion.
103+
104+ ## Implemented variants
105+ - [`Fixed`](@ref)
106+ - [`EisenstatWalker`](@ref)
107+ """
92108abstract type Forcing end
109+
110+ """
111+ Fixed(η = 0.1)
112+ """
93113@kwdef struct Fixed <: Forcing
94114 η:: Float64 = 0.1
95115end
@@ -99,6 +119,9 @@ function (F::Fixed)(args...)
99119end
100120inital (F:: Fixed ) = F. η
101121
122+ """
123+ EisenstatWalker(η_max = 0.999, γ = 0.9)
124+ """
102125@kwdef struct EisenstatWalker <: Forcing
103126 η_max:: Float64 = 0.999
104127 γ:: Float64 = 0.9
@@ -121,11 +144,44 @@ function (F::EisenstatWalker)(η, tol, n_res, n_res_prior)
121144end
122145inital (F:: EisenstatWalker ) = F. η_max
123146
147+ const KWARGS_DOCS = """
148+ ## Keyword Arguments
149+ - `tol_rel`: Relative tolerance
150+ - `tol_abs`: Absolute tolerance
151+ - `max_niter`: Maximum number of iterations
152+ - `forcing`: Maximum forcing term for inexact Newton.
153+ If `nothing` an exact Newton method is used.
154+ - `verbose`:
155+ - `Solver`:
156+ - `M`:
157+ - `N`:
158+ - `krylov_kwarg`
159+ - `callback`:
160+ """
161+
162+ """
163+ newton_krylov(F, u₀::AbstractArray, M::Int = length(u₀); kwargs...)
164+
165+ ## Arguments
166+ - `F`: `res = F(u₀)` solves `res = F(u₀) = 0`
167+ - `u₀`: Initial guess
168+ - `M`: Length of the output of `F`. Defaults to `length(u₀)`.
169+
170+ $(KWARGS_DOCS)
171+ """
124172function newton_krylov (F, u₀:: AbstractArray , M:: Int = length (u₀); kwargs... )
125173 F! (res, u) = (res .= F (u); nothing )
126174 return newton_krylov! (F!, u₀, M; kwargs... )
127175end
128176
177+ """
178+ ## Arguments
179+ - `F!`: `F!(res, u)` solves `res = F(u) = 0`
180+ - `u₀`: Initial guess
181+ - `M`: Length of the output of `F!`. Defaults to `length(u₀)`
182+
183+ $(KWARGS_DOCS)
184+ """
129185function newton_krylov! (F!, u₀:: AbstractArray , M:: Int = length (u₀); kwargs... )
130186 res = similar (u₀, M)
131187 return newton_krylov! (F!, u₀, res; kwargs... )
148204 - `F!`: `F!(res, u)` solves `res = F(u) = 0`
149205 - `u`: Initial guess
150206 - `res`: Temporary for residual
151- ## Keyword Arguments
152- - `tol_rel`: Relative tolerance
153- - `tol_abs`: Absolute tolerance
154- - `max_niter`: Maximum number of iterations
155- - `forcing`: Maximum forcing term for inexact Newton.
156- If `nothing` an exact Newton method is used.
207+
208+ $(KWARGS_DOCS)
157209"""
158210function newton_krylov! (
159211 F!, u:: AbstractArray , res:: AbstractArray ;
0 commit comments