This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to save a mesh in gmsh format

+2 votes

I have a mesh created in this way

omega = BoxMesh(-6, -4, -4, 6, 4, 4, 10, 10, 10)

and saved is this way

File('temp.xml') << omega

¿how to convert the 'temp.xml' file to gmsh format?

asked Aug 21, 2013 by ljofre FEniCS Novice (720 points)

3 Answers

0 votes

You will need to write a converter by yourself. You can check dolfin/site-packages/dolfin_utils/meshconvert/meshconvert.py for the way a reverse conversion is done. You can also commit your work there. Another way is to stick to io module framework.

answered Aug 21, 2013 by Jan Blechta FEniCS Expert (51,420 points)
0 votes

Support for gmsh output will not be supported in DOLFIN.

If you want mesh output against a community standard/specification, use XDMF.

answered Aug 21, 2013 by Garth N. Wells FEniCS Expert (35,930 points)
+2 votes

Hi,
a simple solution would be to use Octave and the packages msh and fpl.
You can do as follow:
1) save the mesh in the .xml file as you are doing in Dolfin
2) load the mesh in Octave using msh
3) save it in a format compatible with gmsh using fpl
Quite long but you don't have to write code :-)

answered Aug 28, 2013 by gedeone FEniCS User (1,110 points)

I am trying to implement what gedeone has mentioned above:
This is a function that receives a mesh, sends it to gmesh, remeshes it, gets it back and returns the refined mesh. When I run this script, there is an error regarding octave library refers to:

oct_msh = octave.mshm_dolfin_read('f1.xml.gz')

Note: I have installed octave, gmsh, etc. other octave commans work but this one.

Moreover, how does the rest of the code look like?

def gmsh_refine(mesh):

        dolfin.File('f1.xml.gz') << mesh 

        f2 = open('out.geo', 'wb')

        # writing geo file for gmesh
        f2.write('''
        Mesh.CharacteristicLengthFactor=0.1;
        Mesh.Algorithm3D = 4; //Frontal (4) Delaunay(1)
        Mesh.RemeshAlgorithm=1;
        Merge "f2.stl";

        Compound Surface(200)={1};

        Surface Loop(300)={200};
        Volume(301)={300};

        Physical Surface (501)={200};
        Physical Volume(502)={301};
        ''')

        #reading in octave
        oct_msh = octave.mshm_dolfin_read('f1.xml.gz')

        #writing for gmsh
        octave.msh3m_gmsh_write('f2.stl', oct_msh)

        #remeshing
        os.system('gmsh f2.geo -3')

        #converting to xml
        os.system('dolfin-convert f2.msh f3.xml')

      #reading for dolfin
    return dolfin.Mesh('f3.xml')
...