snappyhexmesh basic training single region meshing ... · in .stp format. this .stp file is then...
TRANSCRIPT
snappyHexMesh Basic Training
single Region meshing
simulation of heat transfer with
scalarTransportFoam
1st edition, Aug. 2015
Editor:
Philipp Schretter (TU Wien)
OpenFOAM® Basic Training
snappyHexMesh
1
Tutorial One: Single Region Meshing
Mesh creation
The procedure described in this tutorial is structured in the following order:
Creation of the geometry data
Meshing a geometry with one single region
Run an OpenFOAM simulation with the generated mesh using
scalarTransportFOAM
The reference for this tutorial is a tutorial for meshing in OpenFoam. It is located in
OpenFOAM/OpenFOAM-2.x.x/tutorials/mesh/snappyHexMesh/flange
Objectives
The aim of the tutorial is to give a basic introduction to single region meshing
with the meshing tool snappyHexMesh.
Understanding the advantages of snappyHexMesh
No commercial software package is ultimately necessary. For the meshing,
the OpenFoam environment is sufficient and no further software is
necessary.
The geometry can be created with any CAD program like CATIA,
FreeCAD, etc. As the geometry is to be only surface data, the files need to
be in .stl, .nas or .obj. format.
The meshing process can be run in parallel mode. If high computational
capabilities are available, high quality meshes can be generated in little
time.
Understanding the three basic steps of snappyHexMesh
Castellation: The cells which are beyond a region set by a predefined point
are deleted
Snapping: Reconstructs the cells to move the edges from inside the region
to the required boundary
Layering: Creates additional layers in the boundary region.
Post processing
Import your simulation to ParaView. Analyze the heat distribution in the flange
OpenFOAM® Basic Training
snappyHexMesh
2
Step by step meshing
Creation of the .stl files
For the geometry data, the CAD software CATIA was used, to create the solid
geometry. The creation of the .stl files for single region and multi-region is slightly
different. Either way, it is necessary, to create the .stl files as ASCII .stl and not as
binary .stl.
For the single region case, only one .stl file for the whole geometry is necessary. In
case the software CATIA is used, the file can easily be created by exporting the file
as .stl. CATIA automatically exports the file as ASCII .stl. Nevertheless, with CATIA,
it is not possible to export different surface areas of the flange, for example only the
outside part or the inside part. Therefore, the geometry data is exported from CATIA
in .stp format. This .stp file is then read into FreeCAD. With FreeCAD, the .stl files
can be extracted from the .stp solid geometry: Open the .stp geometry file in the draft
workbench and select the object in the tree view view-section. Then click on
Downgrade in the combo view view-section. This gives a list of all faces of the
geometry, which can be selected and exported as .ast format. In FreeCAD, it's
necessary to distinguish between .stl, which is binary .stl, and .ast, which is ASCII .stl.
In FreeCAD, the surface file is exported in .ast format and afterwards renamed to .stl.
OpenFOAM® Basic Training
snappyHexMesh
3
Figure 1 Select the surfaces from a solid geometry
In case which was prepared for this tutorial, the dimensions from from the .stl files
exported from the CAD software are in meters. To convert the dimensinos, the open
source software Blender can be used. Therefore, import the .stl files and use the scale
tool with a factor 0.001 to convert from m to mm. To export the file, it is necessary to
tick the box for Ascii to save the .stl file in ascii format. Otherwise, OpenFoam won't
be able to deal with the file.
In the single region case, the header line and the base line of the .stl files, exported
from blender need to be updated. For example the headers and baselines in the two
available .stl files are renamed to flange_outside_surface and flange_inside_surface.
This is necessary to have appropriate entries in the boundary file later on for the
OpenFoam simulation.
In order to create a .stl from a geometry which is already available in gambit, the
geometry data can be exported in .stp or alternatively in .igs format. Afterwards,
the .stp or .igs (msbo) file can be imported to FreeCAD and converted via export
as .stl.
The technical drawing with the dimensions of the geometry for this tutorial is
depicted below.
OpenFOAM® Basic Training
snappyHexMesh
4
OpenFOAM® Basic Training
snappyHexMesh
5
The folder constant is necessary for the mesh files. The folder system is necessary for
the system settings.
constant directory
The constant directory must initially have the following folders
- polyMesh:
Which contains the base mesh as blockMeshDict. Here we define a base block
mesh inside. The blockmesh will contain the flange geometry. The dimensions
of the blockmesh are as follows.
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 1;
Eight coordinates of a rectangular block
vertices
(
(-0.03 -0.03 -0.02)
(0.03 -0.03 -0.02)
(0.03 0.03 -0.02)
(-0.03 0.03 -0.02)
(-0.03 -0.03 0.02)
(0.03 -0.03 0.02)
(0.03 0.03 0.02)
(-0.03 0.03 0.02)
);
blocks labels the vertices, define number of cells along the axes and expansion
ratio of cells
blocks
(
hex (0 1 2 3 4 5 6 7) (30 30 20) simpleGrading (1 1 1)
);
edges
(
);
boundary defines different faces if any, based on vertices label. In this case we
do not define different boundaries like 'inlet' 'outlet' etc
boundary
OpenFOAM® Basic Training
snappyHexMesh
6
(
allBoundary
{
type patch;
faces
(
(3 7 6 2)
(0 4 7 3)
(2 6 5 1)
(1 5 4 0)
(0 3 2 1)
(4 5 6 7)
);
}
);
// ************************************************************************ //
- triSurface:
The folder triSurface should contain a file with the geometry data to be
meshed (stl, nas, obj). The file name is to be used as a reference pointer in
later stages.
system directory
The system directory may have the following files,
- controlDict
- decomposeParDict
If the mesh is to be run in parallel using the decomposePar utility, this file
defines the parameters for distributed processors
- fvSchemes
- fvSolution
- meshQualityDict
minFaceWeight- can be kept at the default value of 0.02.
- snappyHexMeshDict:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
set castellatedMesh, snap, addLayers to true or false depending on the
stages required
castellatedMesh true;
snap true;
addLayers true;
geometry lists all surfaces except the blockMesh geometry, in the
constant/triSurface directory , and define a name for each of them to be
used as reference
a refinementBox() can be defined. This is a a region in the blockMesh
geometry which has a refined mesh. The level of refinement of this box is
defined in the section refinementRegions below.
geometry
{
flange_single_region.stl
{
type triSurfaceMesh;
name flange_single_region;
OpenFOAM® Basic Training
snappyHexMesh
7
}
The refinement box has to be larger than one cell of the blockmesh. In
Order to reach a fine region in the blockmesh, several refinement
boxes can be defined whereas always a smaller box is refined inside
the refined box. It is always necessary to keep each box larger than
the smallest cell in that region.
refinementBox
{
}
};
CASTELLATING
castellatedMeshControls
{
maxLocalCells 200000;
maxGlobalCells 5000000;
minRefinementCells 0;
maxLoadUnbalance 0.0;
nCellsBetweenLevels 1;
The section features is used for user-defined edge refinement. It uses
The eMesh files, created with the surfaceFeatureExtract command. These
.eMesh files are extracted parts from the .stl surfaces, specified in
The surfaceFeatureExtractDict.
Also the extendedFeatureEdgeMesh file from the
constant/extendedFeatureEdgeMesh folder can be used. In this case,both
files give the same result.
features
(
{
file "flange_single_region.eMesh";
level 3;
}
);
All surfaces defined in the geometry subdirectory must be listed here.
List of the surfaces, which need to be listed in in the boundary files
In constant/polyMesh/boundary
refinementSurfaces
{
flange_single_region
{
level (3 3);
}
}
resolveFeatureAngle is an important setting. Edges, whose adjacent
surface normals are at an angle higher than the value set, are
resolved. The lower the value, the better is the resolution at sharp
edges
resolveFeatureAngle 30;
refinementRegions()- the refinement of the refinement box is defined.
The cells in this box are split up to the number of levels defined, or
until the max number of cells is reached. In this case, no refined
regions are defined.
refinementRegions
{
}
locationInMesh()- Important coordinate for single region cases, to
define a region which is to be kept from the blockmesh
locationInMesh (6 0 0); allowFreeStandingZoneFaces false;
}
SNAPPING
Important parameters are number of mesh displacement iterations,
nSolveIter
and the number of feature edge snapping iterations, nFeatureSnapIter.
snapControls
{
nSmoothPatch 4;
tolerance 1.2;
nSolveIter 185;
nRelaxIter 6;
nFeatureSnapIter 5;
OpenFOAM® Basic Training
snappyHexMesh
8
implicitFeatureSnap false;
explicitFeatureSnap true;
multiRegionFeatureSnap false;
}
LAYERING
addLayersControls
{
relativeSizes false;
layers
{
The label for the layering is equal to the labeling of the
Boundary surface in the boundary file in the constant/polyMesh
folder
flange_single_region_flange_inside
{
define the number of surface layers
nSurfaceLayers 3;
}
flange_single_region_flange_outside
{
nSurfaceLayers 3;
}
}
define the expansion ratio of the surface layers
expansionRatio 1.005;
define the min and the final thickness of the surface layers
finalLayerThickness 0.0001;
minThickness 0.00005;
nGrow 0;
featureAngle 85;
slipFeatureAngle 25;
nRelaxIter 5;
nSmoothSurfaceNormals 4;
nSmoothNormals 3;
nSmoothThickness 10;
maxFaceThicknessRatio 0.5;
maxThicknessToMedialRatio 0.2;
minMedianAxisAngle 90;
nBufferCellsNoExtrude 0;
nLayerIter : If not snapped smoothly enough, the max number of layer
addition iteration can be increased
nLayerIter 50;
}
meshQualityControls
{
#include "meshQualityDict"
nSmoothScale 4;
errorReduction 0.75;
}
writeFlags
(
scalarLevels
layerSets
layerFields
);
mergeTolerance 1e-6;
// ******************************************************************* //
- surfaceFeatureExtractDict:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
flange_single_region.stl
OpenFOAM® Basic Training
snappyHexMesh
9
{
extractionMethod extractFromSurface;
extractFromSurfaceCoeffs
{
All edges are refined, whose surface normals include angles with
less than the angle specified. For the included angels, a special
level of refinement can be set in the snappyHexMeshDict in the
features subdictionary.
includedAngle 150;
}
writeObj yes;
}
// ******************************************************************** //
Setting Refinement level in snappyHexMeshDict and surfaceFeatureExtractDict
In the first step, the castellatedMeshControls, the initial mesh can be refined with
levels. The level depends on the refinement set in the blockMesh, and the required
refinement on the surfaces. Therefore, levels can be set in the snappyHexMesh
subdirectories features, refinementSurfaces and refinementRegions.
Level 0 stands for no refinement and each level splits the cell into 4 separate
cells.
Figure 2 Refinement level 0, level 1, level 2, level 3
Only the relevant changes, which were used in the sample flange case, are commented
in the snappyHexMeshDict. For more information see the literature in [1], [2], [3],
[4].
The background mesh is created with the command blockMesh.
>blockMesh
To ensure that also the sharp edges are refined properly, it is very important to create
perfect cubes in the first place. In this case, the mesh was created with 30 cells in x-
and y direction and with 20 cells in z direction. Thus, according to the settings in the
blockMeshDict each cube has a length of 2mm in each direction.
OpenFOAM® Basic Training
snappyHexMesh
10
Figure 3 Block mesh for flange
One .stl file is needed with the information about the surfaces inside and outside of
the flange to set the appropriate boundary conditions. So both surfaces are are
combined to a single file.
As mentioned above, this is necessary to have appropriate entries in the boundary
file.
>cat cad/flange_inside.stl cad/flange_outside.stl >
constant/triSurface/flange_single_region.stl
In this case, the combined .stl can look similar to the following extract.
solid flange_inside
facet normal 0 0 0
outer loop
vertex 0.000000 0.012000 0.007250
vertex -0.000422 0.025000 0.007238
vertex 0.000000 0.025000 0.007250
endloop
endfacet
.
.
.
facet normal 0 0 0
outer loop
vertex 0.000758 0.012000 -0.007210
vertex 0.000842 0.025000 -0.007201
vertex 0.000422 0.025000 -0.007238
endloop
endfacet
endsolid flange_inside
solid flange_outside
facet normal 0 0 0
outer loop
vertex -0.006500 -0.005000 -0.014250
vertex -0.003273 -0.000588 -0.014250
vertex -0.003088 -0.000773 -0.014250
endloop
endfacet
.
OpenFOAM® Basic Training
snappyHexMesh
11
.
.
facet normal 0 0 0
outer loop
vertex -0.005437 0.025000 -0.007483
vertex -0.004886 0.010000 -0.007854
vertex -0.006500 0.010000 -0.006581
endloop
endfacet
endsolid flange_outside
The command surfaceFeatureExtract creates the .eMesh files from the .stl files
and creates the folder extendedFeatureEdgeMesh in the /constant directory. Refining
certain parts of the surface geometry with the surfaceFeatureExtract tool is optional.
>surfaceFeatureExtract
OpenFOAM® Basic Training
snappyHexMesh
12
a) Run snappyHexMesh on one processor
The meshing process with snappyHexMesh can be run in on one processor or on
several processors in parallel. The command to mesh the flange geometry on one
processor is
>snappyHexMesh
The command snappyHexMesh creates a folder with the mesh files for each mesh
step. If, for example, in the snappyHexMeshDict, only castellatedMesh is set to true
and snap and addLayers are set to false, only one folder is created. If also snap is set
to true, 2 folders are created and if also addLayers is set to true, 3 folders with 3
polyMesh folders are created.
In order to avoid the creation of these folders and only keep the final mesh, the
following command can be used to overwrite the previous meshing steps. In this case,
only one polyMesh folder exits in the /constant directory.
>snappyHexMesh -overwrite
OpenFOAM® Basic Training
snappyHexMesh
13
b) Run snappyHexMesh on several processors in
parallel
For running the simulation in parallel, a decomposeParDict file is necessary in the
system folder. In this file, the decomposition method can be specified. This can be
hierarchical, simple, scotch or manual.
Note: It is recommended, not to use the scotch method to decompose the region.
Rather, the hierarchical or the simple method should be used. In case of scotch
method, errors can occur while executing snappyHexMesh or while reconstructing the
mesh, so that more domains are reconstructed than have been decomposed before.
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
numberOfSubdomains 2;
method hierarchical;
//method simple;
//method scotch;
//method manual;
hierarchicalCoeffs
{
n (1 2 1);
delta 0.001;
order xyz;
}
simpleCoeffs
{
n (1 2 1);
delta 0.001;
}
manualCoeffs
{
dataFile "cellDecomposition";
}
// ************************************************************************* //
>decomposePar
After executing decomposePar, the processor* folders are created. The number of
created folders are according to the number of subdomains specified in the
decomposeParDict.
>mpirun -np 2 snappyHexMesh -parallel
OpenFOAM® Basic Training
snappyHexMesh
14
To examine, what each of the steps in the snappyHexMeshDict really does, the
following commands can be used.
To reconstruct and examine the castelleting step
>reconstructParMesh -time 1
Figure 4 flange mesh for step castellate with surface refinement level 2
Figure 5 flange mesh for step castellate with surface refinement level 3
OpenFOAM® Basic Training
snappyHexMesh
15
To reconstruct and examine the snap step
>reconstructParMesh -time 2
Figure 6 flange mesh for step snap with surface refinement level 3
To reconstruct and examine the layering step
>reconstructParMesh -time 3
In case, only the latest timestep available needed, also the following command can be
used
>reconstructParMesh -latestTime
Figure 7 flange mesh for step addlayers with surface refinement level 3
OpenFOAM® Basic Training
snappyHexMesh
16
The figures 4 to 7, are slice views taken with paraview from the center of the flange.
The slices are depicted by the red plain in figure XX on the right
Figure 8 flange with sectional plain
The following command only creates a single folder 0 in the processor* folders
whereas the preceding mesh folders 1 or 2 are overwritten.
OpenFOAM® Basic Training
snappyHexMesh
17
>mpirun -np 2 snappyHexMesh -parallel -overwrite
By overwriting the previous time steps, the mesh can be reconstructed with
>reconstructParMesh –constant
Review the mesh quality with the tool checkMesh
>checkMesh
In case the checkMesh tool finds erros, the corrupted cells or faces are written to the folder sets in the folder polyMesh. These cells or faces can be examined with paraview by converting the files to the VTK format. Depending on the sort of corrupted cells depicted in the terminal output from checkMesh, the following commands can be used among others
>foamToVTK –region insideZone –faceSet nonOrthoFaces
>foamToVTK –region outsideZone –faceSet skewFaces
>foamToVtK –region insideZone –cellSet zeroVolumeCells
OpenFOAM® Basic Training
snappyHexMesh
18
Running OpenFoam simulation with scalarTransportFoam
The mesh files, created with snappyHexMesh are copied to the scalarTransportFoam
tutorial sample case pitzDaily which is provided by OpenFoam.
Some adjustments are necessary to run the case and check if the mesh quality is
satisfactory.
- Delete the entry defaultFaces in the boundary file in the polyMesh folder
- In the controlDict file change the endTime to 0.05 and the writeInterval to
100.
- Update the file temperature where the flange has an initial temperature of
293K and is heated up from the inside with 350K. The outside of the flange is
adiabatic
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 1 0 0 0];
internalField uniform 293;
boundaryField
{
flange_single_region_flange_inside
{
type fixedValue;
value uniform 350;
}
flange_single_region_flange_outside
{
type zeroGradient;
}
}
// ******************************************************************** //
- Update the file velocity where the whole velocity in the flange and at the
boundaries is zero.
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0 );
boundaryField
{
flange_single_region_flange_inside
{
type fixedValue;
value uniform (0 0 0);
}
flange_single_region_flange_outside
{
type fixedValue;
value uniform (0 0 0);
}
}
OpenFOAM® Basic Training
snappyHexMesh
19
// ******************************************************************** //
Run the solver with the command
>scalarTransportFoam
Convert the results with
>foamToVTK
0.01s 0.02s 0.03s
0.04s 0.05s
Figure 7 Heating of the flange from 0.01 to 0.05s
OpenFOAM® Basic Training
snappyHexMesh
20
Literature
[1] http://cfd.direct/openfoam/user-guide/snappyhexmesh/
[2] http://www.openfoamwiki.net/index.php/SnappyHexMesh
[3] https://openfoamwiki.net/images/f/f0/Final-AndrewJacksonSlidesOFW7.pdf
[4] https://sites.google.com/site/snappywiki/snappyhexmesh#TOC-snappyHexMesh