evaluate the residual For relative errors (defined in convergence%absoluteError ), the result is divided by the current status value
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tem_convergence_type), | intent(inout) | :: | me |
Convergence description |
||
real(kind=rk), | intent(in) | :: | state |
Spatially reduced variable value |
||
integer, | intent(in) | :: | iScalar |
Current scalar |
residual to check for convergence
function evaluate_residual( me, state, iScalar ) result( res )
! -------------------------------------------------------------------- !
!> Convergence description
type(tem_convergence_type), intent(inout) :: me
!> Spatially reduced variable value
real(kind=rk), intent(in) :: state
!> Current scalar
integer, intent(in) :: iScalar
!> residual to check for convergence
real(kind=rk) :: res
! -------------------------------------------------------------------- !
integer :: pos_lastState
real(kind=rk) :: average
! -------------------------------------------------------------------- !
! Reset the result
res = huge( res )
select case (me%norm_kind )
case( norm_simple )
if (me%nChecks > 1) then
res = abs((state - me%lastState(1, iScalar)))
end if
! update the result at t-1 to t as when we arrive at t+1, it will
! be required
me%lastState(1, iScalar) = state
case( norm_average )
pos_lastState = mod( me%nChecks - 1, me%header%nLastVals ) + 1
if ( me%nChecks <= me%header%nLastVals ) then
average = sum( me%lastState(1:pos_lastState, iScalar) ) &
& / real( pos_lastState, kind=rk )
else
average = sum( me%lastState(:, iScalar) ) &
& / real( me%header%nLastVals, kind=rk )
end if
res = abs( (state - average ) )
me%lastState( pos_lastState, iScalar ) = state
!write(*,*) 'nCheck ', me%nChecks, iScalar
!write(*,*) 'lastState', me%lastState
!write(*,*) 'state:', state,'average', average, 'res', res, &
! & 'pos last', pos_lastState
end select
end function evaluate_residual