meshOptimizer.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Class
25  meshOptimizer
26 
27 Description
28  Mesh smoothing without any topological changes
29 
30 SourceFiles
31  meshOptimizer.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef meshOptimizer_H
36 #define meshOptimizer_H
37 
38 #include "polyMeshGen.H"
39 #include "boolList.H"
40 #include "VRWGraph.H"
41 #include "DynList.H"
42 #include "partTet.H"
43 #include "HashSet.H"
44 #include "boundBox.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward declarations
52 class meshOctree;
53 class meshSurfaceEngine;
54 class plane;
55 class partTetMesh;
56 
57 /*---------------------------------------------------------------------------*\
58  Class meshOptimizer Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class meshOptimizer
62 {
63  // Private data
64  //- reference to the mesh
66 
67  //- location of vertex (internal, boundary, edge, corner)
69 
70  //- locked faces which shall not be changed
72 
73  //- mesh surface
74  mutable meshSurfaceEngine* msePtr_;
75 
76  //- enforce constraints
78 
79  //- name of the subset contaning tangled points
81 
82  // Private member functions
83  //- return mesh surface
84  const meshSurfaceEngine& meshSurface() const;
85  void clearSurface();
86 
87  //- find problematic faces
88  label findBadFaces(labelHashSet&, const boolList&) const;
90 
91  //- mark point locations
93 
94  // Nested classes
95 
96  class laplaceSmoother
97  {
98  // Private data
99  //- reference to the mesh
101 
102  //- location of vertex (internal, boundary, edge, corner)
104 
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);
110 
111  void laplacianParallel
112  (
113  const labelLongList& procPoints,
114  const bool smoothOnlySurfaceNodes = false
115  );
116 
117  //- smooth the node using the laplacian smoother
118  //- new position is the average of the centres of faces attached
119  //- to the vertex
120  void laplacianPC(const labelLongList&, const label);
121  void laplacianPCParallel(const labelLongList& procPoints);
122 
123  //- smooth the node using the laplacian smoother
124  //- new position is the average of the centres of faces attached
125  //- to the vertex
126  void laplacianWPC(const labelLongList&, const label);
127  void laplacianWPCParallel(const labelLongList& procPoints);
128 
129  //- update geometry after smoothing
130  void updateMeshGeometry(const labelLongList& smoothPoints);
131 
132  //- Disallow default bitwise copy construct
134 
135  //- Disallow default bitwise assignment
136  void operator=(const laplaceSmoother&);
137 
138  public:
139 
140  // Constructor
141 
142  //- Construct from mesh and vertex locations
144 
145  // Destructor
146 
148 
149  // Member Functions
150  //- new position is the average of the neighbouring vertices
151  void optimizeLaplacian(const label nIterations = 1);
152  void optimizeLaplacian
153  (
154  const labelHashSet& badFaces,
155  const label nIterations = 1
156  );
157 
158  //- new position of surface point is the average of
159  //- the neighbouring surface vertices
161  (
162  const labelHashSet& badFaces,
163  const label nIterations = 1
164  );
165 
166  //- new positions are the average of the centres of the cells
167  //- adjacent to the vertex
168  void optimizeLaplacianPC(const label nIterations = 1);
170  (
171  const labelHashSet& badFaces,
172  const label nIterations = 1
173  );
174 
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);
179  (
180  const labelHashSet& badFaces,
181  const label nIterations = 1
182  );
183  };
184 
185  //- Disallow default bitwise copy construct
187 
188  //- Disallow default bitwise assignment
189  void operator=(const meshOptimizer&);
190 
191  // enumerators
192  enum vertexType_
193  {
194  INSIDE = 1,
195  BOUNDARY = 2,
196  EDGE = 4,
197  CORNER = 8,
199  LOCKED = 32
200  };
201 
202 public:
203 
204  // Constructors
205 
206  //- Construct from mesh
208 
209 
210  // Destructor
211 
212  ~meshOptimizer();
213 
214  // Member Functions
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");
220 
221  //- lock the cells which shall not be modified
222  template<class labelListType>
223  inline void lockCells(const labelListType&);
224 
225  //- lock cells which shall not be modified
226  //- contained inside the specified subset
227  void lockCellsInSubset(const word& subsetName);
228 
229  //- lock the faces whih shall not be modified
230  template<class labelListType>
231  inline void lockFaces(const labelListType&);
232 
233  //- lock faces which shall not be modified
234  //- stored in a face subset
235  void lockFacesInSubset(const word& subsetName);
236 
237  //- lock points which shall not be moved
238  template<class labelListType>
239  inline void lockPoints(const labelListType&);
240 
241  //- lock points which shall not be modified
242  //- given as a point subset
243  void lockPointsInSubset(const word& subsetName);
244 
245  //- reset to default constraints
246  void removeUserConstraints();
247 
248  //- smooth surface vertices
249  void optimizeSurface(const meshOctree&);
250 
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
255  void untangleMeshFV
256  (
257  const label maxNumGlobalIterations = 10,
258  const label maxNumIterations = 50,
259  const label maxNumSurfaceIterations = 2,
260  const bool relaxedCheck = false
261  );
262 
263  //- performs optimisation of boundary layer cells
264  //- it is applied to the first boundary layer, only
265  void optimizeBoundaryLayer(const bool addBufferLayer = true);
266 
267  //- performs untangling of boundary layer cells
268  //- if the user requests for it
269  void untangleBoundaryLayer();
270 
271  //- performs mesh optimisation for faces with high non-orthogonality
272  //- and skewness
273  void optimizeLowQualityFaces(const label maxNumIterations = 10);
274 
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
279  (
280  const label maxNumIterations = 10,
281  const label numLayersOfCells = 2
282  );
283 
284  //- final optimisation
285  void optimizeMeshFV
286  (
287  const label numLaplaceIterations = 5,
288  const label maxNumGlobalIterations = 10,
289  const label maxNumIterations = 50,
290  const label maxNumSurfaceIterations = 2
291  );
292 
293  //- greedy optimisation until the mesh can be improved
295  (
296  const label maxNumIterations = 50,
297  const scalar threshold = 0.1
298  );
299 };
300 
301 
302 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
303 
304 } // End namespace Foam
305 
306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
307 
308 #include "meshOptimizerI.H"
309 
310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
311 
312 #endif
313 
314 // ************************************************************************* //
Foam::meshOptimizer::optimizeMeshFV
void optimizeMeshFV(const label numLaplaceIterations=5, const label maxNumGlobalIterations=10, const label maxNumIterations=50, const label maxNumSurfaceIterations=2)
final optimisation
Definition: optimizeMeshFV.C:557
Foam::meshOptimizer
Definition: meshOptimizer.H:60
Foam::meshOptimizer::laplaceSmoother::laplacianPCParallel
void laplacianPCParallel(const labelLongList &procPoints)
Definition: meshOptimizerOptimizePointParallel.C:192
Foam::meshOptimizer::laplaceSmoother::laplaceSmoother
laplaceSmoother(const laplaceSmoother &)
Disallow default bitwise copy construct.
Foam::meshOptimizer::lockCells
void lockCells(const labelListType &)
lock the cells which shall not be modified
Definition: meshOptimizerI.H:39
boolList.H
Foam::meshOptimizer::laplaceSmoother::laplacianParallel
void laplacianParallel(const labelLongList &procPoints, const bool smoothOnlySurfaceNodes=false)
Definition: meshOptimizerOptimizePointParallel.C:48
Foam::meshOptimizer::optimizeLowQualityFaces
void optimizeLowQualityFaces(const label maxNumIterations=10)
Definition: optimizeMeshFV.C:469
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::meshOptimizer::optimizeMeshNearBoundaries
void optimizeMeshNearBoundaries(const label maxNumIterations=10, const label numLayersOfCells=2)
Definition: optimizeMeshFV.C:522
meshSurfaceEngine
Calculates surface of the mesh.
Foam::meshOptimizer::untangleBoundaryLayer
void untangleBoundaryLayer()
Definition: optimizeMeshFV.C:405
VRWGraph.H
Foam::meshOptimizer::vertexLocation_
List< direction > vertexLocation_
location of vertex (internal, boundary, edge, corner)
Definition: meshOptimizer.H:67
Foam::meshOptimizer::vertexType_
vertexType_
Definition: meshOptimizer.H:191
Foam::meshOptimizer::laplaceSmoother::optimizeSurfaceLaplacian
void optimizeSurfaceLaplacian(const labelHashSet &badFaces, const label nIterations=1)
Definition: meshOptimizerOptimizePoint.C:379
Foam::meshOptimizer::lockPoints
void lockPoints(const labelListType &)
lock points which shall not be moved
Definition: meshOptimizerI.H:203
Foam::meshOptimizer::laplaceSmoother
Definition: meshOptimizer.H:95
Foam::polyMeshGen
Definition: polyMeshGen.H:46
Foam::meshOptimizer::lockCellsInSubset
void lockCellsInSubset(const word &subsetName)
Definition: meshOptimizer.C:199
Foam::meshOptimizer::laplaceSmoother::laplacian
void laplacian(const labelLongList &, const label)
Definition: meshOptimizerOptimizePoint.C:47
Foam::meshOptimizer::CORNER
@ CORNER
Definition: meshOptimizer.H:196
Foam::meshOptimizer::laplaceSmoother::vertexLocation_
const List< direction > & vertexLocation_
location of vertex (internal, boundary, edge, corner)
Definition: meshOptimizer.H:102
Foam::meshOptimizer::operator=
void operator=(const meshOptimizer &)
Disallow default bitwise assignment.
Foam::HashSet< label, Hash< label > >
Foam::meshOptimizer::laplaceSmoother::mesh_
polyMeshGen & mesh_
reference to the mesh
Definition: meshOptimizer.H:99
Foam::meshOptimizer::lockFaces
void lockFaces(const labelListType &)
lock the faces whih shall not be modified
Definition: meshOptimizerI.H:123
Foam::meshOptimizer::enforceConstraints_
bool enforceConstraints_
enforce constraints
Definition: meshOptimizer.H:76
Foam::LongList< label >
Foam::meshOptimizer::BOUNDARY
@ BOUNDARY
Definition: meshOptimizer.H:194
Foam::meshOptimizer::lockPointsInSubset
void lockPointsInSubset(const word &subsetName)
Definition: meshOptimizer.C:235
Foam::meshOptimizer::laplaceSmoother::laplacianWPC
void laplacianWPC(const labelLongList &, const label)
Definition: meshOptimizerOptimizePoint.C:199
Foam::meshOptimizer::laplaceSmoother::laplacianWPCParallel
void laplacianWPCParallel(const labelLongList &procPoints)
Definition: meshOptimizerOptimizePointParallel.C:322
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
meshOptimizerI.H
Foam::meshOptimizer::findLowQualityFaces
label findLowQualityFaces(labelHashSet &, const boolList &) const
Definition: meshOptimizer.C:108
Foam::meshOptimizer::msePtr_
meshSurfaceEngine * msePtr_
mesh surface
Definition: meshOptimizer.H:73
polyMeshGen.H
Foam::meshOptimizer::laplaceSmoother::optimizeLaplacianPC
void optimizeLaplacianPC(const label nIterations=1)
Definition: meshOptimizerOptimizePoint.C:388
Foam::meshOptimizer::lockFacesInSubset
void lockFacesInSubset(const word &subsetName)
Definition: meshOptimizer.C:217
partTetMesh
Mesh smoothing without any topological changes.
Foam::meshOptimizer::laplaceSmoother::optimizeLaplacianWPC
void optimizeLaplacianWPC(const label nIterations=1)
Definition: meshOptimizerOptimizePoint.C:413
Foam::meshOptimizer::clearSurface
void clearSurface()
Definition: meshOptimizer.C:53
Foam::meshOptimizer::lockedFaces_
labelLongList lockedFaces_
locked faces which shall not be changed
Definition: meshOptimizer.H:70
HashSet.H
Foam::meshOptimizer::INSIDE
@ INSIDE
Definition: meshOptimizer.H:193
Foam::meshOptimizer::laplaceSmoother::laplacianSurface
void laplacianSurface(const labelLongList &, const label)
Definition: meshOptimizerOptimizePoint.C:94
Foam::meshOptimizer::~meshOptimizer
~meshOptimizer()
Definition: meshOptimizer.C:185
Foam::meshOptimizer::laplaceSmoother::laplacianPC
void laplacianPC(const labelLongList &, const label)
Definition: meshOptimizerOptimizePoint.C:147
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::meshOptimizer::laplaceSmoother::~laplaceSmoother
~laplaceSmoother()
Definition: meshOptimizerOptimizePoint.C:350
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::meshOptimizer::mesh_
polyMeshGen & mesh_
reference to the mesh
Definition: meshOptimizer.H:64
Foam::meshOptimizer::meshOptimizer
meshOptimizer(const meshOptimizer &)
Disallow default bitwise copy construct.
Foam::meshOptimizer::enforceConstraints
void enforceConstraints(const word subsetName="badPoints")
Definition: meshOptimizer.C:192
Foam::meshOptimizer::LOCKED
@ LOCKED
Definition: meshOptimizer.H:198
boundBox.H
Foam::meshOptimizer::badPointsSubsetName_
word badPointsSubsetName_
name of the subset contaning tangled points
Definition: meshOptimizer.H:79
Foam::meshOptimizer::findBadFaces
label findBadFaces(labelHashSet &, const boolList &) const
find problematic faces
Definition: meshOptimizer.C:59
Foam::meshOptimizer::untangleMeshFV
void untangleMeshFV(const label maxNumGlobalIterations=10, const label maxNumIterations=50, const label maxNumSurfaceIterations=2, const bool relaxedCheck=false)
Definition: optimizeMeshFV.C:57
Foam::meshOptimizer::laplaceSmoother::optimizeLaplacian
void optimizeLaplacian(const label nIterations=1)
new position is the average of the neighbouring vertices
Definition: meshOptimizerOptimizePoint.C:356
Foam::List< direction >
Foam::meshOctree
Definition: meshOctree.H:55
Foam::meshOptimizer::calculatePointLocations
void calculatePointLocations()
mark point locations
Definition: meshOptimizer.C:136
Foam::meshOptimizer::optimizeBoundaryLayer
void optimizeBoundaryLayer(const bool addBufferLayer=true)
Definition: optimizeMeshFV.C:302
meshOctree
Octree for mesh generation.
Foam::meshOptimizer::optimizeSurface
void optimizeSurface(const meshOctree &)
smooth surface vertices
Definition: meshOptimizerOptimizeSurface.C:44
Foam::meshOptimizer::meshSurface
const meshSurfaceEngine & meshSurface() const
return mesh surface
Definition: meshOptimizer.C:45
Foam::meshOptimizer::laplaceSmoother::updateMeshGeometry
void updateMeshGeometry(const labelLongList &smoothPoints)
update geometry after smoothing
Definition: meshOptimizerOptimizePoint.C:258
Foam::meshOptimizer::EDGE
@ EDGE
Definition: meshOptimizer.H:195
Foam::meshOptimizer::removeUserConstraints
void removeUserConstraints()
reset to default constraints
Definition: meshOptimizer.C:253
Foam::meshSurfaceEngine
Definition: meshSurfaceEngine.H:54
DynList.H
Foam::meshOptimizer::optimizeMeshFVBestQuality
void optimizeMeshFVBestQuality(const label maxNumIterations=50, const scalar threshold=0.1)
greedy optimisation until the mesh can be improved
Definition: optimizeMeshFV.C:580
Foam::meshOptimizer::PARALLELBOUNDARY
@ PARALLELBOUNDARY
Definition: meshOptimizer.H:197
partTet.H
Foam::meshOptimizer::laplaceSmoother::operator=
void operator=(const laplaceSmoother &)
Disallow default bitwise assignment.