Python interpreter dies using vtkHDFWriter to write partitioned data set collection

I’m trying to write a PartitionedDataSetCollection to a vtkhdf file using vtk in python. In the collection, I have two separate partitioned data sets, each with one partition. The first one’s partition contains a sphere (polydata) and the other’s partition contains an unstructured grid. However, the interpreter dies in vtkhdfwriter; the partitionedatasetcollection itself seems to be well formed.

Here’s a code sample:

import numpy as np
import pyvista as pv
from vtkmodules.vtkCommonDataModel import VTK_HEXAHEDRON, VTK_TETRA, VTK_TRIANGLE
from vtkmodules.vtkIOHDF import vtkHDFWriter
from vtkmodules.vtkFiltersSources import vtkSphereSource
from vtkmodules.vtkFiltersCore import vtkTriangleFilter
from vtkmodules.vtkCommonDataModel import vtkUnstructuredGrid, vtkPartitionedDataSetCollection, vtkDataObject
# from vtkmodules.vtkCommonCore import vtkDataObject
from vtkmodules.vtkFiltersGeneral import (vtkGroupDataSetsFilter,
                                          vtkSpatioTemporalHarmonicsAttribute,
                                          vtkWarpScalar)
from vtkmodules.vtkFiltersHybrid import vtkGenerateTimeSteps
from pathlib import Path

def write_vtk_hdf_nontransient(path: Path | None):
    sphere = vtkSphereSource()
    sphere.SetThetaResolution(20)
    sphere.SetPhiResolution(20)
    sphere.Update()

    surf_polydata = sphere.GetOutput()

    # Convert surface to unstructured grid (for demo)
    tri_filter = vtkTriangleFilter()
    tri_filter.SetInputData(surf_polydata)
    tri_filter.Update()
    volume_ugrid = vtkUnstructuredGrid()
    volume_ugrid.ShallowCopy(tri_filter.GetOutput())

    # Create a surface mesh (PolyData) as-is
    surface = surf_polydata

    # Create a vtkPartitionedDataSetCollection
    pdc = vtkPartitionedDataSetCollection()
    pdc.Initialize()

    # Partition 0 = volume mesh
    pdc.SetNumberOfPartitionedDataSets(2)
    pdc.SetNumberOfPartitions(0, 1)
    pdc.SetNumberOfPartitions(1, 1)

    pdc.SetPartition(0, 0, volume_ugrid)
    # pdc.GetMetaData(0).Set(vtkDataObject.FIELD_NAME(), "Volume")

    # Partition 1 = surface mesh
    pdc.SetPartition(1, 0, surface)
    # pdc.GetMetaData(1).Set(vtkDataObject.FIELD_NAME(), "Surface")
    if path:
        writer = vtkHDFWriter()
        writer.SetFileName(str(path))
        # Important: set input as the PDC
        writer.SetInputDataObject(pdc)

        writer.Write()
    return pdc

p = Path("test.vtkhdf")
write_vtk_hdf_nontransient(p) # dies

Any thoughts? Thanks in advance.

When I run your program, it prints these errors:

vtkHDFWriter.cxx:1451   ERR| vtkHDFWriter (0x55f6c67f5fe0): Could not retrieve assembly from composite vtkPartitionedDataSetCollection
vtkHDFWriter.cxx:403    ERR| vtkHDFWriter (0x55f6c67f5fe0): Can't write vtkDataObjectTree to file:test.vtkhdf

Perhaps your PDC needs a vtkDataAssembly in order to work with vtkHDFWriter?

1 Like

AFAIR we need it yes

FYI @Louis_Gombert

1 Like

Yes, you need to create a vtkDataAssembly and attach it to your PartitionedDataSetCollection. VTKHDF requires composite structures to define a block hierarchy.

1 Like