-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add meshing tools and stats #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 20 commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
6968e2c
Move vtkUtils and multiblockInspectorTreeFunctions + update dependencies
paloma-martinez 605d0f3
Merge branch 'main' into pmartinez/refactor/MoveMultiblockInspectorAn…
paloma-martinez 14b0c14
Merge branch 'main' into pmartinez/refactor/MoveMultiblockInspectorAn…
paloma-martinez b2d635d
Update dependencies and correct typo in name
paloma-martinez 21ae37e
Add SplitMesh and MergeColocatedPoints filters
mlemayTTE 5d42638
Add array transfer from parent to child mesh and tests
mlemayTTE 6ec82d2
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE c2286b5
add helpers to create mesh with multiple cells
mlemayTTE fb5f274
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE 5544b5f
fix and add tests to MergeColocatedPoints
mlemayTTE 606379b
add MeshIdCard class and tests + linting
mlemayTTE 4c68085
create vtk filters to compute mesh stats
mlemayTTE b6b05ee
create Paraview plugins to wrap vtk filters
mlemayTTE 9979dcf
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE 465622b
First tests implementation
paloma-martinez 954270e
Merge branch 'main' into pmartinez/refactor/MoveMultiblockInspectorAn…
paloma-martinez 072cd8e
remove empty folder
paloma-martinez b0f06e1
upgrade github actions
paloma-martinez 28ae96f
Linting and typing
paloma-martinez 996bc17
Remove useless comment
paloma-martinez fec1bf2
Fix dependencies
paloma-martinez c5ade9e
rename MeshIdCard and associated filters by CellTypeCounts
mlemayTTE 261793d
Add data for test and modify useless functions
paloma-martinez 2f54610
typo
paloma-martinez 9282283
linting
paloma-martinez 416ca06
Update data test path
paloma-martinez 7adc08b
add tests and update cellTypeCounter filter
mlemayTTE a35eb2c
ci fix
mlemayTTE 1574799
fix test
mlemayTTE f1b0c99
add missing dependency
mlemayTTE 95191fc
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE ed9f0a5
add comment
paloma-martinez c77a4c5
Merge helpers
mlemayTTE 7fb8e79
Linting, formating, typing
mlemayTTE 9af63b0
linting
mlemayTTE 15d9df9
fix tests
mlemayTTE 0575b1e
Addition of data for tests
paloma-martinez 0ef062e
Comment and fix typos
paloma-martinez 31271ba
vtkUtils tests implemented
paloma-martinez 1c21a71
Remove comments - linting - typo
mlemayTTE c10edba
Typing & linting
paloma-martinez d6b1ae1
Linting
paloma-martinez bed516c
Fix import path
paloma-martinez 34574ef
Merge branch 'main' into pmartinez/refactor/MoveMultiblockInspectorAn…
paloma-martinez 2f7339e
Refactoring
paloma-martinez 8614bef
Updating documentation
paloma-martinez 6b7eb09
Typo when refactoring
paloma-martinez 60374be
Fix documentation
paloma-martinez 50d90c8
Yapf
paloma-martinez f23f8cd
Yapf again
paloma-martinez cbaf414
Remove MergeColocatedPoints and replace with CellTypeCounts
mlemayTTE 8f31c51
yapf fix
mlemayTTE e9d11ea
fix tests
mlemayTTE efaf0be
Reorganize utilities & update paths accordingly
paloma-martinez b9dfb8f
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE 29d3f4f
Documentation
paloma-martinez 2486847
Merge branch 'main' into pmartinez/refactor/MoveMultiblockInspectorAn…
paloma-martinez c70f353
Fix doc and yapf for ci
paloma-martinez 32af612
Documentation and formating
alexbenedicto 923897f
Fix import errors
alexbenedicto c22f4b4
Merge branch 'main' into pmartinez/refactor/MoveMultiblockInspectorAn…
paloma-martinez efb92a8
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE 8c9d934
typo
mlemayTTE 24582d1
Merge branch 'pmartinez/refactor/MoveMultiblockInspectorAndVtkUtils' …
mlemayTTE 7e65787
Adding more documentation
paloma-martinez 2ff6fda
documentation + typing, liniting, formating
mlemayTTE 7775fbb
Merge branch 'pmartinez/refactor/MoveMultiblockInspectorAndVtkUtils' …
mlemayTTE 9c0d60b
bugs and tests fix
mlemayTTE 8a3c4ab
Fix merge and tests
mlemayTTE 2318b7e
yapf fix
mlemayTTE 1bc1631
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE 4b54e48
linting fix
mlemayTTE File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies. | ||
| # SPDX-FileContributor: Antoine Mazuyer, Martin Lemay | ||
| import numpy as np | ||
| import numpy.typing as npt | ||
| from typing_extensions import Self | ||
| from vtkmodules.vtkCommonDataModel import ( vtkCellTypes, VTK_TRIANGLE, VTK_QUAD, VTK_TETRA, VTK_VERTEX, VTK_POLYHEDRON, | ||
| VTK_POLYGON, VTK_PYRAMID, VTK_HEXAHEDRON, VTK_WEDGE, | ||
| VTK_NUMBER_OF_CELL_TYPES ) | ||
|
|
||
| __doc__ = """ | ||
| CellTypeCounts stores the number of elements of each type. | ||
| """ | ||
|
|
||
|
|
||
| class CellTypeCounts(): | ||
|
|
||
| def __init__( self: Self ) -> None: | ||
| """CellTypeCounts stores the number of cells of each type.""" | ||
| self._counts: npt.NDArray[ np.int64 ] = np.zeros( VTK_NUMBER_OF_CELL_TYPES, dtype=float ) | ||
|
|
||
| def __str__( self: Self ) -> str: | ||
| """Overload __str__ method. | ||
|
|
||
| Returns: | ||
| str: counts as string. | ||
| """ | ||
| return self.print() | ||
|
|
||
| def __add__( self: Self, other: Self ) -> Self: | ||
| """Addition operator. | ||
|
|
||
| CellTypeCounts addition consists in suming counts. | ||
|
|
||
| Args: | ||
| other (Self): other CellTypeCounts object | ||
|
|
||
| Returns: | ||
| Self: new CellTypeCounts object | ||
| """ | ||
| assert isinstance( other, CellTypeCounts ), "Other object must be a CellTypeCounts." | ||
| newCounts: CellTypeCounts = CellTypeCounts() | ||
| newCounts._counts = self._counts + other._counts | ||
| return newCounts | ||
|
|
||
| def addType( self: Self, cellType: int ) -> None: | ||
| """Increment the number of cell of input type. | ||
|
|
||
| Args: | ||
| cellType (int): cell type | ||
| """ | ||
| self._counts[ cellType ] += 1 | ||
| self._updateGeneralCounts( cellType, 1 ) | ||
|
|
||
| def setTypeCount( self: Self, cellType: int, count: int ) -> None: | ||
| """Set the number of cells of input type. | ||
|
|
||
| Args: | ||
| cellType (int): cell type | ||
| count (int): number of cells | ||
| """ | ||
| prevCount = self._counts[ cellType ] | ||
| self._counts[ cellType ] = count | ||
| self._updateGeneralCounts( cellType, count - prevCount ) | ||
|
|
||
| def getTypeCount( self: Self, cellType: int ) -> int: | ||
| """Get the number of cells of input type. | ||
|
|
||
| Args: | ||
| cellType (int): cell type | ||
|
|
||
| Returns: | ||
| int: number of cells | ||
| """ | ||
| return int( self._counts[ cellType ] ) | ||
|
|
||
| def _updateGeneralCounts( self: Self, cellType: int, count: int ) -> None: | ||
| """Update generic type counters. | ||
|
|
||
| Args: | ||
| cellType (int): cell type | ||
| count (int): count increment | ||
| """ | ||
| if ( cellType != VTK_POLYGON ) and ( vtkCellTypes.GetDimension( cellType ) == 2 ): | ||
| self._counts[ VTK_POLYGON ] += count | ||
| if ( cellType != VTK_POLYHEDRON ) and ( vtkCellTypes.GetDimension( cellType ) == 3 ): | ||
| self._counts[ VTK_POLYHEDRON ] += count | ||
|
|
||
| def print( self: Self ) -> str: | ||
| """Print counts string. | ||
|
|
||
| Returns: | ||
| str: counts string. | ||
| """ | ||
| card: str = "" | ||
| card += "| | |\n" | ||
| card += "| - | - |\n" | ||
| card += f"| **Total Number of Vertices** | {int(self._counts[VTK_VERTEX]):12} |\n" | ||
| card += f"| **Total Number of Polygon** | {int(self._counts[VTK_POLYGON]):12} |\n" | ||
| card += f"| **Total Number of Polyhedron** | {int(self._counts[VTK_POLYHEDRON]):12} |\n" | ||
| card += f"| **Total Number of Cells** | {int(self._counts[VTK_POLYHEDRON]+self._counts[VTK_POLYGON]):12} |\n" | ||
| card += "| - | - |\n" | ||
| for cellType in ( VTK_TRIANGLE, VTK_QUAD ): | ||
| card += f"| **Total Number of {vtkCellTypes.GetClassNameFromTypeId(cellType):<13}** | {int(self._counts[cellType]):12} |\n" | ||
| for cellType in ( VTK_TETRA, VTK_PYRAMID, VTK_WEDGE, VTK_HEXAHEDRON ): | ||
| card += f"| **Total Number of {vtkCellTypes.GetClassNameFromTypeId(cellType):<13}** | {int(self._counts[cellType]):12} |\n" | ||
| return card |
184 changes: 184 additions & 0 deletions
184
geos-mesh/src/geos/mesh/processing/MergeColocatedPoints.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies. | ||
| # SPDX-FileContributor: Antoine Mazuyer, Martin Lemay | ||
| import numpy as np | ||
| from typing_extensions import Self | ||
| from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase | ||
| from vtkmodules.vtkCommonCore import ( | ||
| vtkIntArray, | ||
| vtkInformation, | ||
| vtkInformationVector, | ||
| vtkPoints, | ||
| reference, | ||
| vtkIdList, | ||
| ) | ||
| from vtkmodules.vtkCommonDataModel import ( | ||
| vtkUnstructuredGrid, | ||
| vtkIncrementalOctreePointLocator, | ||
| vtkCellTypes, | ||
| vtkCell, | ||
| ) | ||
|
|
||
| __doc__ = """ | ||
| MergeColocatedPoints module is a vtk filter that merges colocated points from input mesh. | ||
|
|
||
| Filter input and output types are vtkUnstructuredGrid. | ||
|
|
||
| .. Warning:: This operation uses geometrical tests that may not be accurate in case of very small cells. | ||
|
|
||
|
|
||
| To use the filter: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from geos.mesh.processing.MergeColocatedPoints import MergeColocatedPoints | ||
|
|
||
| # filter inputs | ||
| input :vtkUnstructuredGrid | ||
|
|
||
| # instanciate the filter | ||
| filter :MergeColocatedPoints = MergeColocatedPoints() | ||
| # set input data object | ||
| filter.SetInputDataObject(input) | ||
| # do calculations | ||
| filter.Update() | ||
| # get output object | ||
| output :vtkUnstructuredGrid = filter.GetOutputDataObject(0) | ||
| """ | ||
|
|
||
|
|
||
| class MergeColocatedPoints( VTKPythonAlgorithmBase ): | ||
|
|
||
| def __init__( self: Self ) -> None: | ||
| """MergeColocatedPoints filter merges duplacted points of the input mesh.""" | ||
| super().__init__( nInputPorts=1, nOutputPorts=1, outputType="vtkUnstructuredGrid" ) | ||
|
|
||
| def FillInputPortInformation( self: Self, port: int, info: vtkInformation ) -> int: | ||
| """Inherited from VTKPythonAlgorithmBase::RequestInformation. | ||
|
|
||
| Args: | ||
| port (int): input port | ||
| info (vtkInformationVector): info | ||
|
|
||
| Returns: | ||
| int: 1 if calculation successfully ended, 0 otherwise. | ||
| """ | ||
| if port == 0: | ||
| info.Set( self.INPUT_REQUIRED_DATA_TYPE(), "vtkUnstructuredGrid" ) | ||
|
|
||
| def RequestDataObject( | ||
| self: Self, | ||
| request: vtkInformation, # noqa: F841 | ||
| inInfoVec: list[ vtkInformationVector ], # noqa: F841 | ||
| outInfoVec: vtkInformationVector, | ||
| ) -> int: | ||
| """Inherited from VTKPythonAlgorithmBase::RequestDataObject. | ||
|
|
||
| Args: | ||
| request (vtkInformation): request | ||
| inInfoVec (list[vtkInformationVector]): input objects | ||
| outInfoVec (vtkInformationVector): output objects | ||
|
|
||
| Returns: | ||
| int: 1 if calculation successfully ended, 0 otherwise. | ||
| """ | ||
| inData = self.GetInputData( inInfoVec, 0, 0 ) | ||
| outData = self.GetOutputData( outInfoVec, 0 ) | ||
| assert inData is not None | ||
| if outData is None or ( not outData.IsA( inData.GetClassName() ) ): | ||
| outData = inData.NewInstance() | ||
| outInfoVec.GetInformationObject( 0 ).Set( outData.DATA_OBJECT(), outData ) | ||
| return super().RequestDataObject( request, inInfoVec, outInfoVec ) | ||
|
|
||
| def RequestData( | ||
| self: Self, | ||
| request: vtkInformation, # noqa: F841 | ||
| inInfoVec: list[ vtkInformationVector ], # noqa: F841 | ||
| outInfoVec: vtkInformationVector, | ||
| ) -> int: | ||
| """Inherited from VTKPythonAlgorithmBase::RequestData. | ||
|
|
||
| Args: | ||
| request (vtkInformation): request | ||
| inInfoVec (list[vtkInformationVector]): input objects | ||
| outInfoVec (vtkInformationVector): output objects | ||
|
|
||
| Returns: | ||
| int: 1 if calculation successfully ended, 0 otherwise. | ||
| """ | ||
| inData: vtkUnstructuredGrid = vtkUnstructuredGrid.GetData( inInfoVec[ 0 ] ) | ||
| output: vtkUnstructuredGrid = self.GetOutputData( outInfoVec, 0 ) | ||
| assert inData is not None, "Input mesh is undefined." | ||
| assert output is not None, "Output mesh is undefined." | ||
| vertexMap: list[ int ] = self.setMergePoints( inData, output ) | ||
| self.setCells( inData, output, vertexMap ) | ||
| return 1 | ||
|
|
||
| def setMergePoints( self: Self, input: vtkUnstructuredGrid, output: vtkUnstructuredGrid ) -> list[ int ]: | ||
| """Merge duplicated points and set new points and attributes to output mesh. | ||
|
|
||
| Args: | ||
| input (vtkUnstructuredGrid): input mesh | ||
| output (vtkUnstructuredGrid): output mesh | ||
|
|
||
| Returns: | ||
| list[int]: list containing new point ids. | ||
| """ | ||
| vertexMap: list[ int ] = [] | ||
| newPoints: vtkPoints = vtkPoints() | ||
| # use point locator to check for colocated points | ||
| pointsLocator = vtkIncrementalOctreePointLocator() | ||
| pointsLocator.InitPointInsertion( newPoints, input.GetBounds() ) | ||
| # create an array to count the number of colocated points | ||
| vertexCount: vtkIntArray = vtkIntArray() | ||
| vertexCount.SetName( "Count" ) | ||
| ptId = reference( 0 ) | ||
| countD: int = 0 # total number of colocated points | ||
| for v in range( input.GetNumberOfPoints() ): | ||
| inserted: bool = pointsLocator.InsertUniquePoint( input.GetPoints().GetPoint( v ), ptId ) | ||
| if inserted: | ||
| vertexCount.InsertNextValue( 1 ) | ||
| else: | ||
| vertexCount.SetValue( ptId, vertexCount.GetValue( ptId ) + 1 ) | ||
| countD = countD + 1 | ||
| vertexMap += [ ptId.get() ] | ||
|
|
||
| output.SetPoints( pointsLocator.GetLocatorPoints() ) | ||
| # copy point attributes | ||
| output.GetPointData().DeepCopy( input.GetPointData() ) | ||
| # add the array to points data | ||
| output.GetPointData().AddArray( vertexCount ) | ||
| return vertexMap | ||
|
|
||
| def setCells( self: Self, input: vtkUnstructuredGrid, output: vtkUnstructuredGrid, vertexMap: list[ int ] ) -> bool: | ||
| """Set cell point ids and attributes to output mesh. | ||
|
|
||
| Args: | ||
| input (vtkUnstructuredGrid): input mesh | ||
| output (vtkUnstructuredGrid): output mesh | ||
| vertexMap (list[int)]): list containing new point ids | ||
|
|
||
| Returns: | ||
| bool: True if calculation successfully ended. | ||
| """ | ||
| nbCells: int = input.GetNumberOfCells() | ||
| nbPoints: int = output.GetNumberOfPoints() | ||
| assert np.unique( | ||
| vertexMap ).size == nbPoints, "The size of the list of point ids must be equal to the number of points." | ||
| cellTypes: vtkCellTypes = vtkCellTypes() | ||
| input.GetCellTypes( cellTypes ) | ||
| output.Allocate( nbCells ) | ||
| # create mesh cells | ||
| for cellId in range( nbCells ): | ||
| cell: vtkCell = input.GetCell( cellId ) | ||
| # create cells from point ids | ||
| cellsID: vtkIdList = vtkIdList() | ||
| for ptId in range( cell.GetNumberOfPoints() ): | ||
| ptIdOld: int = cell.GetPointId( ptId ) | ||
| ptIdNew: int = vertexMap[ ptIdOld ] | ||
| cellsID.InsertNextId( ptIdNew ) | ||
| output.InsertNextCell( cell.GetCellType(), cellsID ) | ||
| # copy cell attributes | ||
| assert output.GetNumberOfCells() == nbCells, "Output and input mesh must have the same number of cells." | ||
| output.GetCellData().DeepCopy( input.GetCellData() ) | ||
| return True |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this script redundant with the already existing methods in vtk to remove colocated points such as vtkCleanPolyData, vtkCleanUnstructuredGrid or vtkMergePoints ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, it does the same thing as vtkCleanUnstructuredGrid. The only difference is that MergeColocatedPoints adds a point attributes containing the number of merged points. Maybe not usefull to keep this filter.