dynamic_tol_sp Subroutine

public subroutine dynamic_tol_sp(tol, target_tol, rnorm, iter, info)

Dynamic tolerance scheduler for the Newton iteration setting tol based on the current residual tol

Arguments

Type IntentOptional Attributes Name
real(kind=sp), intent(out) :: tol

Tolerance to be used

real(kind=sp), intent(in) :: target_tol

Target tolerance

real(kind=sp), intent(in) :: rnorm

Norm of the residual of the current iterate

integer, intent(in) :: iter

Newton iteration count

integer, intent(out) :: info

Information flag


Source Code

    subroutine dynamic_tol_sp(tol, target_tol, rnorm, iter, info)
        !! Dynamic tolerance scheduler for the Newton iteration setting tol based on the current residual tol
        real(sp), intent(out) :: tol
        !! Tolerance to be used
        real(sp), intent(in) :: target_tol
        !! Target tolerance
        real(sp), intent(in)  :: rnorm
        !! Norm of the residual of the current iterate
        integer,  intent(in)  :: iter
        !! Newton iteration count
        integer,  intent(out)  :: info
        !! Information flag
        ! internals
        character(len=*), parameter :: this_procedure = 'dynamic_tol_sp'
        real(sp) :: tol_old, target_tol_
        character(len=256) :: msg

        target_tol_ = max(target_tol, atol_sp)
        if (target_tol < atol_sp) then
            write(msg,'(A,E9.2)') 'Input target tolerance below atol! Resetting target to atol= ', target_tol_
            call logger%log_warning(msg, this_module, this_procedure)
        end if
        
        tol_old = tol
        tol = max(0.1*rnorm, target_tol_)

        if (tol /= tol_old) then
            if (tol == target_tol_) then
                write(msg,'(A,E9.2)') 'Solver tolerance set to input target. tol= ', tol
            else
                write(msg,'(A,E9.2)') 'Solver tolerance set to tol= ', tol
            end if
            call logger%log_information(msg, this_module, this_procedure)
        else
            write(msg,'(A,E9.2)') 'solver tolerances unchanged at tol= ', tol_old
            call logger%log_information(msg, this_module, this_procedure)
        end if
        return
    end subroutine dynamic_tol_sp