@@ -12,11 +12,19 @@ def transfer_meshtags_to_submesh(
1212 # Invert map from sub-mesh to parent-mesh to parent-mesh to sub-mesh
1313 tdim = mesh .topology .dim
1414 cell_imap = mesh .topology .index_map (tdim )
15- num_cells = cell_imap .size_local + cell_imap .num_ghosts
16- mesh_to_submesh = np .full (num_cells , - 1 )
17- mesh_to_submesh [sub_cell_to_parent ] = np .arange (
18- len (sub_cell_to_parent ), dtype = np .int32
19- )
15+ try :
16+ from dolfinx .mesh import EntityMap # noqa: F401
17+
18+ legacy_entity_map = False
19+ except ImportError :
20+ legacy_entity_map = True
21+
22+ if legacy_entity_map :
23+ num_cells = cell_imap .size_local + cell_imap .num_ghosts
24+ mesh_to_submesh = np .full (num_cells , - 1 )
25+ mesh_to_submesh [sub_cell_to_parent ] = np .arange (
26+ len (sub_cell_to_parent ), dtype = np .int32
27+ )
2028
2129 # Compute and access various entity to vertex and vertex to
2230 # entity connectivity for parent and sub-mesh.
@@ -38,22 +46,51 @@ def transfer_meshtags_to_submesh(
3846 p_f_to_v = mesh .topology .connectivity (entity_tag .dim , 0 )
3947 p_f_to_c = mesh .topology .connectivity (entity_tag .dim , mesh .topology .dim )
4048 sub_to_parent_entity_map = np .full (num_child_entities , - 1 , dtype = np .int32 )
41- for facet , value in zip (entity_tag .indices , entity_tag .values ):
42- facet_found = False
43- for cell in p_f_to_c .links (facet ):
44- if facet_found :
45- break
46- if (child_cell := mesh_to_submesh [cell ]) != - 1 :
47- for child_facet in c_c_to_e .links (child_cell ):
48- child_vertices = c_e_to_v .links (child_facet )
49- child_vertices_as_parent = sub_vertex_to_parent [child_vertices ]
50- is_facet = np .isin (
51- child_vertices_as_parent , p_f_to_v .links (facet )
52- ).all ()
53- if is_facet :
54- child_markers [child_facet ] = value
55- facet_found = True
56- sub_to_parent_entity_map [child_facet ] = facet
49+
50+ if legacy_entity_map :
51+ for facet , value in zip (entity_tag .indices , entity_tag .values ):
52+ facet_found = False
53+ for cell in p_f_to_c .links (facet ):
54+ if facet_found :
55+ break
56+ if (child_cell := mesh_to_submesh [cell ]) != - 1 :
57+ for child_facet in c_c_to_e .links (child_cell ):
58+ child_vertices = c_e_to_v .links (child_facet )
59+ child_vertices_as_parent = sub_vertex_to_parent [child_vertices ]
60+ is_facet = np .isin (
61+ child_vertices_as_parent , p_f_to_v .links (facet )
62+ ).all ()
63+ if is_facet :
64+ child_markers [child_facet ] = value
65+ facet_found = True
66+ sub_to_parent_entity_map [child_facet ] = facet
67+ else :
68+ for facet , value in zip (entity_tag .indices , entity_tag .values ):
69+ facet_found = False
70+ parent_cells = p_f_to_c .links (facet )
71+ sub_cells = sub_cell_to_parent .sub_topology_to_topology (
72+ parent_cells , inverse = True
73+ )
74+
75+ for child_cell in sub_cells :
76+ if facet_found :
77+ break
78+ if child_cell != - 1 :
79+ for child_facet in c_c_to_e .links (child_cell ):
80+ child_vertices = c_e_to_v .links (child_facet )
81+ child_vertices_as_parent = (
82+ sub_vertex_to_parent .sub_topology_to_topology (
83+ child_vertices , inverse = False
84+ )
85+ )
86+ is_facet = np .isin (
87+ child_vertices_as_parent , p_f_to_v .links (facet )
88+ ).all ()
89+ if is_facet :
90+ child_markers [child_facet ] = value
91+ facet_found = True
92+ sub_to_parent_entity_map [child_facet ] = facet
93+
5794 tags = dolfinx .mesh .meshtags (
5895 submesh ,
5996 entity_tag .dim ,
0 commit comments