CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Pre-Processing (
-   -   Converting mesh from gmsh (

newbee March 30, 2006 10:43

Hello! I want to creata a m

I want to creata a mesh that is described by a area (lets say in x-y plane) and then extruded in the z direction because it is uniform in with hight.

I have created the 2D mesh in gmsh (.msh ending) and I'm presently trying to transfer it to OpenFOAM. I dont know whether I should extrude it first with the Openfoam command or if I have to convert it first with gmshToFoam command and then try to extrude it.

Either way I get Error messages.

Does anyone have an idea of how to create a mesh in this manner?


mattijs March 31, 2006 04:45

You probably want to do the ex
You probably want to do the extrusion in gmsh itself. The gmshToFoam converter only converts 3D meshes.

newbee March 31, 2006 05:02

Thanks for the hint! When I
Thanks for the hint!

When I try to extrude my 2D mesh in gmsh I want to form prism and hexahedral cells, but it wont extrude the mesh, only the "geometrical configuration".


newbee March 31, 2006 05:05

Do you know if I can convert m
Do you know if I can convert my 2D mesh to OpenFOAM- format and then extrude it as an alternative method?


mattijs March 31, 2006 05:09

Use extrudeMesh on an existing
Use extrudeMesh on an existing mesh with the -sourcePatch -sourceRoot -sourceCase arguments. Check the surface file it writes. Is a very simple format you can easily write a converter to from another meshing program. Then use extrudeMesh with the -surface option to extrude from that surface file.

Would be nice if you could post your steps & solution over here.

newbee April 3, 2006 05:41

Thank you Ok I will do that
Thank you

Ok I will do that once I get it to work.

Im trying to extrude icoFoam/cavity, but since the command extrudeMesh only expects 4 arguments I can only write:

target root
target case
number of layers
overall thickness

And with the execution of only this arguments it complaints about the missing root, case and patch ofcourse.

A second question concerning this is how the sourcePatch should be defined in the case above with openfoam. Should it perhaps be named:
"empty FrontAndBack"

mattijs April 3, 2006 08:12

Is this a question? The error
Is this a question? The error message I get is

--> FOAM FATAL ERROR : Need to specify either -sourceRoot/Case/Patch or -surface option to specify the source of the patch to extrude

and if I type 'extrudeMesh' without any arguments to see all possibilities I see it has -sourceRoot, -sourceCase and -sourcePatch arguments which is exactly all the data it requires (root+case gives a mesh, patch gives the faces to extrude). The source root/case does not have to be the same as the destination root/case.

newbee April 3, 2006 08:53

I managed to get past that pro
I managed to get past that problem.

The way I got it go work was by having the source and destination root/cases diferent from eachother.

I tried first to handle the problem in FoamX but got an error message as soon as I entered the -sourceCase.
It said something like rootAndCase file can not be split up to root directory and case file.

But now Im past that.

Thank You!

newbee April 4, 2006 04:22

Hello! Ive managed to get t

Ive managed to get the format in which OpenFOAM describes an meshed surface as explained to me above. Now im trying to extrude a 2D mesh surface of my own choosing with this format.

I use the etrude command with arguments:
-surface to be extruded(with .sMesh ending)

When using this arguments I get the following error message:

Exec : extrudeMesh /home/erik/OpenFOAM/erik-1.3/run/tutorials/icoFoam cavity 3 5.0 -surface surface.sMesh
Date : Apr 04 2006
Time : 10:14:29
Host : compadre
PID : 8496
Root :
Case :
Nprocs : 1
Target: "/home/erik/OpenFOAM/erik-1.3/run/tutorials/icoFoam" "cavity"
Extruding layers:
number of layers 3
overall thickness 5

Create time

Extruding surfaceMesh read from file "surface.sMesh"

Read patch from file "surface.sMesh":
points : 82
faces : 108

--> FOAM FATAL ERROR : Error in face ordering: mixed used and unused faces at the end of face list.
Number of used faces: 842 and face 874 is owned by cell 88

From function void polyMesh::initMesh(cellList& c) const
in file meshes/polyMesh/polyMeshCalcFaceCells.C at line 266.

FOAM aborting

Foam::polyMesh::polyMesh(Foam::IOobject const&, Foam::Field<foam::vector<double> > const&, Foam::List<foam::face> const&, Foam::List<foam::cell> const&)
extrudeMesh [0x805ce57]

Could anybody please tell me what to do to correct this error.


newbee April 4, 2006 04:44

Sorry for my frequent messagin
Sorry for my frequent messaging.

I had a mesh (surface.sMesh) consisting of elements with both 2 and 4 nods.

Since 2 nods cant make up an element I tried to delete these. I got rid of the error message but the figure in paraview looks vary messed up and nothing in resemblance with the mesh I made in gmsh.

Was the 2 nod elements necessary, or what should I do to extrude my 2D mesh correctly?


mattijs April 4, 2006 05:01

You've tried the extruding fro
You've tried the extruding from a patch I assume ? (-sourceXXX options).

Can you use the .sMesh file this writes as a -surface argument correctly? (i.e. does extrudeMesh work)

My guess is that the sMesh file has to have the vertices numbered compactly so starting from 0 and no gaps. Maybe gmsh has options for what to export?

newbee April 4, 2006 05:22

I chose to extrude the movingW
I chose to extrude the movingWall patch in the cavity case with the source- arguments entered.

Then I got a file caled movingWall.sMesh which looks like this:

(0 0.1 0)
(0.005 0.1 0)
(0.01 0.1 0)
....and so on...

4(0 21 22 1)
4(1 22 23 2)
4(2 23 24 3)
....and so on...

This should be nodes (42) and elements (20) probably in correct order but without indexnumbers.

I altered my 2D mesh to have this format (thru spread sheet program) and removing 2 nod elements. After that I extruded it using the surface- argument (.sMesh ending). This gave a totaly messed up picture in parafoam.

I will now look into what you said about certain orderig of nodes and elements

newbee April 4, 2006 05:30

And yes, the movingWall looked
And yes, the movingWall looked ok when I extruded it using surface argument

newbee April 5, 2006 03:56

Thank you Mattijs for all your
Thank you Mattijs for all your help trying to convert the 2D mesh from gmsh.

I have now found a way to extrude both the geometry and my mesh simultaneous im gmsh. So now Im on the road again.

I still dont know what I did wrong when trying to extrude the 2D mesh from gmsh (when alterd in same format as in openfoam)

But Im leaving that subject now.


mattijs April 5, 2006 04:02

Shame that you did not find a
Shame that you did not find a way to do the extrusion in OF. Could you post your gmsh solution?

newbee April 5, 2006 04:25

=) It was an easy solution.

It was an easy solution. The function extrude had two extra (alternative) argument i.e. -Layers and -Recombine-

If only Surface is difined below then only the geometry will be extruded. The Recombine argument recombines the cells in the direction of the extrudsion, so that thay have the same cross section area at their topp as their bottom i.e. rods not pyramids.

my entre of the command extrude:

Extrude {0,0,50} {
Surface{19}; Layers{ {1}, {1}, {1} }; Recombine;
entry explanation:

Extrude { expression-list } { extrude-list layers }
Extrudes both the geometry and the mesh using a translation (see section 3.1.5 Extrusions). The layers option determines how the mesh is extruded and has the following syntax:

Layers { { expression-list }, <{>
{ expression-list } } | Recombine; ...

The first expression-list defines how many elements should be created in each extruded layer. The (optional) second expression-list assigns a region number to each layer, which, if non-zero, overrides the elementary entity number of the extruded entity. This is useful when there is more than one layer, as the elements in each layer can then be identified in a unique way. If the region number is set to zero, or if the expression-list is omitted, the elements are associated with the automatically created elementary geometrical entity (line, surface or volume) created during the extrusion. The last expression-list gives the normalized height of each layer (the list should contain a sequence of n numbers 0 < h1 < h2 < ... < hn <= 1). See 7.3 `t3.geo', for an example.

For line extrusions, the Recombine option will recombine triangles into quadrangles when possible. For surface extrusions, the Recombine option will recombine tetrahedra into prisms, hexahedra or pyramids.

This was maybe a bit to thorough.


mss November 7, 2006 10:41

Hi, I am tring play with tu

I am tring play with tutorial (cavity). When I started paraFoam I get this error:

--> FOAM FATAL ERROR : Cannot find file "points" in directory "constant/polyMesh"

Could you help me?

Best regards,

dmoroian November 7, 2006 15:05

You have to run blockMesh firs
You have to run blockMesh first! This will generate the actual mesh, including the "points" file.


louisgag July 21, 2008 16:58

I successfully imported a "vir
I successfully imported a "virtual 2D" mesh using gmshToFoam into OpenFOAM 1.5. The trick I had to perform was to use the Layers and Recombine options of the extrude function in Gmsh (see Gmsh documentation). I was also able to choose between extruded rectangle or triangle meshes; both successfully ran into OF icoFoam and Paraview.

kawikablyth November 7, 2009 03:57

Thanks for gmsh command help
Hey thanks to "newbee" up there for the insight on the gmsh extrude command. Big help with my 2D case.

All times are GMT -4. The time now is 12:32.