snappyHexMesh‎ > ‎

cube case

In this little tutorial is shown the influence of some simple controls on a geometry that can be simply meshed with blocks (a cube) following the line described in snappyHexMesh page.

First of all a picture that describes the case settings (each aspect will be explained later). You can copy the files contained in motorBike tutorial contained in $FOAM_TUTORIALS/incompressible/simpleFoam/motorBike and modify the case.

At this link you can download the whole case. It may contain errors so check all the files while reading this guide and then try to modify some parameters to see what changes in results.



STL



First of all create the STL file with a CAD software (SolidWorks, Rhinoceros, Salome, MeshLab, etc.). In this case there aren't curve surfaces so the tolerance is not important.
Don't create different regions on STL file, we don't need them, we want to refine the interior of the cube from the faces to the center. In this simple case the cube is zero centered, size of 2.


controlDict



The choices regarding this file will not be very influential, the time step you choose will be responsible for the name of the directories that snappy creates.

application         snappyHexMesh;
startFrom           startTime;
startTime           0;
stopAt              endTime;
endTime             10;
deltaT              1;
writeControl        timeStep;
writeInterval       1;
purgeWrite          0;
writeFormat         ascii;
writePrecision      6;
writeCompression    uncompressed;
timeFormat          general;
timePrecision       6;
runTimeModifiable   yes;


decomposeParDict, fvSchemes and fvSolution



Leave the default values.


blockMeshDict



For this simple case the blockMesh should be larger than the STL cube and contain it all. In blockMeshDict you can define some parameters (such as x, y, z coordinates) for a rapid change of parameters. It's a simple case, we don't need patches or particulare geometry construction.

convertToMeters 1;

a 32;
b 32;
c 32;
yi -2;
yf 2;
zi -2;
zf 2;
xi -2;
xf 2;

vertices
(
    ($xi $yi $zi) //0
    ($xf $yi $zi) //1
    ($xf $yf $zi) //2
    ($xi $yf $zi) //3
    ($xi $yi $zf) //4
    ($xf $yi $zf) //5
    ($xf $yf $zf) //6
    ($xi $yf $zf) //7
);


blocks
(
    hex (0 1 2 3 4 5 6 7) ($a $b $c) simpleGrading (1 1 1)
);

edges
(
);

patches
(
);

mergePatchPairs
(
);

After setting all parameters in blockMeshDict (contained in constant/polyMesh) you can type blockMesh in a terminal window and launch the program.
in Paraview the result of blockMesh should be like this:



snappyHexMeshDict



The snappyHexMesh process turns around the snappyHexMeshDict file, so we're gonna analyze the controls in it, expecially those that affect our case.
Then we will comment the results and eventually modify the snappyHexMeshDict.


snappyHexMeshDict


activation rows

We don't want to snap or add layers in this case, so we unselect the snap and addLayers options in activation rows sub-menu. Snappy will create just one directories (following time step in controlDict). We don't want to snap because a cube is a geometry which can be perfectly discretized with blocks, the snapping process could only make things worse because of its incapacity to work fine on sharp edges.

castellatedMesh true;
snap            false;
addLayers       false;

geometry

In this sub-menu we specify the STL files naming it as cubo. No regions are called in Dict file since they are not defined in STL file.

geometry
{
    cube.stl
    {
        type triSurfaceMesh;
        name cube;
    }
};

castellatedMeshControls

- Leave the Refinement parameters as default, except for nCellsBetweenLevels on which you can play (don't grow too much or you wouldn't see the different refinement inside the cube).

// Refinement parameters
   
maxLocalCells 1500000;
maxGlobalCells 2000000;
minRefinementCells 10;
nCellsBetweenLevels 2;

- Ignore Explicit feature edge refinement

- In Surface based refinement sub-menu select the desired level of refinement for the whole surface cubo, in this case (1 2) means one level of refinement and max two.

// Surface based refinement
   
refinementSurfaces
{
    cube
    {
        level (1 2);
    }
}

- In Resolve sharp angles set 95 degrees or you will obtain maximum refinement for cell near to the corner. We set 95 because the cube has corners of 90 degrees and we want snappy to mesh them at level 1, like other refined cells. See results for further information.

// Resolve sharp angles

resolveFeatureAngle 95;

- Ignore Region-wise refinement because we don't have user defined regions.

- Select an internal point in Mesh selection sub-menu

// Mesh selection

locationInMesh (0 0 0.5);

snapControls

This submenu is unecessary because we have deselected the snapping part of the program, but you can try to run it with this two sets of controls (one more intensive than the other) to see that it makes no difference: on sharp edges snappyHexMesh doesn't work properly. See results for further information.

snapControls
{
    nSmoothPatch 5; // or 15;
    tolerance 4.0;  // or 0.1;
    nSolveIter 30;  // or 300;
    nRelaxIter 5;   // or 15
}

Other menu

- AddLayersControls is useless because we don't add layers in this case
- Don't touch Mesh quality controls, is useless in a simple geometry like this
- Ignore advanced

Results


SnappyHexMesh creates one directory (named 1) which contains the castellated mesh; with paraView you can see the blockMesh (at step 0) and the meshed cube at step number one.

 

And this is an internal slice which shows the different refinement of the mesh


If we had set a resolveFeatureAngle of 60 (as default), we got a mesh like this. (See the over-refined corners)


If we had run the snap part we obtained this results. Also with two different sets of values (the second more accurate than the first) snappy does not work well on sharp edges. Obviously the program will create two directories (1 and 2), snapped mesh is in the second.


And more accurate snapping


For sharp edges there is an user created utility called snapEdge (not official but works well), but in this case just don't run snap part (or delete directory 2) because a cube can be perfectly discretized with blocks.

Conclusion



- Geometries that can be perfectly discretized with blocks should not be snapped (deselect snap part in activation rows).
- Play on resolveFeatureAngle if you obtain high refinement zones in corner region.
- Snappy does not work very well on sharp edges
Comments