CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Native Meshers: snappyHexMesh and Others (
-   -   SnappyHexMesh - How to set-up to avoid skewfaces? (

pcaron December 2, 2009 13:37

SnappyHexMesh - How to set-up to avoid skewfaces?
2 Attachment(s)
Hello forum!

I started using snappy a few weeks ago. So I haven't too much experience using it.

I'm trying to mesh the air around a body. I changed almost every parameter I think can improve my mesh. No matter what I change I always get some skewfaces. These skewfaces always follow the same patern: It's an hex over the patch in the castellated mesh, in the snap step it become a skewfaces.

What I did: I Changed the number of refinement steps in this patch, I changed the tolerance in the snap settings.

I attached two screenshots and below there's my snappyHexMeshDict


/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  1.6                                  |
|  \\  /    A nd          | Web:              |
|    \\/    M anipulation  |                                                |
    version    2.0;
    format      ascii;
    class      dictionary;
    object      snappyHexMeshDict;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// Which of the steps to run
castellatedMesh true;
snap            true;
addLayers      false;

// Geometry. Definition of all surfaces. All surfaces are of class
// searchableSurface.
// Surfaces are used
// - to specify refinement for any mesh cell intersecting it
// - to specify refinement for any mesh cell inside/outside/near
// - to 'snap' the mesh boundary to the surface
        type triSurfaceMesh;
        name body;
        name anotherPart;

        type searchableBox;
        min ( 0    -2200 -60);
        max ( 1100  8000  1500);

// Settings for the castellatedMesh generation.

    // Refinement parameters
    // ~~~~~~~~~~~~~~~~~~~~~

    // While refining maximum number of cells per processor. This is basically
    // the number of cells that fit on a processor. If you choose this too small
    // it will do just more refinement iterations to obtain a similar mesh.
    maxLocalCells 1000000;

    // Overall cell limit (approximately). Refinement will stop immediately
    // upon reaching this number so a refinement level might not complete.
    // Note that this is the number of cells before removing the part which
    // is not 'visible' from the keepPoint. The final number of cells might
    // actually be a lot less.
    maxGlobalCells 4000000;

    // The surface refinement loop might spend lots of iterations refining just a
    // few cells. This setting will cause refinement to stop if <= minimumRefine
    // are selected for refinement. Note: it will at least do one iteration
    // (unless the number of cells to refine is 0)
    minRefinementCells 10;

    // Number of buffer layers between different levels.
    // 1 means normal 2:1 refinement restriction, larger means slower
    // refinement.
    nCellsBetweenLevels 3;

    // Explicit feature edge refinement
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    // Specifies a level for any cell intersected by its edges.
    // This is a featureEdgeMesh, read from constant/triSurface for now.
        //    file "someLine.eMesh";
        //    level 2;

    // Surface based refinement
    // ~~~~~~~~~~~~~~~~~~~~~~~~

    // Specifies two levels for every surface. The first is the minimum level,
    // every cell intersecting a surface gets refined up to the minimum level.
    // The second level is the maximum level. Cells that 'see' multiple
    // intersections where the intersections make an
    // angle > resolveFeatureAngle get refined up to the maximum level.

        level (0 0);
            level (5 6);
            level (8 8);

    // Resolve sharp angles
    resolveFeatureAngle 20;

    // Region-wise refinement
    // ~~~~~~~~~~~~~~~~~~~~~~

    // Specifies refinement level for cells in relation to a surface. One of
    // three modes
    // - distance. 'levels' specifies per distance to the surface the
    //  wanted refinement level. The distances need to be specified in
    //  descending order.
    // - inside. 'levels' is only one entry and only the level is used. All
    //  cells inside the surface get refined up to the level. The surface
    //  needs to be closed for this to be possible.
    // - outside. Same but cells outside.

            mode inside;
            levels ((1E15 2));

    // Mesh selection
    // ~~~~~~~~~~~~~~

    // After refinement patches get added for all refinementSurfaces and
    // all cells intersecting the surfaces get put into these patches. The
    // section reachable from the locationInMesh is kept.
    // NOTE: This point should never be on a face, always inside a cell, even
    // after refinement.
    locationInMesh (1000 -2000 100);

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

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

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

    //- 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 1;
            nSurfaceLayers 1;

    // Expansion factor for layer mesh
    expansionRatio 1.0;

    //- 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.3;

    //- 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 50;

// 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;

// Advanced

// Flags for optional output
// 0 : only write final meshes
// 1 : write intermediate meshes
// 2 : write volScalarField with cellLevel for postprocessing
// 4 : write current intersections as .obj files
debug 0;

// Merge tolerance. Is fraction of overall bounding box of initial mesh.
// Note: the write tolerance needs to be higher than this.
mergeTolerance 1E-6;

// ************************************************************************* //

I would appreciate any help in setting-up my snappyHexMeshDict.



prashantsonakar March 31, 2010 02:02

Nice illustration

pcaron March 31, 2010 08:19

Dear Prashant, Thank you,

Have you had similar problems? I've used snappy a bit more, but I couldn't solve this problem yet.



louisgag April 20, 2010 10:49

I also have issues with skew faces and am not yet able to tell you how to avoid it.


pcaron April 20, 2010 11:46

Louis, thanks for your reply. This problem arises when your surface is almost aligned with the mesh. Then some nodes and/or elements are deleted. In my pictures the element is deleted so the surface has a cube inside the mesh, so in the snap stage the nodes are attracted by the stl surface. But, this is the problem, not the solution :( I don't have a solution either.

Some hints
1) Start with a coarse mesh and add layers. I don't have layer in my pictures.
2) Increase the tolerance in snapControls. In this case the resulting surface has a lot of bumps.

These are just some ideas. I think there isn't a unique solution.



louisgag April 20, 2010 12:07

although if you reduce the max skewness setting in the snappyHexMeshDict to something very low (eg. 0.5 for both) it seems to help.


PS: thanks for your help also :)

EDIT: It seems however that seeting my max skewneww really low makes the mesh really coarse.. perhaps not the best solution..!

Mo-ITB April 27, 2010 09:23

hi everybody,

may it be that the layer-addition phase is the problem here? i also have problems with "bumps" on my surface at the moment, and if i dont add layers and leave everything else the same, everything is smooth...


louisgag April 27, 2010 10:02

Hi Moritz,

for me it seems that layers usually reduce the skewness, however, if I set the skewness tolerance in snappyhexmeshdict to a very low value (ex: below 0.5) that's when I see a very rough surface mesh, even without layers, but, skewness is reduced.. which is useless since my mesh is wrong!

pcaron May 1, 2010 12:28

I agree
Hi Louis and Moritz

I agree with Louis, I test to reduce the skewness option recently. The result is a bumped surface :( . I solved it with a higher value in maxBoundarySkewness option, say 10. But with a lower value in maxInternalSkewness.

I have no tested to add layers yet. So, I haven't experience using that option.



AlanR May 2, 2010 19:24

I had a lot of strange problems with snappy - not exactly as described above. The source was the fvSolution and fvSchemes files. These files in the motorbike tutorial are not the right ones for mesh generation with snappy (they are for running the wind tunnel simulation part of the motorbike tutorial, not the mesh part). Using the fvSolution and fvSchemes from the moveDynamicMesh tutorial fixed all of my mesh problems. Check both files and make sure they have settings for cellDisplacement, cellMotionU, etc.

Good luck,


louisgag May 5, 2010 16:34

Hi Alan,

thanks for pointing this out; however, changing to the fvSchemes and fvSolution files that do contain de CellMotion part does not change anything in the mesh that snappyHexMesh generates for me.

My solution so far has been to tolerate the maximum skewness of 5-6 since the results still seem very reasonable and my simulation converges.

Best regards,


PS: as for trying a low internalSkew and high boundaryskew, it still does the rough mesh problem.

cjm February 3, 2011 11:44

Hi there,

I have the very same problem with skewed faces on a very complex geometry. ca. 300 SF with the max bound. skewness of 10 and 2. Does anyone have a solution yet for that problem or is it something you have to live with using sHM? How do you set it up the right way without making the mesh to coarse?

Open for any answers.

Bye cjm

cjm March 2, 2011 08:30

Hej all,

I found the same as Louis. MaxBoundSkew ~5 give the best results by keeping the shape of the grid (at least for the case I am working on). Another important thing is to make the blockMesh cells the way that the edge length in X,Y,Z are more or less the same or times 0.5 of each other, i.e. cube like or semi-cube like. This enables sHM to produce less skewed Faces as well.

Bye cjm

panpanzhong June 14, 2013 12:15

You may need to set surface refinement levels so that min and max are the same number.

kuechenrole July 9, 2013 13:01

solution for my case

i set up a few cases and raised always another setting.
nSmoothPatch killed the skew faces at my case without decreasing the quality of my mesh.

BenJ August 14, 2014 05:03

1 Attachment(s)
Hi everybody!

I have been reading your solutions, but I still have bad cells on surface (see attachement).

I am using OpenFoam 2.3.0. I already changed the following parameters:
And it did not help.

I also tried to run the three snappyHexMesh steps separately, but it did not help.

Has anybody experienced such difficulty and could give me a tip?

Best regards

BenJ August 19, 2014 03:12


I have been changing other parameters in snapControls:

without any success.

Has anybody any tip to avoid this kind of cell?

Best regards

wyldckat September 13, 2014 15:58

Greetings BenJ,

I've had this thread on my to-do list for a while now and only now did I manage to come look into this.
I don't know if you've found an answer for this or not, but if not, the problem is that although I think I might be able to help, there isn't much I can do without a test case to work with and test things myself :(

Therefore, if you could provide a test case where this occurs, I can take a look into it.

Best regards,

WernerW September 2, 2015 20:38

Folder to solve high Skewness Faces
Dear Forum,

I'm facing this issue as well and I believe it might be the cause why the solver pimpleDyMFoam crashes.

Following your recomendations I setted


maxBoundarySkewness 5;
maxInternalSkewness 4;

nSmoothPatch 5; //it was 3

addLayers true;
in different places of snappyHexMeshDict, but I still get


***Max skewness = 6.39899, 8 highly skew faces detected which may impair the quality of the results
<<Writing 8 skew faces to set skewFaces
Coupled point location match (average 0) OK.

Failed 1 mesh checks.
with checkMesh.

So if Bruno ,or anyone, still want like to get the bottom of this, I would be grateful that you help me out.

You can find the case in the link:

best regards,

ps.By the way, could you check the result when running pimpleDyMFoam ? What might be the origin of it ? Is it really the mesh ?


Create time

Create mesh for time = 0

Selecting dynamicFvMesh solidBodyMotionFvMesh
Selecting solid-body motion function rotatingMotion
Applying solid body motion to cellZone Cylinder

PIMPLE: no residual control data found. Calculations will employ 2 corrector loops

Reading field p

Reading field U

Reading/calculating face flux field phi

AMI: Creating addressing and weights between 11445 source faces and 11385 target faces
AMI: Patch source sum(weights) min/max/average = 0.527315, 1.60143, 0.999512
AMI: Patch target sum(weights) min/max/average = 0, 1.31695, 0.983254
Selecting incompressible transport model Newtonian
Selecting turbulence model type RASModel
Selecting RAS turbulence model kEpsilon
bounding k, min: 0 max: 0.24 average: 0.24
[6] #0 [0] #0 Foam::error::printStack(Foam::Ostream&)[3] #0 Foam::error::printStack(Foam::Ostream&)[1] #0 [2] #0

louisgag September 7, 2015 04:34

Dear Werner,

The skewFaces are likely not the cause of OF interrupting.


AMI: Patch target sum(weights) min/max/average = 0, 1.31695, 0.983254
The zero weight is most likely your issue. This means that you have AMI faces that do not overlap their corresponding (slave/master) AMI patch.

You can ignore the error by adding a directive such as


        type            cyclicAMI;
        inGroups        1(cyclicAMI);
        nFaces          31968;
        startFace      11637721;
        matchTolerance  0.0001;
        transform      noOrdering;
        neighbourPatch  AMI3;
        lowWeightCorrection 0.2;

to your constant/polyMesh/boundary file. This will however decrease accuracy and I suggest you verify the results accordingly.



All times are GMT -4. The time now is 08:18.