11# Sadly `Broyden` is taken up by SimpleNonlinearSolve.jl
22"""
3- GeneralBroyden(; max_resets = 3, linesearch = LineSearch() , reset_tolerance = nothing)
3+ GeneralBroyden(; max_resets = 3, linesearch = nothing , reset_tolerance = nothing)
44
55An implementation of `Broyden` with reseting and line search.
66
@@ -21,7 +21,7 @@ An implementation of `Broyden` with reseting and line search.
2121 linesearch
2222end
2323
24- function GeneralBroyden (; max_resets = 3 , linesearch = LineSearch () ,
24+ function GeneralBroyden (; max_resets = 3 , linesearch = nothing ,
2525 reset_tolerance = nothing )
2626 linesearch = linesearch isa LineSearch ? linesearch : LineSearch (; method = linesearch)
2727 return GeneralBroyden (max_resets, reset_tolerance, linesearch)
5454 stats:: NLStats
5555 ls_cache
5656 tc_cache
57+ trace
5758end
5859
5960get_fu (cache:: GeneralBroydenCache ) = cache. fu
@@ -66,19 +67,22 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::GeneralBroyde
6667 @unpack f, u0, p = prob
6768 u = alias_u0 ? u0 : deepcopy (u0)
6869 fu = evaluate_f (prob, u)
70+ du = _mutable_zero (u)
6971 J⁻¹ = __init_identity_jacobian (u, fu)
7072 reset_tolerance = alg. reset_tolerance === nothing ? sqrt (eps (real (eltype (u)))) :
7173 alg. reset_tolerance
7274 reset_check = x -> abs (x) ≤ reset_tolerance
7375
7476 abstol, reltol, tc_cache = init_termination_cache (abstol, reltol, fu, u,
7577 termination_condition)
78+ trace = init_nonlinearsolve_trace (alg, u, fu, J⁻¹, du; uses_jac_inverse = Val (true ),
79+ kwargs... )
7680
77- return GeneralBroydenCache {iip} (f, alg, u, zero (u), _mutable_zero (u) , fu, zero (fu),
81+ return GeneralBroydenCache {iip} (f, alg, u, zero (u), du , fu, zero (fu),
7882 zero (fu), p, J⁻¹, zero (_reshape (fu, 1 , :)), _mutable_zero (u), false , 0 ,
7983 alg. max_resets, maxiters, internalnorm, ReturnCode. Default, abstol, reltol,
8084 reset_tolerance, reset_check, prob, NLStats (1 , 0 , 0 , 0 , 0 ),
81- init_linesearch_cache (alg. linesearch, f, u, p, fu, Val (iip)), tc_cache)
85+ init_linesearch_cache (alg. linesearch, f, u, p, fu, Val (iip)), tc_cache, trace )
8286end
8387
8488function perform_step! (cache:: GeneralBroydenCache{true} )
@@ -90,6 +94,9 @@ function perform_step!(cache::GeneralBroydenCache{true})
9094 _axpy! (- α, du, u)
9195 f (fu2, u, p)
9296
97+ update_trace_with_invJ! (cache. trace, cache. stats. nsteps + 1 , get_u (cache),
98+ get_fu (cache), J⁻¹, du, α)
99+
93100 check_and_update! (cache, fu2, u, u_prev)
94101 cache. stats. nf += 1
95102
@@ -131,6 +138,9 @@ function perform_step!(cache::GeneralBroydenCache{false})
131138 cache. u = cache. u .- α * cache. du
132139 cache. fu2 = f (cache. u, p)
133140
141+ update_trace_with_invJ! (cache. trace, cache. stats. nsteps + 1 , get_u (cache),
142+ get_fu (cache), cache. J⁻¹, cache. du, α)
143+
134144 check_and_update! (cache, cache. fu2, cache. u, cache. u_prev)
135145 cache. stats. nf += 1
136146
@@ -173,6 +183,7 @@ function SciMLBase.reinit!(cache::GeneralBroydenCache{iip}, u0 = cache.u; p = ca
173183 cache. fu = cache. f (cache. u, p)
174184 end
175185
186+ reset! (cache. trace)
176187 abstol, reltol, tc_cache = init_termination_cache (abstol, reltol, cache. fu, cache. u,
177188 termination_condition)
178189
0 commit comments