Not able to read transient UnstructuredGrid data in Paraview

Hi,
I am trying to write a vtkhdf file containing transient PointData. I read the manual and tried to write a vtkhdf file with dummy data. But I am not able to read that in Paraview, Although I do see the pressure dataset and the timesteps as well in Paraview.
The writer python code is as follows

try:
    import h5py as h5
    import numpy    as np
    import os
    import sys
except:
    print( "Failed to import")
fType = 'f'
idType = 'i8'

class HfuVtkHdf:
    def writeHdf(self):
        try:
            hdfObj = h5.File('test.vtkhdf', 'w')

            # Generate the root content which will have the Version and Type attributes
            root = hdfObj.create_group('VTKHDF', track_order=True)
            root.attrs['Version'] = (2,1)
            ascii_type = 'UnstructuredGrid'.encode('ascii')
            root.attrs.create('Type', ascii_type, dtype=h5.string_dtype('ascii', len(ascii_type))) 

            self.generate_geometry_structure(root)

            hdfObj.close()
            print( "done..." )
        except:
            hdfObj.close()
            print("Exception in writeHdf")

    def generate_geometry_structure(self,f):
        try:
            root = f

            crd = np.array([[ 0.,  0.,  0.],
                   [ 5.,  0.,  0.],
                   [ 5.,  5.,  0.]])

            res = np.array([1.0 ,3.0 ,5.0 ,6.0 ,7.0 ,8.0 ,9.0 ,11.0 ,13.0 ])        

            crd = crd.astype(np.float32)
            res = res.astype(np.float32)                               
            cnn = np.array([0, 1, 2])
            cnn = cnn.astype(np.int64)       
            osets = np.array([0, 3])
            osets = osets.astype(np.int64)
            etypes  = np.zeros( 1, dtype='i' ) + 5
            etypes = etypes.astype(np.uint8)
            mat = [0]
            dset1 = root.create_dataset('NumberOfPoints', (1,), maxshape=(None,), dtype=idType)
            dset1[0] = 3
            dset4 = root.create_dataset('NumberOfConnectivityIds', (1,), maxshape=(None,), dtype=idType)
            dset4[0] = 3
            dset5 = root.create_dataset('NumberOfCells', (1,), maxshape=(None,), dtype=idType)
            dset5[0] = 1

            dset2 = root.create_dataset('Types', shape = etypes.shape, data = etypes, maxshape=(None,), dtype=np.uint8)
            dset3 = root.create_dataset('Points', shape = crd.shape, data = crd, maxshape=(None,3), dtype=fType)
            dset6 = root.create_dataset('Offsets', shape=osets.shape,data = osets, maxshape=(None,), dtype=idType)
            dset7 = root.create_dataset('Connectivity', shape=cnn.shape,data = cnn, maxshape=(None,), dtype=idType)
            pData = root.create_group('PointData')
            pData.create_dataset('pressure', shape= res.shape, data = res,  maxshape=(None,), dtype=fType)

            steps = root.create_group('Steps')
            steps.attrs['NSteps'] = 3
            timeSteps = np.array([0, 3, 6])
            timeSteps = timeSteps.astype(np.int64)
            steps.create_dataset('Values', shape= timeSteps.shape, data = timeSteps,  maxshape=(None,), dtype=fType)
            
            demotypes  = np.zeros( 3, dtype='i' )
            demotypes  = demotypes.astype(np.int64)
            singleDSs = ['PartOffsets', 'PointOffsets']
            for name in singleDSs:
                #steps.create_dataset(name, (0,), maxshape=(None,), dtype=idType)
                steps.create_dataset(name, shape= demotypes.shape, data = demotypes,  maxshape=(None,), dtype=fType)
            nTopoDSs = ['CellOffsets', 'ConnectivityIdOffsets']
            for name in nTopoDSs:
                #steps.create_dataset(name, (0,4), maxshape=(None,4), dtype=idType)
                steps.create_dataset(name, shape= demotypes.shape, data = demotypes,  maxshape=(None,), dtype=fType)

            pData = steps.create_group('PointDataOffsets')
            prOffsets = np.array([0, 3, 6])
            prOffsets  = prOffsets.astype(np.int64)
            pData.create_dataset('pressure', shape= prOffsets.shape, data = prOffsets,  maxshape=(None,), dtype=fType)

        except:
            print("Exception in generate_geometry_structure")

        
if __name__ == '__main__':
    print( "Starting...")
    obj = HfuVtkHdf( )
    obj.writeHdf()

The error is as follows:

ERROR: In vtkExecutive.cxx, line 730
vtkPVCompositeDataPipeline (00000201EBCC3060): Algorithm vtkFileSeriesReader (00000201EB97CE40) returned failure for request: vtkInformation (00000201F039C550)
Debug: Off
Modified Time: 452274
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0

Attaching the hdf file as well:
test.vtkhdf (41.9 KB)

Please tell me what I am missing. Thanks!

Hi, you’re not too far off! The NumberOfPoints, NumberOfConnectivityId and NumberOfCells datasets need to be of size 3 (your number of timesteps), and the offsets arrays should be of IdType type. The following file should open in ParaView.
test.vtkhdf (41.8 KB)

Hope this helps!

fyi @Lucas_Givord @mwestphal

1 Like

Thanks a lot! That worked for me!