@@ -4740,8 +4740,9 @@ def Submesh(mesh, subdim, subdomain_id, label_name=None, name=None, ignore_halo=
47404740 Parent mesh (`MeshGeometry`).
47414741 subdim : int
47424742 Topological dimension of the submesh.
4743- subdomain_id : int
4743+ subdomain_id : int | None
47444744 Subdomain ID representing the submesh.
4745+ `None` defines the submesh owned by the sub-communicator.
47454746 label_name : str
47464747 Name of the label to search ``subdomain_id`` in.
47474748 name : str
@@ -4813,23 +4814,22 @@ def Submesh(mesh, subdim, subdomain_id, label_name=None, name=None, ignore_halo=
48134814 raise NotImplementedError ("Can not create a submesh of a ``VertexOnlyMesh``" )
48144815 plex = mesh .topology_dm
48154816 dim = plex .getDimension ()
4816- if subdim not in [dim , dim - 1 ]:
4817- raise NotImplementedError (f"Found submesh dim ({ subdim } ) and parent dim ({ dim } )" )
4818- if label_name is None :
4819- if subdim == dim :
4820- label_name = dmcommon .CELL_SETS_LABEL
4821- elif subdim == dim - 1 :
4822- label_name = dmcommon .FACE_SETS_LABEL
4823- name = name or _generate_default_submesh_name (mesh .name )
4824- if comm is None or comm == mesh .comm :
4825- subplex = dmcommon .submesh_create (plex , subdim , label_name , subdomain_id , ignore_halo , comm )
4817+ if subdomain_id is None :
4818+ # Filter the plex with PETSc's default label (cells owned by comm)
4819+ if subdim != dim :
4820+ raise NotImplementedError (f"Found submesh dim ({ subdim } ) and parent dim ({ dim } )" )
4821+ subplex , _ = plex .filter (sanitizeSubMesh = True , ignoreHalo = ignore_halo , comm = comm )
48264822 else :
4827- # FIXME
4828- subplex , _ = plex .filter (label = plex .getLabel (label_name ),
4829- value = subdomain_id ,
4830- sanitizeSubMesh = True ,
4831- ignoreHalo = ignore_halo ,
4832- comm = comm )
4823+ if subdim not in [dim , dim - 1 ]:
4824+ raise NotImplementedError (f"Found submesh dim ({ subdim } ) and parent dim ({ dim } )" )
4825+ if label_name is None :
4826+ if subdim == dim :
4827+ label_name = dmcommon .CELL_SETS_LABEL
4828+ elif subdim == dim - 1 :
4829+ label_name = dmcommon .FACE_SETS_LABEL
4830+ subplex = dmcommon .submesh_create (plex , subdim , label_name , subdomain_id , ignore_halo , comm = comm )
4831+
4832+ name = name or _generate_default_submesh_name (mesh .name )
48334833 subplex .setName (_generate_default_mesh_topology_name (name ))
48344834 if subplex .getDimension () != subdim :
48354835 raise RuntimeError (f"Found subplex dim ({ subplex .getDimension ()} ) != expected ({ subdim } )" )
0 commit comments