From 19fb541615ee64780dd871325b2629254b41c09c Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Fri, 27 Oct 2023 12:32:51 -0400 Subject: [PATCH] Fix TR scalars --- src/default.jl | 3 +-- src/trustRegion.jl | 15 ++++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/default.jl b/src/default.jl index a163903bb..1c992a527 100644 --- a/src/default.jl +++ b/src/default.jl @@ -127,8 +127,7 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::FastShortcutNonlinearPolyalg, args...; kwargs...) where {uType, iip} @unpack adkwargs, linsolve, precs = alg - algs = ( - GeneralKlement(; linsolve, precs), + algs = (GeneralKlement(; linsolve, precs), GeneralBroyden(), NewtonRaphson(; linsolve, precs, adkwargs...), NewtonRaphson(; linsolve, precs, linesearch = BackTracking(), adkwargs...), diff --git a/src/trustRegion.jl b/src/trustRegion.jl index 4339b4739..09f02b13a 100644 --- a/src/trustRegion.jl +++ b/src/trustRegion.jl @@ -388,11 +388,16 @@ function perform_step!(cache::TrustRegionCache{false}) cache.g = _restructure(fu, J' * _vec(fu)) cache.stats.njacs += 1 - # do not use A = cache.H, b = _vec(cache.g) since it is equivalent - # to A = cache.J, b = _vec(fu) as long as the Jacobian is non-singular - linres = dolinsolve(cache.alg.precs, cache.linsolve, A = cache.J, b = -_vec(fu), - linu = _vec(cache.u_gauss_newton), p = p, reltol = cache.abstol) - cache.linsolve = linres.cache + if cache.linsolve === nothing + # Scalar + cache.u_gauss_newton = -cache.H \ cache.g + else + # do not use A = cache.H, b = _vec(cache.g) since it is equivalent + # to A = cache.J, b = _vec(fu) as long as the Jacobian is non-singular + linres = dolinsolve(cache.alg.precs, cache.linsolve, A = cache.J, b = -_vec(fu), + linu = _vec(cache.u_gauss_newton), p = p, reltol = cache.abstol) + cache.linsolve = linres.cache + end end # Compute the Newton step.