Written by: M. van der Eijk 3-8-2023
...
Choice of meshing tool:
Below a flowchart for choosing a meshing tool is shown. This document describes the workflow for CfMesh. Documents for the meshing tools Salome, SnappyHexMesh (SHM), and Gmsh are still under construction and not part of this document.
The starting point of this document is using Salome and requires some understanding of how to use Salome. Some additional information about how to check the mesh quality is added.
General introduction CfMesh
A manual description of using CfMesh is given in User_Guide-cfMesh_v1.1.pdf. This document is supplementary to describe the workflow for using CfMesh in combination with OpenFOAM.
“CfMesh is a cross-platform library for automatic mesh generation that is built on top of OpenFOAM. CfMesh supports various 3D and 2D workflows, built by using components from the main library, which are extensible and can be combined into various meshing workflows. The core library utilizes the concept of mesh modifiers, which allows for efficient parallelization using both shared memory parallelization (SMP) and distributed memory parallelization using MPI. In addition, special care has been taken on memory usage, which is kept low by implementing data containers (lists, graphs, etc.) that do not require any dynamic memory allocation operations during the meshing process.”
CfMesh can produce cartesian meshes (2D and 3D), tetrahedral meshes, and polyhedral meshes. The functions behind these kinds of meshes remain the same. The execution is done by the command cartesianMesh, cartesian2DMesh, tetMesh, or pMesh, respectively.
The differences and similarities between cfMesh and SnappyHexMesh are given in Figure 01. The most important conclusion is that CfMesh is in general faster than SnappyHexMesh and the boundary layer meshing is more reliable.
Figure 01: Similarities and differences CfMesh compared with SnappyHexMesh. Reference: Wolf dynamics.
Procedure for using CfMesh
Requirements
The following software/packages/files are needed:
- Salome (v 9.1.0 or higher).
- Python 3 (tested for v 3.7 or higher).
- OpenFOAM (tested for v2012).
- cfMesh built on top of OpenFOAM (v 1.1.2 or higher).
- e.g. OpenFOAM-v2012/modules/cfmesh/…
- Contains a guide for explanation.
- Modified python 3 files (ask martin.vandereijk@deltares.nl)
- The python files in the module cfMesh are outdated.
- ExtractFeatureEdges3.py and salomeTriSurf3.py.
- Template meshDict file defining the mesh (ask martin.vandereijk@deltares.nl) positioned in folder ‘system’.
- Template bash file to run the full procedure (ask martin.vandereijk@deltares.nl).
Global procedure
Below the steps needed for pre-meshing and pro-meshing are given. In red: the path of the tutorial files is given:
- Generation of fluid domain
- Output: preferably ‘step’ or ‘brep’ file of the fluid domain that needs to mesh. Working with an ‘stl’ file requires some additional steps when using Salome. (docs/solarPanel.brep)
...
- FMS file (best input for cfMesh) preparation
- Open Salome and load in the CAD model with the fluid domain. (docs/solarPanel.brep)
- Go to the geometry module by opening.
- Select patches in Salome and/or refinement boundaries you want.
- Geometry: New entity -> group -> create group
- Press surface as shape type, fill in the name of the patch that matches the name of your working directory in OpenFOAM, press the arrow and select the surface, apply, and start with the next patch.
- Extract edges covering the domain.
- Geometry: Select geometry -> press CTRL+t-> select ExtractFeatureEdges3.py
- Check the feature edges. Are these the main edges that describe the domain? If not remove the ones you do not need.
- Generate surface Mesh.
- Go to the mesh module, and press
- Mesh for 2D -> algorithm NETGEN 1D-2D -> set settings to represent the shape.
- Apply and close.
- Build the 2D mesh using the gear tool
- Delete the groups and edges in the mesh directory (only if it contains not only the name of the patches you gave).
- Open the generated mesh.
- Open either groups or edges and remove everything from groups and edges.
- Mesh: select the mesh in the toolbar -> go to mesh -> create groups from geometry -> select the patches and featureEdges -> Apply and close
- The groups and edges should now appear again.
- Output as FMS file.
- Do not use surfaceFeatureEdges module. It can lose data (stl -> fms).
- Mesh: select the mesh -> press CTRL+t -> Open SalomeTriSurf.py
- In the command shell of Salome (python): type triSurf('<path>').writeFms('<filename>.fms') and press enter
- File is generated on the given path (usually the OpenFOAM directory -> folder called ‘surfaceMeshes’).
- Mesh using CfMesh
- <see next section>
- Makes use of docs/solarPanel.stl, docs/solarPanel.fms
- Check the mesh for quality
- Use the checkMesh utility of OpenFOAM.
- Improve the mesh with improveMeshQuality.
- This reads the meshDict file and uses the defined settings again for improving the mesh.
Mesh using CfMesh
Meshing with CfMesh is done using a meshDict file. The file should be positioned in the working directory (OpenFOAM) in the folder ‘system’. A .FMS file is required for the best quality meshing and has the format that CfMesh can directly read (including patches). The structure of meshDict is:
...
boundaryCellSize …;
minCellSize …;
….
objectRefinements{
...
}
localRefinement{
...
}
...
}
boundaryLayers{
...
patchBoundaryLayers{
...
}
optimisationParameters{
...
}
}
renameBoundary{
...
}
There are more options (see CfMesh manual), but these are most often used. The manual explains the options that can be used in each refinement part.
Steps for making a mesh:
- Make mesh without boundary layer iteratively to increase the quality (checkMesh).
- Option to improve mesh quality is the utility improveMeshQuality.
- In gaps use mesh cells with a maximum cell size smaller than half of the gap width.
- Capture the whole object in one object refinement region to prevent skewness problems.
- Make the mesh with boundary layer iteratively and improve the quality such that it meets the requirements.
- Layer addition remains an art and asks the most time.
- Boundary layer thickness rate should not exceed 1.3.
- The added layers are generated in the cell attached to the patch/object. This means that the total thickness of the added layers can never exceed the cell size and can give smoothness problems.
- If you are not managing the quality, you can change the optimization settings a bit.
The file can be executed either with the command cartesianMesh, pMesh, or tetMesh.
Bash file running mesh using CfMesh
The template bash file running the meshDict file consists of multiple steps. It requires three inputs now. The positions of the FMS-file, the meshDict file, and the STL-file for surface refinement. To run the meshDict, a controlDict is also needed. The structure is:
- Checking the surface mesh quality, creating a directory for the surfaceMesh and copying to this folder, and creating a ParaView file.
- Log file produced with check if the surface mesh (FMS) is good.
- Production of a VTK-file to show the surfaceMesh in ParaView.
- (Decomposing if necessary).
- Generate the volume mesh and check the mesh.
- Choice can be made to do multi-threading when memory is too small. Decomposition is needed.
- The STL file is for adding refinement at the object and is not mandatory.
- cartesianMesh can be replaced either by pMesh or tetMesh.
- checkMesh is performed.
- Produce output of bad quality mesh cells if existing to illustrate in ParaView.
- Non-orthogonal cells.
- Skew faces.
- Wrong-oriented faces.
- Zero volume cells.
Mesh quality
The mesh quality check is done in OpenFOAM using the utility checkMesh. This section is based on the output generated by checkMesh. The quality checks are explained beneath, and a thumb-rule value (for indication) is given for mesh quality. The results using cfMesh and snappyHexMesh are compared at the end.
Explanation of mesh quality terms
A brief explanation of mesh quality is given below:
Non orthogonality
- Affects gradient of the face center of the cell (difference between orange and black).
- Adds diffusion to the solution.
- Mainly affects the diffusive terms.
- Maximum of 80.
Smoothness
- Expansion rate, growth, or uniformity.
- Adds diffusion when large.
- Maximum change should be less than 20% (30%).
Aspect ratio
- Ratio between dx and dy.
- Large AR is ok if gradients in the largest direction are small.
- It smears the gradients.
- Should be lower than 80.
Skewness
- Deviation of the black vector and the face center f.
- Affects the interpolation.
- Adds diffusion.
- Affects the convective term.
- Does not play a role when using upwind.
- When solution is uniform not a problem.
- Maximum of 8.
Cells at boundary
- Cell face aligned with flow results in a smaller error in flow and gradients (truncation).
- In general: hexahedral is more accurate.
- Easily aligned with the flow.
- Stretched to resolve BL without losing much quality.
- Prefered for force calculations.
- Without dominant flow direction: hex has no advantage anymore.
- Polyhedral approximates better in that case the gradients.
- Skewness can be a problem -> oscillatory due to more faces.
- Growth rate control and volumetric refinement are difficult.
- Tetrahedal fewer faces:
- Fewer problems with oscillatory results.
- Growth rate is easily controlled.
- Larger truncation errors at the wall.
- Can easily adapt to a structure.
- Needs more computing resources but less mesh time.
- Small changes in flow -> larger mesh cells can be used.
Comparison CfMesh and SnappyHexMesh
A comparison between CfMesh and SnappyHexMesh in performance is shown in Table 1. The results are to the advantage of CfMesh. The SnappyHexMesh includes snapping and layering and is run parallel on 2 cores. CfMesh is performed without external parallelization. Note that the statistics are given as examples but also depend on the amount of optimization iterations and thresholds.
Table 1: Mesh quality and creation comparison CfMesh and SnappyHexMesh including boundary layer for 0[deg] rotated solar panel array.
Layers vs (no Layers) | CfMesh (OS) | SnappyHexMesh (example) |
No. layers requested [-] | 10 | 7 |
Expansion rate [-] | 1.3 | 1.3 |
CPU time [s] | 292 (110) | 6398 (3630) |
Grid cells [mil.] | 9.5 (5.5) | 12.3 (10.9) |
Hex [%] | 95.7 (94.8) | 96.7 (97.1) |
Max. aspect [-] | 162.4 (6.8) | 23.2 (5.8) |
Max. non-orthogonal [deg] | 79 (56) | 65 (58) |
Max. skewness [-] | 2.66 (1.78) | 20.5 (16.5) |
It has to be said that the CPU time increases a lot when increases either the expansion rate or the number of layers.
Examples of a mesh generated by CfMesh and SnappyHexMesh including boundary layers are illustrated in Figure 01 (sense hub gap between rotated floating solar panels) and Figure 02 (from literature).
Figure 01: BL In gap between four solar panels when 22.5 [deg] rotated with CfMesh (left) while SnappyHexMesh cannot produce it after a couple of tries tweaking the many options (right).
Figure 02: CfMesh (left) vs SnappyHexMesh (right) from literature.