Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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. 

 Image Removed

 

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.  

 Image Removed

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. 
  • The python files in the module cfMesh are outdated.  
  • ExtractFeatureEdges3.py and salomeTriSurf3.py. 

Global procedure 

Below the steps needed for pre-meshing and pro-meshing are given. In red: the path of the tutorial files is given: 

  1. Generation of fluid domain 
    1. Output: preferably ‘step’ or ‘brep’ file of the fluid domain that needs to mesh.  Working with a simple ‘stl’ file requires some additional steps when using Salome. (docs/solarPanel.brep) 

...

  1. Go to the geometry module by opening.

...

  1. Geometry: New entity -> group -> create group  
  2. 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.

...

  1. Geometry: Select geometry -> press CTRL+t-> select ExtractFeatureEdges3.py 
  2. Check the feature edges. Are these the main edges that describe the domain? If not remove the ones you do not need.

...

  1. Go to the mesh module, and press  
  2. Mesh for 2D -> algorithm NETGEN 1D-2D -> set settings to represent the shape.
  3. Apply and close.
  4. Build the 2D mesh using the gear tool  

...

  1. Unfold the generated mesh.
  2. Unfold either groups or edges and remove everything from groups and edges.
  3. Mesh: select the mesh in the toolbar -> go to mesh -> create groups from geometry -> select the patches and featureEdges -> Apply and close
  4. The groups and edges should now appear again.

...

  1. Do not use surfaceFeatureEdges module. It can lose data (stl -> fms).
  2. Mesh: select the mesh -> press CTRL+t -> Open SalomeTriSurf.py
  3. In the command shell of Salome (python): type triSurf('<path>').writeFms('<filename>.fms') and press enter
  4. File is generated on the given path (usually the OpenFOAM directory -> folder called ‘surfaceMeshes’).

...

  1. 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: 

surfaceFile “…”; 

                          

maxCellSize …; 

boundaryCellSize …; 

minCellSize …; 

…. 

objectRefinements{ 

… 

localRefinement{ 

… 

}

surfaceMeshRefinement{

<solarPanel.stl> 

… 

boundaryLayers{ 

… 

patchBoundaryLayers{ 

… 

optimisationParameters{ 

… 

renameBoundary{ 

…  

(mandatory) <solarPanel.fms> 

(mandatory) 

<Define shapes like box, cone for refining a volume area in mesh> 

<Set refinement of a patch as defined by the geometry file> 

<Refinement surface meshed provided by additional surface files (STL)> 

<Set the boundary layers global refinement> 

<Set the boundary layers at a patch> 

<Optimisation settings for boundary layers, often use original values> 

<Rename or define patches>

 

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: 

...

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: 

...

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. 

 Image Removed

  • Maximum of 80. 

 

Smoothness 

  • Expansion rate, growth, or uniformity. 
  • Adds diffusion when large. 
  • Maximum change should be less than 20% (30%). 

 Image Removed

 

Aspect ratio 

...

 Image Removed

 

Skewness 

  • Deviation of the black vector and the face center f. 

 Image Removed

  • 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). 

 Image Removed

...

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). 

 Image Removed                                                              

Image RemovedImage Removed

Figure 01: BL In gap between four solar panels when 22.5 [deg] rotated with CfMesh (top) while SnappyHexMesh cannot produce it after a couple of tries tweaking the many options (bottom). 

 Image Removed

Figure 02: CfMesh (left) vs SnappyHexMesh (right) from literature.