CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Native Meshers: snappyHexMesh and Others (
-   -   meshing with snappy: im a very beginner (

samiam1000 October 1, 2009 06:17

meshing with snappy: im a very beginner
Hi all,

I am a very beginner with OpenFOAM and I do have a stl model that I wanna mesh.

So, which are the steps to do? I wanna use SnappyHexMesh in order to be able to run the OpenFOAM analysis, later.

What I am asking you is: could you suggest me the steps I had to follow?

Or, even simpler, could you explain me how I can run the motorbike example in the tutorial?

Thanks a lot,


bigphil October 1, 2009 11:22

Hi Samuele,

You can find snappyHexMesh described in the User's Guide.

You could start by copying the '$FOAM_TUTORIALS/snappyHexMesh/motorBike' directory to your '$FOAM_RUN' directory.

Basically the motorBike case consists of a man on a motorbike (STL file), and presumably the aerodynamics wish to be looked at so a large box is created around the man on the motorbike (like a wind tunnel).

The way snappyHexMesh works is that it meshes the box first with blockMesh (or any other mesher) and then cuts the STL out of that box and either keeps the part of the mesh that it cut out or the mesh that remains.
It then 'snaps' the castellated surface to the STL (ie it smoothes the mesh at the STL surface).
Then an optional step is to add a boundary layer.

So enter the '$FOAM_RUN/motorBike' and execute 'blockMesh' - this creates the box around the motorbike.

Then execute snappyHexMesh, which does its thing and creates the new mesh in the next time directory. I think time '1' is the castellated mesh, time '2' is the snapped mesh and time '3' has a boundary layer. You have to zoom in close to see the motorbike.

So to use your own STL, place it in the 'constant/triSurface' directory and then edit the 'snappyHexMeshDict' in the 'system' directory appropriately. You can change the refinement level etc and turn on/off boundary layers.

Hope it helps,
Philip C

samiam1000 October 1, 2009 11:35

Ok, it really helps.
Can you give me any suggestion about the layer feature?
I have tryied to delete them, but it tells me that there's something wrong.
Is the point explained in the user guide?

Thanks a lot,

bigphil October 1, 2009 11:45

At the top of the snappyHexMeshDict,
you can set the layers feature to on or off.

Don't delete the layers stuff from the dictionary.

I think you can turn the other two steps on or off there too.


samiam1000 October 1, 2009 11:52

Just a question: but do you think that SnappyHexMesh is a good choice???
Thanks a lot,


bigphil October 1, 2009 12:00

There are a lot of meshing softwares out there, so it really depends on what you want to do.

I haven't used snappyHexMesh too much, and I'd have to do some mesh comparison studies before I could really say, but it's easy enough to use once you figure it out, and it's built in to OpenFOAM. You'll probably have to mess around with the mesh refinement until it's right and you get a mesh independent result.

But as I said there are lots of software choices out there and it depends what you want to do.


Eridian November 12, 2009 05:22

Hello everyone,

I'm a newbie to the OpenFOAM world and I'd like to make my first own meshes. (I've already completed all the tutorials and excercises in the User's and Programmer's Guid.) I'm on

To start off, I have two questions:

Like samiam1000, I wanted to make the Motorbike Tutorial. When I executed snappyHesMesh, it started fine, but it ended with following message and aborted:

Create time

Create mesh for time = 3

Read mesh in = 3.91 s

Overall mesh bounding box : (-5 -4 0) (15 4 8)
Relative tolerance : 1e-06
Absolute matching distance : 2.29783e-05

Reading refinement surfaces.
Read refinement surfaces in = 2.05 s

Reading refinement shells.
Refinement level 4 for all cells inside refinementBox
Read refinement shells in = 0 s

Setting refinement level of surface to be consistent with shells.
Checked shell refinement in = 0.02 s

Determining initial surface intersections

Edge intersection testing:
Number of edges : 1065751
Number of edges to retest : 1065751
Number of intersected edges : 30128
Calculated surface intersections in = 6.4 s

Initial mesh : cells:339662 faces:1065751 points:392459
Cells per refinement level:
0 934
1 1720
2 5040
3 9472
4 131655
5 24036
6 166805

Adding patches for surface regions

Patch Region
----- ------

5 motorBike_frt-fairing:001%1
6 motorBike_windshield:002%2
7 motorBike_rr-wh-rim:005%5
8 motorBike_rr-wh-rim:010%10
9 motorBike_fr-wh-rim:011%11
10 motorBike_fr-wh-brake-disk:012%12
11 motorBike_frame:016-shadow%13
12 motorBike_rear-susp:014%14
13 motorBike_rear-susp:014-shadow%15
14 motorBike_frame:016%16
15 motorBike_rr-wh-rim:005-shadow%17
16 motorBike_rr-wh-chain-hub:022%22
17 motorBike_rearseat%24
18 motorBike_frt-fairing%25
19 motorBike_windshield%26
20 motorBike_headlights%27
21 motorBike_driversseat%28
22 motorBike_rear-body%29
23 motorBike_fuel-tank%30
24 motorBike_exhaust%31
25 motorBike_rr-wh-rim%32
26 motorBike_fr-mud-guard%33
27 motorBike_fr-wh-rim%34
28 motorBike_fr-wh-brake-disk%35
29 motorBike_fr-brake-caliper%36
30 motorBike_fr-wh-tyre%37
31 motorBike_hbars%38
32 motorBike_fr-forks%39
33 motorBike_chain%40
34 motorBike_rr-wh-tyre%41
35 motorBike_square-dial%42
36 motorBike_round-dial%43
37 motorBike_dial-holder%44
38 motorBike_rear-susp%45
39 motorBike_rear-brake-lights%46
40 motorBike_rear-light-bracket%47
41 motorBike_frame%48
42 motorBike_rear-mud-guard%49
43 motorBike_rear-susp-spring-damp%50
44 motorBike_fairing-inner-plate%51
45 motorBike_clutch-housing%52
46 motorBike_radiator%53
47 motorBike_water-pipe%54
48 motorBike_water-pump%55
49 motorBike_engine%56
50 motorBike_rear-shock-link%57
51 motorBike_rear-brake-fluid-pot-bracket%58
52 motorBike_rear-brake-fluid-pot%59
53 motorBike_footpeg%60
54 motorBike_rr-wh-chain-hub%61
55 motorBike_rear-brake-caliper%62
56 motorBike_rider-helmet%65
57 motorBike_rider-visor%66
58 motorBike_rider-boots%67
59 motorBike_rider-gloves%68
60 motorBike_rider-body%69
61 motorBike_frame:0%70
62 motorBike_frt-fairing:001-shadow%74
63 motorBike_windshield-shadow%75
64 motorBike_fr-mud-guard-shadow%81
65 motorBike_fr-wh-brake-disk-shadow%83
66 motorBike_rear-mud-guard-shadow%84
67 motorBike_rear-susp-spring-damp-shadow%85
68 motorBike_radiator-shadow%86
69 motorBike_rear-shock-link-shadow%87
70 motorBike_rear-brake-fluid-pot-bracket-shadow%88
71 motorBike_rr-wh-chain-hub-shadow%89

Added patches in = 0.01 s

Selecting decompositionMethod hierarchical

Refinement phase

Found point (3 3 0.43) in cell 169409 on processor 0
Reading external feature lines.
Read feature lines in = 0 s

Surface refinement iteration 0

Marked for refinement due to surface intersection : 0 cells.
Marked for refinement due to curvature/regions : 14 cells.
Determined cells to refine in = 0.26 s
Selected for refinement : 14 cells (out of 339662)
hexRef8 : Dumping cell as obj to "/home/fa1/OpenFOAM/eschirach/run/tutorials/incompressible/simpleFoam/motorBike/cell_334436.obj"

cell 334436 of level 5 uses more than 8 points of equal or lower level
Points so far:8(20342 45178 56201 56206 83600 83601 388097 388098)#0 Foam::error::printStack(Foam::Ostream&) in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#1 Foam::error::abort() in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#2 Foam::hexRef8::setRefinement(Foam::List<int> const&, Foam::polyTopoChange&) in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#3 Foam::meshRefinement::refine(Foam::List<int> const&) in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#4 Foam::meshRefinement::refineAndBalance(Foam::strin g const&, Foam::decompositionMethod&, Foam::fvMeshDistribute&, Foam::List<int> const&) in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#5 Foam::autoRefineDriver::surfaceOnlyRefine(Foam::re finementParameters const&, int) in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#6 Foam::autoRefineDriver::doRefine(Foam::dictionary const&, Foam::refinementParameters const&, bool, Foam::dictionary const&) in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#7 main in "/opt/OpenFOAM/OpenFOAM-1.6/applications/bin/linux64GccDPOpt/snappyHexMesh"
#8 __libc_start_main in "/lib/"
#9 _start at /usr/src/packages/BUILD/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:116

From function hexRef8::setRefinement(const labelList&, polyTopoChange&)
in file polyTopoChange/polyTopoChange/hexRef8.C at line 3481.

FOAM aborting


Could someone please tell me what this exactly means? I could start ParaView on the mesh and see the motorbike in it's third iteration.

My second question:

I have an .stl file and I want to mesh it with snappy. I created a folder and made everything that's in the User's Guide. But I don't realy understand how to deal with the snappyHexMeshDict dictionary. How can I tell snappy, that I need the interior mesh for my calculation (I have to mesh a bended tube). What about the boundary definitions? How do I creat them? What exactly do I need to define?

Best greetings from a sunny autumn day in Munich,


I have one more question. I tried to adapt the motorbike case to my own test case. When I try to run sHM, I reviece the following error:


Create time

Create mesh for time = 0

Read mesh in = 0.04 s
--> FOAM Warning :
From function entry::getKeyword(keyType&, Istream&)
in file db/dictionary/entry/entryIO.C at line 78
Reading /home/fa1/OpenFOAM/eschirach/run/testmodelle/uebung_box/box_stl/system/snappyHexMeshDict
found on line 33 the punctuation token '{'
expected either } or EOF

keyword castellatedMeshControls is undefined in dictionary "/home/fa1/OpenFOAM/eschirach/run/testmodelle/uebung_box/box_stl/system/snappyHexMeshDict"

file: /home/fa1/OpenFOAM/eschirach/run/testmodelle/uebung_box/box_stl/system/snappyHexMeshDict from line 18 to line 35.

From function dictionary::subDict(const word& keyword)
in file db/dictionary/dictionary.C at line 467.

FOAM exiting


#1 Error

The command lines in snappyHexMeshDict are (line 29 - 44)
type triSurfaceMesh;
name box;

type searchableBox;
min (-1.0 -0.7 0.0);
max ( 8.0 0.7 2.5);

I don't know, why there should be an "}" or an "EOF" in line 33. What is actually an "EOF"?

#2 Error
I don't unterstand, why the castellatedMeshControls seems to be undefined. All braces are closed and I did the same things in there like in the motorbike tutorial. Moreover I tried zu set the boundaryLayers on "false", because, I'm not sure what to enter there. Can I delete now the code from the sHMDict or must I leave in there - but then, with which Information in it?

A lot of questions, I know, but I'd realy appreciate it, if someone could help me!

stark22 November 16, 2009 22:04


I have successfully generated the mesh ( I think, i ran blockmesh and snappyhexmesh with no errors). I'm still not able to see the bike in parefoam any suggestions on to adjust the settings to see it?

Also, this tutorial is equipped with the appropriate files to run a flow case correct?

Thank you

bigphil November 17, 2009 06:32

2 Attachment(s)

It sounds as if it ran fine. The bike is very small relative to the size of the flow domain, so as far as I can remember you set the view to wireframe and zoom in very close to the centre of the bottom of the domain.

I have attached a picture of the zoomed out geometry (you can see the motorbike is where the mesh is refined at the bottom) and the zoomed in view where you can see the motorbike.

I have never ran the motorbike case so I don't know but I'm sure you can give it a try.


bigphil November 17, 2009 06:59

1 Attachment(s)
Hi Eridian,

I can't answer all your questions but hopefully I can be of some help.

Firstly, I am not sure why snappyHexMesh ended in an error - possibly it ran out of RAM, have you very little? - i'm not sure, but I have attached the snappyHexMeshDict from my OF-1.5-dev case that works for me, so you could try that.

To tell snappy to keep the interior part of your mesh, just specify 'locationInMesh' (line 155 I think) to be a point inside that part of the mesh you want to keep.

So you specify this point and you specify the STL surface(s) you are using and the refinement on these surfaces.
Specify boundary patches is a slightly more difficult, I think you can find some answers by searching the forum. You can define patches on your blockMesh box and these patches will be kept (if theyre still left).

I am not sure what you edited in snappyHexMeshDict but there are three parts to snappy that can be turned on or off at the top: castellate, snapping and addLayer (or something like that) so if you don't want one just set to no but don't delete things in the dictionary.

Hopefully it helps a bit,

stark22 November 17, 2009 09:56


Thanks for the response.

I did set the view to wireframe but I didn't obtain the same mesh model as you do. My grid is much coarser and doesn't contain the refined region where the motorbike is located. I must be doing something wrong although there are no error messages after running snappyhexmesh. Im running a dual core (intel) 64 bit OS with 8G of memory. It takes about 187s for the mesh to be generatated. How long does it take you to create this mesh on your system? Ill keep working at it.

Thanks again

bigphil November 17, 2009 10:01


Ye mine takes about the same length of time on my machine.

Hmmnn did you change to the last time step? The final mesh will be in the third timestep usually - the first will be just the blockMesh, the second will be the castellated mesh and the third will be the snapped mesh.

Maybe that'll work,

stark22 November 17, 2009 22:03


When I run blockmesh and snappyHexMesh the following is created:
Folders 1, 2, 3 and file motorBike.OpenFoam.

If I change directories to folder "3" and run paraFoam, it will not run. It seems parafoam will only run the motorBike.OpenFoam file that was in the original directory. When I run this file it looks like it only generates to the overall fluid domain boundary. Any thoughts.

I really appreciate your help.

bigphil November 18, 2009 07:11


I'm not sure what the motorbike.OpenFOAM file is, I suspect it is created by paraFoam. I don't use paraFoam, I use 'foamToVTK' and then open the VTK file in 'paraview'.

So you could try that - from the case directory run 'foamToVTK', then run 'paraview'. In paraview, go to 'open' and go into the 'VTK' directory that was created and open the '*.vtk' file.

It should then work if you go to the last time-step.

Or you could try:
delete your mesh by 'rm -rf constant/polyMesh'
then move the mesh in '3' to the constant directory 'mv 3/polyMesh constant/'

then remove the time directories 'rm -rf 1 2 3'

then when you run 'paraFoam' it should work.


stark22 November 18, 2009 08:30


I ran foamtoVTK and then launched paraview (parafoam is the script that launches paraview). I opened the last time step mesh *.vtk (3) and sure enough it worked.

Thank for your help I really appreciate it. Now I just need to run an analysis!

bigphil November 18, 2009 08:42

No problem,

good luck!


stark22 November 18, 2009 21:54


I know this is off topic but if you generate the motorbike mesh and then run simpleFoam it will generate solution files. The last solution file is "500" which I believe relates to the time step specified in one of the boundary condition directories (I forget the actual name, I believe it was in the "systems" directory).

How then do you post process it in paraview?

Thanks, and sorry to the rest for going off topic.

bigphil November 19, 2009 06:20


I am not sure what your question is exactly, but the first tutorial in the OpenFOAM user's guide ( explains clearly how to run a simple fluid simulation and how to perform post-processing with paraview (streamlines, pressure/velocity plots, glyphs).

I am guessing that the same methods can be applied to your case.


stark22 November 19, 2009 07:44

I did the cavity flow tutorial but I'll keep trying. Thanks for the help.

sErik November 23, 2009 06:03

Hello everyone,

I'm trying to mesh a test file i created, but I recieve two different errors:

It is about the locationInMesh in the castellatedMeshControls dictionary. This happens, when I enter (580 430 -45) for the locaitonInMesh


Patch Region
----- ------

5 Rohrelement_NASTRAN

Added patches in = 0 s

Selecting decompositionMethod hierarchical

Refinement phase

Point (580 430 -45) is not inside the mesh or on a face or edge.
Bounding box of the mesh:(-390 0 -150) (2190 584 50)

From function refinementParameters::findCells(const polyMesh&) const
in file autoHexMesh/autoHexMeshDriver/refinementParameters/refinementParameters.C at line 104.

FOAM exiting
I don't understand, why the point isn't inside the mesh, althoug it is included in the bounding box of the mesh?

When entering (188 270 -50) for locationInMesh, I get this error:


Splitting mesh at surface intersections

Introducing baffles for 2256 faces that are intersected by the surface.

Edge intersection testing:
Number of edges : 55094
Number of edges to retest : 9877
Number of intersected edges : 2292
Created baffles in = 0.12 s

After introducing baffles : cells:16447 faces:55094 points:22330
Cells per refinement level:
0 715
1 1588
2 3822
3 10322

Introducing baffles to block off problem cells

#0 Foam::error::printStack(Foam::Ostream&) in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#1 Foam::sigSegv::sigSegvHandler(int) in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#2 ?? in "/lib/"
#3 Foam::primitiveMesh::pointCells(int, Foam::DynamicList<int, 0u, 2u, 1u>&) const in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#4 Foam::meshRefinement::markFacesOnProblemCells(Foam ::dictionary const&, bool, Foam::Field<double> const&, Foam::List<int> const&) const in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#5 Foam::meshRefinement::baffleAndSplitMesh(bool, bool, Foam::Field<double> const&, bool, Foam::dictionary const&, Foam::Time&, Foam::List<int> const&, Foam::Vector<double> const&) in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#6 Foam::autoRefineDriver::baffleAndSplitMesh(Foam::r efinementParameters const&, bool, Foam::dictionary const&) in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#7 Foam::autoRefineDriver::doRefine(Foam::dictionary const&, Foam::refinementParameters const&, bool, Foam::dictionary const&) in "/opt/OpenFOAM/OpenFOAM-1.6/lib/linux64GccDPOpt/"
#8 main in "/opt/OpenFOAM/OpenFOAM-1.6/applications/bin/linux64GccDPOpt/snappyHexMesh"
#9 __libc_start_main in "/lib/"
#10 _start at /usr/src/packages/BUILD/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:116
The file is located in ".../run/testmodelle/pisoFoam/les/rohrelement_stl". I don't know what the problem could be?

All times are GMT -4. The time now is 21:29.