tem_LevelOf Function

public elemental function tem_LevelOf(TreeID) result(res)

This function delivers the refinement level of a TreeID

The refinement level of a \ref treelmesh_module::treelmesh_type::treeid "treeID" is found by repeatedly computing the parents with the equation used in the [tem_ParentOf function] (@ref tem_parentatlevel) and counting the iterations, until the universal root is reached.

Arguments

Type IntentOptional Attributes Name
integer(kind=long_k), intent(in) :: TreeID

ID in the complete tree to look up

Return Value integer

Level of the given TreeID


Source Code

  elemental function tem_LevelOf( TreeID ) result(res)
    ! ---------------------------------------------------------------------------
    !> ID in the complete tree to look up
    integer(kind=long_k), intent(in) :: TreeID
    !> Level of the given TreeID
    integer :: res
    ! ---------------------------------------------------------------------------
    integer(kind=long_k) :: tElem
    integer :: level
    ! ---------------------------------------------------------------------------

    level = 0
    tElem = TreeID
    do while (tElem /= 0)
      ! bit operation is more efficient than division
      ! tElem = (tElem-1) / 8
      tElem = ishft( (tElem-1), -3 )
      level = level + 1
    end do
    res = level

  ! end function tem_LevelOf_singleTreeID
  end function tem_LevelOf