Generating a (Rectangle-Circle)-Mesh in dolfinx

Hello everyone,

i’m trying to build a mesh in dolfinx that is similar to a one i’ve built in fenics but i don’t seem get how to do it in dolfinx.

my fenics-code for the mesh:

channel = Rectangle(Point(0, 0), Point(2, 2))
cylinder = Circle(Point(1, 1), 0.05)
domain = channel - cylinder
mesh = generate_mesh(domain, 64)

could someone maybe guide me on how to change that into a dolfinx syntax.


Use a mesh generator. E.g. gmsh. See also this demo.


Thank you so much.
with the help of the mentioned demo and this Tutorial it has worked.

as shown in the tutorial, one must mark the different surfaces on the mesh in order to set the boundary conditions later on.
i’m interested in the obstacle surface and the bottom side of the wall which i implemented using this code, which im not sure it’s right tbh:

wall_marker, obstacle_marker = 4, 5
walls, obstacle = [], []
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, [L/2, 0, 0]):
    gmsh.model.addPhysicalGroup(1, walls, wall_marker)
    gmsh.model.setPhysicalName(1, wall_marker, "Walls")
    gmsh.model.addPhysicalGroup(1, obstacle, obstacle_marker)
    gmsh.model.setPhysicalName(1, obstacle_marker, "Obstacle")

i basically didn’t change much from the code given in the tutorial in order to generate the mesh afterwards and i even kept the notations from the tuturial for better visualisation and comparison of the script.

Is this the right way to tag those 2 surfaces of the mesh?

I would really appreciate your help.