@@ -1345,6 +1345,29 @@ def _concatenate_face_ids(face_ids_list):
1345
1345
faces = np .concatenate ([ids .faces for ids in face_ids_list ]))
1346
1346
1347
1347
1348
+ def _find_matching_index_pairs_merged (indices ):
1349
+ """
1350
+ Return an array of dimension ``(2, nmatches)`` containing pairs of indices into
1351
+ *indices* representing entries that are the same.
1352
+ """
1353
+ order = np .lexsort (indices )
1354
+ diffs = np .diff (indices [:, order ], axis = 1 )
1355
+ match_indices , = (~ np .any (diffs , axis = 0 )).nonzero ()
1356
+ return np .stack ((order [match_indices ], order [match_indices + 1 ]))
1357
+
1358
+
1359
+ def _find_matching_index_pairs (left_indices , right_indices ):
1360
+ """
1361
+ Return an array of dimension ``(2, nmatches)`` containing pairs of indices into
1362
+ *left_indices* (row 0) and *right_indices* (row 1) representing entries that
1363
+ are the same.
1364
+ """
1365
+ index_pairs = _find_matching_index_pairs_merged (
1366
+ np .concatenate ((left_indices , right_indices ), axis = 1 ))
1367
+ index_pairs [1 , :] -= left_indices .shape [1 ]
1368
+ return index_pairs
1369
+
1370
+
1348
1371
def _match_faces_by_vertices (groups , face_ids , vertex_index_map_func = None ):
1349
1372
"""
1350
1373
Return matching faces in *face_ids* (expressed as pairs of indices into
@@ -1388,13 +1411,8 @@ def vertex_index_map_func(vertices):
1388
1411
1389
1412
# Normalize vertex-based "face identifiers" by sorting
1390
1413
face_vertex_indices_increasing = np .sort (face_vertex_indices , axis = 0 )
1391
- # Lexicographically sort the face vertex indices, then diff the result to find
1392
- # faces with the same vertices
1393
- order = np .lexsort (face_vertex_indices_increasing )
1394
- diffs = np .diff (face_vertex_indices_increasing [:, order ], axis = 1 )
1395
- match_indices , = (~ np .any (diffs , axis = 0 )).nonzero ()
1396
1414
1397
- return np . stack (( order [ match_indices ], order [ match_indices + 1 ]) )
1415
+ return _find_matching_index_pairs_merged ( face_vertex_indices_increasing )
1398
1416
1399
1417
1400
1418
def _compute_facial_adjacency_from_vertices (
@@ -1486,22 +1504,10 @@ def _compute_facial_adjacency_from_vertices(
1486
1504
is_tagged = np .full (len (bdry_elements ), False )
1487
1505
1488
1506
for tag , tagged_elements_and_faces in tag_to_faces [igrp ].items ():
1489
- # Combine known tagged faces and current boundary faces into a
1490
- # single array, lexicographically sort them, and find identical
1491
- # neighboring entries to get tags
1492
- extended_elements_and_faces = np .concatenate ((
1493
- tagged_elements_and_faces ,
1494
- np .stack (
1495
- (bdry_elements , bdry_element_faces ),
1496
- axis = - 1 )))
1497
- order = np .lexsort (extended_elements_and_faces .T )
1498
- diffs = np .diff (extended_elements_and_faces [order , :], axis = 0 )
1499
- match_indices , = (~ np .any (diffs , axis = 1 )).nonzero ()
1500
- # lexsort is stable, so the second entry in each match corresponds
1501
- # to the yet-to-be-tagged boundary face
1502
- face_indices = (
1503
- order [match_indices + 1 ]
1504
- - len (tagged_elements_and_faces ))
1507
+ face_index_pairs = _find_matching_index_pairs (
1508
+ tagged_elements_and_faces .T ,
1509
+ np .stack ((bdry_elements , bdry_element_faces )))
1510
+ face_indices = face_index_pairs [1 , :]
1505
1511
if len (face_indices ) > 0 :
1506
1512
elements = bdry_elements [face_indices ]
1507
1513
element_faces = bdry_element_faces [face_indices ]
0 commit comments