# Fluent.msh to XDMF; error

**URL:** <https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262>\
**Category:** mesh\
**Created:** [January 21, 2020, 3:09pm UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262 "2020-01-21T15:09:53Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacktat](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jacktat](https://fenicsproject.discourse.group/u/jacktat)\
**Post date:** [January 21, 2020, 3:09pm UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/1 "2020-01-21T15:09:53Z")

</div>

Hello,

I have a .msh file which I obtained by meshing my 3D model with ANSYS ICEM, and I have a fenics model which takes XDMF mesh. A previous researcher gave me a python function which converts a fluent .msh mesh to a .xdmf filetype. Only now I get an error and I’m not sure how to resolve this.  
I get the following error now:

> (fenicsproject) [jack@furnace Oasis\_meshes]$ python fluentConvert.py -i fluent.msh -o MeshVenAna3D.xdmf  
> Input: fluent.msh  
> Output: MeshVenAna3D.xdmf  
> Reading dimensions  
> Reading zone info  
> Reading 81012 vertices in zone 11  
> Traceback (most recent call last):  
> File “fluentConvert.py”, line 537, in   
> fluentConvert(in\_file, out\_file)  
> File “fluentConvert.py”, line 530, in fluentConvert  
> scan\_fluent\_mesh(ifile, mesh, editor)  
> File “fluentConvert.py”, line 391, in scan\_fluent\_mesh  
> read\_zone\_vertices(dim, first\_id, last\_id, ifile, editor)  
> File “fluentConvert.py”, line 288, in read\_zone\_vertices  
> editor.add\_vertex(i - Nmin, vertex[0], vertex[1], vertex[2])  
> TypeError: add\_vertex(): incompatible function arguments. The following argument types are supported:  
> 1. (self: dolfin.cpp.mesh.MeshEditor, arg0: int, arg1: dolfin::Point) → None  
> 2. (self: dolfin.cpp.mesh.MeshEditor, arg0: int, arg1: List[float]) → None  
> Invoked with: \<dolfin.cpp.mesh.MeshEditor object at 0x2b0382217688\>, 0, 164.7931724336632, 74.35946440134452, 33.59019191582424

Whereas previously the original mesh come from a SolidWorks model and then meshed with ICEM, now I have a patient specific model which I got from SimVascular and loaded in ICEM and meshed the same way. I don’t know if maybe due to this faces and such of the model are not as explicity difined as before?  
Can someone maybe tell me what I’m doing wrong.

Cheers,  
Jack

---

<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:** [January 21, 2020, 3:53pm UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/2 "2020-01-21T15:53:31Z")

</div>

Without attaching the script you are using for conversion, it is hard to tell what’s wrong with your code. However, you should consider following [Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio](https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412/3)

---

<div class="post-metadata">

**Author:** ![jacktat](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jacktat](https://fenicsproject.discourse.group/u/jacktat)\
**Post date:** [January 21, 2020, 7:15pm UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/4 "2020-01-21T19:15:08Z")

</div>

Hey Dokken,

When I run the following script:

> import meshio  
> msh = meshio.read(“fluent.msh”)

I get the following error:

> Traceback (most recent call last):  
> File “jacktest.py”, line 3, in   
> msh = meshio.read(“fluent.msh”)  
> File “/home/jack/anaconda2/envs/fenicsproject/lib/python3.7/site-packages/meshio/\_helpers.py”, line 67, in read  
> return reader\_mapfile\_format  
> File “/home/jack/anaconda2/envs/fenicsproject/lib/python3.7/site-packages/meshio/gmsh/main.py”, line 15, in read  
> mesh = read\_buffer(f)  
> File “/home/jack/anaconda2/envs/fenicsproject/lib/python3.7/site-packages/meshio/gmsh/main.py”, line 31, in read\_buffer  
> raise ReadError()  
> meshio.\_exceptions.ReadError

It seems that it is not able to read the .msh file.  
Any tips?

Cheers,  
Jack

---

<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:** [January 21, 2020, 8:26pm UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/5 "2020-01-21T20:26:29Z")

</div>

I would ask the meshio developers at their github page.

---

<div class="post-metadata">

**Author:** ![amir](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/amir/32/683_2.png) [@amir](https://fenicsproject.discourse.group/u/amir)\
**Post date:** [January 21, 2020, 8:32pm UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/6 "2020-01-21T20:32:00Z")

</div>

Hey,

Since gmsh and Fluent produce the mesh files with same file extensions, meshio thinks you are working with a gmsh file. You need to specify that your file is created by Fluent using

```
import meshio
msh = meshio.read("fluent.msh", file_format = "ansys-binary") 

```

or

```
import meshio
msh = meshio.read("fluent.msh", file_format = "ansys-ascii")
```

---

<div class="post-metadata">

**Author:** ![jacktat](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jacktat](https://fenicsproject.discourse.group/u/jacktat)\
**Post date:** [January 22, 2020, 10:45am UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/7 "2020-01-22T10:45:40Z")

</div>

Hey Amir,

Thanks for your response.  
I tried to read the .msh file using your instructions, however, I still was not able to read the file.

> import meshio  
> msh = meshio.read(“fluentbin.msh”, file\_format = “ansys-binary”)

gave me:

> Traceback (most recent call last):  
> File “jacktest.py”, line 2, in   
> msh = meshio.read(“fluentbin.msh”, file\_format = “ansys-binary”)  
> File “/home/jack/anaconda2/envs/fenicsproject/lib/python3.7/site-packages/meshio/\_helpers.py”, line 65, in read  
> raise ReadError(msg)  
> meshio.\_exceptions.ReadError: Unknown file format ‘ansys-binary’ of ‘fluentbin.msh’.

Trying with ansys-ascii gave a similar error. From ANSYS ICEM I tried option _write as binary file_ with ‘yes’ and ‘no’. All .msh files gave errors.  
Have you got any idea what’s going wrong?  
Cheers,  
Jack

---

<div class="post-metadata">

**Author:** ![jacktat](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jacktat](https://fenicsproject.discourse.group/u/jacktat)\
**Post date:** [January 22, 2020, 11:19am UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/8 "2020-01-22T11:19:05Z")

</div>

I think I solved it by adding this in the terminal window: --input-format ansys

> meshio-convert fluent.msh fluentme.xdmf --input-format ansys

This seemed to have done the trick.

---

<div class="post-metadata">

**Author:** ![amir](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/amir/32/683_2.png) [@amir](https://fenicsproject.discourse.group/u/amir)\
**Post date:** [January 22, 2020, 3:03pm UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/9 "2020-01-22T15:03:00Z")

</div>

Oh, it seems in the newer versions of meshio it is sufficient to state

> import meshio  
> msh = meshio.read(“fluentbin.msh”, file\_format = “ansys”)

And try to check your output mesh is the same as your input mesh, i.e. check the number of elements in your .msh file and your .xdmf, because it might be the case that the meshio-convert might not write the mesh correctly. You may refer to [this link](https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412/3) for instructions on how to write meshes readable by dolfin.

---

<div class="post-metadata">

**Author:** ![jacktat](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jacktat](https://fenicsproject.discourse.group/u/jacktat)\
**Post date:** [January 22, 2020, 3:33pm UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/10 "2020-01-22T15:33:54Z")

</div>

The number of elements etc. seem to still be correct. Ive been looking through the thread that you sent, however, it seems to be about gmsh .msh files only. I have a .msh file from ansys icem. So I do not know if I can write the boundary parts like so:

> meshio.write(“mesh.xdmf”, meshio.Mesh(points=msh.points, cells={“tetra”: msh.cells[“tetra”]}))  
> meshio.write(“mf.xdmf”, meshio.Mesh(points=msh.points, cells={“triangle”: msh.cells[“triangle”]},  
> cell\_data={“triangle”: {“name\_to\_read”: msh.cell\_data[“triangle”][“gmsh:physical”]}}))

when I try and run my code this part gives me an error .

> boundaries = MeshFunction(“size\_t”, mesh, 2) # Read the boundary indicators  
> xdmf.read(boundaries, ‘boundaries’)  
> ds = Measure(“ds”)(subdomain\_data=boundaries)  
> ds\_wall = ds(wall[0]) + ds(wall[1])  
> ds\_veinwall = ds(wall[0])

this gives

> File “/home/jack/anaconda2/envs/fenicsproject/lib/python3.7/site-packages/oasis-2018.1-py3.7.egg/oasis/problems/NSfracStep/simulation\_Jack\_3D.py”, line 183, in   
> xdmf.read(boundaries, ‘boundaries’)  
> 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 MeshFunction for reading.  
> \*\*\* Reason: Mesh Grid with data Attribute not found in XDMF.  
> \*\*\* Where: This error was encountered inside XDMFFile.cpp.  
> \*\*\* Process: 0\*\*\* \*\*\* DOLFIN version: 2019.1.0  
> \*\*\* Git changeset: f3de96341c54e434c48115de5a3975b482aee933  
> \*\*\* -------------------------------------------------------------------------

Any advice?  
Cheers,  
Jack

---

<div class="post-metadata">

**Author:** ![jacktat](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jacktat](https://fenicsproject.discourse.group/u/jacktat)\
**Post date:** [January 22, 2020, 4:08pm UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/11 "2020-01-22T16:08:51Z")

</div>

I see that for some reason my .xdmf file does not contain the part “boundaries”, which is probably why it cant load it in. this is how the xdmf file looks like:

```
 <Xdmf Version="3.0">
  <Domain>
<Grid Name="Grid">
  <Information Name="Information" Value="0"><![CDATA[<main/>]]></Information>
  <Geometry GeometryType="XYZ">
    <DataItem DataType="Float" Dimensions="81012 3" Format="HDF" Precision="8">fluentme.h5:/data0</DataItem>
  </Geometry>
  <Topology TopologyType="Triangle" NumberOfElements="860292">
    <DataItem DataType="Int" Dimensions="860292 3" Format="HDF" Precision="8">fluentme.h5:/data1</DataItem>
  </Topology>
 </Grid>
</Domain>
</Xdmf>

```

I would not know where I needed to add the boundaries part.

The picture shows my xdmf file vs an old one from another researcher that worked with the code. I do not know why they are different and if that is due to an error made by me. The other file clearly has a boundaries part whereas I do not. How can I be sure to have this boundaries function?  
Cheers,  
Jack

 ![xdmff](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/1X/9caf2a38251dd1f94b46817305c400a36e9129ec.png)

---

<div class="post-metadata">

**Author:** ![amir](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/amir/32/683_2.png) [@amir](https://fenicsproject.discourse.group/u/amir)\
**Post date:** [January 22, 2020, 6:04pm UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/12 "2020-01-22T18:04:26Z")

</div>

So, if you look at [meshio code for ansys](https://github.com/nschloe/meshio/blob/master/meshio/ansys/_ansys.py), in function read, cell\_data will stay empty by the end of the function. So, when in your code you are writing mf.xdmf,

> [@jacktat](#):
>
> meshio.write(“mf.xdmf”, meshio.Mesh(points=msh.points, cells={“triangle”: msh.cells[“triangle”]},  
> cell\_data={“triangle”: {“name\_to\_read”: msh.cell\_data[“triangle”][“gmsh:physical”]}}))

you are not adding anything new to your xdmf file. I believe the problem must be with meshio’s script for reading from ansys files and you are not doing anything wrong.

---

<div class="post-metadata">

**Author:** ![jacktat](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jacktat](https://fenicsproject.discourse.group/u/jacktat)\
**Post date:** [January 22, 2020, 9:37pm UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/13 "2020-01-22T21:37:01Z")

</div>

Ah okay… I did not yet try this:

> meshio.write(“mf.xdmf”, meshio.Mesh(points=msh.points, cells={“triangle”: msh.cells[“triangle”]},  
> cell\_data={“triangle”: {“name\_to\_read”: msh.cell\_data[“triangle”][“gmsh:physical”]}}))

I only asked if I needed to try it.

---

<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:** [January 22, 2020, 9:42pm UTC](https://fenicsproject.discourse.group/t/fluent-msh-to-xdmf-error/2262/14 "2020-01-22T21:42:08Z")

</div>

@jacktat, I think what @amir is trying to say is that if you want to use the boundary data, you need to get in touch with the[meshio](https://github.com/nschloe/meshio) developers giving them the minimal example (the MSH file) and your meahio read and write script:

```auto
#add the appropriate read in msh files 
meshio.Mesh(points=msh.points, cells={“triangle”: msh.cells[“triangle”]},
cell_data={“triangle”: {“name_to_read”: msh.cell_data[“triangle”][“gmsh:physical”]}}))

```
