Skip to content

Commit

Permalink
Correction of erroneous copy of pre-split tags to new split meshes (#34)
Browse files Browse the repository at this point in the history
* First correction now allowing for the copy of fields from the original mesh to the 2 split meshes.
But the indexes of fields are not correct yet for fracture mesh.

* Module import paths update

* Fields are now copied correctly for fracture_mesh.

* Test case added to check the __copy_fields feature.

* Invalid packages import for geos-mesh, impacting documentation (#32)

Updating sphinx and sphinx-argparse solved the issue.

* Correction for yapf valid format.

* Had to make a workaround to avoid a weird yapf formatting suggestion.

* Mistake correction

* First correction now allowing for the copy of fields from the original mesh to the 2 split meshes.
But the indexes of fields are not correct yet for fracture mesh.

* Module import paths update

* Fields are now copied correctly for fracture_mesh.

* Test case added to check the __copy_fields feature.

* Correction for yapf valid format.

* Had to make a workaround to avoid a weird yapf formatting suggestion.

* Mistake correction

* First part of review corrections

* Second part correction of reviews

* Last part of correction review

* Updated method when linking old cells to new cells ids to copy correctly the fields
  • Loading branch information
alexbenedicto authored Oct 14, 2024
1 parent 98680c5 commit 8cc89f5
Show file tree
Hide file tree
Showing 4 changed files with 457 additions and 297 deletions.
53 changes: 18 additions & 35 deletions geos-mesh/src/geos/mesh/doctor/checks/check_fractures.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
from dataclasses import dataclass
import logging

from typing import (
Collection,
FrozenSet,
Iterable,
Sequence,
Set,
Tuple,
)

from tqdm import tqdm
import numpy

from vtkmodules.vtkCommonDataModel import (
vtkUnstructuredGrid,
vtkCell,
)
from vtkmodules.vtkCommonCore import (
vtkPoints, )
from vtkmodules.vtkIOXML import (
vtkXMLMultiBlockDataReader, )
from vtkmodules.util.numpy_support import (
vtk_to_numpy, )
from vtk_utils import (
vtk_iter, )
from dataclasses import dataclass
from typing import Collection, Iterable, Sequence
from tqdm import tqdm
from vtkmodules.vtkCommonDataModel import vtkUnstructuredGrid, vtkCell
from vtkmodules.vtkCommonCore import vtkPoints
from vtkmodules.vtkIOXML import vtkXMLMultiBlockDataReader
from vtkmodules.util.numpy_support import vtk_to_numpy
from geos.mesh.doctor.checks.vtk_utils import vtk_iter
from geos.mesh.doctor.checks.generate_fractures import Coordinates3D


@dataclass( frozen=True )
Expand All @@ -44,7 +28,7 @@ class Result:


def __read_multiblock( vtk_input_file: str, matrix_name: str,
fracture_name: str ) -> Tuple[ vtkUnstructuredGrid, vtkUnstructuredGrid ]:
fracture_name: str ) -> tuple[ vtkUnstructuredGrid, vtkUnstructuredGrid ]:
reader = vtkXMLMultiBlockDataReader()
reader.SetFileName( vtk_input_file )
reader.Update()
Expand Down Expand Up @@ -73,9 +57,9 @@ def format_collocated_nodes( fracture_mesh: vtkUnstructuredGrid ) -> Sequence[ I


def __check_collocated_nodes_positions(
matrix_points: Sequence[ Tuple[ float, float, float ] ], fracture_points: Sequence[ Tuple[ float, float, float ] ],
g2l: Sequence[ int ], collocated_nodes: Iterable[ Iterable[ int ] ]
) -> Collection[ Tuple[ int, Iterable[ int ], Iterable[ Tuple[ float, float, float ] ] ] ]:
matrix_points: Sequence[ Coordinates3D ], fracture_points: Sequence[ Coordinates3D ], g2l: Sequence[ int ],
collocated_nodes: Iterable[ Iterable[ int ] ]
) -> Collection[ tuple[ int, Iterable[ int ], Iterable[ Coordinates3D ] ] ]:
issues = []
for li, bucket in enumerate( collocated_nodes ):
matrix_nodes = ( fracture_points[ li ], ) + tuple( map( lambda gi: matrix_points[ g2l[ gi ] ], bucket ) )
Expand All @@ -98,14 +82,14 @@ def my_iter( ccc ):

def __check_neighbors( matrix: vtkUnstructuredGrid, fracture: vtkUnstructuredGrid, g2l: Sequence[ int ],
collocated_nodes: Sequence[ Iterable[ int ] ] ):
fracture_nodes: Set[ int ] = set()
fracture_nodes: set[ int ] = set()
for bucket in collocated_nodes:
for gi in bucket:
fracture_nodes.add( g2l[ gi ] )
# For each face of each cell,
# if all the points of the face are "made" of collocated nodes,
# then this is a fracture face.
fracture_faces: Set[ FrozenSet[ int ] ] = set()
fracture_faces: set[ frozenset[ int ] ] = set()
for c in range( matrix.GetNumberOfCells() ):
cell: vtkCell = matrix.GetCell( c )
for f in range( cell.GetNumberOfFaces() ):
Expand All @@ -116,7 +100,7 @@ def __check_neighbors( matrix: vtkUnstructuredGrid, fracture: vtkUnstructuredGri
# Finding the cells
for c in tqdm( range( fracture.GetNumberOfCells() ), desc="Finding neighbor cell pairs" ):
cell: vtkCell = fracture.GetCell( c )
cns: Set[ FrozenSet[ int ] ] = set() # subset of collocated_nodes
cns: set[ frozenset[ int ] ] = set() # subset of collocated_nodes
point_ids = frozenset( vtk_iter( cell.GetPointIds() ) )
for point_id in point_ids:
bucket = collocated_nodes[ point_id ]
Expand All @@ -129,9 +113,8 @@ def __check_neighbors( matrix: vtkUnstructuredGrid, fracture: vtkUnstructuredGri
if f in fracture_faces:
found += 1
if found != 2:
logging.warning(
f"Something went wrong since we should have found 2 fractures faces (we found {found}) for collocated nodes {cns}."
)
logging.warning( f"Something went wrong since we should have found 2 fractures faces (we found {found})" +
f" for collocated nodes {cns}." )


def __check( vtk_input_file: str, options: Options ) -> Result:
Expand Down
Loading

0 comments on commit 8cc89f5

Please sign in to comment.