CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Open Source Meshers: Gmsh, Netgen, CGNS, ... (
-   -   gmsh basics (

lindsaywestraadt January 21, 2010 08:21

gmsh basics
Hi there

I'm really new to OpenFoam and gmsh, so please bear with me. For starters I simply want to create a mesh in gmsh and then convert that to something that can be used in OpenFoam. So, I copied the cavity tutorial into my run folder. I deleted everything in the polyMesh folder except for the boundary file. I then pasted cavity.msh and cavity.geo into the polyMesh folder (these are the files I created in gmsh). I then went back to the cavity directory and entered: gmshToFoam cavity.msh .... but its not working. The last line of the error message says segmentation fault.

Any ideas? Should have installed gmshToFoam somewhere along the line? I saw it in the utilities folder so I figured it should take care of its self.

Any help will be greatly appreciated! :D


ericnutsch January 21, 2010 23:51

Kindof the right start.

First OpenFOAM doesnt care about the .geo file. This is solely for gmsh's use.

Second OpenFOAM doesnt read the .msh file directly. You use the utility you mentioned (gmshToFoam) to convert the .msh file into the mesh files that OpenFOAM reads. gmshToFoam is pre-installed by the way, go ahead and type it in your terminal and the errors will direct you.

Once the mesh is converted you will continue to get errors, because the boundary conditions are not correctly set up yet. Try to get as far as you can. The errors are detailed and helpful. Post again when(or if, lets stay positive) you get stuck.


lindsaywestraadt January 22, 2010 03:34

Hi Eric

Thanks so much for your help! I made my first mesh and viewed it in paraFoam! yay :p

lindsaywestraadt January 26, 2010 03:22

still having problems
Hi there

So, I can make a mesh in gmsh and convert it so that I can use it in OpenFoam, but there's still a problem. When I run icoFoam (still working with the cavity tutorial) and view the results in paraFoam, the results are wrong (there is no pressure field, and the velocity field is 'broken' and incorrect). I checked all the boundary conditions and the only thing that is different between my cavity example and the one provided in the tutorial is the mesh.

Does anyone know why this is not working? Am I using the wrong type of mesh? (I specified the all hexas algorithm)

Help will be greatly appreciated at this point :(


ericnutsch January 26, 2010 12:42

Does the mesh look the same as the original in paraview?(redundant but note worthy)

For viewing the contours; did you view all the time steps or just zero?(upper right hand corner of paraview)

The boundary conditions will likely not work exactly the same unless the names of the boundaries in your mesh are eXAcTly the same(case sensitive). More times than not this is where the problem is.

If none of those things spark and idea, post a full screen print screen of the broken mesh/contours in paraview.

Hope that helps!

lindsaywestraadt January 27, 2010 01:54

Hi Eric

Thanks again for your response. Below are some screenshots that might help explain my problem:

I am running all the time steps. Also, I made sure that the patch names in the boundary file match those in the initial boundary conditions of p and U. The only thing that I changed in the boundary conditions is the velocity of the movingWall: I changed it from (1 0 0) to (0 0 1) because the coordinates are different in my mesh.


ericnutsch February 3, 2010 21:04

Sorry to take such a long time to reply.

FYI: In the future I would attach my screen shots by clicking the manage attachments button below. If they are too big just trim them down in GIMP.(this is easier to read, and helps out people 20years down the road when the 3rd party site doesnt exist any more)

Your mesh is much different than I had visualised. You may have just have a convergence issue. Try doubling or tripling the resolution and give it another go.

If that doesn't help it is still probably a boundary issue. Confirm that you have properly specified your boundary conditions in the following files:

YOURCASE/0/nut (if you have one)
YOURCASE/0/nuTilda (if you have one)
YOURCASE/0/... (if you have any others in your "0" folder)

If you have transformed these to your mesh and still cant get it to work, attach the files specified above to your post.

Best of luck!

lindsaywestraadt February 4, 2010 00:37

Aah ... that's how I attach files :p

There was something wrong with the boundary conditions. I was correct in assuming that the velocity of the moving wall was no longer (1 0 0), but, it wasn't (0 0 1) either, it was (0 1 0) :cool: So, things are looking better, but the output is still not as smooth as the original example. I think I should just use a finer mesh. The problem I am having now is with generating a finer mesh. I need the mesh to be only 1 element thick, but when I make the mesh finer in gmsh, it also adds an extra layer of elements to the mesh, and OpenFoam doesn't like this. Make sense?

ericnutsch February 4, 2010 01:34

Dont refine using the gmsh gui. You should only control mesh size with the "characteristic length" variable.

The tutorials section of the user-guide also has good information on its use.

lindsaywestraadt February 4, 2010 06:56

Thanks Eric, that helped :D

Kenny June 27, 2010 23:17


So how do you phrase the command to convert *.msh into someting OpenFoam can read?

ericnutsch June 28, 2010 02:35

In a sourced shell type:

gmshToFoam yourMeshName.msh

flowris July 14, 2010 09:12


I am also a beginner in gmsh, trying to convert using gmshToFoam. I am sure I have a nice msh-file, because I can see the mesh in gmsh. But when I convert it, the console complains that it cannot find any cell.

This is the lower part of the console output:


Unhandled element 1 at line 4738
Unhandled element 1 at line 4739
Unhandled element 1 at line 4740
Unhandled element 1 at line 4741
Unhandled element 1 at line 4742
Unhandled element 1 at line 4743
Unhandled element 1 at line 4744
Unhandled element 1 at line 4745
Unhandled element 1 at line 4746
Unhandled element 1 at line 4747
Unhandled element 1 at line 4748
Mapping region 0 to Foam patch 0
    hex  :0
    pyr  :0
    tet  :0

No cells read from file "blok01.msh"
Does your file specify any 3D elements (hex=5, prism=6, pyramid=7, tet=4)?
Perhaps you have not exported the 3D elements?

    From function readCells(..)
    in file gmshToFoam.C at line 662.

FOAM exiting

This is my msh-file:

flowris July 14, 2010 09:23

1 Attachment(s)
Posting again for coarser mesh and smaller file. The same console output:


Unhandled element 1 at line 435
Unhandled element 1 at line 436
Unhandled element 1 at line 437
Unhandled element 1 at line 438
Mapping region 0 to Foam patch 0
    hex  :0
    pyr  :0
    tet  :0

No cells read from file "blok01.msh"
Does your file specify any 3D elements (hex=5, prism=6, pyramid=7, tet=4)?
Perhaps you have not exported the 3D elements?

    From function readCells(..)
    in file gmshToFoam.C at line 662.

FOAM exiting

And the msh file attached:

ericnutsch July 14, 2010 13:51

Just because you can see the mesh does not indicate its quality or compatibility.

Did you make the mesh in gmsh? If so post the geo file. Its possible you have not created any volumes (openfoam only sees volumes, even in 2d)

If you are just viewing the mesh in gmsh you will need to use the openfoam converter for the program that generated it. (you may be able to import into gmsh and save, but it is hard to debug things like the existence of volumes in this fashion.

flowris July 14, 2010 16:22

1 Attachment(s)
Thanks for the quick reply. Indeed I meshed with gmsh, here is the geo-file.

flowris July 14, 2010 16:39

1 Attachment(s)
Hello again,

I am also converting a mesh around an extruded "lens-shaped" half ship. The mesh has two problems:

1. Three unused points: these are the centres of the arcs. They are outside the mesh and not needed, but I do not know how to delete them.

2. High aspect ratio cells. I was able to improve mesh quality by refining the cells and by smoothing and optimizing. I used following command:
gmsh -3 -smooth 5 -optimize lens.geo

How can I use other mesh algorithms. I tried the option -algo front3d, but the concole responded
Fatal : Unknown mesh algorithm
(this also happened with the other algorithms)

BTW: I use gmsh-2.4.2 and OpenFOAM-1.6

ericnutsch July 14, 2010 22:19

Well you have stumped me. I cleaned up you file to just the active code so others can review it quickly.



lc = 0.03;

Point(0) = {0, 0, 0, lc};
Point(1) = {.1, 0,  0, lc} ;
Point(2) = {.1, .3, 0, lc} ;
Point(3) = {0,  .3, 0, lc} ;
Point(4) = {0, 0, .3, lc};
Point(5) = {.1, 0,  .3, lc} ;
Point(6) = {.1, .3, .3, lc} ;
Point(7) = {0,  .3, .3, lc} ;

Line(0) = {0,1} ;
Line(1) = {1,2} ;
Line(2) = {3,2} ;
Line(3) = {0,3} ;
Line(4) = {0,4} ;
Line(5) = {1,5} ;
Line(6) = {2,6} ;
Line(7) = {3,7} ;
Line(8) = {4,5} ;
Line(9) = {5,6} ;
Line(10) = {7,6} ;
Line(11) = {4,7} ;

Line Loop(12) = {0,1,-2,-3} ;
Line Loop(13) = {0,5,-8,-4} ;
Line Loop(14) = {1,6,-9,-5} ;
Line Loop(15) = {2,6,-10,-7} ;
Line Loop(16) = {3,7,-11,-4} ;
Line Loop(17) = {8,9,-10,-11} ;

Plane Surface(20) = {12} ;
Plane Surface(21) = {13} ;
Plane Surface(22) = {14} ;
Plane Surface(23) = {15} ;
Plane Surface(24) = {16} ;
Plane Surface(25) = {17} ;

Surface Loop(100) = {20,21,22,23,24,25};
Volume(101) = {100};

It is probably a negative volume issue. I messed with the face orientations some, but didnt have any luck. I have had problems like this before and it always comes down to an issue in the .geo file. Some times it is easier to start over with a working example. I belive there is a similar tutorial here:

If this is a practice case you will need to resolve the issue. If you are only trying to create a box, I strongly encourage you to use the extrude command instead of the surface loop method.

I will review it later as time alots...

Here is my error statement if it helps. It recognizes the tets but not much different.


Unhandled element 1 at line 558
Unhandled element 1 at line 559
Unhandled element 1 at line 560
Unhandled element 1 at line 561
Unhandled element 1 at line 562
Unhandled element 1 at line 563
Unhandled element 1 at line 564
Unhandled element 1 at line 565
Mapping region 0 to Foam patch 0
Mapping region 0 to Foam cellZone 0
    hex  :0
    pyr  :0
    tet  :1748

Zone    Size
    0    1748

Skipping tag  at line 2971
Patch 0 gets name patch0

--> FOAM Warning :
    From function polyMesh::polyMesh(... construct from shapes...)
    in file meshes/polyMesh/polyMeshFromShapeMesh.C at line 582
    Found 656 undefined faces in mesh; adding to default patch.
Finding faces of patch 0

All times are GMT -4. The time now is 15:26.