temporal_from_file_periodic_for Function

private function temporal_from_file_periodic_for(me, time) result(res)

This function searches for the right values in the periodic data read from file and interpolates them if needed.

Two different kinds of interpolation between the data tuples are available. \li \a 'none': No interpolation between the data points is performed. The data is evaluated as ]t1,t2] -> v1, ]t2,t3] -> v2, ... \li \a 'linear': The value is interpolated in a linear fashion from the provided data.

Arguments

Type IntentOptional Attributes Name
type(tem_from_file_temporal_type) :: me

datatype incl. the data read from file

type(tem_time_type), intent(in) :: time

timer object incl. the current time information

Return Value real(kind=rk)

return value


Source Code

  function temporal_from_file_periodic_for( me, time ) result(res)
    ! --------------------------------------------------------------------------
    !> datatype incl. the data read from file
    type(tem_from_file_temporal_type) :: me
    !> timer object incl. the current time information
    type(tem_time_type), intent(in)  :: time
    !> return value
    real(kind=rk) :: res
    ! --------------------------------------------------------------------------
    ! local variables
    integer :: iData
    ! period in physical units
    real(kind=rk) :: rPeriod
    real(kind=rk) :: ratio
    ! remainder in physical units
    real(kind=rk) :: rRem
    ! --------------------------------------------------------------------------

    ! calculate the period in physical units (last time signal
    ! - first time signal)
    rPeriod = me%signal%val(1,me%signal%nVals) - me%signal%val(1,1)
    ratio = time%sim / rPeriod
    rRem =  (ratio - floor(ratio))*rPeriod
    res = 1.0_rk

    ! search for the correct entry in the data read from file
    do iData = 1, me%signal%nVals-1
      if ( ( (rRem+eps) >= me%signal%val(1, iData) ) .and.                   &
        &  ( (rRem) <= me%signal%val(1, iData+1) ) )then
        exit
      end if
    end do

    if( .not. me%ramp .or. time%sim >= me%rampT)then
      select case( trim(adjustl(me%intp)) )
        case( 'none' )
          ! result is the data stored in the position directly
          res = me%signal%val(2, iData)
        case( 'linear' )
          ! result is the linear interpolation between the data from
          ! iData and iData+1
          res = ( me%signal%val(2, iData+1) - me%signal%val(2, iData) ) &
            & / ( me%signal%val(1, iData+1) - me%signal%val(1, iData) ) &
            & * (rRem - me%signal%val(1, iData) )                       &
            & + me%signal%val(2, iData)
      end select
    else
      res = me%rampVal * sin( PI * 0.5_rk * (time%sim/me%rampT))
    end if

  end function temporal_from_file_periodic_for