CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Native Meshers: snappyHexMesh and Others (
-   -   optimize snapping (

foam_noob December 17, 2009 05:18

optimize snapping
2 Attachment(s)
Greetings foamers,

After seeing my mesh in paraview, I wasn't too happy with the snapping phase (see attached pictures). The attachments only contain the symmetry plane. I blended out the parts of the vehicle. As you can see there are still a lot of elements sticking out. Is there a way to smoothen these shown areas?

A digital pat on the back for your help.


Here is a section of my snappydict.

// Settings for the snapping.
//- Number of patch smoothing iterations before finding correspondence
// to surface
nSmoothPatch 8;

//- Relative distance for points to be attracted by surface feature point
// or edge. True distance is this factor times local
// maximum edge length.
tolerance 4.0;

//- Number of mesh displacement relaxation iterations.
nSolveIter 40;

//- Maximum number of snapping relaxation iterations. Should stop
// before upon reaching a correct mesh.
nRelaxIter 7;

// Settings for the layer addition.
relativeSizes true;

// Per final patch (so not geometry!) the layer information
nSurfaceLayers 5;

the patches all have 5 as their nSurfaceLayers value

// Expansion factor for layer mesh
expansionRatio 1.5;

//- Wanted thickness of final added cell layer. If multiple layers
// is the
// thickness of the layer furthest away from the wall.
// Relative to undistorted size of cell outside layer.
finalLayerThickness 0.8;

//- Minimum thickness of cell layer. If for any reason layer
// cannot be above minThickness do not add layer.
// Relative to undistorted size of cell outside layer.
minThickness 0.1;

//- If points get not extruded do nGrow layers of connected faces that are
// also not grown. This helps convergence of the layer addition process
// close to features.
nGrow 1;

// Advanced settings

//- When not to extrude surface. 0 is flat surface, 90 is when two faces
// make straight angle.
featureAngle 30;

//- Maximum number of snapping relaxation iterations. Should stop
// before upon reaching a correct mesh.
nRelaxIter 3;

// Number of smoothing iterations of surface normals
nSmoothSurfaceNormals 1;

// Number of smoothing iterations of interior mesh movement direction
nSmoothNormals 3;

// Smooth layer thickness over surface patches
nSmoothThickness 10;

// Stop layer growth on highly warped cells
maxFaceThicknessRatio 0.5;

// Reduce layer growth where ratio thickness to medial
// distance is large
maxThicknessToMedialRatio 0.3;

// Angle used to pick up medial axis points
minMedianAxisAngle 130;

// Create buffer region for new layer terminations
nBufferCellsNoExtrude 0;

// Overall max number of layer addition iterations
nLayerIter 15;

// Generic mesh quality settings. At any undoable phase these determine
// where to undo.
//- Maximum non-orthogonality allowed. Set to 180 to disable.
maxNonOrtho 65;

//- Max skewness allowed. Set to <0 to disable.
maxBoundarySkewness 20;
maxInternalSkewness 4;

//- Max concaveness allowed. Is angle (in degrees) below which concavity
// is allowed. 0 is straight face, <0 would be convex face.
// Set to 180 to disable.
maxConcave 80;

//- Minimum projected area v.s. actual area. Set to -1 to disable.
minFlatness 0.5;

//- Minimum pyramid volume. Is absolute volume of cell pyramid.
// Set to very negative number (e.g. -1E30) to disable.
minVol 1e-13;

//- Minimum face area. Set to <0 to disable.
minArea -1;

//- Minimum face twist. Set to <-1 to disable. dot product of face normal
//- and face centre triangles normal
minTwist 0.02;

//- minimum normalised cell determinant
//- 1 = hex, <= 0 = folded or flattened illegal cell
minDeterminant 0.001;

//- minFaceWeight (0 -> 0.5)
minFaceWeight 0.02;

//- minVolRatio (0 -> 1)
minVolRatio 0.01;

//must be >0 for Fluent compatibility
minTriangleTwist -1;

// Advanced

//- Number of error distribution iterations
nSmoothScale 4;
//- amount to scale back displacement at error points
errorReduction 0.75;

Axel_T December 19, 2009 14:49

Hi Patrick,

I've got my problems with snappy, too.
But at least the snap-to surface-part works better than in your screenshots.
My suggestion would be to try another tolerance in the snapControl section.

foam_noob January 12, 2010 03:34

Hi Axel,

I think I know what the problem is. After inspecting the internal mesh in Paraview, I realized that the snapping did a fine job. The picture above shows a boundary region, more specifically a symmetry plane. The symmetry plane was already created in the STL file, which I meshed with snappy. My assumption is that snapping only influences the internal mesh, but has no influence on already existing boundaries.

Can someone verify my assumption?

Appreciate the help.


fra76 January 13, 2010 14:15

Simply, snappyHexMesh does not recognise feature lines, so sharp edges are not preserved.
If you want to improve the aspect of your mesh in those cases, all you can do is refine it, unfortunately...

Hope this helps,

vinz January 14, 2010 17:25

hi all,

from what I saw using SnappyHexMesh, the aspect ratio plays an important role for the snapping phase. if you use an aspect ratio closer to one for the cells in this region the snapping should work better. At least that's the case for me.

I am currently working on trying to find a workaround for that. If you can try and tell us what you get.



foam_noob January 18, 2010 03:12

Thanks everybody. You've all been very helpful.


MadsR January 21, 2010 10:28

@Vincent: It seems from the screen-shot, that Patrick already has an aspect ratio around 1, or am I not following what you mean?


vinz January 21, 2010 11:05

From the screen shot I wouls say the aspect ratio is more around 3 or 4. I know that's it's the same order but from the use of snappyHexMesh I did so far I saw that it can have some influence.

However I didn't get so bad results. Coud it come from the stl discretisation? too large? too small?

I still think that unfortunately I don't understand the influence of all the parameters inside SnappyHexMesh. I don't know which parameter can result in this behaviour.

SnappyHexMesh looks very close to be a very useful tool, but each time I create a mesh, I get something which makes me think that there are few things missing to get a very good grid.



foam_noob January 21, 2010 11:26

aspec ratio
Hey Vincent,

I would like to try to mesh the file with an aspect ratio value of 1. I looked through the snappyDict, but I didn't find the option for aspect ratio. Can you tell me where I can adjust it?



vinz January 21, 2010 11:33

To get an aspect ratio of 1, you have to change the values of number of points in the x direction in blockMeshDict, not in snappyHexMeshDict.

Your base mesh should have an aspect ratio close to 1, and then your final mesh will have the same since cells are split equally in each direction.

Hope this helps.


foam_noob January 21, 2010 11:45

Hey Vincent,

This is a short segment of the blockmeshdict.

hex (0 1 2 3 4 5 6 7) // vertex numbers
(10 10 10) // numbers of cells in each direction
simpleGrading (1 2 3) // cell expansion ratios

Do you mean the number after simpleGrading or the ones before //numbers of cells....

And why only change the aspect ratio of the cells in x direction??

Your help is much appreciated :).


vinz January 21, 2010 11:55

I was talking about the "number of cells in each direction"
You can change (10 10 10) by (30 10 10) for exemple

This comes from the fact that you place the same number of cells in each direction, but the size of your domain is larger in x direction than in y direction, so at the end cells are larger in x direction.

If you take a domain of 3m in x direction and 1 m in y direction, that you devide by 10 (number of cells in each direction in your dictionary), at the end, cells in x are 0.3m wide and 0.1m in y direction. You see what I mean?
Then what I call the aspect ration here deltaX / deltaY = 3

If you choose to put 30 cells in x direction, then the deltaX is equal to 0.1, and the aspect ratio is equal to 1.

It would be also interesting maybe later to twice or four time as many cells in each direction, so let say (120 40 40) in our example to refine the base mesh. But then in snappy, you use a refinement level one or two below the one you currently have, to obtain the same number of cells at the end. I don't know if the base mesh is very important in SnappyHexMesh.

Hope this helps.


foam_noob January 22, 2010 08:04



Originally Posted by vinz (Post 243324)

It would be also interesting maybe later to twice or four time as many cells in each direction, so let say (120 40 40) in our example to refine the base mesh. But then in snappy, you use a refinement level one or two below the one you currently have, to obtain the same number of cells at the end. I don't know if the base mesh is very important in SnappyHexMesh.

What do you mean by "use a refinement level one or two below the one you currently have, to obtain the same number of cells at the end."
What is my current refinement level??
I thought the whole point of snappy was to create a finer mesh of the geometry and have more cells.


vinz January 22, 2010 08:34

In the snappyhexmesh dict, you have a part which is named "castellatedMeshControls"
In this part, there is something like this:
// Surface-wise min and max refinement level
level (5 5);
the part level (5 5) means that around your model, in your case, the car, the cells of your original blockMesh grid are going to be split in two, and this five times. there are two numbers, the minimum refinement level and maximum refinement level

So let say you want a final cell size of 0.25m, you can do this in several way:
- chose a blockmesh grid with cells of 1m and chose a refinement level of 2. The cell is going to be devided by 2, and then again by 2, so you'll get a size of 0.25m.
- you can also chose to create a blockMesh grid with cells of 0.5m and then chose a refinement level of 1 which will split the cell only once and give you cells of 0.25m.

Not easy to explain, but I hope you can understand. Or maybe someone else will be able to give a better explanation.


foam_noob January 25, 2010 10:22


I just remeshed my structure with an aspect ratio close to 1. Although it didn't solve my problem with the elements jagged elements sticking out of the symmetry plane, it did however create a mesh with no quality errors (CheckMesh => Mesh Ok). I always had skewFaces in my mesh and didn't know how to remove them with the mesh utilities.

Vincent do you by any chance know how to use the mesh utilities to remove flaws in the mesh?

Thanks again, you helped me out big time. :)


vinz January 25, 2010 10:33

Hi Patrick,

Unfortunately I don't have much experience with the mesh utilities.
I was thinking about an other possible cause of your problem. Does your problem only appear at the intersection between the car and the symmetry plane? Because it could be due to a bad intersection of the model with the symmetry plane if your are using only half of the car as input. Or it could also come from a bad discretisation of the stl model itself making it hard for SnappyHexMesh to find the correct position of the surface?

Would you be able to share the input model so I can try with my usual settings and tell you if I get the same results?

I hope you'll find a solution.


tachyon_me February 15, 2010 14:13

I 'm trying to view mesh section cut with paraview, it show me all the cross lines ,
How to get a clean reactanguar mesh , the one you showed in your post with paraview .


sjrees February 16, 2010 05:24

Unfortunately Paraview (VTK) does not have an explicit representation of polyhedra - you will only see tets, hexs and pyramids. Hence a polyhedra in openfoam will be devolved into these shapes. When you cut through an unstructured mesh the plane is always decomposed into triangles. This can be missleading when viewing the openFOAM mesh made with SHM but is just a 'feature' of Paraview (VTK really). I don't know a way arround this except to use another visualisation tool. I just live with it and find it good enough when visualising the mesh.


sjrees February 16, 2010 06:12

As snapping to edges is a recurring theme perhaps one of the SHM developers could add something?

It would be good to know if there is a development plan. I am sure some of us would like to commit to using the tool but the edge snapping problem is something of a stumbling block.


vinz February 16, 2010 06:49

Unfortunately, as it has been said a lot of times on this forum, something has already been developed, but from what I know, it is kept inside the software of Icon named FoamPro. It is not in the public domain, and i didn't heard anything so far telling me that it would become public some time soon.

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