Skip to content

Commit 08bd8e2

Browse files
committed
Fix for PVPythonViewConfigurator to handle new MultiblockDataSet input. Can still crash in some cases and will need separate PR to deal with it.
1 parent 358a45f commit 08bd8e2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

geos-pv/src/geos/pv/plugins/PVPythonViewConfigurator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
update_paths()
1818

19+
from geos.mesh.utils.multiblockModifiers import mergeBlocks
1920
import geos.pv.utils.paraviewTreatments as pvt
2021
from geos.pv.utils.checkboxFunction import ( # type: ignore[attr-defined]
2122
createModifiedCallback, )
@@ -44,7 +45,10 @@
4445
from paraview.util.vtkAlgorithm import ( # type: ignore[import-not-found]
4546
VTKPythonAlgorithmBase )
4647

47-
from vtkmodules.vtkCommonDataModel import vtkDataObject
48+
from vtkmodules.vtkCommonDataModel import (
49+
vtkDataObject,
50+
vtkMultiBlockDataSet,
51+
)
4852
from geos.pv.utils.details import SISOFilter, FilterCategory
4953

5054
__doc__ = """
@@ -84,6 +88,9 @@ def __init__( self: Self ) -> None:
8488
# Input source and curve names.
8589
inputSource = GetActiveSource()
8690
dataset = servermanager.Fetch( inputSource )
91+
# Handle vtkMultiBlockDataSet by merging blocks first
92+
if isinstance( dataset, vtkMultiBlockDataSet ):
93+
dataset = mergeBlocks( dataset, keepPartialAttributes=True )
8794
dataframe: pd.DataFrame = pvt.vtkToDataframe( dataset )
8895
self.m_pathPythonViewScript: Path = geos_pv_path / "src/geos/pv/pythonViewUtils/mainPythonView.py"
8996

geos-pv/src/geos/pv/utils/paraviewTreatments.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
vtkTable,
3838
vtkUnstructuredGrid,
3939
)
40+
from vtkmodules.vtkFiltersParallelDIY2 import vtkGenerateGlobalIds
4041

4142
from geos.utils.GeosOutputsConstants import (
4243
ComponentNameEnum,
@@ -122,8 +123,18 @@ def vtkUnstructuredGridCellsToDataframe( grid: vtkUnstructuredGrid ) -> pd.DataF
122123
Returns:
123124
pd.DataFrame: Pandas dataframe.
124125
"""
125-
cellIdAttributeName = GeosMeshOutputsEnum.VTK_ORIGINAL_CELL_ID.attributeName
126+
cellIdAttributeName: str = GeosMeshOutputsEnum.VTK_ORIGINAL_CELL_ID.attributeName
126127
cellData = grid.GetCellData()
128+
if not cellData.HasArray( GeosMeshOutputsEnum.VTK_ORIGINAL_CELL_ID.attributeName ):
129+
print( "We have to create global ids." )
130+
idFilter = vtkGenerateGlobalIds()
131+
idFilter.SetInputData( grid )
132+
idFilter.Update()
133+
grid = idFilter.GetOutput()
134+
cellData = grid.GetCellData() # Update cellData to point to the new grid's cell data
135+
cellIdAttributeName = "GlobalCellIds"
136+
assert cellData.HasArray(cellIdAttributeName), "Invalid global ids array name selected."
137+
127138
numberCells: int = grid.GetNumberOfCells()
128139
data: dict[ str, Any ] = {}
129140
for i in range( cellData.GetNumberOfArrays() ):

0 commit comments

Comments
 (0)