combine_fromIndex Subroutine

private recursive subroutine combine_fromIndex(fun, varSys, time, iLevel, idx, idxLen, nVals, res)

Same as combine_from Point except it combine from points via indices which are setup before

The interface has to comply to the abstract interface tem_varSys_module#tem_varSys_proc_getvalofIndex.

Arguments

Type IntentOptional Attributes Name
class(tem_varSys_op_type), intent(in) :: fun

Description of the method to obtain the variables, here some preset values might be stored, like the space time function to use or the required variables.

type(tem_varSys_type), intent(in) :: varSys

The variable system to obtain the variable from.

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

Point in time at which to evaluate the variable.

integer, intent(in) :: iLevel

Level on which values are requested

integer, intent(in) :: idx(:)

Index of points in the growing array and variable val array to return. Size: nVals

integer, intent(in), optional :: idxLen(:)

With idx as start index in contiguous memory, idxLength defines length of each contiguous memory Size: nVals

integer, intent(in) :: nVals

Number of values to obtain for this variable (vectorized access).

real(kind=rk), intent(out) :: res(:)

Resulting values for the requested variable.

Dimension: n requested entries x nComponents of this variable Access: (iElem-1)*fun%nComponents + iComp


Calls

proc~~combine_fromindex~~CallsGraph proc~combine_fromindex combine_fromIndex proc~tem_varsys_check_inargs tem_varSys_check_inArgs proc~combine_fromindex->proc~tem_varsys_check_inargs

Source Code

  recursive subroutine combine_fromIndex( fun, varSys, time, iLevel, idx, &
    &                                     idxLen, nVals, res              )
    ! ---------------------------------------------------------------------- !
    !> Description of the method to obtain the variables, here some preset
    !! values might be stored, like the space time function to use or the
    !! required variables.
    class(tem_varSys_op_type), intent(in) :: fun

    !> The variable system to obtain the variable from.
    type(tem_varSys_type), intent(in) :: varSys

    !> Point in time at which to evaluate the variable.
    type(tem_time_type), intent(in) :: time

    !> Level on which values are requested
    integer, intent(in) :: iLevel

    !> Index of points in the growing array and variable val array to
    !! return.
    !! Size: nVals
    integer, intent(in) :: idx(:)

    !> With idx as start index in contiguous memory,
    !! idxLength defines length of each contiguous memory
    !! Size: nVals
    integer, optional, intent(in) :: idxLen(:)

    !> Number of values to obtain for this variable (vectorized access).
    integer, intent(in) :: nVals

    !> Resulting values for the requested variable.
    !!
    !! Dimension: n requested entries x nComponents of this variable
    !! Access: (iElem-1)*fun%nComponents + iComp
    real(kind=rk), intent(out) :: res(:)
    ! ---------------------------------------------------------------------- !
    integer :: iVal, iDep
    integer :: maxComponents, compOff, dep_nComps, depVar_pos
    real(kind=rk), allocatable :: input_varRes(:)
    integer :: e_start, t_start, res_size
    type(tem_varSys_op_data_type), pointer :: opData
    ! ---------------------------------------------------------------------- !
    call C_F_POINTER( fun%method_Data, opData )

    call tem_varSys_check_inArgs( fun, varSys, time, iLevel, idx, idxLen, &
      &    nVals, label = 'combine_fromIndex'                             )

    ! Need to obtain the data variable for variable, and store it in an
    ! intermediate array, because all components should be put together in the
    ! res array.
    ! The temporary array therefore needs to be sufficiently large to store the
    ! maximal number of components.
    maxComponents = maxval(varSys%method%val(fun%input_varPos(:))%nComponents)

    ! Using a temporary array to store the variables and transfer them to res
    ! in the correct ordering afterwards.
    allocate(input_varRes(nVals*maxComponents))

    compOff = 0
    do iDep = 1, fun%nInputs

      ! get the position of dependent variable
      depVar_pos = fun%input_varPos(iDep)

      ! get the number of components for variable iVar
      dep_nComps = varSys%method%val(depVar_pos)%nComponents

      ! get the size of the needed part of the res array
      res_size = nVals * dep_nComps

      ! derive dependent variable
      call varSys%method%val(depVar_pos)%get_valOfIndex( &
          & varSys  = varSys,                            &
          & time    = time,                              &
          & iLevel  = iLevel,                            &
          & idx     = opData%input_pntIndex(iDep)        &
          &           %indexLvl(iLevel)%val( idx(:) ),   &
          & nVals   = nVals,                             &
          & res     = input_varRes(:res_size)            )

      ! copy the information to the right positions in the result array
      ! res contains results for all variables,
      ! input_varRes is only for one variable
      do iVal = 1, nVals
        e_start = (iVal-1)*fun%nComponents + compOff
        t_start = (iVal-1)*dep_nComps
        res( (e_start+1) : (e_start+dep_nComps) )               &
          &  = input_varRes( t_start + 1 : t_start + dep_nComps )
      end do
      ! Increase the component offset for the next variables.
      compOff = compOff + dep_nComps
    end do !iDep

    deallocate(input_varRes)

  end subroutine combine_fromIndex