Correct way to import 3D subdomains with complex geometries

Hello all,

I am trying to create a 3D mesh with two subdomains. I have the XML file for the entire domain and the XML files for each subdomain. For what it’s worth, one subdomain is contained completely within the other.

I have followed the approach in this 2D example. Using these two lines

mesh = Mesh("my_mesh.xml")
sub_domains = MeshFunction("size_t", mesh, "subdomains.xml")

where my_mesh.xml is the XML mesh of both domains combined and subdomains.xml is the geometry.xml file created when converting a GMSH .msh to an XML using meshio.

I don’t have a way to verify that this approach works yet so I’m wondering if this is the correct method of importing a 3D mesh with subdomains. I’ve seen other ways of doing this, such as in this example, where they somehow have their subdomain information and mesh information all stored in one .xml file and they import it on one line

mesh = Mesh("../aneurysm.xml.gz")

This might even be a question for GMSH or XML creation but I’m curious as to what the standard approach for importing 3D multi-domain meshes of complicated (ruling out approaches like this) geometry is.

Any insight or feedback would be greatly appreciated.


Hi, I would recommand to use the XDMF format. GMSH meshes can be converted to XDMF using meshio as well. Then you can create a MeshFunction that contains tags for your elements. Something like :

cell_markers = MeshFunction("size_t", mesh, mesh.topology().dim())
1 Like