# Issue Loading XDMF Mesh File into FEniCS

**URL:** <https://fenicsproject.discourse.group/t/issue-loading-xdmf-mesh-file-into-fenics/15971>\
**Category:** mesh\
**Tags:** mesh\
**Created:** [October 4, 2024, 7:23am UTC](https://fenicsproject.discourse.group/t/issue-loading-xdmf-mesh-file-into-fenics/15971 "2024-10-04T07:23:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ardaaydinn](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@ardaaydinn](https://fenicsproject.discourse.group/u/ardaaydinn)\
**Post date:** [October 4, 2024, 7:23am UTC](https://fenicsproject.discourse.group/t/issue-loading-xdmf-mesh-file-into-fenics/15971/1 "2024-10-04T07:23:55Z")

</div>

Hello FEniCS Community,

I am currently working on designing a mesh system and have been following Jorgen S. Dokken’s tutorial, which includes using Meshio to convert a `.msh` file to `.xdmf`. I successfully performed the conversion, and I am able to visually inspect the `.xdmf` file in ParaView without any issues. However, I’m encountering difficulties when attempting to load the `.xdmf` file into FEniCS.

Here is the code snippet I am using to load the mesh:

```auto
from fenics import *

# Load mesh from XDMF file
mesh = Mesh()
with XDMFFile("tetra_mesh.xdmf") as infile:
    infile.read(mesh)

```

The error I am facing is as follows:

```auto
RuntimeError Traceback (most recent call last)
Input In [2], in <cell line: 5>()
      4 mesh = Mesh()
      5 with XDMFFile("tetra_mesh.xdmf") as infile:
----> 6 infile.read(mesh)
      8 # Load mesh function from XDMF file
      9 volumes = MeshValueCollection("size_t", mesh, mesh.topology().dim())

```

I am unsure whether the problem lies within the mesh file itself or if I might be missing some important details or steps required to read the mesh file correctly in FEniCS. Here are my system details:

- FEniCS Version: Legacy Edition 2019.1.0
- Installation: Docker
- Platform: Linux

I would greatly appreciate any guidance or suggestions you could provide to help resolve this issue. To assist in diagnosing the problem, below in the github link you can see both the `.xdmf` and `.msh` files.

> **[GitHub - ardaydin/my\_mesh\_file\_fenics: Mesh Files for Fenics](https://github.com/ardaydin/my_mesh_file_fenics)**
>
> Mesh Files for Fenics

![physical_groups_4](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/8/8df63c7bb51ba27f7ce32be69524aa9827723f14.png)  
 ![physical_groups_3](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/4/4706e5ea76fade035a103a0c61186e2cea8559ae.png)  
 ![physical_groups_2](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/f/f27b9ff43a4f5da31ef6ce61e2e456ca19989dd5.png)  
 ![physical_groups_1](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/b/ba5a3d60ae30b59d6a0684e3f3fcc64493b19b3b.png)  
 ![paraview xdmf](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/4/43ec53a1415139f3827cfbdacf7ac8027feaae73.png)

Thank you in advance for your assistance!

Best regards,

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [October 4, 2024, 2:33pm UTC](https://fenicsproject.discourse.group/t/issue-loading-xdmf-mesh-file-into-fenics/15971/2 "2024-10-04T14:33:14Z")

</div>

Without the corresponding `tetra_mesh.h5` we cannot help you.  
Also add the full error message of the RunTimeError, as it seems like you haven’t included it all

---

<div class="post-metadata">

**Author:** ![ardaaydinn](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@ardaaydinn](https://fenicsproject.discourse.group/u/ardaaydinn)\
**Post date:** [October 7, 2024, 5:59am UTC](https://fenicsproject.discourse.group/t/issue-loading-xdmf-mesh-file-into-fenics/15971/3 "2024-10-07T05:59:22Z")

</div>

I have updated the github. Please see the link below.  
Hence, the error message in full can be seen below:

> **[GitHub - ardaydin/my\_mesh\_file\_fenics: Mesh Files for Fenics](https://github.com/ardaydin/my_mesh_file_fenics)**
>
> Mesh Files for Fenics

* * *

RuntimeError Traceback (most recent call last)  
Input In [2], in \<cell line: 5\>()  
4 mesh = Mesh()  
5 with XDMFFile(“tetra\_mesh.xdmf”) as infile:  
----\> 6 infile.read(mesh)  
8 # Load mesh function from XDMF file  
9 volumes = MeshValueCollection(“size\_t”, mesh, mesh.topology().dim())

RuntimeError:

\*\*\* -------------------------------------------------------------------------  
\*\*\* DOLFIN encountered an error. If you are not able to resolve this issue  
\*\*\* using the information listed below, you can ask for help at

* * *

\*\*\* [fenics-support@googlegroups.com](mailto:fenics-support@googlegroups.com)

* * *

\*\*\* Remember to include the error message listed below and, if possible,  
\*\*\* include a _minimal_ running example to reproduce the error.

* * *

\*\*\* -------------------------------------------------------------------------  
\*\*\* Error: Unable to open HDF5 file.  
\*\*\* Reason: File “tetra\_mesh.h5” does not exist.  
\*\*\* Where: This error was encountered inside HDF5Interface.cpp.  
\*\*\* Process: 0

* * *

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

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [October 7, 2024, 7:18am UTC](https://fenicsproject.discourse.group/t/issue-loading-xdmf-mesh-file-into-fenics/15971/4 "2024-10-07T07:18:37Z")

</div>

> [@ardaaydinn](#):
>
> \*\* -------------------------------------------------------------------------  
> \*\*\* Error: Unable to open HDF5 file.  
> \*\*\* Reason: File “tetra\_mesh.h5” does not exist.  
> \*\*\* Where: This error was encountered inside HDF5Interface.cpp.  
> \*\*\* Process: 0

The error is quite explicit.  
You do not have the `h5` file and `xdmf` file in the same repo (it seems).

For using the code

```python
from fenics import *

# Load mesh from XDMF file
mesh = Mesh()
with XDMFFile("tetra_mesh.xdmf") as infile:
    infile.read(mesh)

```

from your updated git repo works fine.
