From 5c78b4b6e216ff398d570e55c9cdc62cd2a44472 Mon Sep 17 00:00:00 2001 From: Keita Nakamura Date: Fri, 16 Aug 2024 21:49:54 +0900 Subject: [PATCH] Refactor newton method --- src/implicit.jl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/implicit.jl b/src/implicit.jl index 76fdb9cf..2063701f 100644 --- a/src/implicit.jl +++ b/src/implicit.jl @@ -217,6 +217,8 @@ function newton!( maxiter::Int=100, atol::Real=zero(T), rtol::Real=sqrt(eps(T)), linsolve=(x,A,b)->copyto!(x,A\b), verbose::Bool=false) where {T} + compact(val) = rpad(sprint(show, val; context = :compact=>true), 11) + fx = f(x) f0 = norm(fx) δx = similar(x) @@ -229,8 +231,11 @@ function newton!( linsolve(fillzero!(δx), ∇f(x), fx) @. x -= δx fx = f(x) - verbose && println("| f | = ", norm(fx)) - solved = norm(fx) ≤ max(atol, rtol*f0) + fx_norm = norm(fx) + if verbose + println("‖f‖ = ", compact(fx_norm), " ", "‖f‖/‖f₀‖ = ", compact(fx_norm/f0)) + end + solved = fx_norm ≤ max(atol, rtol*f0) giveup = ((iter += 1) ≥ maxiter || any(!isfinite, fx)) end