meshSurfaceOptimizer.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  meshSurfaceOptimizer
26 
27 Description
28  Surface smoothing without any topological changes
29 
30 SourceFiles
31  meshSurfaceOptimizer.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef meshSurfaceOptimizer_H
36 #define meshSurfaceOptimizer_H
37 
38 #include "polyMeshGen.H"
39 #include "boolList.H"
40 #include "labelLongList.H"
41 #include "DynList.H"
42 #include "triFace.H"
43 #include "meshSurfaceEngine.H"
44 #include "parTriFace.H"
45 #include "meshSurfacePartitioner.H"
46 #include "partTriMesh.H"
47 
48 #include <map>
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward declarations
56 class meshOctree;
57 class meshSurfaceMapper;
58 class plane;
59 
60 /*---------------------------------------------------------------------------*\
61  Class meshSurfaceOptimizer Declaration
62 \*---------------------------------------------------------------------------*/
63 
65 {
66  // Private data
67  //- const reference to the mesh surface
69 
70  //- type of surface vertex
72 
73  //- locked faces which shall not be changed
75 
76  //- surface partitioner
78  const bool deletePartitioner_;
79 
80  //- pointer to mesh octree
81  const meshOctree* octreePtr_;
82 
83  //- mesh of surface triangles needed for some smoothers
84  mutable partTriMesh* triMeshPtr_;
85 
86  //- enforce constraints
88 
89  //- name of the subset contaning tangled points
91 
92  // Private member functions
93  //- classify surface vertices as PARTITION, EDGE, CORNER
95 
96  //- calculate surface triangulation
98  inline const partTriMesh& triMesh() const;
99  inline void updateTriMesh(const labelLongList&);
100  inline void updateTriMesh();
101 
102  //- find vertices which are inverted
103  //- mark additional layers of vertices near the inverted ones
105  (
106  boolList& smoothVertex,
107  const label nAdditionalLayers = 2
108  ) const;
109 
110  //- transform into a 2D space in plane
111  inline bool transformIntoPlane
112  (
113  const label bpI,
114  const plane& pl,
115  vector& vecX,
116  vector& vecY,
117  DynList<point>& pts,
118  DynList<triFace>& trias
119  ) const;
120 
121  //- new position of a node after laplacian smoothing
122  //- the position is the average of neighbouring vertex positions
124  (
125  const label bpI,
126  const bool transformIntoPlane = true
127  ) const;
128 
129  //- new position of a node after laplacian smoothing
130  //- the position is the average of neighbouring face centres
132  (
133  const label bpI,
134  const bool transformIntoPlane = true
135  ) const;
136 
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
141  (
142  const label bpI,
143  const bool transformIntoPlane = true
144  ) const;
145 
146  //- new position of a node after using surfaceOptimizer
148  (
149  const label bpI,
150  const scalar tol = 0.001
151  ) const;
152 
153  //- new position of edge vertex
154  //- the position is the average of neighbouring edge vertices
155  inline point newEdgePositionLaplacian(const label bpI) const;
156 
157  //- smooth the node using the laplacian smoother
158  //- new position is the average of the neighbouring vertices
160  (
161  const label bpI,
162  const bool transformIntoPlane = true
163  ) const;
164 
165  //- smooth the node using the laplacian smoother
166  //- new position is the average of the centres of faces attached
167  //- to the vertex
169  (
170  const label bpI,
171  const bool transformIntoPlane = true
172  ) const;
173 
174  //- smooth the node using surface optimizer
176  (
177  const label bpI,
178  const scalar tol = 1.0
179  );
180 
181  //- smooth edge node
182  void edgeNodeDisplacement(const label bpI) const;
183 
184  //- smooth selected edge points
185  void smoothEdgePoints
186  (
187  const labelLongList& edgePoints,
188  const labelLongList& procEdgePoints
189  );
190 
191  //- smooth selected points using laplaceFC
192  void smoothLaplacianFC
193  (
194  const labelLongList& selectedPoints,
195  const labelLongList& selectedProcPoints,
196  const bool transform = true
197  );
198 
199  //- smooth selected points using surface optimizer
201  (
202  const labelLongList& selectedPoints,
203  const labelLongList& selectedProcPoints
204  );
205 
206  // Functions needed for parallel runs
207 
208  //- transfer data between processors
209  void exchangeData
210  (
211  const labelLongList& nodesToSmooth,
212  std::map<label, DynList<parTriFace> >& m
213  ) const;
214 
215  //- laplacian smoothing of points at processor boundaries
216  //- new position is the average of the neighbouring vertices
218  (
219  const labelLongList& nodesToSmooth,
220  const bool transformIntoPlane = true
221  );
222 
223  //- laplacian smoothing of points at processor boundaries
225  (
226  const labelLongList& nodesToSmooth,
227  const bool transformIntoPlane = true
228  );
229 
230  //- smooth edge nodes at processor boundaries
232  (
233  const labelLongList& nodesToSmooth
234  );
235 
236  //- Disallow default bitwise copy construct
238 
239  //- Disallow default bitwise assignment
240  void operator=(const meshSurfaceOptimizer&);
241 
242  // Enumerators
243  enum vertexTypes
244  {
246  EDGE = 2,
247  CORNER = 4,
248  PROCBND = 8,
249  LOCKED = 16
250  };
251 
252 public:
253 
254  // Constructors
255 
256  //- Construct from mesh surface
258 
259  //- Construct from partitioner
261 
262  //- Construct from mesh surface and octree
264 
265  //- Construct from partitioner and octree
267  (
268  const meshSurfacePartitioner&,
269  const meshOctree&
270  );
271 
272 
273  // Destructor
274 
276 
277  // Member Functions
278  //- lock the boundary faces which shall not be modified
279  template<class labelListType>
280  inline void lockBoundaryFaces(const labelListType&);
281 
282  //- lock boundary points. They are not be moved.
283  template<class labelListType>
284  inline void lockBoundaryPoints(const labelListType&);
285 
286  //- lock edge points
287  inline void lockFeatureEdges();
288 
289  //- reset to default constraints
290  void removeUserConstraints();
291 
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");
297 
298  //- runs a surface smoother on the selected boundary points
299  bool untangleSurface
300  (
301  const labelLongList& activeBoundaryPoints,
302  const label nAdditionalLayers = 0
303  );
304 
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);
311 
312  //- optimize boundary nodes after boundary regions are created
313  void optimizeSurface(const label nIterations = 5);
314 
315  //- optimize the surface of a 2D mesh
316  void optimizeSurface2D(const label nIterations = 5);
317 
318  //- untangle the surface of a 2D mesh
319  void untangleSurface2D();
320 };
321 
322 
323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
324 
325 } // End namespace Foam
326 
327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
328 
329 #include "meshSurfaceOptimizerI.H"
330 
331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
332 
333 #endif
334 
335 // ************************************************************************* //
Foam::meshSurfaceOptimizer::~meshSurfaceOptimizer
~meshSurfaceOptimizer()
Definition: meshSurfaceOptimizer.C:143
Foam::meshSurfaceOptimizer::deletePartitioner_
const bool deletePartitioner_
Definition: meshSurfaceOptimizer.H:77
Foam::meshSurfaceOptimizer::updateTriMesh
void updateTriMesh()
Definition: meshSurfaceOptimizerI.H:71
Foam::meshSurfaceOptimizer::nodeDisplacementLaplacianFC
void nodeDisplacementLaplacianFC(const label bpI, const bool transformIntoPlane=true) const
Definition: meshSurfaceOptimizerOptimizePoint.C:61
Foam::meshSurfaceOptimizer::smoothLaplacianFC
void smoothLaplacianFC(const labelLongList &selectedPoints, const labelLongList &selectedProcPoints, const bool transform=true)
smooth selected points using laplaceFC
Definition: meshSurfaceOptimizerOptimizeSurface.C:215
Foam::meshSurfaceOptimizer::smoothSurfaceOptimizer
void smoothSurfaceOptimizer(const labelLongList &selectedPoints, const labelLongList &selectedProcPoints)
smooth selected points using surface optimizer
Definition: meshSurfaceOptimizerOptimizeSurface.C:283
boolList.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::meshSurfaceOptimizer::meshSurfaceOptimizer
meshSurfaceOptimizer(const meshSurfaceOptimizer &)
Disallow default bitwise copy construct.
Foam::meshSurfaceOptimizer::newPositionLaplacian
point newPositionLaplacian(const label bpI, const bool transformIntoPlane=true) const
Definition: meshSurfaceOptimizerI.H:187
Foam::meshSurfaceOptimizer::lockedSurfaceFaces_
labelLongList lockedSurfaceFaces_
locked faces which shall not be changed
Definition: meshSurfaceOptimizer.H:73
Foam::meshSurfaceOptimizer::classifySurfaceVertices
void classifySurfaceVertices()
classify surface vertices as PARTITION, EDGE, CORNER
Definition: meshSurfaceOptimizer.C:44
Foam::meshSurfaceOptimizer::triMeshPtr_
partTriMesh * triMeshPtr_
mesh of surface triangles needed for some smoothers
Definition: meshSurfaceOptimizer.H:83
Foam::meshSurfaceOptimizer::nodeDisplacementLaplacian
void nodeDisplacementLaplacian(const label bpI, const bool transformIntoPlane=true) const
Definition: meshSurfaceOptimizerOptimizePoint.C:46
Foam::meshSurfaceOptimizer::lockBoundaryPoints
void lockBoundaryPoints(const labelListType &)
lock boundary points. They are not be moved.
Definition: meshSurfaceOptimizerI.H:502
Foam::meshSurfaceOptimizer::LOCKED
@ LOCKED
Definition: meshSurfaceOptimizer.H:248
Foam::meshSurfaceOptimizer::exchangeData
void exchangeData(const labelLongList &nodesToSmooth, std::map< label, DynList< parTriFace > > &m) const
transfer data between processors
Definition: meshSurfaceOptimizerOptimizePointParallel.C:427
Foam::meshSurfaceOptimizer::newEdgePositionLaplacian
point newEdgePositionLaplacian(const label bpI) const
Definition: meshSurfaceOptimizerI.H:398
Foam::meshSurfaceOptimizer::PROCBND
@ PROCBND
Definition: meshSurfaceOptimizer.H:247
Foam::meshSurfaceOptimizer::triMesh
const partTriMesh & triMesh() const
Definition: meshSurfaceOptimizerI.H:51
Foam::meshSurfaceOptimizer::nodeDisplacementSurfaceOptimizer
void nodeDisplacementSurfaceOptimizer(const label bpI, const scalar tol=1.0)
smooth the node using surface optimizer
Definition: meshSurfaceOptimizerOptimizePoint.C:76
triFace.H
Foam::meshSurfaceOptimizer::transformIntoPlane
bool transformIntoPlane(const label bpI, const plane &pl, vector &vecX, vector &vecY, DynList< point > &pts, DynList< triFace > &trias) const
transform into a 2D space in plane
Definition: meshSurfaceOptimizerI.H:83
Foam::meshSurfaceOptimizer::badPointsSubsetName_
word badPointsSubsetName_
name of the subset contaning tangled points
Definition: meshSurfaceOptimizer.H:89
Foam::transform
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:465
Foam::plane
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:60
parTriFace.H
Foam::LongList< label >
Foam::meshSurfaceOptimizer::PARTITION
@ PARTITION
Definition: meshSurfaceOptimizer.H:244
Foam::meshSurfaceOptimizer::untangleSurface
bool untangleSurface(const labelLongList &activeBoundaryPoints, const label nAdditionalLayers=0)
runs a surface smoother on the selected boundary points
Definition: meshSurfaceOptimizerOptimizeSurface.C:327
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
Foam::meshSurfaceOptimizer::findInvertedVertices
label findInvertedVertices(boolList &smoothVertex, const label nAdditionalLayers=2) const
Definition: meshSurfaceOptimizerOptimizeSurface.C:60
polyMeshGen.H
Foam::meshSurfaceOptimizer::optimizeSurface2D
void optimizeSurface2D(const label nIterations=5)
optimize the surface of a 2D mesh
Definition: meshSurfaceOptimizerOptimizeSurface.C:658
Foam::meshSurfaceOptimizer::vertexType_
List< direction > vertexType_
type of surface vertex
Definition: meshSurfaceOptimizer.H:70
Foam::meshSurfaceOptimizer::untangleSurface2D
void untangleSurface2D()
untangle the surface of a 2D mesh
Definition: meshSurfaceOptimizerOptimizeSurface.C:759
Foam::meshSurfaceOptimizer::CORNER
@ CORNER
Definition: meshSurfaceOptimizer.H:246
Foam::meshSurfaceOptimizer::nodeDisplacementLaplacianFCParallel
void nodeDisplacementLaplacianFCParallel(const labelLongList &nodesToSmooth, const bool transformIntoPlane=true)
laplacian smoothing of points at processor boundaries
Definition: meshSurfaceOptimizerOptimizePointParallel.C:167
Foam::meshSurfaceOptimizer::edgeNodeDisplacementParallel
void edgeNodeDisplacementParallel(const labelLongList &nodesToSmooth)
smooth edge nodes at processor boundaries
Definition: meshSurfaceOptimizerOptimizePointParallel.C:289
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
meshSurfaceEngine.H
Foam::DynList
Definition: DynList.H:53
Foam::meshSurfaceOptimizer::newPositionSurfaceOptimizer
point newPositionSurfaceOptimizer(const label bpI, const scalar tol=0.001) const
new position of a node after using surfaceOptimizer
Definition: meshSurfaceOptimizerI.H:339
Foam::meshSurfaceOptimizer::surfaceEngine_
const meshSurfaceEngine & surfaceEngine_
const reference to the mesh surface
Definition: meshSurfaceOptimizer.H:67
Foam::meshSurfacePartitioner
Definition: meshSurfacePartitioner.H:52
Foam::partTriMesh
Definition: partTriMesh.H:59
Foam::meshSurfaceOptimizer::calculateTrianglesAndAddressing
void calculateTrianglesAndAddressing() const
calculate surface triangulation
Definition: meshSurfaceOptimizerCalculateTrianglesAndAddressing.C:47
Foam::meshSurfaceOptimizer::octreePtr_
const meshOctree * octreePtr_
pointer to mesh octree
Definition: meshSurfaceOptimizer.H:80
Foam::meshSurfaceOptimizer::optimizeSurface
void optimizeSurface(const label nIterations=5)
optimize boundary nodes after boundary regions are created
Definition: meshSurfaceOptimizerOptimizeSurface.C:581
Foam::meshSurfaceOptimizer::newPositionLaplacianFC
point newPositionLaplacianFC(const label bpI, const bool transformIntoPlane=true) const
Definition: meshSurfaceOptimizerI.H:232
Foam::meshSurfaceOptimizer::enforceConstraints
void enforceConstraints(const word subsetName="badPoints")
Definition: meshSurfaceOptimizer.C:163
Foam::meshSurfaceOptimizer::smoothEdgePoints
void smoothEdgePoints(const labelLongList &edgePoints, const labelLongList &procEdgePoints)
smooth selected edge points
Definition: meshSurfaceOptimizerOptimizeSurface.C:159
Foam::Vector< scalar >
Foam::meshSurfaceOptimizer
Definition: meshSurfaceOptimizer.H:63
Foam::List< direction >
meshSurfaceOptimizerI.H
Foam::meshOctree
Definition: meshOctree.H:55
Foam::meshSurfaceOptimizer::operator=
void operator=(const meshSurfaceOptimizer &)
Disallow default bitwise assignment.
Foam::meshSurfaceOptimizer::enforceConstraints_
bool enforceConstraints_
enforce constraints
Definition: meshSurfaceOptimizer.H:86
Foam::meshSurfaceOptimizer::lockBoundaryFaces
void lockBoundaryFaces(const labelListType &)
lock the boundary faces which shall not be modified
Definition: meshSurfaceOptimizerI.H:441
labelLongList.H
Foam::meshSurfaceOptimizer::removeUserConstraints
void removeUserConstraints()
reset to default constraints
Definition: meshSurfaceOptimizer.C:153
meshOctree
Octree for mesh generation.
Foam::meshSurfaceOptimizer::vertexTypes
vertexTypes
Definition: meshSurfaceOptimizer.H:242
Foam::meshSurfaceOptimizer::edgeNodeDisplacement
void edgeNodeDisplacement(const label bpI) const
smooth edge node
Definition: meshSurfaceOptimizerOptimizePoint.C:123
Foam::meshSurfaceOptimizer::lockFeatureEdges
void lockFeatureEdges()
lock edge points
Definition: meshSurfaceOptimizerI.H:557
Foam::meshSurfaceOptimizer::newPositionLaplacianWFC
point newPositionLaplacianWFC(const label bpI, const bool transformIntoPlane=true) const
Definition: meshSurfaceOptimizerI.H:279
Foam::meshSurfaceOptimizer::nodeDisplacementLaplacianParallel
void nodeDisplacementLaplacianParallel(const labelLongList &nodesToSmooth, const bool transformIntoPlane=true)
Definition: meshSurfaceOptimizerOptimizePointParallel.C:47
partTriMesh.H
Foam::meshSurfaceEngine
Definition: meshSurfaceEngine.H:54
Foam::meshSurfaceOptimizer::EDGE
@ EDGE
Definition: meshSurfaceOptimizer.H:245
DynList.H
meshSurfacePartitioner.H
meshSurfaceMapper
Maps vertices to the nearest point on the geometry surface.
Foam::meshSurfaceOptimizer::partitionerPtr_
const meshSurfacePartitioner * partitionerPtr_
surface partitioner
Definition: meshSurfaceOptimizer.H:76