@@ -4756,6 +4756,7 @@ def Submesh(mesh, subdim, subdomain_id, label_name=None, name=None, ignore_halo=
47564756 Whether to reorder the mesh entities.
47574757 comm : PETSc.Comm | None
47584758 An optional sub-communicator to define the submesh.
4759+ By default, the submesh is defined on `mesh.comm`.
47594760
47604761 Returns
47614762 -------
@@ -4817,26 +4818,24 @@ def Submesh(mesh, subdim, subdomain_id, label_name=None, name=None, ignore_halo=
48174818 raise NotImplementedError ("Can not create a submesh of a ``VertexOnlyMesh``" )
48184819 plex = mesh .topology_dm
48194820 dim = plex .getDimension ()
4821+ if subdim not in [dim , dim - 1 ]:
4822+ raise NotImplementedError (f"Found submesh dim ({ subdim } ) and parent dim ({ dim } )" )
4823+ if label_name is None :
4824+ if subdim == dim :
4825+ label_name = dmcommon .CELL_SETS_LABEL
4826+ elif subdim == dim - 1 :
4827+ label_name = dmcommon .FACE_SETS_LABEL
48204828 if subdomain_id is None :
48214829 # Filter the plex with PETSc's default label (cells owned by comm)
4822- if label_name is not None :
4823- raise ValueError ("subdomain_id == None requires label_name == None ." )
4824- if subdim != dim :
4825- raise NotImplementedError ( f"Found submesh dim ( { subdim } ) and parent dim ( { dim } )" )
4826- subplex , _ = plex . filter ( sanitizeSubMesh = True , ignoreHalo = ignore_halo , comm = comm )
4830+ if label_name != dmcommon . CELL_SETS_LABEL :
4831+ raise ValueError ("subdomain_id == None requires label_name == CELL_SETS_LABEL ." )
4832+ subplex , sf = plex . filter ( sanitizeSubMesh = True , ignoreHalo = ignore_halo , comm = comm )
4833+ dmcommon . submesh_update_facet_labels ( plex , subplex )
4834+ dmcommon . submesh_correct_entity_classes ( plex , subplex , sf )
48274835 else :
4828- if comm is not None and comm != mesh .comm :
4829- raise NotImplementedError ("Submesh on subcommunicator not implemented on cell subsets." )
4830- if subdim not in [dim , dim - 1 ]:
4831- raise NotImplementedError (f"Found submesh dim ({ subdim } ) and parent dim ({ dim } )" )
4832- if label_name is None :
4833- if subdim == dim :
4834- label_name = dmcommon .CELL_SETS_LABEL
4835- elif subdim == dim - 1 :
4836- label_name = dmcommon .FACE_SETS_LABEL
48374836 subplex = dmcommon .submesh_create (plex , subdim , label_name , subdomain_id , ignore_halo , comm = comm )
4838- comm = mesh .comm
48394837
4838+ comm = comm or mesh .comm
48404839 name = name or _generate_default_submesh_name (mesh .name )
48414840 subplex .setName (_generate_default_mesh_topology_name (name ))
48424841 if subplex .getDimension () != subdim :
0 commit comments