CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Open Source Meshers: Gmsh, Netgen, CGNS, ... (
-   -   GmshToFoam correct face orientation (

billy July 17, 2005 12:45

Hello, I built a mesh using

I built a mesh using gmsh and converted it to FOAM using gmshToFoam. When I run checkMesh, I get the following error:

Owner cell vertex labels: 8(31771 10586 1329 10765 10591 1330 10764 31766)
bool primitiveMesh::checkFacePyramids(const bool, const scalar, labelHashSet*) const: face 93327 points the wrong way.
Pyramid volume: -3.34611e-09 Face 4(10765 1328 47 1329) area: 5.23744e-06 Ownercell: 28043
Owner cell vertex labels: 8(10586 1329 47 1341 10581 1328 10765 31771)
--> FOAM Serious Error : Error in face pyramids: faces pointing the wrong way!
Writing 29260 faces with incorrect orientation to set wrongOrientedFaces

It seems there is a problem with the orientation of some faces. I would like to know if openFOAM has a tool to correct the above error. Because in gmsh I can't seem to correct the problem.

adorean July 18, 2005 03:34

Hi, Try the modified gmshTo

Try the modified gmshToFoam from this forum, see if it helps.


billy July 29, 2005 13:29

Yes, this version works OK.
Yes, this version works OK.

Although it would be nice if the program could automatically detect if the element needs to be inverted or not. Because I ended up converting the mesh, assigning BC, solving and then I used the -invertHex option and did it all again.

I also have only tested it with a mesh in which all elements needed to be inverted. I haven't tested it with a mesh that has some elements that need to be inverted and others that do not.

billy August 2, 2005 20:48

I just tested this version in
I just tested this version in a mesh where only some elements needed to be inverted and it did not work. I tried to modify the gmshToFoam to detect and invert automatically but I don't know the specific functions to do that.

What I wanted to do was to compute dot product of the normal of a face with the vector from the face center point to the element centroid point. Maybe computing the volume could also indicate the if the element needs to be inverted or not. Any suggestions?

mattijs August 3, 2005 18:32

element centroid: when you
element centroid:

when you have a cellShape:

(cells[cellI++] = cellShape(tet, tetPoints))

you can ask it for its centre (see cellShape.H).

You can also ask for the faces of the cellShape (cellShape::faces) and each of the faces for their centre and area vector (face.H)

If you have something working & tested can you send it back?

billy August 4, 2005 18:01

Hi Mattijs Janssens, I alre
Hi Mattijs Janssens,

I already fixed this problem using my own routine in C to invert the whole mesh in the same direction (outwards or inwards).

I can send you this code if you like. However, I think it would "nicer" to do it using OpenFOAM classes.

mattijs August 5, 2005 12:57

I agree it would be nicer. You
I agree it would be nicer. You feel like adding it to gmshToFoam? With a bit of searching you should be able to find out the information you need.

The Foam orientation of cells is somewhere in the user guide (chapter 6 i think)

billy August 5, 2005 13:45

Hi Mattijs Janssens, I ju
Hi Mattijs Janssens,

I just altered the gmshToFoam.C file: gmshToFoam.C

Please note, I haven't tested it on meshes with prisms. Although it produces several warnings, it seems to work with hexahedral mesh. Please give it a try.

mattijs August 8, 2005 15:16

Hi Billy, thanks. I changed
Hi Billy,

thanks. I changed it to test on cellShape and put the inverting under a switch. Seems to work for prism cases as well. gmshToFoam.C

billy August 8, 2005 16:19

Hi Mattijs Janssens, It loo
Hi Mattijs Janssens,

It looks like a better implementation than mine. I have tested it on a hexahedral mesh and it worked OK. However, is it possible to hide those warnings during conversion? It seems to slow down the process.

mattijs August 8, 2005 17:47

Hi Billy, Could you warn th
Hi Billy,

Could you warn the GMSH author that his cell shape orientation is incorrect? I think it should be solved in gmsh.

I'd rather not hide the warning in Foam. If it is terminal output that is slowing you down redirect gmshToFoam output to a file.

billy October 26, 2005 15:35

Hi, I just tried to convert

I just tried to convert a gmsh file with only prisms and autoinvert gave me a strange result. Maybe it is not working with prisms or there is a mixup with gmsh orientation.

billy October 26, 2005 16:11

I altered the gmshToFoam file
I altered the gmshToFoam file and this reordering seems to work better:

// Reorder prism.
prismPoints[0] = cell[3];
prismPoints[1] = cell[4];
prismPoints[2] = cell[5];
prismPoints[3] = cell[0];
prismPoints[4] = cell[1];
prismPoints[5] = cell[2];

mattijs November 25, 2005 16:42

There is a new gmsh out (1.61)
There is a new gmsh out (1.61) which says in the changelog:

"hexas and prisms are now always saved with positive volume" !!

Can someone test this and get back to me?

billy November 26, 2005 14:54

Hi, I have already download

I have already downloaded it and it looks good. I also like the STL remesher!

mattijs November 26, 2005 15:01

So the 1.2 gmshToFoam works wi
So the 1.2 gmshToFoam works without any switches or your changes?

billy November 26, 2005 15:08

I haven't tested that yet. I o
I haven't tested that yet. I only installed the windows version for now, but I will test it in a few days.

billy November 26, 2005 16:20

Hi, I tested with both pris

I tested with both prisms and hexas and it seems that using this new version of gmsh (1.61), you do not need -autoInvert switch.

I imported them using gmshToFoam and then tested them using checkMesh. I didn't actually run a simulation on them yet.

mattijs November 27, 2005 06:55

Excellent news! checkMesh s
Excellent news!

checkMesh should be good enough.

unoder November 27, 2005 08:40

Hi, I tried this new gmsh (

I tried this new gmsh (1.61) on some .stl file but got some error when I tried gmshToFoam, perhaps I did something wrong. I haven't tried this program before. Looks nice anyway. And gmsh can do hex-meshing (bodyfitted)?

If so, I think I'll take a closer look but I have no earlier experience with gmsh... You use it as preprocessor instead of blockMesh, right?

All times are GMT -4. The time now is 09:20.