tem_IdOfCoord Function

public pure function tem_IdOfCoord(coord, offset) result(nTreeID)

This function calculates the tree ID for a given x,y and z on the given refinement level. This ID in the complete tree does not have to be in the list of leafs (treeIDlist) An example of this procedure is following: 1. Convert coordinates into binary representation: (x,y,z) = (5,9,1) = (0101,1001,0001) 2. Interleaving the bits by 3 digits for each direction: x(0101): 0 1 0 1 y(1001): 1 0 0 1 z(0001): 0 0 0 1 Combining these bits results in a binary number: 010 001 000 111, which is 1095 when seen as a 10-base number. 3. This number is the cell position in a single level sorted element list. Its treeID can be obtained by adding the correspoding level offset.

Periodic displacement for requested elements outside the cube

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: coord(4)

3D Coordinates to translate

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

Return Value integer(kind=long_k)

resulting treeID


Called by

proc~~tem_idofcoord~~CalledByGraph proc~tem_idofcoord tem_IdOfCoord proc~evaluate_add_spacetime_vectorbycoordinate evaluate_add_spacetime_vectorByCoordinate proc~evaluate_add_spacetime_vectorbycoordinate->proc~tem_idofcoord proc~tem_calc_vrtx_coord_noqval tem_calc_vrtx_coord_noqval proc~tem_calc_vrtx_coord_noqval->proc~tem_idofcoord proc~tem_cano_initsubtree tem_cano_initSubTree proc~tem_cano_initsubtree->proc~tem_idofcoord proc~load_bc_intern_1d load_BC_intern_1D proc~load_bc_intern_1d->proc~tem_idofcoord proc~generate_treelm_slice generate_treelm_slice proc~generate_treelm_slice->proc~tem_idofcoord proc~evaluate_first_spacetime_vectorbycoordinate evaluate_first_spacetime_vectorByCoordinate proc~evaluate_first_spacetime_vectorbycoordinate->proc~tem_idofcoord proc~load_bc_intern_2d load_BC_intern_2D proc~load_bc_intern_2d->proc~tem_idofcoord proc~tem_cano_checkneigh tem_cano_checkNeigh proc~tem_cano_checkneigh->proc~tem_idofcoord proc~append_pointdata append_pointData proc~append_pointdata->proc~tem_idofcoord proc~generate_treelm_line generate_treelm_line proc~generate_treelm_line->proc~tem_idofcoord proc~tem_get_faceneigh tem_get_faceNeigh proc~tem_get_faceneigh->proc~tem_idofcoord proc~evaluate_first_spacetime_scalarbycoordinate evaluate_first_spacetime_scalarByCoordinate proc~evaluate_first_spacetime_scalarbycoordinate->proc~tem_idofcoord proc~setup_indices_spacetime setup_indices_spacetime proc~setup_indices_spacetime->proc~tem_idofcoord proc~tem_init_surfdata tem_init_surfData proc~tem_init_surfdata->proc~tem_idofcoord proc~tem_calc_neighbors tem_calc_neighbors proc~tem_calc_neighbors->proc~tem_idofcoord proc~generate_treelm_elements generate_treelm_elements proc~generate_treelm_elements->proc~tem_idofcoord proc~tem_calc_vrtx_coord tem_calc_vrtx_coord proc~tem_calc_vrtx_coord->proc~tem_idofcoord proc~tem_adddep_down tem_addDep_down proc~tem_adddep_down->proc~tem_idofcoord proc~evaluate_add_spacetime_scalarbycoordinate evaluate_add_spacetime_scalarByCoordinate proc~evaluate_add_spacetime_scalarbycoordinate->proc~tem_idofcoord proc~tem_cano_storepntsinsubtree tem_cano_storePntsInSubTree proc~tem_cano_storepntsinsubtree->proc~tem_idofcoord proc~tem_unify_surfacedata tem_unify_surfaceData proc~tem_unify_surfacedata->proc~tem_idofcoord proc~add_all_virtual_children add_all_virtual_children proc~add_all_virtual_children->proc~tem_idofcoord proc~update_childneighborid update_childNeighborID proc~update_childneighborid->proc~tem_idofcoord

Contents

Source Code


Source Code

  pure function tem_IdOfCoord(coord, offset) result(nTreeID)
    ! ---------------------------------------------------------------------------
    !> 3D Coordinates to translate
    integer, intent(in) :: coord(4)
    !>
    integer(kind=long_k), intent(in), optional :: offset
    !> resulting treeID
    integer(kind=long_k) :: nTreeID
    ! ---------------------------------------------------------------------------
    integer :: iLevel    ! level iterator
    ! this variable defines the upper threshold for x, y and z coordinates
    ! for a given refinement level e.g. for level = 1 only x, y and z
    ! from 0 to 1 are allowed, otherwise this neighbor is outside of the
    ! geometry
    integer :: upperBoundary
    integer :: myCoord(3)
    integer :: fak2
    integer(kind=long_k) :: fak8
    ! ---------------------------------------------------------------------------

    ! the offset has to be added to the level summation
    ! @todo: level offset is hard coded in array firstIdAtLevel,
    !        thus no need to pass offset as an argument.
    if (present(offset)) then
      nTreeID = offset
    else
      nTreeID = firstIdAtLevel(coord(4))
    end if

    !! Periodic displacement for requested elements outside the cube
    upperBoundary = 2**coord(4)
    myCoord = mod(coord(1:3) + upperBoundary, upperBoundary)

    ! To compute the tree ID of a neighbor on the same refinement level the
    ! following formula is used:
    ! newTreeID = sum(i=0, level) {8**i * (mod( (x / (2**level) ) , 2)
    !                                      + 2 * mod( ( y / (2**level) ) , 2)
    !                                      + 4 * mod( (z / (2**level) ) , 2) ) }
    fak8 = 1
    fak2 = 1
    do iLevel = 0, coord(4) - 1
      nTreeID = nTreeID + fak8 * (      mod( (myCoord(1) / fak2), 2) &
        &                         + 2 * mod( (myCoord(2) / fak2), 2) &
        &                         + 4 * mod( (myCoord(3) / fak2), 2) )
      fak2 = fak2 * 2
      fak8 = fak8 * 8
    end do

  end function tem_IdOfCoord