# Tag surfaces inside the domain

**URL:** <https://fenicsproject.discourse.group/t/tag-surfaces-inside-the-domain/7674>\
**Category:** dolfinx\
**Created:** [February 11, 2022, 6:35pm UTC](https://fenicsproject.discourse.group/t/tag-surfaces-inside-the-domain/7674 "2022-02-11T18:35:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JLorenteMacias](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/jlorentemacias/32/4742_2.png) [@JLorenteMacias](https://fenicsproject.discourse.group/u/JLorenteMacias)\
**Post date:** [February 11, 2022, 6:35pm UTC](https://fenicsproject.discourse.group/t/tag-surfaces-inside-the-domain/7674/1 "2022-02-11T18:35:01Z")

</div>

Dear all,

I am solving a flow in a rectangular domain and I need to compute the mass flux on the mid transverse plane (plane S of the following figure).

 ![Image (1)](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/c/ca0b2a033fd79c873921c8308ff3c8af14a1e113.png)

Therefore, I need to define a differential of surface such as:

```auto
dSurf = Measure("ds", domain=mesh, subdomain_data=ft, subdomain_id=surface_marker)

```

My problem is that I do not know how to tag that surface, since it is not part of the boundaries set. Therefore, if I use the usual approach, that is:

```auto
import numpy as np
surface_marker = 2
surface = []
if rank == 0:
    boundaries = gmsh.model.getBoundary(volumes, oriented=False)
    for boundary in boundaries:
        center_of_mass = gmsh.model.occ.getCenterOfMass(boundary[0], boundary[1])
        if np.allclose(center_of_mass, [0, 0, 0]):
            surface.append(boundary[1])

```

the mass flux is always zero because there is not any real boundary at [0,0,0].

Does anybody know how to tag surfaces in dolfinx that are not part of the boundaries set?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![hawkspar](https://avatars.discourse-cdn.com/v4/letter/h/b487fb/32.png) [@hawkspar](https://fenicsproject.discourse.group/u/hawkspar)\
**Post date:** [October 12, 2022, 1:03pm UTC](https://fenicsproject.discourse.group/t/tag-surfaces-inside-the-domain/7674/2 "2022-10-12T13:03:16Z")

</div>

I know this is an old question, but did you try :

```python
facet_indices, facet_markers = [], []
fdim = spy.mesh.topology.dim - 1
for (marker, locator) in boundaries:
	facets = dfx.mesh.locate_entities(spy.mesh, fdim, locator)
	facet_indices.append(facets)
	facet_markers.append(np.full_like(facets, marker))
facet_indices = np.hstack(facet_indices).astype(np.int32)
facet_markers = np.hstack(facet_markers).astype(np.int32)
sorted_facets = np.argsort(facet_indices)
facet_tag = dfx.mesh.meshtags(spy.mesh, fdim, facet_indices[sorted_facets], facet_markers[sorted_facets])

ds = ufl.Measure("ds", domain=spy.mesh, subdomain_data=facet_tag)

```

Seems to work for me. Taken straight from [this excellent tutorial](https://jorgensd.github.io/dolfinx-tutorial/chapter3/robin_neumann_dirichlet.html?highlight=meshtags) - credit’s due where it’s due
