Evaluate if the convergence was achieved
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tem_convergence_type), | intent(inout) | :: | me |
Convergence description contians |
||
logical, | intent(out) | :: | achieved |
is all Scalars in current convergence_type are converged |
subroutine tem_convergence_evaluate( me, achieved )
! -------------------------------------------------------------------- !
!> Convergence description contians
type(tem_convergence_type), intent(inout) :: me
!> is all Scalars in current convergence_type are converged
logical, intent(out) :: achieved
! -------------------------------------------------------------------- !
integer :: iVar, iComp, iScalar
real(kind=rk) :: residual, threshold_fac
logical :: isConverged(me%varMap%nScalars)
! -------------------------------------------------------------------- !
! Increase the counter for the checks
me%nChecks = me%nChecks + 1
iScalar = 0
do iVar = 1, me%varMap%varPos%nVals
do iComp = 1, me%redSpatial(iVar)%nComponents
iScalar = iScalar + 1
! Compare the results against threshold
!norm = abs(state(1) - me%result_prev)
residual = evaluate_residual( &
& me = me, &
& state = me%redspatial(ivar)%val(icomp), &
& iScalar = iScalar )
if( me%header%absoluteError ) then
! For absolute error, just use threshold
threshold_fac = me%header%cond(iVar)%threshold
else
! For relative errors, multiply threshold with current state value
threshold_fac = me%redSpatial(iVar)%val(iComp) &
& * me%header%cond(iVar)%threshold
end if
isConverged(iScalar) = tem_comparator( &
& val = residual, &
& operation = me%header%cond(iVar)%operation, &
& threshold = threshold_fac )
end do
end do
! update the convergence achieved if the last compare was succesful
achieved = all(isConverged)
end subroutine tem_convergence_evaluate