tem_CoordOfId Function

public pure function tem_CoordOfId(TreeID, offset) result(coord)

The following function provides the spatial index triple for a given ID in the complete mesh, on its refinement level. The returned coordinates start at 0. The fourth entry is the level on which the coordinates are located in the tree. The steps are following: 1. calculate the refinement level, store to coord(4). 2. Calcualte the level offset. 3. the Morton index is obtained by subtracting the offset from treeID. 4. Apply bit interleaving rule to generate coordinates.

Arguments

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

input element ID

integer(kind=long_k), intent(in), optional :: offset

First Elem of current level, if known, to avoid recomputations

Return Value integer, (4)

coordinate of element return value


Calls

proc~~tem_coordofid~~CallsGraph proc~tem_coordofid tem_CoordOfId proc~tem_levelof tem_LevelOf proc~tem_coordofid->proc~tem_levelof

Called by

proc~~tem_coordofid~~CalledByGraph proc~tem_coordofid tem_CoordOfId proc~add_all_virtual_children add_all_virtual_children proc~add_all_virtual_children->proc~tem_coordofid proc~exit_element exit_element proc~exit_element->proc~tem_coordofid proc~load_bc_intern_1d load_BC_intern_1D proc~load_bc_intern_1d->proc~tem_coordofid proc~load_bc_intern_2d load_BC_intern_2D proc~load_bc_intern_2d->proc~tem_coordofid proc~tem_adddep_down tem_addDep_down proc~tem_adddep_down->proc~tem_coordofid proc~tem_baryofid tem_BaryOfId proc~tem_baryofid->proc~tem_coordofid proc~tem_calc_vrtx_coord tem_calc_vrtx_coord proc~tem_calc_vrtx_coord->proc~tem_coordofid proc~tem_calc_vrtx_coord_noqval tem_calc_vrtx_coord_noqval proc~tem_calc_vrtx_coord_noqval->proc~tem_coordofid proc~tem_cano_checkneigh tem_cano_checkNeigh proc~tem_cano_checkneigh->proc~tem_coordofid proc~tem_cano_storepntsinsubtree tem_cano_storePntsInSubTree proc~tem_cano_storepntsinsubtree->proc~tem_coordofid proc~tem_endofid tem_endOfId proc~tem_endofid->proc~tem_coordofid proc~tem_get_faceneigh tem_get_faceNeigh proc~tem_get_faceneigh->proc~tem_coordofid proc~tem_init_elemlevels tem_init_elemLevels proc~tem_init_elemlevels->proc~tem_coordofid proc~tem_originofid tem_originOfId proc~tem_originofid->proc~tem_coordofid proc~tem_tidinfo tem_tIDinfo proc~tem_tidinfo->proc~tem_coordofid proc~tem_vrtxcoordofid tem_vrtxCoordOfId proc~tem_vrtxcoordofid->proc~tem_coordofid

Source Code

  pure function tem_CoordOfId(TreeID, offset) result(coord)
    ! ---------------------------------------------------------------------------
    !> input element ID
    integer(kind=long_k), intent(in) :: TreeID
    !> First Elem of current level, if known, to avoid recomputations
    integer(kind=long_k), intent(in), optional :: offset
    !> coordinate of element return value
    integer :: coord(4)
    ! ---------------------------------------------------------------------------
    integer(kind=long_k) :: tElem ! temporary element
    integer(kind=long_k) :: fak(3)
    integer :: bitlevel
    integer :: i
    ! ---------------------------------------------------------------------------

    coord(:) = 0
    coord(4) = tem_LevelOf(treeID)
    fak(1) = 1
    fak(2) = 2
    fak(3) = 4
    bitlevel = 1

    ! offset has to be subtracted to get the "real" TreeID
    if (present(offset)) then
      tElem = TreeID - offset
    else
      tElem = TreeID - FirstIdAtLevel(coord(4))
    end if

    ! get x coordinate from
    !
    ! x = sum(iLevel=0, inf) { 2**iLevel * mod(tElem / (8**iLevel) ),2)   }
    ! y = sum(iLevel=0, inf) { 2**iLevel * mod(tElem /(2 * (8**iLevel) ),2)   }
    ! z = sum(iLevel=0, inf) { 2**iLevel * mod(tElem /(4 * (8**iLevel) ),2)   }
    !
    do while ((tElem / fak(1)) > 0)
      do i=1,3
        coord(i) = coord(i) + bitlevel * int(mod(tElem / fak(i), 2_long_k))
      end do
      bitlevel = bitlevel * 2
      fak = fak * 8
    end do
  end function tem_CoordOfId