1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 cfMesh is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
28 Mesh smoothing without any topological changes
33 \*---------------------------------------------------------------------------*/
35 #ifndef meshOptimizer_H
36 #define meshOptimizer_H
38 #include "polyMeshGen.H"
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 // Forward declarations
53 class meshSurfaceEngine;
57 /*---------------------------------------------------------------------------*\
58 Class meshOptimizer Declaration
59 \*---------------------------------------------------------------------------*/
64 //- reference to the mesh
67 //- location of vertex (internal, boundary, edge, corner)
68 List<direction> vertexLocation_;
70 //- locked faces which shall not be changed
71 labelLongList lockedFaces_;
74 mutable meshSurfaceEngine* msePtr_;
76 //- enforce constraints
77 bool enforceConstraints_;
79 //- name of the subset contaning tangled points
80 word badPointsSubsetName_;
82 // Private member functions
83 //- return mesh surface
84 const meshSurfaceEngine& meshSurface() const;
87 //- find problematic faces
88 label findBadFaces(labelHashSet&, const boolList&) const;
89 label findLowQualityFaces(labelHashSet&, const boolList&) const;
91 //- mark point locations
92 void calculatePointLocations();
99 //- reference to the mesh
102 //- location of vertex (internal, boundary, edge, corner)
103 const List<direction>& vertexLocation_;
105 // Private member functions
106 //- smooth the node using the laplacian smoother
107 //- new position is the average of the neighbouring vertices
108 void laplacian(const labelLongList&, const label);
109 void laplacianSurface(const labelLongList&, const label);
111 void laplacianParallel
113 const labelLongList& procPoints,
114 const bool smoothOnlySurfaceNodes = false
117 //- smooth the node using the laplacian smoother
118 //- new position is the average of the centres of faces attached
120 void laplacianPC(const labelLongList&, const label);
121 void laplacianPCParallel(const labelLongList& procPoints);
123 //- smooth the node using the laplacian smoother
124 //- new position is the average of the centres of faces attached
126 void laplacianWPC(const labelLongList&, const label);
127 void laplacianWPCParallel(const labelLongList& procPoints);
129 //- update geometry after smoothing
130 void updateMeshGeometry(const labelLongList& smoothPoints);
132 //- Disallow default bitwise copy construct
133 laplaceSmoother(const laplaceSmoother&);
135 //- Disallow default bitwise assignment
136 void operator=(const laplaceSmoother&);
142 //- Construct from mesh and vertex locations
143 laplaceSmoother(polyMeshGen&, const List<direction>&);
150 //- new position is the average of the neighbouring vertices
151 void optimizeLaplacian(const label nIterations = 1);
152 void optimizeLaplacian
154 const labelHashSet& badFaces,
155 const label nIterations = 1
158 //- new position of surface point is the average of
159 //- the neighbouring surface vertices
160 void optimizeSurfaceLaplacian
162 const labelHashSet& badFaces,
163 const label nIterations = 1
166 //- new positions are the average of the centres of the cells
167 //- adjacent to the vertex
168 void optimizeLaplacianPC(const label nIterations = 1);
169 void optimizeLaplacianPC
171 const labelHashSet& badFaces,
172 const label nIterations = 1
175 //- new positions are the average of the centres of the cells
176 //- adjacent to the vertex weighted by cell volumes
177 void optimizeLaplacianWPC(const label nIterations = 1);
178 void optimizeLaplacianWPC
180 const labelHashSet& badFaces,
181 const label nIterations = 1
185 //- Disallow default bitwise copy construct
186 meshOptimizer(const meshOptimizer&);
188 //- Disallow default bitwise assignment
189 void operator=(const meshOptimizer&);
198 PARALLELBOUNDARY = 16,
206 //- Construct from mesh
207 meshOptimizer(polyMeshGen& mesh);
215 //- Flag stopping the meshing process if it is not possible
216 //- to untangle the surface without sacrificing geometry constraints
217 //- Points which must be moved away from the required position are
218 //- stored into a point subset
219 void enforceConstraints(const word subsetName="badPoints");
221 //- lock the cells which shall not be modified
222 template<class labelListType>
223 inline void lockCells(const labelListType&);
225 //- lock cells which shall not be modified
226 //- contained inside the specified subset
227 void lockCellsInSubset(const word& subsetName);
229 //- lock the faces whih shall not be modified
230 template<class labelListType>
231 inline void lockFaces(const labelListType&);
233 //- lock faces which shall not be modified
234 //- stored in a face subset
235 void lockFacesInSubset(const word& subsetName);
237 //- lock points which shall not be moved
238 template<class labelListType>
239 inline void lockPoints(const labelListType&);
241 //- lock points which shall not be modified
242 //- given as a point subset
243 void lockPointsInSubset(const word& subsetName);
245 //- reset to default constraints
246 void removeUserConstraints();
248 //- smooth surface vertices
249 void optimizeSurface(const meshOctree&);
251 //- performs mesh untangling based on detected negative normals
252 //- a global iteration consists of maxNumIterations iterations when
253 //- only internal points are moved and maxNumSurfaceIterations when
254 //- surface points are moved
257 const label maxNumGlobalIterations = 10,
258 const label maxNumIterations = 50,
259 const label maxNumSurfaceIterations = 2,
260 const bool relaxedCheck = false
263 //- performs optimisation of boundary layer cells
264 //- it is applied to the first boundary layer, only
265 void optimizeBoundaryLayer(const bool addBufferLayer = true);
267 //- performs untangling of boundary layer cells
268 //- if the user requests for it
269 void untangleBoundaryLayer();
271 //- performs mesh optimisation for faces with high non-orthogonality
273 void optimizeLowQualityFaces(const label maxNumIterations = 10);
275 //- perform optimization of cells near the boundary
276 //- the use shall specify the number of iterations and the number
277 //- of cell layers which shall be taken into account
278 void optimizeMeshNearBoundaries
280 const label maxNumIterations = 10,
281 const label numLayersOfCells = 2
284 //- final optimisation
287 const label numLaplaceIterations = 5,
288 const label maxNumGlobalIterations = 10,
289 const label maxNumIterations = 50,
290 const label maxNumSurfaceIterations = 2
293 //- greedy optimisation until the mesh can be improved
294 void optimizeMeshFVBestQuality
296 const label maxNumIterations = 50,
297 const scalar threshold = 0.1
302 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
304 } // End namespace Foam
306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
308 #include "meshOptimizerI.H"
310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
314 // ************************************************************************* //