Revert update if residuals or jacobian have NaNs (block_trust_region).

trustregion
Stéphane Adjemian (Ryûk) 2022-03-25 19:31:46 +01:00
parent 4cccdd9074
commit b9bc1e7cb1
Signed by: stepan
GPG Key ID: 295C1FE89E17EB3C
1 changed files with 10 additions and 1 deletions

View File

@ -132,7 +132,7 @@ contains
real(real64) :: xnorm ! Norm of rescaled x
real(real64), dimension(size(x)) :: p ! Candidate increment computed by dogleg
real(real64) :: pnorm ! Norm of rescaled p
real(real64), dimension(size(x)) :: x2 ! Candidate x for next iteration
real(real64), dimension(size(x)) :: x2, x0 ! Candidate x for next iteration and copy of x
real(real64), dimension(size(x)) :: fvec2 ! Candidate function values
real(real64) :: fn2 ! Norm of the candidate function values
real(real64), dimension(size(x)) :: w ! Candidate in the approximated linear model
@ -212,8 +212,17 @@ contains
! If successful iteration, move x and update various variables
if (ratio >= 1e-4_real64) then
x0 = x
x = x2
call f_and_update_norms
if (any(isnan(fvec)) .or. any(isnan(fjac))) then
x = x0
call f_and_update_norms
delta = delta / 2
ncslow = ncslow + 1
niter = niter + 1
cycle
end if
xnorm = norm2(dg * x)
end if