Skip to content

Commit 4fa2085

Browse files
committed
more comments on the Newton-Krylov solver; fix atol passed to Krylov
1 parent 9994e47 commit 4fa2085

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

libs/Theseus/test/runtests.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ end
226226
dts = 2.0 .^ (-3:-1:-7)
227227
errors = compute_errors(ode, u_ana, alg, dts;
228228
newton_tol_abs = 1.0e-8,
229-
newton_tol_rel = 1.0e-8,
230-
krylov_kwargs = (; atol = 1.0e-8, rtol = 1.0e-8)
229+
newton_tol_rel = 1.0e-8
231230
)
232231
eoc = compute_eoc(dts, errors)
233232
@test isapprox(eoc, order; atol = 0.1)

src/Ariadne.jl

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,20 +394,31 @@ function newton_krylov!(
394394
kwargs = (; M = M(J), kwargs...)
395395
end
396396
if forcing !== nothing
397-
# ‖F′(u)d + F(u)‖ <= η * ‖F(u)‖ Inexact Newton termination
398-
kwargs = (; rtol = η, kwargs...)
397+
# The termination cirterion of the inner Krylov solver is
398+
# ‖F′(u) d + F(u)‖ <= η ‖F(u)‖
399+
# i.e., we use an inexact Newton method. Since the initial
400+
# guess of the Krylov solver is zero, we set an absolute
401+
# tolerance of `atol = 0` and a relative tolerance of
402+
# `rtol = η`.
403+
# Since the user-provided `kwargs` are appended at the end,
404+
# the user can override these settings.
405+
kwargs = (; atol = zero(η), rtol = η, kwargs...)
399406
end
400407

401-
# Solve: Jx = -res
402-
# res is modified by J, so we create a copy `-res`
403-
# TODO: provide a temporary storage for `-res`
408+
# Solve: J d = res = F(u)
409+
# Typically, the Newton method is formulated as J d = -F(u)
410+
# with update u = u + d.
411+
# To simplify the implementation, we solve J d = F(u)
412+
# and update u = u - d instead.
413+
# `res` is modified by J, so we create a copy `res`
414+
# TODO: provide a temporary storage for `res`
404415
krylov_solve!(workspace, J, copy(res); kwargs...)
405416

406-
d = workspace.x # Newton direction
407-
s = 1 # Newton step TODO: LineSearch
417+
d = workspace.x # (negative) Newton direction
418+
s = 1 # Scaling of the Newton step TODO: LineSearch
408419

409420
# Update u
410-
u .-= s .* d
421+
u .= muladd.(-s, d, u) # u = u - s * d
411422

412423
# Update residual and norm
413424
n_res_prior = n_res

0 commit comments

Comments
 (0)