Skip to content

Commit 2ff6fda

Browse files
committed
documentation + typing, liniting, formating
1 parent 24582d1 commit 2ff6fda

File tree

14 files changed

+141
-106
lines changed

14 files changed

+141
-106
lines changed

docs/geos_mesh_docs/model.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Model
2+
^^^^^^^
3+
4+
The `model` module of `geos-mesh` package contains data model.
5+
6+
7+
geos.mesh.model.CellTypeCounts filter
8+
--------------------------------------
9+
10+
.. automodule:: geos.mesh.model.CellTypeCounts
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:

docs/geos_mesh_docs/modules.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ GEOS Mesh tools
1111

1212
io
1313

14+
model
15+
16+
processing
17+
18+
stats
19+
1420
utils

docs/geos_mesh_docs/processing.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Processing filters
2+
^^^^^^^^^^^^^^^^^^^
3+
4+
The `processing` module of `geos-mesh` package contains filters to process meshes.
5+
6+
7+
geos.mesh.processing.SplitMesh filter
8+
--------------------------------------
9+
10+
.. automodule:: geos.mesh.processing.SplitMesh
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:

docs/geos_mesh_docs/stats.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Mesh stats tools
2+
^^^^^^^^^^^^^^^^
3+
4+
The `stats` module of `geos-mesh` package contains filter to compute statistics on meshes.
5+
6+
7+
geos.mesh.stats.CellTypeCounter filter
8+
--------------------------------------
9+
10+
.. automodule:: geos.mesh.stats.CellTypeCounter
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:

docs/geos_mesh_docs/utils.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Mesh utilities
22
^^^^^^^^^^^^^^^^
33

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

66

77
geos.mesh.utils.genericHelpers module

geos-mesh/src/geos/mesh/doctor/checks/generate_fractures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from vtkmodules.util.numpy_support import numpy_to_vtk, vtk_to_numpy
1414
from vtkmodules.util.vtkConstants import VTK_ID_TYPE
1515
from geos.mesh.doctor.checks.vtk_polyhedron import FaceStream
16-
from geos.mesh.utils.arrayHelpers import has_invalid_field
16+
from geos.mesh.utils.arrayHelpers import has_array
1717
from geos.mesh.utils.genericHelpers import to_vtk_id_list, vtk_iter
1818
from geos.mesh.io.vtkIO import VtkOutput, read_mesh, write_mesh
1919
"""
@@ -558,7 +558,7 @@ def check( vtk_input_file: str, options: Options ) -> Result:
558558
try:
559559
mesh = read_mesh( vtk_input_file )
560560
# Mesh cannot contain global ids before splitting.
561-
if has_invalid_arrays( mesh, [ "GLOBAL_IDS_POINTS", "GLOBAL_IDS_CELLS" ] ):
561+
if has_array( mesh, [ "GLOBAL_IDS_POINTS", "GLOBAL_IDS_CELLS" ] ):
562562
err_msg: str = ( "The mesh cannot contain global ids for neither cells nor points. The correct procedure " +
563563
" is to split the mesh and then generate global ids for new split meshes." )
564564
logging.error( err_msg )

geos-mesh/src/geos/mesh/model/CellTypeCounts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __str__( self: Self ) -> str:
2727
"""
2828
return self.print()
2929

30-
def __add__( self: Self, other: Self ) -> Self:
30+
def __add__( self: Self, other: Self ) -> 'CellTypeCounts':
3131
"""Addition operator.
3232
3333
CellTypeCounts addition consists in suming counts.

geos-mesh/src/geos/mesh/processing/SplitMesh.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def FillInputPortInformation( self: Self, port: int, info: vtkInformation ) -> i
8282
"""
8383
if port == 0:
8484
info.Set( self.INPUT_REQUIRED_DATA_TYPE(), "vtkUnstructuredGrid" )
85+
return 1
8586

8687
def RequestDataObject(
8788
self: Self,

geos-mesh/src/geos/mesh/stats/CellTypeCounter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def FillInputPortInformation( self: Self, port: int, info: vtkInformation ) -> i
5757
"""
5858
if port == 0:
5959
info.Set( self.INPUT_REQUIRED_DATA_TYPE(), "vtkUnstructuredGrid" )
60+
return 1
6061

6162
def RequestData(
6263
self: Self,

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

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,48 +19,38 @@
1919
__doc__ = """Utilities methods to get information on VTK Arrays."""
2020

2121

22-
def has_invalid_field( mesh: vtkUnstructuredGrid, invalid_fields: list[ str ] ) -> bool:
23-
"""Checks if a mesh contains at least a data arrays within its cell, field or point data
24-
having a certain name. If so, returns True, else False.
22+
def has_array( mesh: vtkUnstructuredGrid, array_names: list[ str ] ) -> bool:
23+
"""Checks if input mesh contains at least one of input data arrays.
2524
2625
Args:
2726
mesh (vtkUnstructuredGrid): An unstructured mesh.
28-
invalid_fields (list[str]): Field name of an array in any data from the data.
27+
array_names (list[str]): List of array names.
2928
3029
Returns:
31-
bool: True if one field found, else False.
30+
bool: True if at least one array is found, else False.
3231
"""
3332
# Check the cell data fields
34-
cell_data = mesh.GetCellData()
35-
for i in range( cell_data.GetNumberOfArrays() ):
36-
if cell_data.GetArrayName( i ) in invalid_fields:
37-
logging.error( f"The mesh contains an invalid cell field name '{cell_data.GetArrayName( i )}'." )
38-
return True
39-
# Check the field data fields
40-
field_data = mesh.GetFieldData()
41-
for i in range( field_data.GetNumberOfArrays() ):
42-
if field_data.GetArrayName( i ) in invalid_fields:
43-
logging.error( f"The mesh contains an invalid field name '{field_data.GetArrayName( i )}'." )
44-
return True
45-
# Check the point data fields
46-
point_data = mesh.GetPointData()
47-
for i in range( point_data.GetNumberOfArrays() ):
48-
if point_data.GetArrayName( i ) in invalid_fields:
49-
logging.error( f"The mesh contains an invalid point field name '{point_data.GetArrayName( i )}'." )
50-
return True
33+
data: vtkFieldData | None
34+
for data in ( mesh.GetCellData(), mesh.GetFieldData(), mesh.GetPointData() ):
35+
if data is None:
36+
continue # type: ignore[unreachable]
37+
for arrayName in array_names:
38+
if data.HasArray( arrayName ):
39+
logging.error( f"The mesh contains the array named '{arrayName}'." )
40+
return True
5141
return False
5242

5343

5444
def getFieldType( data: vtkFieldData ) -> str:
55-
"""A vtk grid can contain 3 types of field data:
45+
"""Returns whether the data is "vtkFieldData", "vtkCellData" or "vtkPointData".
46+
47+
A vtk mesh can contain 3 types of field data:
5648
- vtkFieldData (parent class)
5749
- vtkCellData (inheritance of vtkFieldData)
5850
- vtkPointData (inheritance of vtkFieldData)
5951
60-
The goal is to return whether the data is "vtkFieldData", "vtkCellData" or "vtkPointData".
61-
6252
Args:
63-
data (vtkFieldData)
53+
data (vtkFieldData): vtk field data
6454
6555
Returns:
6656
str: "vtkFieldData", "vtkCellData" or "vtkPointData"
@@ -79,7 +69,7 @@ def getArrayNames( data: vtkFieldData ) -> list[ str ]:
7969
"""Get the names of all arrays stored in a "vtkFieldData", "vtkCellData" or "vtkPointData".
8070
8171
Args:
82-
data (vtkFieldData)
72+
data (vtkFieldData): vtk field data
8373
8474
Returns:
8575
list[ str ]: The array names in the order that they are stored in the field data.
@@ -93,8 +83,8 @@ def getArrayByName( data: vtkFieldData, name: str ) -> Optional[ vtkDataArray ]:
9383
"""Get the vtkDataArray corresponding to the given name.
9484
9585
Args:
96-
data (vtkFieldData)
97-
name (str)
86+
data (vtkFieldData): vtk field data
87+
name (str): array name
9888
9989
Returns:
10090
Optional[ vtkDataArray ]: The vtkDataArray associated with the name given. None if not found.
@@ -109,8 +99,8 @@ def getCopyArrayByName( data: vtkFieldData, name: str ) -> Optional[ vtkDataArra
10999
"""Get the copy of a vtkDataArray corresponding to the given name.
110100
111101
Args:
112-
data (vtkFieldData)
113-
name (str)
102+
data (vtkFieldData): vtk field data
103+
name (str): array name
114104
115105
Returns:
116106
Optional[ vtkDataArray ]: The copy of the vtkDataArray associated with the name given. None if not found.
@@ -125,7 +115,7 @@ def getNumpyGlobalIdsArray( data: Union[ vtkCellData, vtkPointData ] ) -> Option
125115
"""Get a numpy array of the GlobalIds.
126116
127117
Args:
128-
data (Union[ vtkCellData, vtkPointData ])
118+
data (Union[ vtkCellData, vtkPointData ]): Cell or point array.
129119
130120
Returns:
131121
Optional[ npt.NDArray[ np.int64 ] ]: The numpy array of GlobalIds.
@@ -137,26 +127,25 @@ def getNumpyGlobalIdsArray( data: Union[ vtkCellData, vtkPointData ] ) -> Option
137127
return vtk_to_numpy( global_ids )
138128

139129

140-
def getNumpyArrayByName( data: vtkFieldData, name: str, sorted: bool = False ) -> Optional[ npt.NDArray ]:
130+
def getNumpyArrayByName( data: vtkCellData | vtkPointData, name: str, sorted: bool = False ) -> Optional[ npt.NDArray ]:
141131
"""Get the numpy array of a given vtkDataArray found by its name.
132+
142133
If sorted is selected, this allows the option to reorder the values wrt GlobalIds. If not GlobalIds was found,
143134
no reordering will be perform.
144135
145136
Args:
146-
data (vtkFieldData)
147-
name (str)
137+
data (vtkCellData | vtkPointData): vtk field data.
138+
name (str): Array name to sort
148139
sorted (bool, optional): Sort the output array with the help of GlobalIds. Defaults to False.
149140
150141
Returns:
151-
Optional[ npt.NDArray ]
142+
Optional[ npt.NDArray ]: Sorted array
152143
"""
153144
dataArray: Optional[ vtkDataArray ] = getArrayByName( data, name )
154145
if dataArray is not None:
155-
arr: Optional[ npt.NDArray ] = vtk_to_numpy( dataArray )
156-
if sorted:
157-
fieldType: str = getFieldType( data )
158-
if fieldType in [ "vtkCellData", "vtkPointData" ]:
159-
sortArrayByGlobalIds( data, arr )
146+
arr: npt.NDArray[ np.float64 ] = vtk_to_numpy( dataArray )
147+
if sorted and ( data.IsA( "vtkCellData" ) or data.IsA( "vtkPointData" ) ):
148+
sortArrayByGlobalIds( data, arr )
160149
return arr
161150
return None
162151

@@ -484,7 +473,7 @@ def getComponentNamesDataSet( dataSet: vtkDataSet, attributeName: str, onPoints:
484473
485474
"""
486475
array: vtkDoubleArray = getVtkArrayInObject( dataSet, attributeName, onPoints )
487-
componentNames: list[ str ] = list()
476+
componentNames: list[ str ] = []
488477
if array.GetNumberOfComponents() > 1:
489478
componentNames += [ array.GetComponentName( i ) for i in range( array.GetNumberOfComponents() ) ]
490479
return tuple( componentNames )
@@ -651,12 +640,12 @@ def computeCellCenterCoordinates( mesh: vtkDataSet ) -> vtkDataArray:
651640
return pts.GetData()
652641

653642

654-
def sortArrayByGlobalIds( data: Union[ vtkCellData, vtkFieldData ], arr: npt.NDArray[ np.int64 ] ) -> None:
655-
"""Sort an array following global Ids
643+
def sortArrayByGlobalIds( data: Union[ vtkCellData, vtkPointData ], arr: npt.NDArray[ np.float64 ] ) -> None:
644+
"""Sort an array following global Ids.
656645
657646
Args:
658647
data (vtkFieldData): Global Ids array
659-
arr (npt.NDArray[ np.int64 ]): Array to sort
648+
arr (npt.NDArray[ np.float64 ]): Array to sort
660649
"""
661650
globalids: Optional[ npt.NDArray[ np.int64 ] ] = getNumpyGlobalIdsArray( data )
662651
if globalids is not None:

0 commit comments

Comments
 (0)