evaluate_residual Function

private function evaluate_residual(me, state, iScalar) result(res)

evaluate the residual For relative errors (defined in convergence%absoluteError ), the result is divided by the current status value

Arguments

Type IntentOptional 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

Return Value real(kind=rk)

residual to check for convergence


Called by

proc~~evaluate_residual~~CalledByGraph proc~evaluate_residual evaluate_residual proc~tem_convergence_evaluate tem_convergence_evaluate proc~tem_convergence_evaluate->proc~evaluate_residual proc~tem_convergence_check_point tem_convergence_check_point proc~tem_convergence_check_point->proc~tem_convergence_evaluate proc~tem_convergence_check_element tem_convergence_check_element proc~tem_convergence_check_element->proc~tem_convergence_evaluate proc~tem_convergence_check tem_convergence_check proc~tem_convergence_check->proc~tem_convergence_check_point proc~tem_convergence_check->proc~tem_convergence_check_element

Contents

Source Code


Source Code

  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