NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
SnappyHexMesh

Description

snappyHexMesh is a meshing engine that has been developed specifically for quality CFD hex(-dominant) mesh generation. It is included with OpenFOAM and requires that the environment has been properly set. On a default installation, this can be done by executing the following command in the working terminal:

. /usr/lib/openfoam/openfoam2006/etc/bashrc

Mesh generation with snappyHexMesh involves three steps:

  1. Castellating: removes any cell beyond the meshing region of interest set by the user.
  2. Snapping: moves the jagged edges of the cell along the boundary so that they are coincident with the boundary.
  3. Layering: adds layers in the boundary region to ensure higher-quality cells in the transition region.

The tutorial available here provides an excellent visualization of how these three steps are applied to a 2D shape.

snappyHexMesh requires a purely hexahedral base mesh, which can be created with another Promesh tool such as blockMesh.

Examples

Generic code for snappyHexMesh:

{
    "Program Type": "Mesh Generation",
    "Mesh File Options": {
        "Input Geometry File": "geometry.stl"
        "Output Mesh File": "meshed_geometry.vtu"
    },
    "Mesh Generation Options": {
        "Mesh Generation Engine": "snappyHexMesh",
        "snappyHexMesh Parameters": {
            "Castellated Mesh": true,
            "Snapping": true, 
            "Layer Addition": false,
            "mergeTolerance": 1e-06,
            "Geometry Definition": {
                "Enable Multi Patches": true | false
                "Input Patch Name": "patch_name"
                "Custom Patches": [
                    {
                        "Custom Patch Name": "box_patch_name",
                        "Searchable Shape": "searchableBox",
                        "minimum bound": [-0.5, -0.5, -0.5],
                        "maximmum bound": [0.5, 0.5, 0.5]
                    },
                    {
                        "Custom Patch Name": "cylinder_patch_name",
                        "Searchable Shape": "searchableCylinder",
                        "Radius": 0.5,
                        "Axis Point 1": [-0.5, 0., 0.],
                        "Axis Point 2": [0.5, 0., 0.]
                    },
                    {
                        "Custom Patch Name": "sphere_patch_name",
                        "Searchable Shape": "searchableSphere",
                        "Radius": 0.5,
                        "Center": [0., 0., 0.]
                    }
                ]
            },
            "Castellated Mesh Controls": {
                "CellZones": true | false,
                "maxLocalCells": 2000000,
                "maxGlobalCells": 4000000,
                "minRefCells": 0,
                "General GapLevelIncrement": 1,
                "nCellsBetweenLevels": 3,
                "surfaceRefinementLvlMin": 0,
                "surfaceRefinementLvlMax": 0,
                "resolveFeatureAngle": 60,
                "gapLevelIncrement": 1,
                "planarAngle": 30,
                "locationInMesh": [0., 0., 0.],
                "allowFreeStandingZoneFaces": true | false,
                "Feature File": {
                    "File Name": "geometry_feature_edge_file.eMesh",
                    "MinLevel": 1,
                    "MaxLevel": 3
                },
                "SurfaceRefinementRegions": {
                    "Patch Name": "patch_name_from_stl",
                    "Patch Type": "patch" | "wall",
                    "MinLevel": 1,
                    "MaxLevel": 3
                },
                "GeomRefinementRegions": {
                    "Patch Name": "custom_patch_name_from_geometry_def",
                    "Mode": "inside" | "outside",
                    "MinLevel": 1,
                    "MaxLevel": 3
                }
            },
            "Snapping Controls": {
                "nSmoothPatch": 4,
                "tolerance": 0.5,
                "snapSolveIter": 200,
                "snapRelaxIter": 6,
                "nFeatureSnapIter": 10,
                "implicitFeatureSnap": true | false,
                "explicitFeatureSnap": true | false,
                "multiRegionFeatureSnap": true | false,
            },
            "Mesh Layer Controls": {
                "relativeSizes": true | false,
                "expansionRatio": 1.3,
                "finalLayerThickness": 1,
                "minThickness": 0.1,
                "firstLayerThickness": 0.1,
                "thickness": 0.2,
                "nGrow": 0,
                "featureAngle": 30,
                "nRelaxIter": 3,
                "nSmoothSurfaceNormals": 1,
                "nSmoothNormals": 3,
                "nSmoothThickness": 2,
                "maxFaceThicknessRatio":  0.5,
                "maxThicknessToMedialRatio": 1,
                "minMedialAxisAngle": 90,
                "nBufferCellsNoExtrude": 0,
                "nLayerIter": 50,
                "nRelaxedIter": 20,
                "slipFeatureAngle": 30,
                "nMedialAxisIter": 1,
                "nSmoothDisplacement": 1,
                "Layers": [
                    {
                        "Patch Name": "custom_patch_combo_1",
                        "nSurfaceLayers": 1,
                        "minThickness": 0.1,
                        "expansionRatio": 1,
                        "finalLayerThickness": 1
                    },
                    {
                        "Patch Name": "custom_patch_combo_2",
                        "nSurfaceLayers": 1,
                        "minThickness": 0.1,
                        "expansionRatio": 1,
                        "firstLayerThickness": 0.1
                    },
                    {
                        "Patch Name": "custom_patch_combo_3",
                        "nSurfaceLayers": 1,
                        "minThickness": 0.1,
                        "thickness": 1,
                        "finalLayerThickness": 1
                    },
                    {
                        "Patch Name": "custom_patch_combo_4",
                        "nSurfaceLayers": 1,
                        "minThickness": 0.1,
                        "thickness": 1,
                        "firstLayerThickness": 0.1
                    },
                    {
                        "Patch Name": "custom_patch_combo_5",
                        "nSurfaceLayers": 1,
                        "minThickness": 0.1,
                        "expansionRatio": 1,
                        "thickness": 1
                    }
                ]        
            },
            "Mesh Quality Controls": {
                "maxNonOrtho": 65,
                "maxBoundarySkewness": 20,
                "maxInternalSkewness": 4,
                "maxConcave": 80,
                "minVol": 1e-13,
                "minTetQuality": 1e-15,
                "minArea": -1,
                "minTwist": 0.02,
                "minFaceWeight": 0.05,
                "minVolRatio": 0.01,
                "minDeterminant": 0.001,
                "minTriangleTwist": -1,
                "qcnSmoothScale": 5,
                "errorReduction": 0.75
            }
        }
    }
}

Parameters

General

  • Castellated Mesh: If true, enables castellated mesh option. Required
  • Snapping: If true, enables surface snapping option. Required
  • Layer Addition: If true, enables adding layers. Required
  • mergeTolerance: If specified, specifies a merge tolerance as a fraction of the bounding box of the initial mesh. Default is 1e-06

Geometry Definition

  • Enable Multi Patches: Should be enabled if the geometry file has more than one patch. Required
  • Input Patch Name: If specified, will be assigned to the entire surface of the provided geometry. Optional; should only be specified if entire .stl is one solid
  • Custom Patches: Array of custom patches defined with primitive shapes. Optional
    • Custom Patch Name: User provided name given to the custom patch
    • Searchable Shape: One of "searchable<SHAPE>", where <SHAPE> is Box, Cylinder, or Sphere.
    • minimum bound: An array of coordinates specifying the minimum corner of a searchableBox. For example, [-35, -35, -35]
    • maximum bound: An array of coordinates specifying the maximum corner of a searchableBox (the opposite diagonal from the minimum bound). For example, [-50, 35, 52]
    • Axis Point 1: An array of coordinates specifying the center of the base of a searchableCylinder. For example, [0, 0, 0]
    • Axis Point 2: An array of coordinates specifying the center of the top of a searchableCylinder. For example, [0, 0, 35]
    • Radius: The radius of a searchableCylinder or a searchableSphere.
    • Center: An array of coordinates specifying the center of a searchableSphere.

Castellated Mesh Controls

Refinement in snappyHexMesh happens via splitting cells in half. For a 2 cm background mesh, the first level of refinement will refine it to a 1 cm mesh. The second level of refinement will further refine it to a 0.5 cm mesh.

Each level of refinement splits cells in half in each dimension. The general formula is \(N(2^d)^R\), where \(N\) is the number of cells being split, \(d\) is the number of dimensions (2 or 3), and \(R\) is the levels of refinement being applied. For example, in a 2D cell, the first level of refinement splits it into \((2^2)^1 = 4\) cells. The fifth level of refinement would produce \((2^2)^5 = 1024 \) cells, each \(2^{(-5)}\) the size. Similarly, for a 3D cell, the first level of refinement splits it into \((2^3)^1 = 8\) cells. The fifth level of refinement would produce \((2^3)^5 = 32768\) cells.

  • CellZones: If true, indicates that there will be multiple disconnected regions within the mesh. Required
  • maxLocalCells: Specifies the maximum number of cells per processor. Optional; default is 2000000
  • maxGlobalCells: Specifies the global maximum number of cells. Optional; default is 4000000
  • minRefCells: Specifies the minimum number of refinement cells. Optional; default is 0
  • GeneralGapLevelIncrement: Optional; default is 1
  • nCellsBetweenLevels: Sets the number of buffer layers between different levels of refinement. Optional; default is 3
  • surfaceRefinementLvlMin: Sets the minimum level of surface refinement. Optional; default is 0
  • surfaceRefinementLvlMax: Sets the maximum level of surface refinement. Optional; default is 0
  • resolveFeatureAngle: Sets the maximum intersection angle a cell can see—any higher, and the maximum level of refinement will be applied. Note that this is the inverse of the corresponding feature in cfMesh. Optional; default is 60 degrees
  • gapLevelIncrement: Optional; default is 1
  • planarAngle: Optional; default is 30 degrees
  • locationInMesh: Specifies where meshing will occur. If this point falls within a volume, that inner volume will be meshed. If it falls outside the volume, the outer volume will be meshed. Optional; default is [0, 0, 0]
  • allowFreeStandingZoneFaces: Should be set to true if the faceZones (specified in the SurfaceRefinementRegions section) can be free-standing rather than restricted to the boundary of the corresponding cellZones. Optional; default is true
  • Feature File: Optional
    • File Name: Name of the geometry feature edge file (.eMesh format), if it exists. Required
    • MinLevel: Sets the minimum level of refinement at feature edges. Optional; default is 1
    • MaxLevel: Sets the maximum level of refinement at feature edges. Required
  • SurfaceRefinementRegions: Optional
    • Patch Name: Name (taken from the stl file) of the patch. Required
    • Patch Type: Type of patch; can be either "patch" or "wall". Optional; default is "NO"
    • MinLevel: Sets the minimum level of refinement for the surface patch. Optional; default is 1
    • MaxLevel: Sets the maximum level of refinement for the surface patch. Required
  • GeomRefinementRegions: Optional
    • Patch Name: One of the custom patch names defined in the Geometry Definition section.
    • Mode: Indicates whether refinement should take place inside or outside the patch.
    • MinLevel: Sets the minimum level of refinement for the geometry.
    • MaxLevel: Sets the maximum level of refinement for the geometry.

Snapping Controls

  • nSmoothPatch: Specifies the number of smoothing iterations to conform the mesh to the geometry surface. Optional; default is 4
  • tolerance: Sets how far the algorithm will search for a point to snap to. Specifically, the ratio of the distance between a point and the surface feature to the local maximum edge length. Optional; default is 0.5
  • snapSolveIter: Number of iterations for the snapping algorithm solver. Optional; default is 200
  • snapRelaxIter: Number of iterations for the snapping algorithm relaxation. Optional; default is 6
  • nFeatureSnapIter: Number of iterations for feature snapping Optional; default is 10
  • implicitFeatureSnap: If true, enables snapping based on sharp edges in the geometry. Optional; default is false
  • explicitFeatureSnap: If true, enables snapping based on feature edges defined in the Feature File, specified in the Castellated Mesh Controls section. Optional; default is false
  • multiRegionFeatureSnap: If true (and explicitFeatureSnap is enabled), features between multiple surfaces will be captured. Optional; default is false

Mesh Layer Controls

  • relativeSizes: Enables relative sizes option during layer addition. Allows the thickness of layers to be specified relative to the undistorted cell size rather than in absolute terms. Optional; default is true
  • expansionRatio: Expansion ratio for layer addition. Optional; default is 1.3
  • finalLayerThickness: Thickness (relative or absolute) of the layer furthest from the wall. Optional; default is 1.
  • minThickness: Minimum overall thickness of the layers. Optional; default is 0.1
  • firstLayerThickness: Thickness (relative or absolute) of the layer closest to the wall. Optional; default is -1.
  • thickness: Overall thickness of the cells. Ignored if finalLayerThickness or firstLayerThickness are specified. Optional; default is -1.
  • nGrow: Sets the number of layers that should not be grown if points are not extruded. Used to delay layer growth close to features. Optional; default is 0
  • featureAngle: The angle in degrees above which surfaces are not extruded for layer addition. Optional; default is 30 degrees. If layers at corner edges are desired, set to 180
  • nRelaxIter: Number of relaxation steps. Optional; default is 3
  • nSmoothSurfaceNormals: Number of patch normal smoothing operations. Optional; default is 1
  • nSmoothNormals: Number of smoothing iterations of interior mesh movement directions. Optional; default is 3
  • nSmoothThickness: Smooth layer thickness over the surface patches. Optional; default is 2
  • maxFaceThicknessRatio: Sets a maximum face to thickness ratio to stop layer growth on highly warped cells. Optional; default is 0.5
  • maxThicknessToMedialRatio: Sets a maximum thickness to medial distance ratio to reduce layer growth, typically in narrow cavities. Optional; default is 1
  • minMedialAxisAngle: Minimum angle to select the medial axis points. Optional; default is 90 degrees
  • nBufferCellsNoExtrude: Sets the number of cells in a buffer region to gradually step down the number of layers. Optional; default is 0
  • nLayerIter: Maximum number of layer addition iterations. Optional; default is 50
  • nRelaxedIter: Number of iterations after which relaxed mesh quality controls are used. Optional; default is 20
  • slipFeatureAngle: Allows the sliding of points on the patch without the layer grown if angle to the patch extrusion direction is larger than the one specified. Optional; default is 30 degrees
  • nMedialAxisIter: Limits number of steps walking away from the surface. Optional; default is -1
  • nSmoothDisplacement: Smoothing displacement of the mesh after the medial axis is determined. Optional; default is -1
  • Layers: . Optional
    • Patch Name: Name of the patch, defined in the Geometry Definition section.
    • nSurfaceLayers: Number of layers per patch. Optional; default is 1
    • expansionRatio: Expansion ratio. Optional; default is 1.
    • finalLayerThickness: Thickness (relative or absolute) of the layer furthest from the wall. Optional; default is 1.
    • firstLyrThickness: Thickness (relative or absolute) of the layer closest to the wall. Optional; default is -1.
    • thickness: Overall thickness of the cells. Optional; default is -1
    • minThickness: Minimum overall thickness of the layers. Optional; default is 1

Only certain combinations of layer options can be used:

  • "expansionRatio" and "finalLayerThickness"
  • "expansionRatio" and "firstLayerThickness"
  • "thickness" and "finalLayerThickness"
  • "thickness" and "firstLayerThickness"
  • "expansionRatio" and "thickness"

Mesh Quality Controls

  • maxNonOrtho: Specifies the maximum allowable angle made by the vector between adjacent cell centers across the common face and face normal. Optional; default is 65
  • maxBoundarySkewness: Sets the maximum allowable skewness in the boundaries. Optional; default is 20.
  • maxInternalSkewness: Sets the maximum allowable internal skewness. Optional; default is 4.
  • maxConcave: Sets the maximum concavity. Optional; default is 80.
  • minVol: Sets the minimum cell volume in cubic meters. Optional; default is 1e-13
  • minTetQuality: Sets the minimum tetrahedral element quality. Set to a small positive number (1e-15), it enables tracking. Set to a large negative number (-1e30) it enables optimal layer insertion. Optional; default is 1e-15
  • minArea: Sets the minimum area for a cell face, in square meters. Optional; default is -1. (no minimum)
  • minTwist: Sets the minimum value for twist. Optional; default is 0.02
  • minFaceWeight: Sets the minimum face interpolation weight. Optional; default is 0.05
  • minVolRatio: Sets the minimum volume ratio. Optional; default is 0.01
  • minDeterminant: Sets the minimum cell determinant. Optional; default is 0.001
  • minTriangleTwist: Sets the minimum triangle twist. Optional; default is -1. (no minimum)
  • qcnSmoothScale: Smoothing iterations, used in conjunction with errorReduction. Optional; default is 5
  • errorReduction: Error reduction, used in conjunction with qcnSmoothScale. Sets the amount to scale back displacement at points of error. Optional; default is 0.75