Dict file that contains all instructions read by snappyhexMesh utility. The entire process revolves around this file and the parameters set in it.
The first rows of sHMDict can activate or skip the crucial sections of the process.
// Which of the steps to run
castellatedMesh true; //or false to de-activate
snap true;
addLayers true;
Sometimes it's useful to run separately the castellatedMesh+snap and the addLayers sections (because of some problems with sharp edges), or not running at all snap (for geometries that can be perfectly discretized with cubes)
In geometry section all active regions that take part in snappy process can be defined. Starting with the input geometry file (located in constant/triSurface) and the sub-regions defined in the file itself. Both STL and OBJ files can be handled by snappy, they should be characterized by a good refinement level because they will be the reference for snapping process.
file.stl //or file.obj (with right header) //STL file name
{
type triSurfaceMesh;
name my_file; // user-assigned name
regions // definition of regions of stl
{
subregion_1 // STL-defined patch name
{
name my_first_subregion; // user-assigned patch name
}
subregion_2
{
name my_second_subregion;
}
}
}
In this section it is also possible to set some user defined regions, useful for specific refinement of zone that can't be created in geometry file. An example:
refinementBox //USER DEFINED REGION NAME
{
type searchableBox; //REGION DEFINED BY BOUNDING BOX
min (-200.0 -0.18 -0.18); //parameters
max ( 230.0 0.18 0.18);
}
The parameters that govern the process of cell splitting are described in this section (sub-dictionary), following the OpenFOAM user's guide and the sHMDict file itself.
The parameters listed below govern the refinement process, more specifically the number of cells generated in the splitting process. They are well commented in sHMDict file and in the relative section of OpenFOAM user's guide
maxLocalCells
This is well explained in the Dict file.
// 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; // Max number of cells per processor during refinement
maxGlobalCells
// 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 2000000; // Overall cell limit during refinement (i.e. before removal)
minRefinementCells
// 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 100;
In this case the refinement loop will stop if less than 100 cells are selected. Avoids useless loop iterations.
nCellsBetweenLevels
Defines number of cells for each refinement level. The higher it is, the more gradual the mesh is
// Number of buffer layers between different levels.
// 1 means normal 2:1 refinement restriction, larger means slower
// refinement.
nCellsBetweenLevels 6; // Number of buffer layers of cells between different levels of refinement
In this section the user can set specific refinement level for geometry's feature edges.
// Specifies a level for any cell intersected by its edges.
// This is a featureEdgeMesh, read from constant/triSurface for now.
features
(
{file "file.eMesh"; level 2;}
);
The .eMesh file can be obtained with the surfaceFeatureExtract utility. The classic input from command line is
surfaceFeatureExtract -includedAngle 150 constant/triSurface/file.stl file150extraction
Value of includedAngle can be changed, but usually with 150 all features can be captured. Last input file150extraction is the name given to the feature set. In snappyHexMesh process it is useless.
This section is also important to implement feature snapping process in order to (partially) avoid sharp edges problems. See section below.
2.2.x version
In the new version of OpenFOAM something has changed:
"In the latest version, users can specify levels of refinement based on distance to a feature"
features
(
{file "file.eMesh"; levels ((0.0 2) (0.3 1));}
);
"Users can generate feature edge meshes in Paraview by using the Feature Edges filter. Data can be saved in VTK (ASCII) format and then be used by snappyHexMesh."
surfaceFeatureExtract is now useless (for snappyHexMesh)
If the user want to implement feature snap process without particular refinement on edges, is now possible to avoid the creation of featureEdge file.
The new implicit method "uses the resolveFeatureAngle keyword entry to identify surface geometric features" directly from stl file.
In this section the user can set the refinement's levels of all surfaces defined in geometry file (not the user defined regions). The method is well explained in comments and the process in OpenFOAM user's guide. The patches recalled in regions sub-menu get a different refinement level than the whole surface. It's useful when different directions of mesh thickening is required.
// 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.
refinementSurfaces
{
my_file
{
level (1 1);
regions
{
my_first_subregion
{
level (5 6);
}
my_second_subregion
{
level (2 2);
}
}
}
}
In this sub-menu entries about angle treatment appear. Snappy applies maximum refinement to cells whose intersections exceed resolveFeatureAngle. It has to be rosen if local high refinement regions want to be avoided (i.e. the corner of a box)
resolveFeatureAngle
See cube case for an example.
// Resolve sharp angles
// Applies maximum level of refinement to cells that can see intersections whose
// angle exceeds this
resolveFeatureAngle 100;
Section for refinement's selection of user defined regions by three methods explained in sHMDict comments.
Sometimes different type regions tend to override each other, introduce them carefully.
// 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.
refinementRegions
{
refinementBox
{
mode distance;
levels ((0.05 5) (0.1 4));
}
refinementSphere
{
mode inside;
levels ((0.05 4));
}
refinementCylinder
{
mode outside;
levels ((0.05 4));
}
}
Very important parameter. If the chosen point is inside the surface described in geometry file then snappy will create the internal mesh, otherwise the external part (inside the blockMesh) is meshed. Snappy deletes cells that are more than 50% outside the bounding region containing the selected point, after this process the mesh looks like a "LEGO construction" and is ready for the snapping session.
locationInMesh
// 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 (0 0 0);
"The next stage of the meshing process involves moving cell vertex points onto surface geometry to remove the jagged castellated surface from the mesh. The process is:
displace the vertices in the castellated boundary onto the STL surface;
solve for relaxation of the internal mesh with the latest displaced boundary vertices;
find the vertices that cause mesh quality parameters to be violated;
reduce the displacement of those vertices from their initial value (at 1) and repeat from 2 until mesh quality is satisfied."
The snapping process is governed by four parameters that control the number of iterations and tolerance between mesh and STL surface.
Unfortunately they rarely can adjust the bad snapping on sharp edges (see cube case for an example).
nSmoothPatch
This option changes how many times the exterior (the boundary wall) should be iterated. The more iterations, the smoother the mesh will become
// Number of patch smoothing iterations before finding correspondence
// to surface
nSmoothPatch 3;
tolerance
This option changes how long distance the program should look for a point to snap, the distance will be the number put in "tolerance" * "size of the mesh".
// 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;
nSolveIter
This option changes how many times the "snapping" part of snappyHexMesh should be run:
- the higher this number is the better mesh quality will be gained
- the higher this number is the more equidistant mesh will be created when it comes to the boundary
- the higher this number is the longer tha snapping will take
// Number of mesh displacement relaxation iterations.
nSolveIter 30;
nRelaxIter
This option changes how many times the mesh will run a relaxing script that removes some bad mesh point, however snappyHexMesh should stop before, when the correct mesh is created
// Maximum number of snapping relaxation iterations. Should stop
// before upon reaching a correct mesh.
nRelaxIter 5;
To avoid sharp edges problems it is possible to take advantage of extracted feature edge in castellatedMeshControls and attract points to features within snapping iterative process
nFeatureSnapIter
Controls the number of morph iterations within main snapping iterative process, to attract mesh points to surface and avoid sharp edges problems.
// Number of feature edge snapping
// iterations. Leave out altogether to disable.
// Do not use here since mesh resolution too low and baffles present
nFeatureSnapIter 15;
In the latest version of OpenFOAM feature snap process has been improve. Now there are two possible method that can be used:
explicit method
The old concept. Take advantage of extracted feature edges and attract points
implicit method
Now snappyHexMesh can identify surface geometric features using resolveFeatureAngle keyword directly from stl file
From OpenFOAM official site
"The explicit method offers greater control and, from our experience, provides slightly better feature conformation. The implicit method has the advantage of being fully automated."
Some new controls have been implemented
implicitFeatureSnap
True of false to enable implicit method for feature snap process
//- Detect (geometric only) features by sampling the surface
// (default=false).
implicitFeatureSnap true;
explicitFeatureSnap
True of false to enable explicit method for feature snap process
//- Use castellatedMeshControls::features (default = true)
explicitFeatureSnap false;
multiRegionFeatureSnap
Just for explicit method, "...detect features between multiple surfaces..."
//- Detect points on multiple surfaces (only for explicitFeatureSnap)
multiRegionFeatureSnap false;
The process of mesh layer addition involves shrinking the existing mesh from the boundary and inserting layers of cells, broadly as follows:
the mesh is projected back from the surface by a specified thickness in the direction normal to the surface;
solve for relaxation of the internal mesh with the latest projected boundary vertices;
check if validation criteria are satisfied otherwise reduce the projected thickness and return to 2; if validation cannot be satisfied for any thickness, do not insert layers;
if the validation criteria can be satisfied, insert mesh layers;
the mesh is checked again; if the checks fail, layers are removed and we return to 2.
Basic settings
The first group of parameters define the dimensions of layers and the surfaces on which they will be attached
relativeSizes
This option (true or false) changes the way to read the parameters given next.
- true: next parameters define the layers' dimensions as "parameters" * "undistorted cell size outside layers"
- false: next parameters define directly the layers' dimensions (absolute)
relativeSizes true;
layers
In this option you can define teh number of layers and the patch on which attach the layers (must be a STL patch recalled in geometry sub-menu, not a user defined regions)
// Per final patch (so not geometry!) the layer information
layers
{
my_first_subregion
{
nSurfaceLayers 4;
}
}
expansionRatio
This parameters set the grow factor of the layers (ratio between two subsequent layers)
// Expansion factor for layer mesh
expansionRatio 1.2;
finalLayerThickness
This parameters set the thickness of the last layer.
// 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;
minThickness
This parameter set the minimum allowable thickness of layer
// 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;
nGrow
// 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;
The second group of parameters, called Advanced settings, contains more specific controls that can help the layers creation.
featureAngle
Angle above which surface is not extruded. One of the first parameters on which play when layer addition fails.
// When not to extrude surface. 0 is flat surface, 90 is when two faces
// make straight angle.
featureAngle 90;
nRelaxIter
This option changes how many times the mesh will run a relaxing script.
// Maximum number of snapping relaxation iterations. Should stop
// before upon reaching a correct mesh.
nRelaxIter 3;
nSmoothSurfaceNormals
// Number of smoothing iterations of surface normals
nSmoothSurfaceNormals 1;
nSmoothNormals
// Number of smoothing iterations of interior mesh movement direction
nSmoothNormals 3;
nSmoothThickness
?????
// Smooth layer thickness over surface patches
nSmoothThickness 10;
maxFaceThicknessRatio
This option changes the maximum allowable value of aspect ratio. Sometimes (expecially in corners) the layers must be generated over highly warped cells.
// Stop layer growth on highly warped cells
maxFaceThicknessRatio 0.5;
maxThicknessToMedialRatio
??? any ideas/experience/comment ??? please send me an email
minMedianAxisAngle
??? any ideas/experience/comment ??? please send me an email
nBufferCellsNoExtrude
??? any ideas/experience/comment ??? please send me an email
nLayerIter
??? any ideas/experience/comment ??? please send me an email
This parameters set the minimum thresholds to generate mesh in snap and add-layers parts.
In 99% of the cases is better to leave the default values, but sometimes you can deactivate one or more controls to force the mesh generation. Be prepared for the worst!
??? any ideas/experience/comment ??? please send me an email