tem_PosOfPath Function

public pure function tem_PosOfPath(sPath, Pathlist, lower, upper) result(IdPos)

Find the position of a specific path in the list of all paths.

Arguments

Type IntentOptional Attributes Name
type(tem_path_type), intent(in) :: sPath

Specific path to search.

type(tem_path_type), intent(in) :: Pathlist(:)

List of paths for all elements to search in.

integer, intent(in), optional :: lower

Possibly only search on a subinterval, starting at PathList(lower:)

integer, intent(in), optional :: upper

Possibly only search on a subinterval, ending at PathList(:upper)

Return Value integer

Position where sPath is found in Pathlist


Called by

proc~~tem_posofpath~~CalledByGraph proc~tem_posofpath tem_PosOfPath proc~add_ghostfromfiner add_ghostFromFiner proc~add_ghostfromfiner->proc~tem_posofpath proc~add_ghostfromfiner->proc~add_ghostfromfiner proc~identify_local_element identify_local_element proc~identify_local_element->proc~tem_posofpath proc~identify_local_element->proc~add_ghostfromfiner proc~tem_findpath tem_findPath proc~tem_findpath->proc~tem_posofpath proc~tem_findpath->proc~tem_findpath proc~identify_halo identify_halo proc~identify_halo->proc~identify_local_element proc~single_process_element single_process_element proc~single_process_element->proc~identify_local_element proc~identify_elements identify_elements proc~identify_elements->proc~single_process_element proc~identify_elements->proc~identify_elements proc~request_remotehalos request_remoteHalos proc~request_remotehalos->proc~identify_halo proc~build_levelelements build_levelElements proc~build_levelelements->proc~identify_elements proc~communicate_elements communicate_elements proc~communicate_elements->proc~request_remotehalos proc~create_allparentneighbors create_allParentNeighbors proc~create_allparentneighbors->proc~identify_elements proc~identify_additionalneigh identify_additionalNeigh proc~identify_additionalneigh->proc~identify_elements proc~identify_stencilneigh identify_stencilNeigh proc~identify_stencilneigh->proc~identify_elements

Source Code

  pure function tem_PosOfPath(sPath, Pathlist, lower, upper) result(IdPos)
    ! -------------------------------------------------------------------- !
    !> Specific path to search.
    type(tem_path_type), intent(in) :: sPath
    !> List of paths for all elements to search in.
    type(tem_path_type), intent(in) :: Pathlist(:)
    !> Possibly only search on a subinterval, starting at PathList(lower:)
    integer, intent(in), optional :: lower
    !> Possibly only search on a subinterval, ending at PathList(:upper)
    integer, intent(in), optional :: upper
    !> Position where sPath is found in Pathlist
    integer  :: IdPos
    ! -------------------------------------------------------------------- !
    integer :: lb, ub
    integer :: middleSearch
    type(tem_path_type) :: current
    integer(kind=long_k) :: pathRelation
    integer :: maxPathLen
    ! -------------------------------------------------------------------- !

    if (present(lower)) then
      lb = lower
    else
      lb = lbound(PathList,1)
    end if
    if (present(upper)) then
      ub = upper
    else
      ub = ubound(PathList,1)
    end if

    ! Start the Binary search for the neighbor elements
    binSearchLoop: do
      middleSearch = (lb + ub) / 2

      ! Build the path to the currently investigated element from leaf to root.
      current = PathList(middleSearch)

      ! pathRelation = tem_PathComparison(sPath, current)
      ! Inlined tem_PathComparison:
      maxPathLen = min(sPath%level-1, current%level-1)

      pathRelation = sPath%Node(sPath%level - maxPathLen)   &
        &          - current%Node(current%level - maxPathLen)

      if ((pathRelation == 0_long_k) .or. (lb >= ub)) then
        ! Leave the loop, if element has been found, or this
        ! was the last element to investigate.
        exit binSearchLoop
      else
        halves: if (pathRelation > 0_long_k) then
          ! Continue the search in the higher half, as the looked up element is
          ! to small.
          lb = min(middleSearch + 1, ub)
        else
          ! Continue search in the lower half, as the looked up element is to
          ! large.
          ub = max(middleSearch - 1, lb)
        end if halves
      end if

    end do binSearchLoop

    if (pathRelation == 0_long_k) then
      if (current%Level <= sPath%Level) then
        ! The found ID is actually a leaf
        IdPos = middleSearch
      else
        ! The found ID is a child of the searched
        ! virtual treeID
        IdPos = -middleSearch
      end if
    else
      IdPos = 0 ! no matching element found.
    end if

  end function tem_PosOfPath