Fluent.msh to XDMF; error

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

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

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

I would ask the meshio developers at their github page.

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")
2 Likes

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

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.

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 for instructions on how to write meshes readable by dolfin.

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***
*** 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

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

So, if you look at meshio code for ansys, in function read, cell_data will stay empty by the end of the function. So, when in your code you are writing mf.xdmf,

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.

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.

@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 themeshio developers giving them the minimal example (the MSH file) and your meahio read and write script:

#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”]}}))