Skip to content
Merged
Show file tree
Hide file tree
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 Apr 4, 2025
605d0f3
Merge branch 'main' into pmartinez/refactor/MoveMultiblockInspectorAn…
paloma-martinez Apr 7, 2025
14b0c14
Merge branch 'main' into pmartinez/refactor/MoveMultiblockInspectorAn…
paloma-martinez Apr 8, 2025
b2d635d
Update dependencies and correct typo in name
paloma-martinez Apr 8, 2025
21ae37e
Add SplitMesh and MergeColocatedPoints filters
mlemayTTE Apr 9, 2025
5d42638
Add array transfer from parent to child mesh and tests
mlemayTTE Apr 10, 2025
6ec82d2
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE Apr 11, 2025
c2286b5
add helpers to create mesh with multiple cells
mlemayTTE Apr 11, 2025
fb5f274
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE Apr 14, 2025
5544b5f
fix and add tests to MergeColocatedPoints
mlemayTTE Apr 14, 2025
606379b
add MeshIdCard class and tests + linting
mlemayTTE Apr 15, 2025
4c68085
create vtk filters to compute mesh stats
mlemayTTE Apr 15, 2025
b6b05ee
create Paraview plugins to wrap vtk filters
mlemayTTE Apr 15, 2025
9979dcf
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE Apr 16, 2025
465622b
First tests implementation
paloma-martinez Apr 16, 2025
954270e
Merge branch 'main' into pmartinez/refactor/MoveMultiblockInspectorAn…
paloma-martinez Apr 16, 2025
072cd8e
remove empty folder
paloma-martinez Apr 16, 2025
b0f06e1
upgrade github actions
paloma-martinez Apr 16, 2025
28ae96f
Linting and typing
paloma-martinez Apr 16, 2025
996bc17
Remove useless comment
paloma-martinez Apr 16, 2025
fec1bf2
Fix dependencies
paloma-martinez Apr 16, 2025
c5ade9e
rename MeshIdCard and associated filters by CellTypeCounts
mlemayTTE Apr 16, 2025
261793d
Add data for test and modify useless functions
paloma-martinez Apr 17, 2025
2f54610
typo
paloma-martinez Apr 17, 2025
9282283
linting
paloma-martinez Apr 17, 2025
416ca06
Update data test path
paloma-martinez Apr 17, 2025
7adc08b
add tests and update cellTypeCounter filter
mlemayTTE Apr 23, 2025
a35eb2c
ci fix
mlemayTTE Apr 23, 2025
1574799
fix test
mlemayTTE Apr 24, 2025
f1b0c99
add missing dependency
mlemayTTE Apr 24, 2025
95191fc
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE Apr 29, 2025
ed9f0a5
add comment
paloma-martinez Apr 29, 2025
c77a4c5
Merge helpers
mlemayTTE Apr 29, 2025
7fb8e79
Linting, formating, typing
mlemayTTE Apr 29, 2025
9af63b0
linting
mlemayTTE Apr 29, 2025
15d9df9
fix tests
mlemayTTE Apr 29, 2025
0575b1e
Addition of data for tests
paloma-martinez Apr 30, 2025
0ef062e
Comment and fix typos
paloma-martinez Apr 30, 2025
31271ba
vtkUtils tests implemented
paloma-martinez Apr 30, 2025
1c21a71
Remove comments - linting - typo
mlemayTTE Apr 30, 2025
c10edba
Typing & linting
paloma-martinez May 5, 2025
d6b1ae1
Linting
paloma-martinez May 5, 2025
bed516c
Fix import path
paloma-martinez May 5, 2025
34574ef
Merge branch 'main' into pmartinez/refactor/MoveMultiblockInspectorAn…
paloma-martinez May 5, 2025
2f7339e
Refactoring
paloma-martinez May 12, 2025
8614bef
Updating documentation
paloma-martinez May 12, 2025
6b7eb09
Typo when refactoring
paloma-martinez May 12, 2025
60374be
Fix documentation
paloma-martinez May 12, 2025
50d90c8
Yapf
paloma-martinez May 12, 2025
f23f8cd
Yapf again
paloma-martinez May 13, 2025
cbaf414
Remove MergeColocatedPoints and replace with CellTypeCounts
mlemayTTE May 13, 2025
8f31c51
yapf fix
mlemayTTE May 13, 2025
e9d11ea
fix tests
mlemayTTE May 13, 2025
efaf0be
Reorganize utilities & update paths accordingly
paloma-martinez May 19, 2025
b9dfb8f
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE May 19, 2025
29d3f4f
Documentation
paloma-martinez May 19, 2025
2486847
Merge branch 'main' into pmartinez/refactor/MoveMultiblockInspectorAn…
paloma-martinez May 19, 2025
c70f353
Fix doc and yapf for ci
paloma-martinez May 19, 2025
32af612
Documentation and formating
alexbenedicto May 19, 2025
923897f
Fix import errors
alexbenedicto May 20, 2025
c22f4b4
Merge branch 'main' into pmartinez/refactor/MoveMultiblockInspectorAn…
paloma-martinez May 20, 2025
efb92a8
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE May 21, 2025
8c9d934
typo
mlemayTTE May 21, 2025
24582d1
Merge branch 'pmartinez/refactor/MoveMultiblockInspectorAndVtkUtils' …
mlemayTTE May 21, 2025
7e65787
Adding more documentation
paloma-martinez May 21, 2025
2ff6fda
documentation + typing, liniting, formating
mlemayTTE May 21, 2025
7775fbb
Merge branch 'pmartinez/refactor/MoveMultiblockInspectorAndVtkUtils' …
mlemayTTE May 21, 2025
9c0d60b
bugs and tests fix
mlemayTTE May 21, 2025
8a3c4ab
Fix merge and tests
mlemayTTE May 21, 2025
2318b7e
yapf fix
mlemayTTE May 21, 2025
1bc1631
Merge branch 'main' into lemay/feature/add_tte_meshing_tools
mlemayTTE May 22, 2025
4b54e48
linting fix
mlemayTTE May 22, 2025
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
19 changes: 12 additions & 7 deletions geos-mesh/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies = [
"tqdm >= 4.67",
"numpy >= 2.2",
"meshio >= 5.3",
"typing_extensions >= 4.12",
]

[project.scripts]
Expand All @@ -47,7 +48,8 @@ build = [
"build ~= 1.2"
]
dev = [
"mypy",
"mypy",
"ruff",
"yapf",
]
test = [
Expand All @@ -56,9 +58,12 @@ test = [
]

[tool.pytest.ini_options]
addopts = [
"--import-mode=importlib",
]
pythonpath = [
"src",
]
addopts = "--import-mode=importlib"
console_output_style = "count"
pythonpath = ["src"]
python_classes = "Test"
python_files = "test*.py"
python_functions = "test*"
testpaths = ["tests"]
norecursedirs = "bin"
filterwarnings = []
4 changes: 2 additions & 2 deletions geos-mesh/src/geos/mesh/doctor/checks/generate_fractures.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from vtkmodules.util.numpy_support import numpy_to_vtk, vtk_to_numpy
from vtkmodules.util.vtkConstants import VTK_ID_TYPE
from geos.mesh.doctor.checks.vtk_polyhedron import FaceStream
from geos.mesh.vtk.helpers import has_invalid_field, to_vtk_id_list, vtk_iter
from geos.mesh.vtk.helpers import has_invalid_arrays, to_vtk_id_list, vtk_iter
from geos.mesh.vtk.io import VtkOutput, read_mesh, write_mesh
"""
TypeAliases cannot be used with Python 3.9. A simple assignment like described there will be used:
Expand Down Expand Up @@ -557,7 +557,7 @@ def check( vtk_input_file: str, options: Options ) -> Result:
try:
mesh = read_mesh( vtk_input_file )
# Mesh cannot contain global ids before splitting.
if has_invalid_field( mesh, [ "GLOBAL_IDS_POINTS", "GLOBAL_IDS_CELLS" ] ):
if has_invalid_arrays( mesh, [ "GLOBAL_IDS_POINTS", "GLOBAL_IDS_CELLS" ] ):
err_msg: str = ( "The mesh cannot contain global ids for neither cells nor points. The correct procedure " +
" is to split the mesh and then generate global ids for new split meshes." )
logging.error( err_msg )
Expand Down
107 changes: 107 additions & 0 deletions geos-mesh/src/geos/mesh/model/CellTypeCounts.py
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 geos-mesh/src/geos/mesh/processing/MergeColocatedPoints.py
Copy link
Collaborator

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 ?

Copy link
Contributor Author

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.

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
Loading