2424 vtkUnstructuredGrid ,
2525)
2626from vtkmodules .vtkFiltersGeometry import (
27- vtkMarkBoundaryFilter ,
28- )
27+ vtkMarkBoundaryFilter , )
2928from vtk .util .numpy_support import (
30- vtk_to_numpy ,
31- )
29+ vtk_to_numpy , )
3230
3331import networkx
3432
@@ -56,6 +54,7 @@ class FractureNodesInfo:
5654
5755
5856class FractureCellsInfo :
57+
5958 def __init__ (self , mesh : vtkUnstructuredGrid , cell_to_faces : Dict [int , Iterable [int ]]):
6059 # For each cell (the key), gets the local (to the face, i.e. 0 to 3 for a tet) faces that are part of the fracture.
6160 # There can be multiple faces involved.
@@ -93,8 +92,7 @@ def _iter(id_list: vtkIdList) -> Iterator[int]:
9392 yield id_list .GetId (i )
9493
9594
96- def __duplicate_fracture_nodes (mesh : vtkUnstructuredGrid ,
97- connected_components : Iterable [Iterable [int ]],
95+ def __duplicate_fracture_nodes (mesh : vtkUnstructuredGrid , connected_components : Iterable [Iterable [int ]],
9896 node_frac_info : FractureNodesInfo ) -> Tuple [vtkUnstructuredGrid , DuplicatedNodesInfo ]:
9997 """
10098 Splits the mesh on the fracture.
@@ -123,7 +121,7 @@ def __duplicate_fracture_nodes(mesh: vtkUnstructuredGrid,
123121
124122 # Building an indicator to find fracture cells.
125123 # A fracture cell is a cell which touches a fracture internal node.
126- is_fracture_side_cells = numpy .zeros (num_cells , dtype = bool ) # Defaults to "not a fracture cell".
124+ is_fracture_side_cells = numpy .zeros (num_cells , dtype = bool ) # Defaults to "not a fracture cell".
127125 for fracture_side_cells in connected_components :
128126 for fracture_side_cell in fracture_side_cells :
129127 is_fracture_side_cells [fracture_side_cell ] = True
@@ -132,8 +130,8 @@ def __duplicate_fracture_nodes(mesh: vtkUnstructuredGrid,
132130 # The idea is that I do not want to fill holes in the numbering,
133131 # I just want to increment the next number by one.
134132 # A negative number means that this is a duplicated number.
135- renumbered_nodes = numpy .ones (num_points , dtype = int ) * - 1 # Defaults to "moved".
136- next_point_id = 0 # When a node needs to be duplicated, `next_point_id` is the next available node.
133+ renumbered_nodes = numpy .ones (num_points , dtype = int ) * - 1 # Defaults to "moved".
134+ next_point_id = 0 # When a node needs to be duplicated, `next_point_id` is the next available node.
137135 for node_idx in range (num_points ):
138136 if not node_frac_info .is_internal_fracture_node [node_idx ]:
139137 renumbered_nodes [node_idx ] = next_point_id
@@ -157,13 +155,13 @@ def __duplicate_fracture_nodes(mesh: vtkUnstructuredGrid,
157155 # Here we find or build the new number of the node.
158156 if node_frac_info .is_internal_fracture_node [new_cell_point_id ]:
159157 assert renumbered_nodes [new_cell_point_id ] == - 1
160- if new_cell_point_id in dup_nodes : # if already duplicated, take the same
158+ if new_cell_point_id in dup_nodes : # if already duplicated, take the same
161159 new_cell_point_ids .SetId (i , dup_nodes [new_cell_point_id ])
162- else : # otherwise, duplicate
160+ else : # otherwise, duplicate
163161 dup_nodes [new_cell_point_id ] = next_point_id
164162 new_cell_point_ids .SetId (i , next_point_id )
165163 next_point_id += 1
166- else : # Here, it's not an internal fracture node which was not duplicated.
164+ else : # Here, it's not an internal fracture node which was not duplicated.
167165 assert not renumbered_nodes [new_cell_point_id ] == - 1
168166 new_cell_point_ids .SetId (i , renumbered_nodes [new_cell_point_id ])
169167 new_cells .ReplaceCellAtId (fracture_side_cell , new_cell_point_ids )
@@ -184,7 +182,8 @@ def __duplicate_fracture_nodes(mesh: vtkUnstructuredGrid,
184182 new_cells .ReplaceCellAtId (cell_idx , new_cell_point_ids )
185183
186184 # Now we finish the process for vtk points.
187- num_new_points = num_points - sum (node_frac_info .is_internal_fracture_node ) + sum (map (len , component_to_dup_nodes .values ()))
185+ num_new_points = num_points - sum (node_frac_info .is_internal_fracture_node ) + sum (
186+ map (len , component_to_dup_nodes .values ()))
188187 assert next_point_id == num_new_points
189188
190189 old_points = mesh .GetPoints ()
@@ -216,19 +215,16 @@ def __duplicate_fracture_nodes(mesh: vtkUnstructuredGrid,
216215 nodes_validation [renumbered_nodes [n ]] = True
217216 assert all (nodes_validation )
218217
219- output = mesh .NewInstance () # keeping the same instance type.
218+ output = mesh .NewInstance () # keeping the same instance type.
220219 output .SetPoints (new_points )
221- output .SetCells (mesh .GetCellTypesArray (), new_cells ) # The cell types are unchanged; we reuse the old cell types!
220+ output .SetCells (mesh .GetCellTypesArray (), new_cells ) # The cell types are unchanged; we reuse the old cell types!
222221
223- duplicated_nodes_info = DuplicatedNodesInfo (renumbered_nodes = renumbered_nodes ,
224- duplicated_nodes = duplicated_nodes )
222+ duplicated_nodes_info = DuplicatedNodesInfo (renumbered_nodes = renumbered_nodes , duplicated_nodes = duplicated_nodes )
225223
226224 return output , duplicated_nodes_info
227225
228226
229- def __copy_fields (input_mesh : vtkUnstructuredGrid ,
230- output_mesh : vtkUnstructuredGrid ,
231- cell_frac_info : FractureCellsInfo ,
227+ def __copy_fields (input_mesh : vtkUnstructuredGrid , output_mesh : vtkUnstructuredGrid , cell_frac_info : FractureCellsInfo ,
232228 duplicated_nodes_info : DuplicatedNodesInfo ) -> None :
233229 """
234230 Given input and output meshes, copies the fields from the input into the output.
@@ -269,15 +265,16 @@ def __copy_fields(input_mesh: vtkUnstructuredGrid,
269265 # The "field data" will contain the fracture information
270266 field_data = input_mesh .GetFieldData ()
271267 if field_data .GetNumberOfArrays () > 0 :
272- logging .warning (f"Copying field data that already has arrays. No modification was made w.r.t. nodes duplications." )
268+ logging .warning (
269+ f"Copying field data that already has arrays. No modification was made w.r.t. nodes duplications." )
273270
274271 # Building the field data for the fracture
275272 if field_data .HasArray ("fracture_info" ):
276273 logging .warning ("Field data \" fracture_info\" already exists, nothing done." )
277274 else :
278275 frac_array = vtkIntArray ()
279- frac_array .SetName ("fracture_info" ) # TODO hard coded name.
280- frac_array .SetNumberOfComponents (4 ) # Warning the component has to be defined first...
276+ frac_array .SetName ("fracture_info" ) # TODO hard coded name.
277+ frac_array .SetNumberOfComponents (4 ) # Warning the component has to be defined first...
281278 frac_array .SetNumberOfTuples (len (cell_frac_info .field_data ))
282279 for i , data in enumerate (cell_frac_info .field_data ):
283280 frac_array .SetTuple (i , data )
@@ -290,7 +287,8 @@ def __copy_fields(input_mesh: vtkUnstructuredGrid,
290287 duplication_max_multiplicity = max (map (len , duplicated_nodes_info .duplicated_nodes .values ()))
291288 nodes_array = vtkIntArray ()
292289 nodes_array .SetName ("duplicated_points_info" )
293- nodes_array .SetNumberOfComponents (duplication_max_multiplicity ) # Warning the component has to be defined first...
290+ nodes_array .SetNumberOfComponents (
291+ duplication_max_multiplicity ) # Warning the component has to be defined first...
294292 nodes_array .SetNumberOfTuples (len (duplicated_nodes_info .duplicated_nodes ))
295293 for i , data in enumerate (duplicated_nodes_info .duplicated_nodes .values ()):
296294 tmp = list (data ) + [- 1 ] * (duplication_max_multiplicity - len (data ))
@@ -300,21 +298,24 @@ def __copy_fields(input_mesh: vtkUnstructuredGrid,
300298 output_mesh .SetFieldData (field_data )
301299
302300
303- def __color_fracture_sides (mesh : vtkUnstructuredGrid , cell_frac_info : FractureCellsInfo , node_frac_info : FractureNodesInfo ) -> Iterable [Iterable [int ]]:
301+ def __color_fracture_sides (mesh : vtkUnstructuredGrid , cell_frac_info : FractureCellsInfo ,
302+ node_frac_info : FractureNodesInfo ) -> Iterable [Iterable [int ]]:
304303 """
305304 Given all the cells that are in contact with the detected fracture,
306305 we separate them into bucket of connected cells touching the fractures.
307306 We do this because all the cells in one same bucket are connected and need to stay connected.
308307 So they need to share the same nodes as they did before the split.
309308 :return: All the buckets connected fracture cells.
310309 """
311- def does_face_contain_boundary_node (_face_point_ids : Iterable [int ]) -> bool : # Small helper function.
310+
311+ def does_face_contain_boundary_node (_face_point_ids : Iterable [int ]) -> bool : # Small helper function.
312312 for face_point_id in _face_point_ids :
313313 if node_frac_info .is_boundary_fracture_node [face_point_id ]:
314314 return True
315315 return False
316316
317- face_node_set_to_cell = defaultdict (list ) # For each face (defined by its node set), gives all the cells containing this face.
317+ face_node_set_to_cell = defaultdict (
318+ list ) # For each face (defined by its node set), gives all the cells containing this face.
318319 for c , local_frac_f in cell_frac_info .cell_to_faces .items ():
319320 cell = mesh .GetCell (c )
320321 for f in [i for i in range (cell .GetNumberOfFaces ()) if i not in local_frac_f ]:
@@ -357,8 +358,7 @@ def __find_boundary_nodes(mesh: vtkUnstructuredGrid) -> Sequence[int]:
357358 return vtk_to_numpy (is_boundary_point )
358359
359360
360- def __build_fracture_nodes (mesh : vtkUnstructuredGrid ,
361- cell_frac_info : FractureCellsInfo ,
361+ def __build_fracture_nodes (mesh : vtkUnstructuredGrid , cell_frac_info : FractureCellsInfo ,
362362 split_on_domain_boundary : bool ) -> FractureNodesInfo :
363363 """
364364 Given the description of the fracture in @p cell_frac_info, computes the underlying nodes.
@@ -375,9 +375,9 @@ def __build_fracture_nodes(mesh: vtkUnstructuredGrid,
375375 for e in range (face .GetNumberOfEdges ()):
376376 edge = face .GetEdge (e )
377377 edge_nodes = []
378- for i in range (edge .GetNumberOfPoints ()): # TODO, do less pedantic
378+ for i in range (edge .GetNumberOfPoints ()): # TODO, do less pedantic
379379 edge_nodes .append (edge .GetPointId (i ))
380- fracture_edges [tuple (sorted (edge_nodes ))] += 1 # TODO frozenset?
380+ fracture_edges [tuple (sorted (edge_nodes ))] += 1 # TODO frozenset?
381381
382382 boundary_fracture_edges = []
383383 # Boundary edges are seen twice because each 2d fracture element is seen twice too.
@@ -414,7 +414,7 @@ def __build_fracture_nodes(mesh: vtkUnstructuredGrid,
414414
415415 # Now compute the internal fracture nodes by "difference".
416416 is_internal_fracture_node = numpy .zeros (mesh .GetNumberOfPoints (), dtype = bool )
417- for n in range (mesh .GetNumberOfPoints ()): # TODO duplicated, reorg the code.
417+ for n in range (mesh .GetNumberOfPoints ()): # TODO duplicated, reorg the code.
418418 if is_fracture_node [n ] and not is_boundary_fracture_node [n ]:
419419 is_internal_fracture_node [n ] = True
420420
@@ -438,21 +438,21 @@ def __find_involved_cells(mesh: vtkUnstructuredGrid, options: Options) -> Tuple[
438438 raise ValueError (f"Cell field { options .field } does not exist in mesh, nothing done" )
439439
440440 cells_to_faces = defaultdict (list )
441- is_fracture_node = numpy .zeros (mesh .GetNumberOfPoints (), dtype = bool ) # all False
441+ is_fracture_node = numpy .zeros (mesh .GetNumberOfPoints (), dtype = bool ) # all False
442442
443443 # For each face of each cell, we search for the unique neighbor cell (if it exists).
444444 # Then, if the 2 values of the two cells match the field requirements,
445445 # we store the cell and its local face index: this is indeed part of the surface that we'll need to be split.
446446 neighbor_cell_ids = vtkIdList ()
447447 for cell_id in range (mesh .GetNumberOfCells ()):
448- if f [cell_id ] not in options .field_values : # No need to consider a cell if its field value is not in the target range.
448+ if f [cell_id ] not in options .field_values : # No need to consider a cell if its field value is not in the target range.
449449 continue
450450 cell = mesh .GetCell (cell_id )
451451 for i in range (cell .GetNumberOfFaces ()):
452452 face = cell .GetFace (i )
453453 mesh .GetCellNeighbors (cell_id , face .GetPointIds (), neighbor_cell_ids )
454454 assert neighbor_cell_ids .GetNumberOfIds () < 2
455- for j in range (neighbor_cell_ids .GetNumberOfIds ()): # It's 0 or 1...
455+ for j in range (neighbor_cell_ids .GetNumberOfIds ()): # It's 0 or 1...
456456 neighbor_cell_id = neighbor_cell_ids .GetId (j )
457457 if f [neighbor_cell_id ] != f [cell_id ] and f [neighbor_cell_id ] in options .field_values :
458458 cells_to_faces [cell_id ].append (i )
0 commit comments