Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
VTK_POLYHEDRON,
VTK_POLYGON,
)

from vtkmodules.util.numpy_support import ( numpy_to_vtk, vtk_to_numpy )

from geos.processing.pre_processing.CellTypeCounterEnhanced import CellTypeCounterEnhanced
from geos.mesh.model.CellTypeCounts import CellTypeCounts

__doc__ = """
SplitMesh module is a vtk filter that split cells of a mesh composed of Tetrahedra, pyramids, and hexahedra.
SplitMesh module is a vtk filter that splits cells of a mesh composed of tetrahedra, pyramids, hexahedra, triangles, and quads.

Warning: Current implementation only supports meshes composed of either polygons or polyhedra, not both together.

Filter input and output types are vtkUnstructuredGrid.

Expand Down Expand Up @@ -133,21 +133,24 @@ def RequestData(
assert self.inData is not None, "Input mesh is undefined."
assert output is not None, "Output mesh is undefined."

# Count the number of cells before splitting. Then we will be able to know how many new cells and points
# to allocate because each cell type is splitted in a known number of new cells and points.
nbCells: int = self.inData.GetNumberOfCells()
counts: CellTypeCounts = self._getCellCounts()
nbTet: int = counts.getTypeCount( VTK_TETRA )
nbPyr: int = counts.getTypeCount( VTK_PYRAMID )
nbHex: int = counts.getTypeCount( VTK_HEXAHEDRON )
nbTriangles: int = counts.getTypeCount( VTK_TRIANGLE )
nbQuad: int = counts.getTypeCount( VTK_QUAD )
nbTet: int = counts.getTypeCount( VTK_TETRA ) # will divide into 8 tets
nbPyr: int = counts.getTypeCount( VTK_PYRAMID ) # will divide into 6 pyramids and 4 tets so 10 new cells
nbHex: int = counts.getTypeCount( VTK_HEXAHEDRON ) # will divide into 8 hexes
nbTriangles: int = counts.getTypeCount( VTK_TRIANGLE ) # will divide into 4 triangles
nbQuad: int = counts.getTypeCount( VTK_QUAD ) # will divide into 4 quads
nbPolygon: int = counts.getTypeCount( VTK_POLYGON )
nbPolyhedra: int = counts.getTypeCount( VTK_POLYHEDRON )
assert counts.getTypeCount( VTK_WEDGE ) == 0, "Input mesh contains wedges that are not currently supported."
# Current implementation only supports meshes composed of either polygons or polyhedra
assert nbPolyhedra * nbPolygon == 0, ( "Input mesh is composed of both polygons and polyhedra,"
" but it must contains only one of the two." )
nbNewPoints: int = 0
nbNewPoints = nbHex * 19 + nbTet * 6 + nbPyr * 9 if nbPolyhedra > 0 else nbTriangles * 3 + nbQuad * 5
nbNewCells: int = nbHex * 8 + nbTet * 8 + nbPyr * 10 * nbTriangles * 4 + nbQuad * 4
nbNewCells: int = nbHex * 8 + nbTet * 8 + nbPyr * 10 + nbTriangles * 4 + nbQuad * 4

self.points = vtkPoints()
self.points.DeepCopy( self.inData.GetPoints() )
Expand All @@ -159,19 +162,20 @@ def RequestData(
self.originalId.SetName( "OriginalID" )
self.originalId.Allocate( nbNewCells )
self.cellTypes = []
# Define cell type to splitting method mapping
splitMethods = {
VTK_HEXAHEDRON: self._splitHexahedron,
VTK_TETRA: self._splitTetrahedron,
VTK_PYRAMID: self._splitPyramid,
VTK_TRIANGLE: self._splitTriangle,
VTK_QUAD: self._splitQuad,
}
for c in range( nbCells ):
cell: vtkCell = self.inData.GetCell( c )
cellType: int = cell.GetCellType()
if cellType == VTK_HEXAHEDRON:
self._splitHexahedron( cell, c )
elif cellType == VTK_TETRA:
self._splitTetrahedron( cell, c )
elif cellType == VTK_PYRAMID:
self._splitPyramid( cell, c )
elif cellType == VTK_TRIANGLE:
self._splitTriangle( cell, c )
elif cellType == VTK_QUAD:
self._splitQuad( cell, c )
splitMethod = splitMethods.get( cellType )
if splitMethod is not None:
splitMethod( cell, c )
else:
raise TypeError( f"Cell type {vtkCellTypes.GetClassNameFromTypeId(cellType)} is not supported." )
# add points and cells
Expand Down Expand Up @@ -261,7 +265,7 @@ def _splitPyramid( self: Self, cell: vtkCell, index: int ) -> None:
r"""Split a pyramid.

Let's suppose an input pyramid composed of nodes (0, 1, 2, 3, 4),
the cell is splitted in 8 pyramids using edge centers.
the cell is split into 6 pyramids and 4 tetrahedra using edge centers.

4
,/|\
Expand Down Expand Up @@ -310,7 +314,8 @@ def _splitPyramid( self: Self, cell: vtkCell, index: int ) -> None:
self.cells.InsertNextCell( 4, [ pt12, pt7, pt6, pt13 ] )
for _ in range( 10 ):
self.originalId.InsertNextValue( index )
self.cellTypes.extend( [ VTK_PYRAMID ] * 8 )
self.cellTypes.extend( [ VTK_PYRAMID ] * 6 )
self.cellTypes.extend( [ VTK_TETRA ] * 4 )

def _splitHexahedron( self: Self, cell: vtkCell, index: int ) -> None:
r"""Split a hexahedron.
Expand Down Expand Up @@ -378,7 +383,7 @@ def _splitTriangle( self: Self, cell: vtkCell, index: int ) -> None:
r"""Split a triangle.

Let's suppose an input triangle composed of nodes (0, 1, 2),
the cell is splitted in 3 triangles using edge centers.
the cell is split into 4 triangles using edge centers.

2
|\
Expand Down
48 changes: 48 additions & 0 deletions geos-processing/tests/data/hexs3_tets36_pyrs18.vtu
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<VTKFile type="UnstructuredGrid" version="1.0" byte_order="LittleEndian" header_type="UInt64">
<UnstructuredGrid>
<Piece NumberOfPoints="38" NumberOfCells="57">
<PointData>
<DataArray type="Float32" Name="DistanceToCenter" format="binary" RangeMin="0" RangeMax="0.8660253882408142">
mAAAAAAAAADXs10/17NdP9ezXT/Xs10/17NdP9ezXT/Xs10/17NdP9ezXT/Xs10/17NdP9ezXT/Xs10/17NdP9ezXT/Xs10/17NdP9ezXT/Xs10/17NdP9ezXT/Xs10/AAAAANezXT/Xs10/AAAAANezXT/Xs10/17NdP9ezXT/Xs10/17NdPwAAAADXs10/17NdPwAAAAAAAAAAAAAAAA==
</DataArray>
<DataArray type="Float32" Name="Polynomial" format="binary" RangeMin="1" RangeMax="4">
mAAAAAAAAAAAAIA/AAAAQAAAAEAAAEBAAAAAQAAAQEAAAEBAAACAQAAAAEAAAABAAABAQAAAQEAAAEBAAACAQAAAAEAAAABAAABAQAAAQEAAAEBAAACAQAAAAEAAAEBAAACAPwAAAEAAAEBAAACAPwAAgD8AAABAAABAQAAAAEAAAEBAAACAQAAAgD8AAABAAABAQAAAgD8AAIA/AACAPw==
</DataArray>
</PointData>
<CellData>
</CellData>
<Points>
<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary" RangeMin="0" RangeMax="4.358898943540674">
yAEAAAAAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAAAAAAAAAAAAgD8AAIA/AAAAAAAAgD8AAAAAAACAPwAAgD8AAIA/AACAPwAAgD8AAABAAACAPwAAAAAAAIA/AAAAQAAAAAAAAABAAAAAQAAAAAAAAABAAACAPwAAgD8AAIA/AAAAQAAAgD8AAABAAAAAQAAAgD8AAEBAAAAAQAAAAAAAAABAAABAQAAAAAAAAEBAAABAQAAAAAAAAEBAAAAAQAAAgD8AAABAAABAQAAAgD8AAEBAAABAQAAAgD8AAABAAAAAAAAAAAAAAABAAAAAAAAAgD8AAMA/AAAAPwAAAD8AAEBAAACAPwAAAAAAAEBAAACAPwAAgD8AACBAAADAPwAAAD8AAAAAAAAAQAAAAAAAAAAAAABAQAAAAAAAAIA/AABAQAAAAAAAAAAAAAAAQAAAgD8AAAAAAABAQAAAgD8AAIA/AABAQAAAgD8AAAA/AAAgQAAAAD8AAEBAAAAAAAAAAAAAAEBAAAAAAAAAgD8AACBAAAAAPwAAAD8AAAA/AADAPwAAAD8AAMA/AAAgQAAAAD8=
<InformationKey name="L2_NORM_FINITE_RANGE" location="vtkDataArray" length="2">
<Value index="0">
0
</Value>
<Value index="1">
4.3588989435
</Value>
</InformationKey>
<InformationKey name="L2_NORM_RANGE" location="vtkDataArray" length="2">
<Value index="0">
0
</Value>
<Value index="1">
4.3588989435
</Value>
</InformationKey>
</DataArray>
</Points>
<Cells>
<DataArray type="Int64" Name="connectivity" format="binary" RangeMin="0" RangeMax="37">
EAgAAAAAAAAAAA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AAAAAAAAnAAAAAAAAACgAAAAAAAAAKQAAAAAAAAAqAAAAAAAAACtAAAAAAAAALIAAAAAAAAAtwAAAAAAAAC8AAAAAAAAAMEAAAAAAAAAxgAAAAAAAADLAAAAAAAAANAAAAAAAAAA1QAAAAAAAADaAAAAAAAAAN8AAAAAAAAA5AAAAAAAAADpAAAAAAAAAO4AAAAAAAAA8wAAAAAAAAD4AAAAAAAAAP0AAAAAAAAAAgEAAAAAAAA=
</DataArray>
<DataArray type="UInt8" Name="types" format="binary" RangeMin="10" RangeMax="14">
OQAAAAAAAAAMDAwKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoODg4ODg4ODg4ODg4ODg4ODg4=
</DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>
48 changes: 48 additions & 0 deletions geos-processing/tests/data/quads2_tris4.vtu
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<VTKFile type="UnstructuredGrid" version="1.0" byte_order="LittleEndian" header_type="UInt64">
<UnstructuredGrid>
<Piece NumberOfPoints="9" NumberOfCells="6">
<PointData>
<DataArray type="Float32" Name="DistanceToCenter" format="binary" RangeMin="0.7071067690849304" RangeMax="0.7071067690849304">
JAAAAAAAAADzBDU/8wQ1P/MENT/zBDU/8wQ1P/MENT/zBDU/8wQ1P/MENT8=
</DataArray>
<DataArray type="Float32" Name="Polynomial" format="binary" RangeMin="1" RangeMax="3">
JAAAAAAAAAAAAIA/AAAAQAAAAEAAAEBAAAAAQAAAAEAAAEBAAAAAQAAAAEA=
</DataArray>
</PointData>
<CellData>
</CellData>
<Points>
<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary" RangeMin="0" RangeMax="2.8284271247461903">
bAAAAAAAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAAAAAAABAAACAPwAAAAAAAIA/AAAAQAAAAAAAAABAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAA=
<InformationKey name="L2_NORM_FINITE_RANGE" location="vtkDataArray" length="2">
<Value index="0">
0
</Value>
<Value index="1">
2.8284271247
</Value>
</InformationKey>
<InformationKey name="L2_NORM_RANGE" location="vtkDataArray" length="2">
<Value index="0">
0
</Value>
<Value index="1">
2.8284271247
</Value>
</InformationKey>
</DataArray>
</Points>
<Cells>
<DataArray type="Int64" Name="connectivity" format="binary" RangeMin="0" RangeMax="8">
oAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAAAAAACAAAAAAAAAAMAAAAAAAAABAAAAAAAAAAGAAAAAAAAAAUAAAAAAAAAAQAAAAAAAAAHAAAAAAAAAAMAAAAAAAAABwAAAAAAAAAEAAAAAAAAAAMAAAAAAAAAAgAAAAAAAAADAAAAAAAAAAgAAAAAAAAAAwAAAAAAAAAFAAAAAAAAAAgAAAAAAAAA
</DataArray>
<DataArray type="Int64" Name="offsets" format="binary" RangeMin="4" RangeMax="20">
MAAAAAAAAAAEAAAAAAAAAAgAAAAAAAAACwAAAAAAAAAOAAAAAAAAABEAAAAAAAAAFAAAAAAAAAA=
</DataArray>
<DataArray type="UInt8" Name="types" format="binary" RangeMin="5" RangeMax="9">
BgAAAAAAAAAJCQUFBQU=
</DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>
Loading