[vtkusers] Horrible performance partitioning an UnstructuredGrid into connected regions with vtkConnectivityFilter

scotsman60 doug at beachmailing.com
Sun Jun 17 05:44:22 EDT 2018


Hello!!!

I am partitioning a single large vtkUnstructuredGrid with around 15 million
Points and Cells into contiguous cell regions using the
vtkConnectivityFilter.

I'm using VTK 7.1 with Python 3.6.2

The filter finds around 4,700 regions quite quickly - in about 10 seconds.

But then it takes almost the same amount of time to extract each region into
it's own grid and add to a MultiBlockDataSet - this is my end goal at the
moment.

Here is the code,

    def extractConnectedRegions(self):
        start = timer()
        connect = vtk.vtkConnectivityFilter() 
        connect.SetInputData(self.mesh)
        connect.SetExtractionModeToSpecifiedRegions()
        connect.ColorRegionsOn();
        connect.Update() 
        num_regions = connect.GetNumberOfExtractedRegions()
        end = timer()
        print("Extracted " + str(num_regions) + " regions in " +
str(end-start) + " seconds")
               
        self.mb = vtk.vtkMultiBlockDataSet()
                
        i=0
        while True:
            start = timer()
            extractGrid = vtk.vtkUnstructuredGrid()
            connect.AddSpecifiedRegion(i)
            connect.Update() 
            extractGrid.DeepCopy(connect.GetOutput())
            if extractGrid.GetNumberOfCells() <= 0:
                break
            print(i,extractGrid.GetNumberOfCells())
            self.mb.SetBlock(i, extractGrid)
            connect.DeleteSpecifiedRegion(i)
            end = timer()
            print("Processed region " + str(i) + " in " + str(end-start) + "
seconds")
            i+=1
            
        return num_regions

  
The output from this fragment is shown below,

Time to add 15811239 points to vtkUnstructuredGrid - 0.19109638981581245
seconds
Time to size array for 15685372 elements is 8.62148243552241e-06 seconds
Time to create connectivity array for 15685372 elements is
0.6341917319162356 seconds
Time to populate vtkUnstructuredGrid with 15685372 cells is
1.5787703795422896 seconds
Extracted 4739 regions in 10.1558246735332 seconds
0 1
Processed region 0 in 7.074993349142119 seconds
1 1
Processed region 1 in 7.067869541369976 seconds
2 1
Processed region 2 in 6.956592478126069 seconds
3 1
Processed region 3 in 6.968502850836856 seconds


I have to believe that there's a more efficient way to do this than the one
I'm using, but I haven't been able to find one.

Any suggestions, hints or solutions will be gratefully appreciated.

Doug





--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list