Tag surfaces inside the domain

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).

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

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:

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.

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

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 - credit’s due where it’s due

1 Like