# Assigning one VectorFunctionSpace to multiple submeshes

**URL:** <https://fenicsproject.discourse.group/t/assigning-one-vectorfunctionspace-to-multiple-submeshes/6603>\
**Category:** Uncategorized\
**Created:** [September 16, 2021, 6:29pm UTC](https://fenicsproject.discourse.group/t/assigning-one-vectorfunctionspace-to-multiple-submeshes/6603 "2021-09-16T18:29:35Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Emanuel\_Gebauer](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/emanuel_gebauer/32/3004_2.png) [@Emanuel\_Gebauer](https://fenicsproject.discourse.group/u/Emanuel_Gebauer)\
**Post date:** [September 17, 2021, 9:43am UTC](https://fenicsproject.discourse.group/t/assigning-one-vectorfunctionspace-to-multiple-submeshes/6603/2 "2021-09-17T09:43:39Z")

</div>

I personally create my SubMeshes like this:

```auto
def extract_SubMesh(mesh, mf_2d, indices):
    """
    extracts the submesh (meshView-object) with the indices in indices out of the mesh
    Input:
        - mesh: mesh of the system
        - mf_2d: MeshFunction with the indices of the submeshes saved
        - indices: indices of the submesh to be created

    Output:
        - MeshView object of the submesh with the indices in indices
    """
    subdomains = MeshFunction("size_t", mesh, mesh.topology().dim(), 0) # create MeshFunction in order to create the subMesh
    for k in indices:
        subdomains.array()[mf_2d.array()==k] = 1
    extracted_SubMesh_return = MeshView.create(subdomains, 1)

```

I don’t quite remember where, but somewhere I’ve read, that you should use MeshView.create(…) for SubMeshes. However I forgot the reason why.  
The code above however works for me 🙂

Hope this is what you were looking for!

---

_[View the full topic](https://fenicsproject.discourse.group/t/assigning-one-vectorfunctionspace-to-multiple-submeshes/6603)._
