Mismatched Number of Entities Error in FEniCS with XDMFFile

Hello, FEniCS community,

I am encountering an issue when trying to read a MeshFunction from an XDMF file in FEniCS 2019.1.0. The error message indicates a “Mismatched number of entities” inside XDMFFile.cpp.

Here’s a brief overview of my setup:

  • I created the mesh and physical groups using GMSH and exported them to XDMF files.
  • I’m trying to tag facets for boundary conditions on a 3D domain.

After loading my domain mesh and facets into FEniCS, I attempt to read my facets with:

*** -------------------------------------------------------------------------

from fenics import *

mesh = Mesh()
with XDMFFile(“domain_mesh.xdmf”) as infile:
infile.read(mesh)

facet_mesh = MeshFunction(“size_t”, mesh, mesh.topology().dim() - 1)
with XDMFFile(“facet_mesh.xdmf”) as infile:
infile.read(facet_mesh)

V = FunctionSpace(mesh, ‘P’, 1)

*** -------------------------------------------------------------------------

This is where I encounter the error. Below the error message can be seen:

*** -------------------------------------------------------------------------
*** Error: Unable to read MeshFunction.
*** Reason: Mismatched number of entities.
*** Where: This error was encountered inside XDMFFile.cpp.
*** Process: 0


*** DOLFIN version: 2019.1.0
*** Git changeset: ba376b6aebd7a9bc089be46b50bdd9f5c548fb91
*** -------------------------------------------------------------------------

I’ve verified that the mesh and facet files are consistent, but the issue persists. Could this be related to the way physical groups are defined in GMSH, or is there a step I might have missed?

Below is the github link for you to examine the mesh files:

Any insights or suggestions on how to resolve this mismatch would be greatly appreciated. Thank you!

Dear FEniCS Community,

Any guideline on the topic will be much appreciated. Thank you for your time.

Best Regards,

It would be preferable if the repo contained the gmsh geo/script file to generate the mesh. Furthermore, it would help if you added the python snippet above in the repository, or at the very least if you formatted it properly so that anyone could easily copy and paste.

Thank you for your feedback and for highlighting the need for a mesh generation script. I’d like to provide some clarity on the workflow I used:

  1. Mesh Generation Process: I actually used FreeCAD to model the system initially, and subsequently meshed it in Gmsh. Therefore, the process didn’t involve creating a traditional .geo script file directly. As a result, I’m not entirely certain if a .geo file can be exported from FreeCAD as part of this process.

    1. Python Snippet: Additionally, while I am unable to share the entire Python code due to its role in my thesis research, I will include the portion that involves reading the XDMF file, as it pertains to the specific error you encountered. This section will be properly formatted for easy use.

Thank you again for your input and support!