Skip to content

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 72 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions docs/geos_mesh_docs/model.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Model
^^^^^^^

The `model` module of `geos-mesh` package contains data model.


geos.mesh.model.CellTypeCounts filter
--------------------------------------

.. automodule:: geos.mesh.model.CellTypeCounts
:members:
:undoc-members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/geos_mesh_docs/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ GEOS Mesh tools

io

model

processing

stats

utils
13 changes: 13 additions & 0 deletions docs/geos_mesh_docs/processing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Processing filters
^^^^^^^^^^^^^^^^^^^

The `processing` module of `geos-mesh` package contains filters to process meshes.


geos.mesh.processing.SplitMesh filter
--------------------------------------

.. automodule:: geos.mesh.processing.SplitMesh
:members:
:undoc-members:
:show-inheritance:
13 changes: 13 additions & 0 deletions docs/geos_mesh_docs/stats.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Mesh stats tools
^^^^^^^^^^^^^^^^

The `stats` module of `geos-mesh` package contains filter to compute statistics on meshes.


geos.mesh.stats.CellTypeCounter filter
--------------------------------------

.. automodule:: geos.mesh.stats.CellTypeCounter
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/geos_mesh_docs/utils.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Mesh utilities
^^^^^^^^^^^^^^^^

The `utils` module of `geos-mesh` package contains different utilities methods for VTK meshes.
The `utils` module of `geos-mesh` package contains various utilities for VTK meshes.


geos.mesh.utils.genericHelpers module
Expand Down
12 changes: 5 additions & 7 deletions geos-mesh/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ dependencies = [
"networkx >= 2.4",
"tqdm >= 4.67",
"numpy >= 2.2",
"pandas >= 2.2",
"meshio >= 5.3",
"pandas",
"typing_extensions >= 4.12",
]

[project.scripts]
Expand All @@ -48,7 +49,8 @@ build = [
"build ~= 1.2"
]
dev = [
"mypy",
"mypy",
"ruff",
"yapf",
]
test = [
Expand All @@ -57,7 +59,7 @@ test = [
]

[tool.pytest.ini_options]
addopts="--import-mode=importlib"
addopts = "--import-mode=importlib"
console_output_style = "count"
pythonpath = ["src"]
python_classes = "Test"
Expand All @@ -66,7 +68,3 @@ python_functions = "test*"
testpaths = ["tests"]
norecursedirs = "bin"
filterwarnings = []

[tool.coverage.run]
branch = true
source = ["src/geos"]
5 changes: 3 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,8 @@
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.utils.arrayHelpers import has_invalid_field
from geos.mesh.utils.arrayHelpers import has_array

from geos.mesh.utils.genericHelpers import to_vtk_id_list, vtk_iter
from geos.mesh.io.vtkIO import VtkOutput, read_mesh, write_mesh
"""
Expand Down Expand Up @@ -558,7 +559,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_array( 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
1 change: 1 addition & 0 deletions geos-mesh/src/geos/mesh/io/vtkIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def __write_vtu( mesh: vtkUnstructuredGrid, output: str, toBinary: bool = False

def write_mesh( mesh: vtkPointSet, vtk_output: VtkOutput, canOverwrite: bool = False ) -> int:
"""Write mesh to disk.

Nothing is done if file already exists.

Args:
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 ) -> 'CellTypeCounts':
"""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
Loading