I generated a mesh file in gambit and wanted to convert it to xml format. I tried the code below, but there is no output.

from dolfin import *    
from dolfin_utils import meshconvert

dolfin-convert cylinder6.msh out.xml

can anyone tell me how to convert using dolfin??


4 Answers 4


Use dolfin-convert from a terminal window.

  • $\begingroup$ Hi I converted some other mesh file found in web but not exactly the file which was generated in gambit...is there any other conversion for gambit generated mesh ?? $\endgroup$
    – nickrocks
    Commented May 22, 2013 at 16:36
  • $\begingroup$ I am not familiar with gambit generated meshes. Maybe you could upload a small sample mesh? Note that FEniCS only currently support simplices (triangles/tets). $\endgroup$ Commented May 22, 2013 at 19:28

To see which mesh types dolfin-convert can handle see the command line help:

$ dolfin-convert 
Usage: dolfin-convert [OPTIONS] ... input.x output.y


  -h         display this help text and exit
  -i format  specify input format
  -o format  specify output format

Alternatively, the following long options may be used:

  --help     same as -h
  --input    same as -i
  --output   same as -o

Supported formats:

  xml      - DOLFIN XML mesh format (current)
  xml-old  - DOLFIN XML mesh format (DOLFIN 0.6.2 and earlier)
  mesh     - Medit, generated by tetgen with option -g
  Triangle - Triangle file format (input prefix of .ele and .node files)
  gmsh     - Gmsh, version 2.0 file format
  metis    - Metis graph file format
  scotch   - Scotch graph file format
  diffpack - Diffpack tetrahedral grid format
  abaqus   - Abaqus tetrahedral grid format
  ExodusII - Sandia Format (requires ncdump utility from NetCDF)
  Star-CD  - Star-CD tetrahedral grid format

If --input or --output are not specified, the format will
be deduced from the suffix:

  .xml  - xml
  .mesh - mesh
  .gmsh - gmsh
  .msh  - gmsh
  .gra  - metis
  .grf  - scotch
  .grid - diffpack
  .inp  - abaqus
  .e    - Exodus II
  .exo  - Exodus II
  .ncdf - ncdump'ed Exodus II
  .vrt and .cell  - starcd

To call dolfin mesh conversion utilities from python, try:

from dolfin_utils import meshconvert

# Convert to XML
meshconvert.convert2xml(ifilename, ofilename, iformat=iformat)

but then you have to order the mesh yourself (or call the command dolfin-order)

# Order mesh
os.system("dolfin-order %s" % ofilename)

meshio (a small project of mine) has as command-line tool that can do it:

meshio-convert cylinder6.msh out.xml

To run a shell script (such as dolfin-convert) from python, you have to pass the necessary command line to the shell via os.system(), e.g.,

import os
os.system('dolfin-convert carbon_f.msh mesh.xml')
  • $\begingroup$ Could you explain your answer a little bit? $\endgroup$ Commented Jun 4, 2013 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.