HyperTreeGrid in VTK: Data Construction

This is the second part of a series of blog articles about vtkHyperTreeGrid usage and implementation in VTK. The first part : an introduction about HTG can be found here.

After quickly focusing on the TB-AMR (tree-based Adaptive Mesh Refinement) technique, we are now exploring the construction of a HyperTreeGrid (the TB-AMR representation in VTK).

Let’s illustrate the construction of such a representation by following an example written in Python:

A TB-AMR (HTG) based on a 3×2 rectilinear grid.

First step : Declare and construct the rectilinear grid

The definition of a vtkHyperTreeGrid in Python is done as follows:

We continue with the description of the global rectilinear grid:

Then the coordinates of the points along each axis (here, TB-AMR 2D), starting with:

Where xValues ​​is a vtkDoubleArray of 4 values. Respectively, this work needs to be done along Y (3 values) by SetYCoordinates and Z (one value) by SetZCoordinates.

The branch factor still needs to be defined at the global level by the following call:

Second step : Declare and set a cursor on a cell of the rectilinear grid

One of the construction methods is to go only through each root cell of this grid once in order to describe the refined tree of this cell, if necessary.

To do so, we create:

  • A non-oriented cursor. Non-oriented because we want to be able to move from a cell to a child cell:
    ToChild(iChild), or to the parent cell: ToParent()
  • The global offset of the root cell tree being processed.

To identify a root cell in the grid by a global index tree, we can use the method:

With index_tree_i (resp. j and k) starting at 0 as in C language.

We then need to position the cursor following the first cell of this decomposition tree as follows:

The create parameter is set here to True to indicate that we are requesting the creation of a decomposition tree. It does not need to be specified (False by default) when creating a cursor to explore this same tree.
Still in the case of creation, we must give the global offset of the root cell tree.

The cursor then points to the root cell tree. Initially, this cell is created and considered as leaf cell, unrefined.

Third step : Use this cursor to build the tree with successive refinements

From there, we can decide to subdivide this cell:

These diagrams, extracted from the first article,
describe the decomposition tree of the rectilinear mesh with right results.
The numbers in black indicate the course index of the
daughter stitches, a value ranging from 0 to the branch factor
high at the value of the spatial dimension minus 1.

Then we need to move to one of these daughter cells :

Where iChild is the index of the child cell, which must be between 0 and b^d, b being the branch factor and d being the number of spatial dimension..

It is also possible to move to the parent cell:

At any time, information is accessible from this cursor:

  • The global offset, which identifies the index in an array where the value of the current cell must be stored, or how to access its value,
  • The current level (with level 0 as the root cell tree):

Without having to move the cursor to the root cell tree, you can decide to finish building this refined tree. All you have to do is to go to the next tree that has not yet been defined.

Warning: This construction method does not allow you to complete an already described TB-AMR, as it requires a global index definition which will be covered in the next article.

But first, you must update the global offset of the root cell tree from the construction of the current tree :

Fourth step : Move the cursor to another rectilinear grid cell, an unrefined cell.

Before positioning on the next tree to be subdivided down by resetting the cursor:

Then we continue as in step 3.

Build view: an unstructured representation

To view this representation, you can convert it to an unstructured representation with the following call:

Two remarks:

  • The topology of the unstructured mesh produced is not correct but is more than enough to perform the rendering
  • In 3D, only the mesh surface is rendered.

Currently, in 2D, this geometry filter can take a camera as a parameter in order to control an adapted building of the unstructured mesh. This filter roughly builds a pixel level or offscreen cells.

As we arrive to the end of this second article, we need to send a warning: The vtkHyperTreeGrid representation is compact; hence a filter application producing another representation as output (unstructured for example) will generate a memory blast. This is why it is preferable to use, or create, specific filters for this representation.

Simple yet complete example

Here is a small complete Python code whose result will give:

Result of this example building a TB-AMR (HTG) based on a 3×2 rectilinear grid. Only three out of six cells have been defined, only one cell has been refined. Note that if you do not initialize with a cursor under construction on a rectilinear grid cell, the cell is not defined.

Compatible with VTK 9.0.1 and ParaView 5.9.1

A complete example in Python was made by Sébastien Jourdain during a “Hackathon” in January 2019.

Acknowledgements

This work was supported by CEA

CEA, DAM, DIF, F-91297 Arpajon, France

Questions or comments are always welcome!

X