SmoothMesh
OpenFOAM mesh smoothing tool to improve mesh quality
Install / Use
/learn @tkeskita/SmoothMeshREADME
smoothMesh
<img src="images/smooth_mesh.png"/>OpenFOAM mesh smoothing tool to improve mesh quality. Moves mesh points by using primarily the Centroidal smoothing algorithm (a version of the Laplacian smoothing algorithm, which uses surrounding cell centers instead of the neighbour point locations to calculate the new point position). Midpoint of two closest points is applied instead of centroidal point for prismatic high aspect ratio points. Optional heuristic quality constraint options exist to constrain the smoothing, to avoid self-intersections. No changes to mesh topology are made.
Image below illustrates the need for restricting centroidal smoothing. Without quality constraints, centroidal smoothing would move the point highlighted in blue to the location highlighted with green, which is outside of the domain. Thereby, unconstrained centroidal smoothing can create self-intersecting cells, depending on the geometry and topology of the mesh. Self-intersections can be avoided by using additional quality constraints, which restrict the movement of vertices.
<img src="images/base_mesh_with_problematic_vertex.png" width="300"/>Current features and restrictions
- Works on 3D polyhedron meshes (2D meshes are not supported)
- Tested on both OpenFOAM.org v12 and OpenFOAM.com v2412 (likely works on older and possibly also on newer versions)
- Can be run in parallel or in serial
- Requires a consistent (not self-intersecting or tangled) initial mesh with "good enough" quality
- Smoothes internal and (optionally) boundary mesh points
- Optionally controls the thickness and orthogonality of prismatic boundary layers to preserve / create boundary layers using existing mesh cells
- Does not (yet) support meshes with baffles, periodic boundaries or multiple regions in the mesh.
Compilation instructions
You need to first source OpenFOAM in a terminal, then compile with
./Allwclean; ./Allwmake
You can optionally run the test cases (they will be copied to folder
run_tests) after compilation with
./run_tests.sh
Command line options
Basic options
-
-centroidalItersspecifies the maximum number of smoothing iterations (default 1000). -
-relTolis the relative tolerance convergence criteria for stopping smoothing iterations (default 0.02). If residual (maximum length of point moved relative tomaxStepLength) drops below this value, then smoothing is stopped. -
-minEdgeLengthdefines edge length below which edge points are fully frozen at their current location. Freezing happens only if edge length would decrease during smoothing. Edge length is allowed to increase regardless of this value. If no value is provided, a default value of half the length of the shortest edge in the initial mesh is applied. -
-maxStepLengthis the maximum allowed length (in metres) for moving a point in one iteration. Smoothing process seems to be stable when this value is in the range 10% - 50% of the minimum cell side length. If no value is specified, a default value of 0.3 times theminEdgeLengthis applied. -
-relStepFracis a relative step scaling factor, which scales the local step length proposed by smoothing algorithms. It is applied to increase stability of the smoothing process (default value 0.5). -
-totalMinFreezeoption causes mesh points on all edges shorter than-minEdgeLengthto freeze, even if edge length would increase in smoothing (default false). This option is useful to keep boundary layers in the mesh unmodified, and smooth the large cells only, if the special boundary layer related options below are not used. -
-writeIntervaloption writes mesh at the interval of given number of iterations, e.g. value 10 causes write every tenth iteration (default value is same ascentroidalIters).
Quality constraint options
The following options are related to additional heuristic quality control constraints for smoothing. The constraints work by disallowing movement of point (freezing of points) if the movement would cause quality of the mesh to suffer too much. Without constraining, centroidal smoothing may squish cells and create self-intersecting cells e.g. near concave geometry features, depending on the mesh details. Have a look at the algorithm description document for details.
-
-edgeAngleConstraintboolean option enables an additional quality control which restricts decrease of smallest edge-edge angle belowminAngle(default is true). -
-faceAngleConstraintboolean option enables an additional quality control which restricts decrease of smallest and largest face-face angle belowminAngleand abovemaxAngle(default is true). -
-minAngleoption defines the value for minimum angle (in degrees, default value 35). -
-maxAngleoption specifies the value for maximum angle (in degrees, default value 160). -
Note:
-minAnglevalue causes point freezing only if the minimum angle is below this value and if the minimum angle would decrease in smoothing. Points are allowed to move if the minimum angle value increases with smoothing, regardless of this value. The same applies for the-maxAngleoption: Freezing takes place only if maximum angle is above the specified value and if the maximum angle would increase in smoothing.
Boundary point smoothing options
Warning: This is a new and experimental feature!
SmoothMesh has a possibility to move and smooth also boundary points. The usage of this feature requires that the user provides following files in the constant/geometry folder in the case directory in Wavefront OBJ format:
-
constant/geometry/targetSurfaces.obj(required). This surface mesh file must contain the target surface mesh for all boundary surfaces. The boundary points (other than feature edge points) are projected to closest triangulated surface mesh face provided in this file. The surface mesh can be generated e.g. byExtract SurfaceFilter in Paraview, orsurfaceMeshTriangulatecommand in OpenFOAM. -
constant/geometry/initEdges.obj(required). This edge mesh file must contain the initial feature edges (sharp edges) of the whole initial mesh. This edge mesh is used to identify which points in the initial mesh are feature edge and corner points. The point classification information is saved toisFeatureEdgePointandisCornerPointfiles, and imported from those files upon consequtive runs, so thatinitEdges.objdoes not have to be updated in between runs. Identification of points is based on projection of boundary mesh points to edges ininitEdges.obj. Feature edge mesh can be generated e.g. byExtract SurfaceFilter followed byFeature EdgesFilter in Paraview, or bysurfaceFeaturesorsurfaceFeatureExtractcommands in OpenFOAM. -
constant/geometry/targetEdges.obj(optional). This edge mesh file must contain the edge mesh locations for the final target mesh. IftargetEdges.objis provided, the points on the initial feature edges are projected to these edges during smoothing. IftargetEdges.objis not provided, then target edge mesh is assumed to be identical to the initial feature edge mesh. In practice, the result of providing notargetEdges.objis that feature edges stay in their initial locations, but edge points may still move along the feature edges. However, providingtargetEdges.objallows projection of e.g. linear block mesh edges to curves.
Options for smoothMesh related to boundary point smoothing:
-
-smoothingPatchesoption is used to limit the boundary point movement to specified patches only. You can specify one or several patches, optionally with wild cards. For example-smoothingPatches '(walls)'or-smoothingPatches '(stator "rotor.*")'. All patches are included in smoothing by default, so if you provide the above OBJ files in the constant/geometry directory, boundary point smoothing will be applied. -
-internalSmoothingBlendingFractionis related to how the location of the surface points on free boundaries (but not feature edges nor corners!) are calculated. Two methods are applied: Projection of coordinates from centroidal smoothing to closest boundary surface, and projection of inner mesh prismatic point to closest boundary surface. This fraction value specifies the blending (value between 0 and 1) for the inner mesh prismatic point. Value close to 0 means that centroidal smoothing dominates, which results in good boundary surface smoothing. Value close to 1 means that inner mesh point projection dominates, which results in highly orthogonal prismatic boundary edges at the cost of increased cell aspect ratio. The default value of 0 applies only centroidal smoothing. Note: More work is needed to study the effect of this value on the results.
Note: Always view the initial mesh and all OBJ files visually in Paraview for correctness before use!
Example from testcase4 is illustrated below.
<img src="images/boundary_point_smoothing.png" width="600"/>Boundary layer treatment related options
The options below are related to handling of prismatic cells near mesh boundaries, to either preserve or improve the orthogonality and control the thickness of boundary layer cells in the mesh. If the mesh contains prismatic boundary layers, the unconstrained centroidal smoothing will tend to bloat the boundary layer cells into normal size. That can be avoided using the options below. These options affect only the prismatic cell edges near the mesh boundaries (see the algorithm description document for details).
Warning: This is an experimental feature!
-layerPatchesoption is used to limit the boundary layer treatment to cells next to specified patches only. You can specify one or several patches, optionally with wild cards. For example-layerPatches '(walls)'or-layerPatches '(stator "rotor.*")'. No
Related Skills
node-connect
354.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
112.3kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
354.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
354.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
