ElemToRank Subroutine

public subroutine ElemToRank(nDomains, offsetElem, elemID, domain)

Arguments

TypeIntentOptionalAttributesName
integer, intent(in) :: nDomains
integer, intent(in) :: offsetElem(0:nDomains)
integer, intent(in) :: elemID
integer, intent(out) :: domain

Called by

proc~~elemtorank~~CalledByGraph proc~elemtorank ElemToRank proc~setelemtorank_domaindecomposition_t SetElemToRank_DomainDecomposition_t proc~setelemtorank_domaindecomposition_t->proc~elemtorank proc~setelemtorank_domaindecomposition SetElemToRank_DomainDecomposition proc~setelemtorank_domaindecomposition->proc~elemtorank

Contents

Source Code


Source Code

  subroutine ElemToRank(nDomains,offsetElem,elemID,domain)
    ! From https://www.hopr-project.org/externals/Meshformat.pdf, Algorithm 7
    !   "Find domain containing element index"
    !
    implicit none
    integer,intent(in) :: nDomains
    integer,intent(in) :: offsetElem(0:nDomains)
    integer,intent(in) :: elemID
    integer,intent(out) :: domain
    ! Local
    integer :: maxSteps
    integer :: low,up,mid
    integer :: i

    domain = 0
    maxSteps = int(log10(real(nDomains))/log10(2.0))+1
    low = 0
    up = nDomains-1

    if(offsetElem(low) < elemID .and. elemID <= offsetElem(low+1)) then
      domain = low
    elseif(offsetElem(up) < elemID .and. elemID <= offsetElem(up+1)) then
      domain = up
    else
      do i = 1,maxSteps
        mid = (up-low)/2+low
        if(offsetElem(mid) < elemID .and. elemID <= offsetElem(mid+1)) then
          domain = mid
          return
        elseif(elemID > offsetElem(mid+1)) then
          low = mid+1
        else
          up = mid
        endif
      enddo
    endif

  endsubroutine ElemToRank