https://github.com/data-exp-lab/vtk_tools
Some tools for working with vtk output in yt
https://github.com/data-exp-lab/vtk_tools
Last synced: 10 months ago
JSON representation
Some tools for working with vtk output in yt
- Host: GitHub
- URL: https://github.com/data-exp-lab/vtk_tools
- Owner: data-exp-lab
- Created: 2020-08-26T15:18:59.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-26T19:51:14.000Z (almost 6 years ago)
- Last Synced: 2025-03-16T02:19:35.004Z (about 1 year ago)
- Language: Python
- Size: 433 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# vtk_tools
This package provides useful utilities for working with vtk output files. It's current focus is on handling tasks related to cell ordering and underlying shape functions for different cell types to facilitate adding new element types to *yt*. Depending on development, it may make sense to add this functionality directly to *yt* rather than maintaining a second package.
Note that a major limitation at present is that the package's shape function methods are limited to VTK cell type 72, see [Issue 1](https://github.com/data-exp-lab/vtk_tools/issues/1).
## installation
[Awaiting package details]
To install from source, clone or download the repository and use `pip install .` or `pip install -e .`
## requirements
Check `setup.py` for requirements, but it is important to stress that this package requires vtk version of `9.0.1` or later. If you have already installed vtk using pip, vtk will be upgraded during installation of `vtk_tools`. If you have already installed vtk from conda (or from source), you will likely need to uninstall `vtk` first.
Also, note that while this package requires vtk `9.0.1` or later, it can process output that was created with lower vtk versions.
## example usage
### accessing underlying `vtk` cell methods
`vtk_tools.vtk_tools.init_vtk_cell` instantiates a `vtk` cell by cell type name or ID, without having to know the full `vtk` class name:
```
>>> from vtk_tools.vtk_tools import init_vtk_cell
>>> v_cell_72,_ = init_vtk_cell(72)
>>> print(type(v_cell_72))
>>>
>>> v_cell_28,_ = init_vtk_cell(28)
>>> print(type(v_cell_28))
```
The cell objects, `v_cell_72` and `v_cell_28` are instances of python `vtk` objects, with all the associated methods and attributes.
### shape function mapping
To build a shape function mapping for a lagrange hexahedron, use `vtk_tools.shapefunctions(72,order)` where order is the element order. E.g., a first order element:
```
>>> import vtk_tools.shapefunctions as sfs
>>> sf_72_O1 = sfs.sf(72,1)
```
The two most useful attributes are the `node_order_hash` and `shape_functions` attributes. The `node_order_hash` is a dictionary mapping from VTK node ordering convention to ijk ordering. In this case we have 8 entries corresponding to the hexahedral vertices:
```
>>> print(sf_72_O1.node_order_hash)
{0: 0, 4: 1, 3: 2, 7: 3, 1: 4, 5: 5, 2: 6, 6: 7}
```
The corresponding shape functions are
```
>>> print(sf_72_O1.shape_functions)
[-0.125*(x - 1)*(y - 1)*(z - 1), 0.125*(x - 1)*(y - 1)*(z + 1), 0.125*(x - 1)*(y + 1)*(z - 1), -0.125*(x - 1)*(y + 1)*(z + 1), 0.125*(x + 1)*(y - 1)*(z - 1), -0.125*(x + 1)*(y - 1)*(z + 1), -0.125*(x + 1)*(y + 1)*(z - 1), 0.125*(x + 1)*(y + 1)*(z + 1)]
```
The shape functions can be appended to a yaml file with
```
>>> sf_72_O1.write_yaml('testyaml.yaml','a','test_hex8','hex8')
```
The default yaml formatting follows that used by *yt*'s mesh generator configuration file, `yt/utilities/mesh_types.yaml`.