CFD Online Discussion Forums

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

Andrea_85 August 19, 2011 10:21

Hi all,
I have a question regarding gmsh. I would like to construct a geometry using gmsh(only the geometry, not the mesh) and then use snappyHexMesh to construct the mesh around this geometry. Is possible using gmsh (maybe using the stl format output)? If yes, which are the steps?


alberto August 21, 2011 04:39

Yes, it is possible. Once you have the STL, put a box with blockMesh around it and mesh the box fine enough to intersect the details of your geometry. At this point you can follow one of the tutorials of snappyHexMesh to create the mesh.


Andrea_85 August 22, 2011 04:58

Hi Alberto,

thanks a lot


Andrea_85 August 23, 2011 06:24

Hi again,
Is possible also for 2d geometries (1 cell in z direction)? If i want, for example, make a simple mesh of a box with an empty circle (disc with 1 cell in z direction) inside, how i have to construct my STL file using gmsh?



Andrea_85 August 24, 2011 05:28

3 Attachment(s)
following the "wingMotion" tutorial i've been able to create a 2D mesh of the simple geometry that i've mentioned in the previous post. Now, i would like to have a structured mesh as much as possible, at least away from the STL surface. So, why does snappy split cells in a way so weird, instead of dividing the square into four parts (see the attached pictures)? What should I do to keep the mesh structured?
(for example in this post there is a very similar example, in which the mesh away from the STL surface is completly structured).

alberto August 24, 2011 10:05

Do you see the same problem if you activate the option "use VTKkPolyhedron" in paraview? Paraview tends to show some cells as triangles, even when they are actually a single cell.

Andrea_85 August 24, 2011 10:45

4 Attachment(s)
Hi Alberto,
yes, i see the same problem. I made my test case even more simple: now the "hole" is a square. I've attached 2 pictures (with or without "Decompose Polyhedra"), my blockMeshDict and my snappyHexMeshDict.
Where am I doing wrong?


alberto August 24, 2011 21:04

You can probably avoid the problem with a trick:

- Generate the mesh in snappyHexMesh without adding layers or refining around the surfaces.

- Use refineMesh to refine around objects. You basically define boxes where to refine in sequence.

P.S. Does this problem appear in OpenFOAM 2.0.x?


Andrea_85 August 25, 2011 03:45

Hi, and thanks
I've never used the utility refineMesh, do i need a dictionary?if yes, which one?
I'm using OF 1.7.1, i don't know for the new version.
thanks again


Andrea_85 August 25, 2011 09:53

2 Attachment(s)
I've played a bit with refineMesh and it works. I mean now the cells splitting is correct (all hexas, see the attached pictures) but the problem is that now all the mesh is refined. If i want to refine only a particular region (close to the obstacle for example), what i have to do? Is possible using this utility?

I am still a little bit confuse why it doesn't work using snappyHexMesh, i guess the cells splitting procedure should be the same...maybe there is something wrong in the snappyHexMeshDict...I've attached also my checkMesh for the previous case (snappy with refinement).


Time = 0.001

Mesh stats
    points:          22748
    faces:            46056
    internal faces:  26076
    cells:            11910
    boundary patches: 7
    point zones:      0
    face zones:      0
    cell zones:      0

Overall number of cells of each type:
    hexahedra:    11682
    prisms:        0
    wedges:        0
    pyramids:      0
    tet wedges:    0
    tetrahedra:    0
    polyhedra:    228

Checking topology...
    Boundary definition OK.
    Point usage OK.
    Upper triangular ordering OK.
    Face vertices OK.
    Number of regions: 1 (OK).

Checking patch topology for multiply connected surfaces ...
    Patch              Faces    Points  Surface topology                 
    left                100      202      ok (non-closed singly connected) 
    right              100      202      ok (non-closed singly connected) 
    top                100      202      ok (non-closed singly connected) 
    bottom              100      202      ok (non-closed singly connected) 
    front              9390    9902    ok (non-closed singly connected) 
    back                9390    9902    ok (non-closed singly connected) 
    square_CreatedbyGmsh800      1200    ok (non-closed singly connected) 

Checking geometry...
    Overall domain bounding box (0 0 -1e-05) (0.001 0.001 1e-05)
    Mesh (non-empty, non-wedge) directions (1 1 0)
    Mesh (non-empty) directions (1 1 0)
    All edges aligned with or perpendicular to non-empty directions.
    Boundary openness (-3.59019e-17 3.6604e-17 5.67728e-14) OK.
    Max cell openness = 1.29247e-16 OK.
    Max aspect ratio = 1 OK.
    Minumum face area = 2.5e-11. Maximum face area = 2e-10.  Face area magnitudes OK.
    Min volume = 2.5e-16. Max volume = 2e-15.  Total volume = 1.5e-11.  Cell volumes OK.
    Mesh non-orthogonality Max: 36.6992 average: 6.69095
    Non-orthogonality check OK.
    Face pyramids OK.
    Max skewness = 2 OK.

Mesh OK.



alberto August 25, 2011 11:17

SnappyHexMesh greatly improved in 2.0.x, as a consequence I strongly suggest to upgrade to the latest version. If you want more information:

The refineMesh utility can use a cellSet to define the region where you want to apply the refinement. In OpenFOAM 1.7.x, you can select sells with cellSet (via dictionary, see OpenFOAM-1.7.x/applications/utilities/mesh/manipulation/cellSet/cellSetDict, while in OpenFOAM 2.0.x, the utility was merged into setSet.

In other words:

1. Generate with snappy
2. Define the region to refine via cellSet (or setSet)
3. Use refineMesh specifying the name of the cell set you created

You then repeat step 2 and 3 to add the layers. I find this procedure more reliable even if a bit more tricky, in comparison to a direct use of snappyHexMesh.


Andrea_85 August 26, 2011 05:08

Thanks Alberto.
Another the cellSetDict i can, for example, specify a box using boxToCell:

box (whatever) (whatever);

Is also possible to specify a patch? or a region around a patch?


idefix July 14, 2013 11:25


Ive got a question to refineMesh.
Could it be also used two times?

I made a mesh with snappyHexMesh. Afterwards I defined a box, saved the geometry in *.stl.
SnappyHexMesh creates a "0" folder
Then I used the command insideCells refinementbox.stl set
Afterwards: refineMesh -dict
Everything is working fine.
A "1" folder is created.

Now I defined a second (smaller) box.
I did: insideCells refinementbox2.stl set2
set2 is created in 1/polyMesh/sets

but the command refineMesh -dict is not working.
I get the error massage:
Create time

Create polyMesh for time = 1

#0 Foam::error::printStack(Foam::Ostream&) in "OpenFOAM/OpenFOAM-2.1.1/platforms/linux64GccDPOpt/lib/"
#1 Foam::sigFpe::sigHandler(int) in "OpenFOAM/OpenFOAM-2.1.1/platforms/linux64GccDPOpt/lib/"
#2 in "/lib64/"
in "OpenFOAM/OpenFOAM-2.1.1/platforms/linux64GccDPOpt/bin/refineMesh"
in "OpenFOAM/OpenFOAM-2.1.1/platforms/linux64GccDPOpt/bin/refineMesh"
#5 __libc_start_main in "/lib64/"
at /usr/src/packages/BUILD/glibc-2.11.2/csu/../sysdeps/x86_64/elf/start.S:116

Can anybody help?

Thanks a lot

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