Example for the stencil construction

To build the stencil for a given element, all required treeIDs can be obtained with the following procedure: First the integer coordinate tuple of the treeIDs, for which the stencil has to be obtained, is computed. Then for each stencil element the treeID is obtained by the following steps:

  • Add the stencil offset to the coordinate of the central element to obtain the coordinate for the stencil element

  • Convert the obtained coordinate back to a treeID.

To illustrate this procedure with a specific example, lets consider a two dimensional mesh. We would like to find the right neighbor of the element with treeID . An illustration of the geometrical layout for this example is given in the following Figure. As we are looking at a two dimensional mesh, there are elements on each refinement level .

Illustration of the right neighbor identification

The first information, that is needed, is the level of the given treeID. To find this, and the Morton index on that level, we subtract the elements on coarse levels, until the reduced index is smaller than the next number of elements to subtract:

  • Level 0:
  • Level 1:
  • Level 2:
  • Level 3:
  • treeID is located on Level 3 and has a Morton index of .

The binary representation of is . Due to the bit-interleaving rule, odd bits correspond to the X coordinate and even bits correspond to the Y coordinate. Thus we obtain for X and for Y . Now we found the coordinate tuple of [[treelmesh_type:treeID] and can simply add the offset , that represents the right neighbor. By this we obtain the coordinate of this neighbor to be , resulting in a binary representation of . After interleaving the bits, the Morton index of the right neighbor is found to be Finally, by adding the offset, we obtain the treeID of the right neighbor as . Note, that there is no restriction on the offsets, that are to be applied in the neighborhood search, and due to the periodic universe all offset locations are well defined.