Locate_entities_boundary & embed gmsh boundaries?

Hello,

I’m interested in solving a problem on a mesh similar to:

It consists basically of a square domain where is added an embedded line where boundary conditions are to be applied.

The mesh is created with gmsh and converted to dolfinx with the following script:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import dolfinx
from mpi4py import MPI
import numpy as np
import gmsh

#
#======================
# Create the gmsh mesh
#======================
#
gmsh.initialize()
gmsh.model.add("t1")

s1_lower_left  = gmsh.model.geo.addPoint(0.0, 0.0, 0, 0.4)
s1_lower_right = gmsh.model.geo.addPoint(1.0, 0.0, 0, 0.4)
s1_upper_right = gmsh.model.geo.addPoint(1.0, 1.0, 0, 0.4)
s1_upper_left  = gmsh.model.geo.addPoint(0.0, 1.0, 0, 0.4)

s1_left  = gmsh.model.geo.addLine(s1_lower_left, s1_upper_left)
s1_right = gmsh.model.geo.addLine(s1_lower_right, s1_upper_right)
s1_lower = gmsh.model.geo.addLine(s1_lower_left, s1_lower_right)
s1_upper = gmsh.model.geo.addLine(s1_upper_left, s1_upper_right)

s1_surface = gmsh.model.geo.addPlaneSurface([gmsh.model.geo.addCurveLoop([-s1_left, s1_lower, s1_right, -s1_upper])])

embed_left_point = gmsh.model.geo.addPoint(0.5, 0.5, 0, 0.4)
embed_line  = gmsh.model.geo.addLine(embed_left_point, s1_upper_right)


gmsh.model.geo.synchronize()
gmsh.model.mesh.embed(1, [embed_line], 2, s1_surface)
gmsh.model.geo.synchronize()

MARKER = 2
gmsh.model.addPhysicalGroup(2, [s1_surface], 1)
gmsh.model.addPhysicalGroup(1, [s1_left, s1_lower, s1_right, s1_upper, embed_line], MARKER)

gmsh.model.mesh.generate(2)
#
#=========================
# Convert to dolfinx mesh
#=========================
#
msh, cell_tags, facet_tags = dolfinx.io.gmshio.model_to_mesh(gmsh.model, comm=MPI.COMM_WORLD, rank=0, gdim=2)

bdry = dolfinx.mesh.locate_entities_boundary(msh, 1, lambda x: np.full_like(x[0], 1, dtype=np.int8))
print('Number of tags: ',facet_tags.values.size)
print('Number of boundary ',bdry.size)

# gmsh.fltk.run()
gmsh.finalize()

The output of this script is:

Number of tags:  14
Number of boundary  12

This shows that actually locate_entities_boundary does not locate the embedded boundary. This is quite a problem for me because I usually use locate_dofs_topological(function_space, 1, bdry[facet_tags==MARKER]) to impose boundary conditions. How can this be done for embedded boundary conditions?

Best,

Lucas

It is quite natural that the line that is inside the mesh is not found by locate_entities_boundary, as it is not on the boundary, it is shared between two cells.

As you make the mesh with gmsh, you should be able to simply use the facet_tags directly in locate_dofs_topological. I.e facet_tags.find(1) should give you all the marked facets from

which includes the embedded line.

Thanks Dokkfen, that’s the solution I needed.