Conversion from .msh to .xml

I prepared a .msh file and I tried convert it to .xml using dolfin-convert but it is giving me the following errors: Could you please suggest me how to resolve this.

Converting from Gmsh format (.msh, .gmsh) to DOLFIN XML format

Traceback (most recent call last):

File “/usr/bin/dolfin-convert”, line 132, in


File “/usr/bin/dolfin-convert”, line 79, in main

meshconvert.convert2xml(ifilename, ofilename, iformat=iformat)

File “/usr/lib/python3/dist-packages/dolfin_utils/meshconvert/”, line 1301, in convert2xml

convert(ifilename, XmlHandler(ofilename), iformat=iformat)

File “/usr/lib/python3/dist-packages/dolfin_utils/meshconvert/”, line 1322, in convert

gmsh2xml(ifilename, handler)

File “/usr/lib/python3/dist-packages/dolfin_utils/meshconvert/”, line 271, in gmsh2xml

num_elements = int(line)

ValueError: invalid literal for int() with base 10: ‘2204 5123592 1 5123592\n’

Currently, meshio is recommended for conversion of mesh instead of dolfin-convert.

Thank you for your message. I installed meshio and was able to convert my .msh to .xml. Could you please suggest how to get “physical_region” and “facet_region” in .xml format using meshio.


I don’t know really how to do it when it comes to mesh from GMSH, but you can use two general approaches:

  • If geometry is simple enough, you can write some script in python that will select nodes inside a particular geometry. In this case you need to know the equation. If for example the geometry is circle you can check if given coordinates of nodes and elements are satisfying condition: (x-a)^2 + (y-b)^2 + (z-c)^2 <= r^2
  • The second approach is straight forward, but might be labor-intensive if you have a many such regions. Simply export each submesh individually, read those and now you have nodes and elements that belong to a certain geometry.

Thank you for your inputs!

You can take a look here Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio
There it is mentioned how to get the data from gmsh.

Thank you for sharing this!, I will go through it.