SnappyHexMesh Multi Region
SnappyHexMesh Multi Region
Editor:
Philipp Schretter (TU Wien)
OpenFOAM® Basic Training
snappyHexMesh
Mesh creation
Objectives
The aim of the tutorial is to give a basic introduction to multi 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 flow field through the flange and
the heat distribution in the flange.
OpenFOAM® Basic Training
snappyHexMesh
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 multi region case, several .stl files are necessary in order to create the mesh
for the flange. One Possibility is to create the surface files with CATIA with the
Wireframe and Surface Design tool.
Another possibility is to create a solid geometry with CATIA and export the geometry
data as .stp format. This file is imported to FreeCAD to generate the .ast files. 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 the 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 multi region case, the header line and the base line of the .stl files, exported
from blender need to be updated with an appropriate labelling. For example for
header line for the .stl for inlet 1 is renamed to solid inlet_1.
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
OpenFOAM® Basic Training
snappyHexMesh
Multi region layer meshing is used to mesh geometries with several regions. For this
case, the region inside the flange is meshed (region 0) as well as the flange itself
(region 1). Subsequent to the meshing, an OpenFOAM simulation with the solver
chtMultiRegionFoam is run with the created mesh.
For multi region mehsing, the files in the folders constant and system are basically the
same as for single region meshing. The changes in snappyHexMeshDict and
surfaceFeatureExtractDict are described below. 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].
- snappyHexMeshDict
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
castellatedMesh true;
snap true;
addLayers true;
The level number can be the source of an error while running the
meshing process in
parallel, where several regions are created, which belong neither to
the insideDomain nor to outsideDomain.
features
(
OpenFOAM® Basic Training
snappyHexMesh
{
file "insideDomain.eMesh";
level 3;
}
{
file "outsideDomain.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
{
inside
{
It is necessary to define a specific point anywhere inside the
region. Simply labelling the cellZoneInside as inside is not
sufficient.
level (3 3);
faceZone insideFaces;
cellZone insideZone;
cellZoneInside insidePoint;
insidePoint (0.0 0.0 0.0);
}
outside
{
It is necessary to define a specific point anywhere inside the
inside the region. Simply labelling the cellZoneInside as
inside is not sufficient.
level (3 3);
faceZone outsideFaces;
cellZone outsideZone;
cellZoneInside insidePoint;
insidePoint (0.010 0.0 0.0);
}
inletone
{
No empty boundary. Define inlet/outlet as patch
level (0 0);
patchInfo
{
type patch;
}
}
inlettwo
{
No empty boundary. Define inlet/outlet as patch
level (0 0);
patchInfo
{
type patch;
// possibly also define inGroups
}
}
outlet
{
No empty boundary. Define inlet/outlet as patch.
level (0 0);
patchInfo
{
type patch;
possibly also define inGroups
}
}
}
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;
OpenFOAM® Basic Training
snappyHexMesh
layerSets
layerFields
);
mergeTolerance 1e-6;
// ******************************************************************** //
- surfaceFeatureExtractDict
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
outsideDomain.stl
{
extractionMethod extractFromSurface;
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.
extractFromSurfaceCoeffs
{
includedAngle 120;
}
writeObj no;
}
insideDomain.stl
{
extractionMethod extractFromSurface;
extractFromSurfaceCoeffs
{
includedAngle 120;
}
writeObj no;
}
// ******************************************************************** //
Basically, .stl files for the snappyHexMesh tool have to encompass a closed
geometry. This is especially important for geometries which consist of several
different .stl files to create one closed geometry. Therefore it is important to take care
especially of the exact dimensions of the parts of the geometry while creating the .stl
files,
To ensure that the mesh from two domains, stl.inside, and stl.outside, is compatible
and connected, it is necessary, that both domains are created from the same surfaces
which are shared with both domains. In this case, the .stl. file flange_inside is part of
the domains stlinside as well as of stloutside.
This is also depicted in the following:
OpenFOAM® Basic Training
snappyHexMesh
The following commands combine the .stl files for the region inside the flange,
stlinside, and for the region of the flange itself, stloutside. The files are taken from the
folder cad in the main directory.
In figure XX, the combined stl files are depicted. The resulting file insideDomain.stl
OpenFOAM® Basic Training
snappyHexMesh
for the region 0 consists of the stls for the wall inside the flange (black) for the inlet 1
(blue) for the inlet 2 (green) and for the outlet (red).
he resulting file outsideDomain.stl for the region 1 consists of the sls for the wall
outside the flange.
The resulting file outsideDomain.stl for the region 1 consists of the stls for the wall
outside the flange (orange) and for the wall inside the flange (black).
Figure 2 Surface geometry of the flange domain inside (black) and outside (orange)
>blockMesh
The block mesh for the multi region case is the same as for the single region case with
30 cells in x- and y direction and with 20 cells in z direction.
Also in the multi region case, it is very important to create perfect cubes in the first
place to ensure that the sharp edges are refined properly. Otherwise, highly skewed
cells could be generated while the snapping process.
OpenFOAM® Basic Training
snappyHexMesh
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 1;
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
(
hex (0 1 2 3 4 5 6 7) (30 30 20) simpleGrading (1 1 1)
);
.
.
.
// ************************************************************************* //
>surfaceFeatureExtract
OpenFOAM® Basic Training
snappyHexMesh
As the meshing process is run in parallel, the geometry needs to be decomposed prior
to run snappyHexMesh. Depending on the number of subdomains, defined in the
decomposeParDict, the processor folders are created accordingly.
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.
In this case, the domain is divided into 2 subdomains, which is also indicated by the
command mpirun -np 2, whereas np stands for number of processors.
>decomposePar
OpenFOAM® Basic Training
snappyHexMesh
If in the snappyHexMeshDict, castellatedMesh and snap are set to true, the folders 1
and 2 are created after running the command snappyHexMesh in parallel. Folder 1
contains the mesh files after the step castellatiedMesh and folder 2 after the step snap.
After running snappyHexMesh in parallel, the mesh data is located in the different
processor folders. This data needs to be reconstructed. The following command
reconstructs the mesh after the step castellatedMesh.
>reconstructParMesh -time 1
After performing these steps, the flange is meshed, but still the outside mesh needs to
be removed. As the point locationInMesh in the snappyHexMeshDict file is defined
inside the flange domain, no mesh is removed by snappyHexMesh and therefore has
to be removed manually.
In the file boundary in the folder /1/constant/polyMesh, are 4 entries with zero
number of faces: inside, inside_slave, outside, outside_slave. Those entries are
removed by snappyHexMesh while performing the command below.
Occasionally, the entries XXX_slave are not removed and still remain in the
boundary files. The following steps can be attempted to avoid those entries
- rename the header – and bottome lines in the .stl files and remove the labeling
after 'solid'.
- add the entries with the .stl files to both subdirectories in the
snappyHexMeshDict, geometry and refinementSurfaces.
In order to display the geometry with paraview, the mesh files must be copied to the
constant directory.
The folder domain0 contains the mesh which remains after splitting the block mesh
from the flange geometry. These mesh files as well as the block mesh from the
polyMesh folder can be deleted so that only the flange mesh remains. As paraview
displays mesh files from all polyMesh folders, also the folder from the time step 2 is
removed.
>rm -r constant/polyMesh 1/polyMesh constant/domain0
system/domain0 1/domain0
OpenFOAM® Basic Training
snappyHexMesh
Figure 6 Flange mesh after removing domain0 and polyMesh with domain of the
slice (red rectangle)
Occasionally, the surface of the geometry seems to have holes while displaying a Slice
view in paraview. In this case, the tool Crinkle slice can be used to remove the holes,
which are mostly attributed due to triangular cells, intersecting the surface.
OpenFOAM® Basic Training
snappyHexMesh
Step 2 snap
The following command reconstructs the mesh after the step snap.
>reconstructParMesh -time 2
If the geometry is both, castellated and snapped, also the following command can be
used to reconstruct the mesh after the step snap.
>reconstructParMesh -latestTime
The following commands are similar to the step castellatedMesh, except that the mesh
files are copied and removed from folder 2 instead of folder 1.
To display only the mesh of the flange, without the blockmesh, remove the folders
polyMesh and domain0. The mesh between the .stl files and the blockmesh is labelled
as domain0.
The following command reconstructs the final mesh, depending on the settings in
snappyHexMeshDict.
If for example castellatedMesh an snap are set on true in the snappyHexMeshDict,
only the snapped mesh is reconstructed and stored, whereas the intermediate step snap
is overwritten.
If for example castellatedMesh, snap and addLayers are set on true in the
snappyHexMeshDict, only the layered mesh is reconstructed and stored and the
previous intermediate steps castellatedMesh and snap are overwritten.
In the case at hand for this tutorial, the layers are only necessary on the fluid side
which is labelled insideZone. The snappyHexMesh tools needs to have the files,
which have to be layered in the constant/polyMesh directory. Thereofre, in this case,
only the steps castellatedMesh and snap are set to true, as these steps are applied to
the whole mesh.
>reconstructParMesh -constant
As already mentioned above, the mesh around the flange is deleted with the following
command. Even so the files cellToRegion, as they are not needed in the further
process.
After reconstructing the mesh, only the mesh files of insideZone, which is the zone to
be layered, are copied to the /constant/polyMesh folder.
OpenFOAM® Basic Training
snappyHexMesh
>decomposePar
>reconstructParMesh -constant
After layering the inside of the flange domain, the snappyHexMeshDict is reset to
the previous settings.
The case is run similar to the chtMultiRegionHeater tutorial sample case which is
provided by OpenFoam.
Some adjustments are necessary to run the case and check if the mesh quality is
satisfactory.
- Copy the files alphat, epsilon, k, p, p_rgh, rho, T, U from the tutorial folder
/0 to the folder 0/insideZone
- Copy the files p, rho, T from the tutorial folder /0 to the folder 0/outsideZone
- Copy the radiationProperties and thermophysicalProperties from the
tutorial folder constant/heater to the folder constant/outsideZone
- Copy the g, radiationProperties, RASProperties,
thermophysicalProperties, and turbulenceProperties from the tutorial folder
constant/bottomAir to constant/insideZone
- Copy the regionProperties from the tutorial folder constant to the folder
constant and update the regions fluid (insideZone) and solid (outsideZone)
- Copy the controldict from the tutorial system folder to the folder system.
Change the start time to 0, the end time to 0.01, the writeInterval to 0.0005
and the max Courant number to 1.
- Copy the fvSchemes, fvSolution and changeDictionaryDict files from the
tutorial folders system/bottomAir and system/heater to the folders
system/insideZone and system/outsideZone respectively.
- Update the changeDictionaryDict of insideZone
remove the entry boundary
for the velocity
o set the velocity internalField to 1
o velocity inlet 1 is set to 1
o velocity inlet 2 is set to 2
o the outlet is set to zeroGradient
for the temperature
o set the internal field to 298
o temperature at inlet 1 is set to 773
o temperature at inlet 2 is set to 573
o the outlet is set to zeroGradient
o insideZone_to_outsideZone is has type
turbulentTemperatureCoupledBaffleMixed with value uniform
298
for the p_rgh
o the internal field is set to uniform 1e5
o the pressure at the outlet is set to fixedValue with value uniform
OpenFOAM® Basic Training
snappyHexMesh
1e5
o inlet 1 and inlet 2 are set to zeroGradient
o the boundary insideZone_to_outsideZone is set to
fixedFluxPressure with value uniform 1e5
for the p
o the internal field is set to uniform 1e5
o the pressure at the outlet is set to fixedValue with value uniform
1e5
o inlet 1 and inlet 2 are set to zeroGradient
o the boundary insideZone_to_outsideZone is set to calculated
with value uniform 1e5.
Update the changeDictionaryDict of outsideZone
o remove the entry boundary
o set outsideZone_to_domain0 type zeroGradient
o set outsideZone_to_insideZone type
compressible::turbulentTemperatureCoupledBaffleMixed
>decomposePar -allRegions
Reconstruct the mesh and convert the data to the Visualization ToolKit format.
>reconstructPar –allRegions
0.0005s 0.001s
0.0015 0.01s
0.0005s 0.0035s
OpenFOAM® Basic Training
snappyHexMesh
0.0085s 0.01s
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