# tem_geometry_module Module

Geometric methods for the TreElM module to act on a octree based mesh. Make sure to read the introduction to the distributed octree in the Documentation.

This module contains methods that work with the actual sparse mesh, and therefore depends on the treelmesh_module.

## Interfaces

• ### private function tem_intp_bilinear_scalar(srcVal, targetCoord) result(phi)

This function returns the bi-linearly interpolated values from the four source points to the target position located at targetCoord. The source points are arranged in a square from (0,0)x(1,1) The order of the source points are according to the morton curve 1 2 3 4 (0,0); (1,0); (0,1); (1,1)

#### Arguments

Type IntentOptional AttributesName
real(kind=rk), intent(in) :: srcVal(4)

source values of the square corners

real(kind=rk), intent(in) :: targetCoord(2)

interpolation location within the square

#### Return Value real(kind=rk)

interpolated value

• ### private function tem_intp_bilinear_vec(srcVal, targetCoord, nVals) result(phi)

This function returns the bi-linearly interpolated values from the four source points to the target position located at targetCoord. The source points are arranged in a square from (0,0)x(1,1) The order of the source points are according to the morton curve 1 2 3 4 (0,0); (1,0); (0,1); (1,1)

#### Arguments

Type IntentOptional AttributesName
real(kind=rk), intent(in) :: srcVal(nVals,4)

source values of the square corners

real(kind=rk), intent(in) :: targetCoord(2)

interpolation location within the square

integer, intent(in) :: nVals

number of values

#### Return Value real(kind=rk) (nVals)

interpolated values

• ### private function tem_intp_trilinear_scalar(srcVal, targetCoord) result(phi)

This function returns the tri-linearly interpolated values from the eight source points to the target position located at targetCoord. The source points are arranged in a square from (0,0,0)x(1,1,1) The order of the source points are according to the morton curve 1 2 3 4 (0,0,0); (1,0,0); (0,1,0); (1,1,0) 5 6 7 8 (0,0,1); (1,0,1); (0,1,1); (1,1,1)

#### Arguments

Type IntentOptional AttributesName
real(kind=rk), intent(in) :: srcVal(8)

source values of the square corners

real(kind=rk), intent(in) :: targetCoord(3)

interpolation location within the square

#### Return Value real(kind=rk)

interpolated value

• ### private function tem_intp_trilinear_vec(srcVal, targetCoord, nVals) result(phi)

This function returns the tri-linearly interpolated values from the eight source points to the target position located at targetCoord. The source points are arranged in a square from (0,0,0)x(1,1,1) The order of the source points are according to the morton curve 1 2 3 4 (0,0,0); (1,0,0); (0,1,0); (1,1,0) 5 6 7 8 (0,0,1); (1,0,1); (0,1,1); (1,1,1)

#### Arguments

Type IntentOptional AttributesName
real(kind=rk), intent(in) :: srcVal(nVals,8)

source values of the square corners

real(kind=rk), intent(in) :: targetCoord(3)

interpolation location within the square

integer, intent(in) :: nVals

number of values

#### Return Value real(kind=rk) (nVals)

interpolated value

• ### private subroutine tem_setEffBoundingBox_fromTree(tree)

Calculate the real bounding box around the fluid domain

#### Arguments

Type IntentOptional AttributesName
type(treelmesh_type), intent(inout) :: tree

Mesh

• ### private subroutine tem_setEffBoundingBox_fromSubTree(subTree, globalTree)

Calculate the real bounding box around the fluid domain

#### Arguments

Type IntentOptional AttributesName
type(tem_subTree_type) :: subTree

subTree to get effective bounding cube from

type(treelmesh_type), intent(in) :: globalTree

corresponding global tree

• ### private function tem_GetLocalBoundingCube_fromTree(tree) result(BoundingCube)

Run through all the elements, check the vertices and return the fluid bounding cube

#### Arguments

Type IntentOptional AttributesName
type(treelmesh_type), intent(in) :: tree

global mesh information

#### Return Value real(kind=rk) (3,2)

xyz coordinate for min and max of bounding cube

• ### private function tem_GetLocalBoundingCube_fromSubTree(subTree, globalTree) result(BoundingCube)

Run through all the elements, check the vertices and return the fluid bounding cube

#### Arguments

Type IntentOptional AttributesName
type(tem_subTree_type), intent(in) :: subTree

subTree to locate point in

type(treelmesh_type), intent(in) :: globalTree

corresponding global tree

#### Return Value real(kind=rk) (3,2)

xyz coordinate for min and max of bounding cube

## Derived Types

### type, public :: tem_direction_type

derived type for each direction

#### Components

TypeVisibility AttributesNameInitial
type(tem_longList), public, pointer:: first=> null()

first entry of the element list

integer, public :: nElems

number of entries in element list

integer, public :: list

which list JZ:(whether it is fluid, ghost or halo, see tem_levelDesc_type)

integer, public :: pos

position in list

logical, public :: otherLevel =.false.

the current neighbors are of a different level

### type, public :: tem_neighbor_type

type neighbor_type includes the direct neighbors of each tree ID

#### Components

TypeVisibility AttributesNameInitial
integer, public :: nNeighborDirections

number of directions in which the neighbors are located e.g. for cubes and surface neighbors this will be 6 and for cubes with surface, edge and vertex neighbors this will be 22 because stencils will be mapped by this type as well, we are not able to use it as a constant directions for this neighbor JZ: in case of reconstructed DG this has to be extended to all JZ: cells inside the stencil

type(tem_direction_type), public, allocatable:: dir(:)

## Functions

### public pure function tem_CoordOfReal(mesh, point, level) result(coord)

This function returns a coordinate in the given treelmesh for a physical point location on the finest possible level.

#### Arguments

Type IntentOptional AttributesName
type(treelmesh_type), intent(in) :: mesh
real(kind=rk), intent(in) :: point(3)
integer, intent(in), optional :: level

coordinate on

### public pure function tem_ElemSizeLevel(tree, level) result(dx)

Return the size of elements on a given levle in the mesh by taking into account the size of the bounding cube given in the global info of the tree

#### Arguments

Type IntentOptional AttributesName
type(treelmesh_type), intent(in) :: tree

Mesh to locate the point in

integer, intent(in) :: level

given level to get the size for

size of Element

### public pure function tem_ElemSize(tree, treeID) result(dx)

Return the size of a given treeID in the mesh by taking into account the size of the bounding cube given in the global info of the tree

#### Arguments

Type IntentOptional AttributesName
type(treelmesh_type), intent(in) :: tree

Mesh to locate point in

integer(kind=long_k), intent(in) :: treeID

input elements

size of element

### public pure function tem_BaryOfId(tree, TreeID) result(bary)

The following function provides the coordinates of the barycenter for a given treeID in the complete mesh.

#### Arguments

Type IntentOptional AttributesName
type(treelmesh_type), intent(in) :: tree

mesh information

integer(kind=long_k), intent(in) :: TreeID

input Element ID

#### Return Value real(kind=rk) (3)

barycenter return value

### public pure function tem_originOfId(tree, TreeID) result(origin)

The following function provides the coordinates of the origin for a given ID in the complete mesh.

#### Arguments

Type IntentOptional AttributesName
type(treelmesh_type), intent(in) :: tree

mesh information

integer(kind=long_k), intent(in) :: TreeID

input element ID

#### Return Value real(kind=rk) (3)

origin return value

### public pure function tem_endOfId(tree, TreeID) result(origin)

The following function provides the coordinates of the end for a given ID in the complete mesh. The described element lies between the origin and this end point.

#### Arguments

Type IntentOptional AttributesName
type(treelmesh_type), intent(in) :: tree

mesh information

integer(kind=long_k), intent(in) :: TreeID

input element ID

#### Return Value real(kind=rk) (3)

origin return value

### public pure function tem_BaryOfCoord(coord, nPoints, origin, dx) result(bary)

This function provides the coordinates of the element barycenters for a set of given element coordinates on the same refinement level.

#### Arguments

Type IntentOptional AttributesName
integer, intent(in) :: coord(nPoints,3)
integer, intent(in) :: nPoints
real(kind=rk), intent(in) :: origin(3)

spatial index triple for a given ID

real(kind=rk), intent(in) :: dx

### public pure function tem_vrtxCoordOfId(tree, treeID) result(coord)

Calculate all eight vertex coordinates of a given tree ID

#### Arguments

Type IntentOptional AttributesName
type(treelmesh_type), intent(in) :: tree

complete tree for info about dimensions

integer(kind=long_k), intent(in) :: treeID

input element ID

#### Return Value real(kind=rk) (3,8)

all vertices coordinates function return value

### public pure function tem_PosOfId(sTreeID, treeIDlist, lower, upper) result(IdPos)

This subroutine does a binary search on a given (sparse) list of elements. The result is the position of the given tree ID in the list, 0 if no corresponding node is found, or the negative of the found ID, if it is a virtual node.

#### Arguments

Type IntentOptional AttributesName
integer(kind=long_k), intent(in) :: sTreeID

tree ID to search for

integer(kind=long_k), intent(in) :: treeIDlist(:)

List to search in

integer, intent(in), optional :: lower

lowerbound of search interval

integer, intent(in), optional :: upper

upperbound of search interval

#### Return Value integer

position of sTreeID in the list of elements

### public pure function tem_PosOfPath(sPath, Pathlist, lower, upper) result(IdPos)

Find the position of a specific path in the list of all paths.

#### Arguments

Type IntentOptional AttributesName
type(tem_path_type), intent(in) :: sPath

Specific path to search.

type(tem_path_type), intent(in) :: Pathlist(:)

List of paths for all elements to search in.

integer, intent(in), optional :: lower

Possibly only search on a subinterval, starting at PathList(lower:)

integer, intent(in), optional :: upper

Possibly only search on a subinterval, ending at PathList(:upper)

#### Return Value integer

Position where sPath is found in Pathlist

### private function tem_GetLocalBoundingCube_fromTree(tree) result(BoundingCube)

Run through all the elements, check the vertices and return the fluid bounding cube

#### Arguments

Type IntentOptional AttributesName
type(treelmesh_type), intent(in) :: tree

global mesh information

#### Return Value real(kind=rk) (3,2)

xyz coordinate for min and max of bounding cube

### private function tem_GetLocalBoundingCube_fromSubTree(subTree, globalTree) result(BoundingCube)

Run through all the elements, check the vertices and return the fluid bounding cube

#### Arguments

Type IntentOptional AttributesName
type(tem_subTree_type), intent(in) :: subTree

subTree to locate point in

type(treelmesh_type), intent(in) :: globalTree

corresponding global tree

#### Return Value real(kind=rk) (3,2)

xyz coordinate for min and max of bounding cube

### private function tem_intp_bilinear_scalar(srcVal, targetCoord) result(phi)

This function returns the bi-linearly interpolated values from the four source points to the target position located at targetCoord. The source points are arranged in a square from (0,0)x(1,1) The order of the source points are according to the morton curve 1 2 3 4 (0,0); (1,0); (0,1); (1,1)

#### Arguments

Type IntentOptional AttributesName
real(kind=rk), intent(in) :: srcVal(4)

source values of the square corners

real(kind=rk), intent(in) :: targetCoord(2)

interpolation location within the square

#### Return Value real(kind=rk)

interpolated value

### private function tem_intp_bilinear_vec(srcVal, targetCoord, nVals) result(phi)

This function returns the bi-linearly interpolated values from the four source points to the target position located at targetCoord. The source points are arranged in a square from (0,0)x(1,1) The order of the source points are according to the morton curve 1 2 3 4 (0,0); (1,0); (0,1); (1,1)

#### Arguments

Type IntentOptional AttributesName
real(kind=rk), intent(in) :: srcVal(nVals,4)

source values of the square corners

real(kind=rk), intent(in) :: targetCoord(2)

interpolation location within the square

integer, intent(in) :: nVals

number of values

#### Return Value real(kind=rk) (nVals)

interpolated values

### private function tem_intp_trilinear_scalar(srcVal, targetCoord) result(phi)

This function returns the tri-linearly interpolated values from the eight source points to the target position located at targetCoord. The source points are arranged in a square from (0,0,0)x(1,1,1) The order of the source points are according to the morton curve 1 2 3 4 (0,0,0); (1,0,0); (0,1,0); (1,1,0) 5 6 7 8 (0,0,1); (1,0,1); (0,1,1); (1,1,1)

#### Arguments

Type IntentOptional AttributesName
real(kind=rk), intent(in) :: srcVal(8)

source values of the square corners

real(kind=rk), intent(in) :: targetCoord(3)

interpolation location within the square

#### Return Value real(kind=rk)

interpolated value

### private function tem_intp_trilinear_vec(srcVal, targetCoord, nVals) result(phi)

This function returns the tri-linearly interpolated values from the eight source points to the target position located at targetCoord. The source points are arranged in a square from (0,0,0)x(1,1,1) The order of the source points are according to the morton curve 1 2 3 4 (0,0,0); (1,0,0); (0,1,0); (1,1,0) 5 6 7 8 (0,0,1); (1,0,1); (0,1,1); (1,1,1)

#### Arguments

Type IntentOptional AttributesName
real(kind=rk), intent(in) :: srcVal(nVals,8)

source values of the square corners

real(kind=rk), intent(in) :: targetCoord(3)

interpolation location within the square

integer, intent(in) :: nVals

number of values

#### Return Value real(kind=rk) (nVals)

interpolated value

### private function tem_GetRealBoundingCube(tree) result(boundingCube)

Calculate the real bounding box around the fluid domain and return only to root (efficiency reasons)

#### Arguments

Type IntentOptional AttributesName
type(treelmesh_type), intent(in) :: tree

## Subroutines

### public subroutine tem_tIDinfo(me, tree, nUnit)

Prints information about a treeID to a file unit.

#### Arguments

Type IntentOptional AttributesName
integer(kind=long_k), intent(in) :: me

given level to get the size for

type(treelmesh_type), intent(in) :: tree

Mesh to locate the point in

integer, intent(in), optional :: nUnit

the file unit to use for printing the information.

### public pure subroutine tem_eligibleChildren(eligible_child, direction)

Identify all possible children local ids for each of the 27 direct neighbors results are saved in the ElemList

#### Arguments

Type IntentOptional AttributesName
integer, intent(out), allocatable:: eligible_child(:)

Candidate children, which might be considered as neighbors

integer, intent(in) :: direction

In which direction to search for neighbors

### public recursive subroutine tem_findElement(TreeID, eligible_child, ElemList, treeIDlist, nElems, Part_First, Part_Last, otherLevel)

Recursive routine to find all actual (eligible) leave nodes in the local partition for a given treeID. Alternatively use tem_findPath, which uses precomputed paths in the tree and should speed up the search (at the expense of storing the paths beforehand).

#### Arguments

Type IntentOptional AttributesName
integer(kind=long_k) :: TreeID

TreeID to find in the array of Elements

integer :: eligible_child(:)

Candidate childs, which might be considered as neighbors

type(tem_longList), pointer:: ElemList

linked list of resulting elements building the neighbor

integer(kind=long_k), intent(in) :: treeIDlist(nElems)

array of treeIDs

integer, intent(in) :: nElems

number of elements in list

integer(kind=long_k), intent(in) :: Part_First(:)

parts first entry

integer(kind=long_k), intent(in) :: Part_Last(:)

parts last entry

logical, intent(inout), optional :: otherLevel

entry is on another level

### public recursive subroutine tem_findPath(Path, eligible_child, ElemList, pathlist, nElems, otherLevel)

Recursive routine to find all actual (eligible) leave nodes in the local partition for a given treeID.

#### Arguments

Type IntentOptional AttributesName
type(tem_path_type), intent(in) :: Path

Path to the leaf to find in the array of Elements

integer, intent(in) :: eligible_child(:)

Candidate childs, which might be considered as neighbors

type(tem_longList), pointer:: ElemList

linked list of resulting elements building the neighbor

type(tem_path_type), intent(in) :: pathlist(nElems)

array of paths

integer, intent(in) :: nElems

number of elements in list

logical, intent(inout), optional :: otherLevel

entry is on another level

### public subroutine tem_determine_discreteVector(vector, compareVector, angle)

Compare the incoming discrete vector against a set of prevailing vectors and return the found closest prevailing integer vector

#### Arguments

Type IntentOptional AttributesName
integer, intent(inout) :: vector(:)

The given vector, will be set to the vector in compareVector that is best aligned to it.

real(kind=rk), intent(in) :: compareVector(:,:)

Set of unit vectors to select from against. size is (3, nVectors)

real(kind=rk), intent(out), optional :: angle

angle between vectors

### public subroutine tem_build_treeToProp_pointer(treeToProp, nElems, ElemPropertyBits, prp_bit)

This routine builds mapping from tree%treeID to given property data array like boundary_ID or qVal

#### Arguments

Type IntentOptional AttributesName
integer, intent(out) :: treeToProp(nElems)

Pointer from tree to property data to be filled by this routine

integer :: nElems

mesh elements

integer(kind=long_k), intent(in) :: ElemPropertyBits(nElems)

Elements Property Bits

integer, intent(in) :: prp_bit

property bit

### private subroutine tem_setEffBoundingBox_fromTree(tree)

Calculate the real bounding box around the fluid domain

#### Arguments

Type IntentOptional AttributesName
type(treelmesh_type), intent(inout) :: tree

Mesh

### private subroutine tem_setEffBoundingBox_fromSubTree(subTree, globalTree)

Calculate the real bounding box around the fluid domain

#### Arguments

Type IntentOptional AttributesName
type(tem_subTree_type) :: subTree

subTree to get effective bounding cube from

type(treelmesh_type), intent(in) :: globalTree

corresponding global tree