@@ -4797,22 +4797,27 @@ def SubDomainData(geometric_expr):
47974797 return op2 .Subset (m .cell_set , indices )
47984798
47994799
4800- def Submesh (mesh , subdim , subdomain_id , label_name = None , name = None , ignore_halo = False , reorder = None , comm = None ):
4800+ def Submesh (mesh , subdim = None , subdomain_id = None , label_name = None , name = None , ignore_halo = False , reorder = None , comm = None ):
48014801 """Construct a submesh from a given mesh.
48024802
48034803 Parameters
48044804 ----------
48054805 mesh : MeshGeometry
48064806 Parent mesh (`MeshGeometry`).
4807- subdim : int
4807+ subdim : int | None
48084808 Topological dimension of the submesh.
4809+ Defaults to ``mesh.topological_dimension``.
48094810 subdomain_id : int | None
48104811 Subdomain ID representing the submesh.
4811- `None` defines the submesh owned by the sub-communicator.
4812+ If `None` the submesh will cover the entire domain.
4813+ This is useful to obtain a codim-1 submesh over all facets or
4814+ a submesh over a different communicator.
48124815 label_name : str | None
48134816 Name of the label to search ``subdomain_id`` in.
4817+ Defaults to ``'Cell Sets'`` or ``'Face Sets'`` depending on ``subdim``.
48144818 name : str | None
48154819 Name of the submesh.
4820+ Defaults to ``mesh.name + "_submesh"``·
48164821 ignore_halo : bool
48174822 Whether to exclude the halo from the submesh.
48184823 reorder : bool | None
@@ -4855,24 +4860,24 @@ def Submesh(mesh, subdim, subdomain_id, label_name=None, name=None, ignore_halo=
48554860 raise NotImplementedError ("Can not create a submesh of an ``ExtrudedMesh``" )
48564861 elif isinstance (mesh .topology , VertexOnlyMeshTopology ):
48574862 raise NotImplementedError ("Can not create a submesh of a ``VertexOnlyMesh``" )
4863+ if subdim is None :
4864+ subdim = mesh .topological_dimension
48584865 plex = mesh .topology_dm
48594866 dim = plex .getDimension ()
4860- if subdim not in [ dim , dim - 1 ] :
4867+ if subdim not in { dim , dim - 1 } :
48614868 raise NotImplementedError (f"Found submesh dim ({ subdim } ) and parent dim ({ dim } )" )
4862- if label_name is None :
4869+ if subdomain_id is None :
4870+ if label_name is not None :
4871+ raise ValueError ("subdomain_id=None requires label_name=None." )
4872+ # Select all entities
4873+ label_name = "depth"
4874+ subdomain_id = subdim
4875+ elif label_name is None :
48634876 if subdim == dim :
48644877 label_name = dmcommon .CELL_SETS_LABEL
48654878 elif subdim == dim - 1 :
48664879 label_name = dmcommon .FACE_SETS_LABEL
4867- if subdomain_id is None :
4868- # Filter the plex with PETSc's default label (cells owned by comm)
4869- if label_name != dmcommon .CELL_SETS_LABEL :
4870- raise ValueError ("subdomain_id == None requires label_name == CELL_SETS_LABEL." )
4871- subplex , sf = plex .filter (sanitizeSubMesh = True , ignoreHalo = ignore_halo , comm = comm )
4872- dmcommon .submesh_update_facet_labels (plex , subplex )
4873- dmcommon .submesh_correct_entity_classes (plex , subplex , sf )
4874- else :
4875- subplex = dmcommon .submesh_create (plex , subdim , label_name , subdomain_id , ignore_halo , comm = comm )
4880+ subplex = dmcommon .submesh_create (plex , subdim , label_name , subdomain_id , ignore_halo , comm = comm )
48764881
48774882 comm = comm or mesh .comm
48784883 name = name or _generate_default_submesh_name (mesh .name )
0 commit comments