You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Current »

Written by:         M. van der Eijk       3-8-2023 

Reviewed by:      D. Pavilons             22-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. 
  • 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. When a structure is loaded and not the fluid domain, go to the next step, otherwise go to 2.
    1. Fluid domain can also be obtained using Boolean subtraction (in Salome) of the structure when only the structure is loaded.  
      1. Perform inspections of the structure: self-intersections and free boundaries are not allowed.
      2. Make a solid of the structure.  
      3. Make the fluid domain based on points and create a box of it.
      4. Cut the domain with the structure.
  1. FMS file (best input for cfMesh) preparation
    1. Open Salome and load in the CAD model with the fluid domain. (docs/solarPanel.brep)
      1. Go to the geometry module by opening.
    2. Select patches in Salome and/or refinement boundaries you want.
      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.
    3. Extract edges covering the domain.
      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.
    4. Generate surface Mesh.
      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  
    5. Delete the groups and edges in the mesh directory (only if it contains not only the name of the patches you gave).
      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.
    6. Output as FMS file.
      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’).
  2. Mesh using CfMesh
    1. <see next section>
    2. Makes use of when following the tutorial when you did not prepare a structure: docs/solarPanel.stl, docs/solarPanel.fms
  3. Check the mesh for quality
    1. Use the checkMesh utility of OpenFOAM.
    2. Improve the mesh with improveMeshQuality.
      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: 

  • 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: 

  1. Checking the surface mesh quality, creating a directory for the surfaceMesh and copying to this folder, and creating a ParaView file.
    1. Log file produced with check if the surface mesh (FMS) is good.
    2. Production of a VTK-file to show the surfaceMesh in ParaView.
  2. (Decomposing if necessary).
  3. Generate the volume mesh and check the mesh.
    1. Choice can be made to do multi-threading when memory is too small. Decomposition is needed.
    2. The STL file is for adding refinement at the object or a refinement region and is not mandatory.
    3. cartesianMesh can be replaced either by pMesh or tetMesh.
    4. checkMesh is performed.
  4. Produce output of bad quality mesh cells if existing to illustrate in ParaView.
    1. Non-orthogonal cells. 
    2. Skew faces.
    3. Wrong-oriented faces.
    4. 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 (top) while SnappyHexMesh cannot produce it after a couple of tries tweaking the many options (bottom). 

 

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



  • No labels