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 Surface smoothing without any topological changes
31 meshSurfaceOptimizer.C
33 \*---------------------------------------------------------------------------*/
35 #ifndef meshSurfaceOptimizer_H
36 #define meshSurfaceOptimizer_H
38 #include "polyMeshGen.H"
40 #include "labelLongList.H"
43 #include "meshSurfaceEngine.H"
44 #include "parTriFace.H"
45 #include "meshSurfacePartitioner.H"
46 #include "partTriMesh.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 // Forward declarations
57 class meshSurfaceMapper;
60 /*---------------------------------------------------------------------------*\
61 Class meshSurfaceOptimizer Declaration
62 \*---------------------------------------------------------------------------*/
64 class meshSurfaceOptimizer
67 //- const reference to the mesh surface
68 const meshSurfaceEngine& surfaceEngine_;
70 //- type of surface vertex
71 List<direction> vertexType_;
73 //- locked faces which shall not be changed
74 labelLongList lockedSurfaceFaces_;
76 //- surface partitioner
77 const meshSurfacePartitioner* partitionerPtr_;
78 const bool deletePartitioner_;
80 //- pointer to mesh octree
81 const meshOctree* octreePtr_;
83 //- mesh of surface triangles needed for some smoothers
84 mutable partTriMesh* triMeshPtr_;
86 //- enforce constraints
87 bool enforceConstraints_;
89 //- name of the subset contaning tangled points
90 word badPointsSubsetName_;
92 // Private member functions
93 //- classify surface vertices as PARTITION, EDGE, CORNER
94 void classifySurfaceVertices();
96 //- calculate surface triangulation
97 void calculateTrianglesAndAddressing() const;
98 inline const partTriMesh& triMesh() const;
99 inline void updateTriMesh(const labelLongList&);
100 inline void updateTriMesh();
102 //- find vertices which are inverted
103 //- mark additional layers of vertices near the inverted ones
104 label findInvertedVertices
106 boolList& smoothVertex,
107 const label nAdditionalLayers = 2
110 //- transform into a 2D space in plane
111 inline bool transformIntoPlane
118 DynList<triFace>& trias
121 //- new position of a node after laplacian smoothing
122 //- the position is the average of neighbouring vertex positions
123 inline point newPositionLaplacian
126 const bool transformIntoPlane = true
129 //- new position of a node after laplacian smoothing
130 //- the position is the average of neighbouring face centres
131 inline point newPositionLaplacianFC
134 const bool transformIntoPlane = true
137 //- new position of a node after laplacian smoothing
138 //- the position is the weighted average of neighbouring face centres
139 //- the weights are the magnitudes of neighbouring face area vectors
140 inline point newPositionLaplacianWFC
143 const bool transformIntoPlane = true
146 //- new position of a node after using surfaceOptimizer
147 inline point newPositionSurfaceOptimizer
150 const scalar tol = 0.001
153 //- new position of edge vertex
154 //- the position is the average of neighbouring edge vertices
155 inline point newEdgePositionLaplacian(const label bpI) const;
157 //- smooth the node using the laplacian smoother
158 //- new position is the average of the neighbouring vertices
159 void nodeDisplacementLaplacian
162 const bool transformIntoPlane = true
165 //- smooth the node using the laplacian smoother
166 //- new position is the average of the centres of faces attached
168 void nodeDisplacementLaplacianFC
171 const bool transformIntoPlane = true
174 //- smooth the node using surface optimizer
175 void nodeDisplacementSurfaceOptimizer
178 const scalar tol = 1.0
182 void edgeNodeDisplacement(const label bpI) const;
184 //- smooth selected edge points
185 void smoothEdgePoints
187 const labelLongList& edgePoints,
188 const labelLongList& procEdgePoints
191 //- smooth selected points using laplaceFC
192 void smoothLaplacianFC
194 const labelLongList& selectedPoints,
195 const labelLongList& selectedProcPoints,
196 const bool transform = true
199 //- smooth selected points using surface optimizer
200 void smoothSurfaceOptimizer
202 const labelLongList& selectedPoints,
203 const labelLongList& selectedProcPoints
206 // Functions needed for parallel runs
208 //- transfer data between processors
211 const labelLongList& nodesToSmooth,
212 std::map<label, DynList<parTriFace> >& m
215 //- laplacian smoothing of points at processor boundaries
216 //- new position is the average of the neighbouring vertices
217 void nodeDisplacementLaplacianParallel
219 const labelLongList& nodesToSmooth,
220 const bool transformIntoPlane = true
223 //- laplacian smoothing of points at processor boundaries
224 void nodeDisplacementLaplacianFCParallel
226 const labelLongList& nodesToSmooth,
227 const bool transformIntoPlane = true
230 //- smooth edge nodes at processor boundaries
231 void edgeNodeDisplacementParallel
233 const labelLongList& nodesToSmooth
236 //- Disallow default bitwise copy construct
237 meshSurfaceOptimizer(const meshSurfaceOptimizer&);
239 //- Disallow default bitwise assignment
240 void operator=(const meshSurfaceOptimizer&);
256 //- Construct from mesh surface
257 meshSurfaceOptimizer(const meshSurfaceEngine&);
259 //- Construct from partitioner
260 meshSurfaceOptimizer(const meshSurfacePartitioner&);
262 //- Construct from mesh surface and octree
263 meshSurfaceOptimizer(const meshSurfaceEngine&, const meshOctree&);
265 //- Construct from partitioner and octree
268 const meshSurfacePartitioner&,
275 ~meshSurfaceOptimizer();
278 //- lock the boundary faces which shall not be modified
279 template<class labelListType>
280 inline void lockBoundaryFaces(const labelListType&);
282 //- lock boundary points. They are not be moved.
283 template<class labelListType>
284 inline void lockBoundaryPoints(const labelListType&);
287 inline void lockFeatureEdges();
289 //- reset to default constraints
290 void removeUserConstraints();
292 //- Flag stopping the meshing process if it is not possible
293 //- to untangle the surface without sacrificing geometry constraints
294 //- Points which must be moved away from the required position are
295 //- stored into a point subset
296 void enforceConstraints(const word subsetName="badPoints");
298 //- runs a surface smoother on the selected boundary points
301 const labelLongList& activeBoundaryPoints,
302 const label nAdditionalLayers = 0
305 //- checks for invertex surface elements and tries to untangle them
306 //- it tries to keep the points on the surface for a couple
307 //- of iteration and gives up the final iterations
308 //- by default, it smooths two additional layers of elements
309 //- around the inverted ones
310 bool untangleSurface(const label nAdditionalLayers = 2);
312 //- optimize boundary nodes after boundary regions are created
313 void optimizeSurface(const label nIterations = 5);
315 //- optimize the surface of a 2D mesh
316 void optimizeSurface2D(const label nIterations = 5);
318 //- untangle the surface of a 2D mesh
319 void untangleSurface2D();
323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 } // End namespace Foam
327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329 #include "meshSurfaceOptimizerI.H"
331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 // ************************************************************************* //