Skip to content

Commit 6fe3c7b

Browse files
refactor: Move GeosBlockExtractor from geos-posp to geos-proccessing (#142)
* Move GeosBlockExtractor to geos-processing * Refactor using vtkExtractBlock instead of vtkPythonAlgorithmBase * Update file using GeosExtractBlock * Use dataclass for the extracted domain * Update the doc * Add the test file and the test mesh * Clarify the variable names and the doc * Revert Test CI labels identification and dispatch to create a dedicated fix PR * Add a mesh with a well only * Add a function to get the cell dimension of a mesh
1 parent c8aabe5 commit 6fe3c7b

23 files changed

+739
-362
lines changed

docs/geos_mesh_docs/processing.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ geos.mesh.processing.FillPartialArrays filter
2727
:undoc-members:
2828
:show-inheritance:
2929

30+
3031
geos.mesh.processing.meshQualityMetricHelpers module
3132
-----------------------------------------------------
3233

docs/geos_posp_docs/filters.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ vtk Filters
33

44
This package defines vtk filters that allows to process Geos outputs.
55

6-
geos_posp.filters.GeosBlockExtractor module
7-
-----------------------------------------------
8-
9-
.. automodule:: geos_posp.filters.GeosBlockExtractor
10-
:members:
11-
:undoc-members:
12-
:show-inheritance:
13-
146
geos_posp.filters.GeosBlockMerge module
157
-------------------------------------------
168

docs/geos_processing_docs/post_processing.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ geos.processing.post_processing.GeomechanicsCalculator module
1212
.. automodule:: geos.processing.post_processing.GeomechanicsCalculator
1313
:members:
1414
:undoc-members:
15-
:show-inheritance:
15+
:show-inheritance:
16+
17+
geos.processing.post_processing.GeosBlockExtractor module
18+
----------------------------------------------------------
19+
20+
.. automodule:: geos.processing.post_processing.GeosBlockExtractor
21+
:members:
22+
:undoc-members:
23+
:show-inheritance:

geos-mesh/src/geos/mesh/utils/arrayHelpers.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,58 @@
2626
"""
2727

2828

29+
def getCellDimension( mesh: Union[ vtkMultiBlockDataSet, vtkDataSet ] ) -> set[ int ]:
30+
"""Get the set of the different cells dimension of a mesh.
31+
32+
Args:
33+
mesh (Union[vtkMultiBlockDataSet, vtkDataSet]): The input mesh with the cells dimension to get.
34+
35+
Returns:
36+
set[int]: The set of the different cells dimension in the input mesh.
37+
"""
38+
if isinstance( mesh, vtkDataSet ):
39+
return getCellDimensionDataSet( mesh )
40+
elif isinstance( mesh, vtkMultiBlockDataSet ):
41+
return getCellDimensionMultiBlockDataSet( mesh )
42+
else:
43+
raise TypeError( "The input mesh must be a vtkMultiBlockDataSet or a vtkDataSet." )
44+
45+
46+
def getCellDimensionMultiBlockDataSet( multiBlockDataSet: vtkMultiBlockDataSet ) -> set[ int ]:
47+
"""Get the set of the different cells dimension of a multiBlockDataSet.
48+
49+
Args:
50+
multiBlockDataSet (vtkMultiBlockDataSet): The input mesh with the cells dimension to get.
51+
52+
Returns:
53+
set[int]: The set of the different cells dimension in the input multiBlockDataSet.
54+
"""
55+
cellDim: set[ int ] = set()
56+
listFlatIdDataSet: list[ int ] = getBlockElementIndexesFlatten( multiBlockDataSet )
57+
for flatIdDataSet in listFlatIdDataSet:
58+
dataSet: vtkDataSet = vtkDataSet.SafeDownCast( multiBlockDataSet.GetDataSet( flatIdDataSet ) )
59+
cellDim = cellDim.union( getCellDimensionDataSet( dataSet ) )
60+
return cellDim
61+
62+
63+
def getCellDimensionDataSet( dataSet: vtkDataSet ) -> set[ int ]:
64+
"""Get the set of the different cells dimension of a dataSet.
65+
66+
Args:
67+
dataSet (vtkDataSet): The input mesh with the cells dimension to get.
68+
69+
Returns:
70+
set[int]: The set of the different cells dimension in the input dataSet.
71+
"""
72+
cellDim: set[ int ] = set()
73+
cellIter = dataSet.NewCellIterator()
74+
cellIter.InitTraversal()
75+
while not cellIter.IsDoneWithTraversal():
76+
cellDim.add( cellIter.GetCellDimension() )
77+
cellIter.GoToNextCell()
78+
return cellDim
79+
80+
2981
def computeElementMapping(
3082
meshFrom: Union[ vtkDataSet, vtkMultiBlockDataSet ],
3183
meshTo: Union[ vtkDataSet, vtkMultiBlockDataSet ],

geos-mesh/src/geos/mesh/utils/multiblockHelpers.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -190,29 +190,6 @@ def getBlockFromFlatIndex( multiBlockDataSet: Union[ vtkMultiBlockDataSet, vtkCo
190190
return None
191191

192192

193-
def getBlockFromName( multiBlockDataSet: Union[ vtkMultiBlockDataSet, vtkCompositeDataSet ],
194-
blockName: str ) -> Union[ None, vtkDataObject ]:
195-
"""Get the block named blockName from the vtkMultiBlockDataSet.
196-
197-
Args:
198-
multiBlockDataSet (vtkMultiBlockDataSet | vtkCompositeDataSet): MultiBlockDataSet with the block to get.
199-
blockName (str): The name of the block to get.
200-
201-
Returns:
202-
Union[None, vtkDataObject]: The block name blockName if it exists, None otherwise
203-
"""
204-
# initialize data object tree iterator
205-
iterator: vtkDataObjectTreeIterator = vtkDataObjectTreeIterator()
206-
iterator.SetDataSet( multiBlockDataSet )
207-
iterator.VisitOnlyLeavesOff()
208-
iterator.GoToFirstItem()
209-
while iterator.GetCurrentDataObject() is not None:
210-
if iterator.GetCurrentMetaData().Get( vtkMultiBlockDataSet.NAME() ) == blockName:
211-
return iterator.GetCurrentDataObject()
212-
iterator.GoToNextItem()
213-
return None
214-
215-
216193
def extractBlock( multiBlockDataSet: vtkMultiBlockDataSet, blockIndex: int ) -> vtkMultiBlockDataSet:
217194
"""Extract the block with index blockIndex from multiBlockDataSet.
218195

geos-mesh/tests/conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy.typing as npt
1111

1212
from vtkmodules.vtkCommonDataModel import vtkDataSet, vtkMultiBlockDataSet, vtkPolyData
13-
from vtkmodules.vtkIOXML import vtkXMLGenericDataObjectReader, vtkXMLMultiBlockDataReader
13+
from vtkmodules.vtkIOXML import vtkXMLGenericDataObjectReader
1414

1515

1616
@pytest.fixture
@@ -178,6 +178,10 @@ def _get_dataset( datasetType: str ) -> Union[ vtkMultiBlockDataSet, vtkPolyData
178178
vtkFilename = "data/fracture_res5_id.vtp"
179179
elif datasetType == "emptypolydata":
180180
vtkFilename = "data/fracture_res5_id_empty.vtp"
181+
elif datasetType == "meshGeosExtractBlockTmp":
182+
vtkFilename = "data/meshGeosExtractBlockTmp.vtm"
183+
elif datasetType == "well":
184+
vtkFilename = "data/well.vtu"
181185
datapath: str = os.path.join( os.path.dirname( os.path.realpath( __file__ ) ), vtkFilename )
182186
reader.SetFileName( datapath )
183187
reader.Update()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<VTKFile type="vtkMultiBlockDataSet" version="1.0">
3+
<vtkMultiBlockDataSet>
4+
<Block name="CellElementRegion">
5+
<DataSet name="domain" file="domain_res5_id.vtu"/>
6+
<DataSet name="emptyDomain" file="domain_res5_id_empty.vtu"/>
7+
</Block>
8+
<Block name="SurfaceElementRegion">
9+
<DataSet name="fracture" file="fracture_res5_id.vtu"/>
10+
<DataSet name="emptyFracture" file="fracture_res5_id_empty.vtu"/>
11+
</Block>
12+
<Block name="WellElementRegion">
13+
<DataSet name="well" file="well.vtu"/>
14+
</Block>
15+
</vtkMultiBlockDataSet>
16+
</VTKFile>

geos-mesh/tests/data/well.vtu

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<VTKFile type="UnstructuredGrid" version="1.0" byte_order="LittleEndian" header_type="UInt64" compressor="vtkZLibDataCompressor">
2+
<UnstructuredGrid>
3+
<Piece NumberOfPoints="11" NumberOfCells="10">
4+
<PointData>
5+
<DataArray type="Float32" Name="DistanceToCenter" format="binary" RangeMin="0" RangeMax="5">
6+
AQAAAAAAAAAAgAAAAAAAACwAAAAAAAAAIQAAAAAAAAA=eF5jYFjgwMDQAMQOQMwAYtszgAGYhoqD5Bc4AACHAgY/
7+
</DataArray>
8+
<DataArray type="Float32" Name="Polynomial" format="binary" RangeMin="1" RangeMax="11">
9+
AQAAAAAAAAAAgAAAAAAAACwAAAAAAAAAKAAAAAAAAAA=eF5jYGiwZ2BgcAAiIG4A4gVAfACIHwAxgyMDgwAQKwCxgSMAmJ8GpA==
10+
</DataArray>
11+
</PointData>
12+
<CellData>
13+
</CellData>
14+
<Points>
15+
<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary" RangeMin="0" RangeMax="10">
16+
AQAAAAAAAAAAgAAAAAAAAIQAAAAAAAAAKQAAAAAAAAA=eF5jYEAGDfZIHAckJhK7AYm9AIl9AIn9AInN4IhgCiCxFeBsAJt9BjM=
17+
<InformationKey name="L2_NORM_FINITE_RANGE" location="vtkDataArray" length="2">
18+
<Value index="0">
19+
0
20+
</Value>
21+
<Value index="1">
22+
10
23+
</Value>
24+
</InformationKey>
25+
<InformationKey name="L2_NORM_RANGE" location="vtkDataArray" length="2">
26+
<Value index="0">
27+
0
28+
</Value>
29+
<Value index="1">
30+
10
31+
</Value>
32+
</InformationKey>
33+
</DataArray>
34+
</Points>
35+
<Cells>
36+
<DataArray type="Int64" Name="connectivity" format="binary" RangeMin="0" RangeMax="10">
37+
AQAAAAAAAAAAgAAAAAAAAKAAAAAAAAAAJgAAAAAAAAA=eF5dxTkCABAMALA6i/8/2MCULIl4Cldu3Hnw5OTFm8//Ahb4AGU=
38+
</DataArray>
39+
<DataArray type="Int64" Name="offsets" format="binary" RangeMin="2" RangeMax="20">
40+
AQAAAAAAAAAAgAAAAAAAAFAAAAAAAAAAIwAAAAAAAAA=eF5jYoAAFijNBqU5oDQXlOaB0nxQWgBKC0FpESgNAA4QAG8=
41+
</DataArray>
42+
<DataArray type="UInt8" Name="types" format="binary" RangeMin="3" RangeMax="3">
43+
AQAAAAAAAAAAgAAAAAAAAAoAAAAAAAAACwAAAAAAAAA=eF5jZoYBAACvAB8=
44+
</DataArray>
45+
</Cells>
46+
</Piece>
47+
</UnstructuredGrid>
48+
</VTKFile>

geos-mesh/tests/test_arrayHelpers.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919
from geos.mesh.utils.arrayModifiers import createConstantAttribute
2020

2121

22+
@pytest.mark.parametrize( "meshName, cellDimExpected", [
23+
( "dataset", { 3 } ),
24+
( "fracture", { 2 } ),
25+
( "well", { 1 } ),
26+
( "meshGeosExtractBlockTmp", { 3, 2, 1 } ),
27+
] )
28+
def test_getCellDimension(
29+
dataSetTest: vtkDataSet,
30+
meshName: str,
31+
cellDimExpected: set[ int ],
32+
) -> None:
33+
"""Test getting the different cells dimension in a mesh."""
34+
mesh: Union[ vtkDataSet, vtkMultiBlockDataSet ] = dataSetTest( meshName )
35+
cellDimObtained: set[ int ] = arrayHelpers.getCellDimension( mesh )
36+
assert cellDimObtained == cellDimExpected
37+
38+
2239
@pytest.mark.parametrize( "meshFromName, meshToName, points", [
2340
( "multiblock", "emptymultiblock", False ),
2441
( "multiblock", "emptyFracture", False ),

geos-posp/src/PVplugins/PVExtractMergeBlocksVolume.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
getAttributeToTransferFromInitialTime,
2323
)
2424
from geos.utils.Logger import ERROR, INFO, Logger, getLogger
25-
from geos_posp.filters.GeosBlockExtractor import GeosBlockExtractor
25+
from geos.processing.post_processing.GeosBlockExtractor import GeosBlockExtractor
2626
from geos_posp.filters.GeosBlockMerge import GeosBlockMerge
2727
from geos.mesh.utils.arrayModifiers import (
2828
copyAttribute,
@@ -277,13 +277,11 @@ def doExtractAndMerge( self: Self, input: vtkMultiBlockDataSet, output: vtkMulti
277277
bool: True if extraction and merge successfully eneded, False otherwise
278278
"""
279279
# extract blocks
280-
blockExtractor: GeosBlockExtractor = GeosBlockExtractor()
281-
blockExtractor.SetLogger( self.m_logger )
282-
blockExtractor.SetInputDataObject( input )
283-
blockExtractor.Update()
280+
blockExtractor: GeosBlockExtractor = GeosBlockExtractor( input )
281+
blockExtractor.applyFilter()
284282

285283
# recover output objects from GeosBlockExtractor filter
286-
volumeBlockExtracted: vtkMultiBlockDataSet = blockExtractor.getOutputVolume()
284+
volumeBlockExtracted: vtkMultiBlockDataSet = blockExtractor.extractedGeosDomain.volume
287285
assert volumeBlockExtracted is not None, "Extracted Volume mesh is null."
288286

289287
# merge internal blocks

0 commit comments

Comments
 (0)