From d3ce2ace905575654224dbaff320c545467f6aa0 Mon Sep 17 00:00:00 2001 From: Bart de Koning Date: Thu, 29 Aug 2024 22:41:16 +0200 Subject: [PATCH] Add check whether relaxation is better than the full step --- lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl index c1c8f67db7..d9692406b6 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl @@ -456,8 +456,11 @@ function relax!(dz, nlsolver::AbstractNLSolver, integrator::DEIntegrator, f::TF, end α0 = one(eltype(ustep)) ϕ0, dϕ0 = ϕdϕ(zero(α0)) - α, _ = linesearch(ϕ, dϕ, ϕdϕ, α0, ϕ0, dϕ0) - @.. dz = dz * α + α, ϕα = linesearch(ϕ, dϕ, ϕdϕ, α0, ϕ0, dϕ0) + # Check whether relaxation is better than the full step + if ϕα < ϕ(1) + @.. dz = dz * α + end return dz end end @@ -510,8 +513,11 @@ function relax(dz, nlsolver::AbstractNLSolver, integrator::DEIntegrator, f::TF, end α0 = one(eltype(dz)) ϕ0, dϕ0 = ϕdϕ(zero(α0)) - α, _ = linesearch(ϕ, dϕ, ϕdϕ, α0, ϕ0, dϕ0) - dz = dz * α + α, ϕα = linesearch(ϕ, dϕ, ϕdϕ, α0, ϕ0, dϕ0) + # Check whether relaxation is better than the full step + if ϕα < ϕ(1) + dz = dz * α + end return dz end end