edgeCollapser.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::edgeCollapser
28 
29 Description
30  Does polyTopoChanges to remove edges. Can remove faces due to edge
31  collapse but can not remove cells due to face removal!
32  Also removes unused points.
33 
34 SourceFiles
35  edgeCollapser.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef edgeCollapser_H
40 #define edgeCollapser_H
41 
42 #include "pointEdgeCollapse.H"
43 #include "DynamicList.H"
44 #include "Field.H"
45 #include "pointFieldFwd.H"
46 #include "Map.H"
47 #include "labelPair.H"
48 #include "HashSet.H"
49 #include "typeInfo.H"
50 #include "Switch.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // Forward Declarations
58 class polyMesh;
59 class bitSet;
60 class polyTopoChange;
61 class globalIndex;
62 class face;
63 class edge;
64 
65 /*---------------------------------------------------------------------------*\
66  Class edgeCollapser Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class edgeCollapser
70 {
71 public:
72 
73  // The type of collapse of a face
74  enum collapseType
75  {
77  toPoint = 1,
78  toEdge = 2
79  };
80 
81 
82 private:
83 
84  // Private data
85 
86  //- Reference to mesh
87  const polyMesh& mesh_;
88 
89  //- Controls collapse of a face to an edge
90  const scalar guardFraction_;
91 
92  //- Only collapse face to a point if high aspect ratio
93  const scalar maxCollapseFaceToPointSideLengthCoeff_;
94 
95  //- Allow a face to be collapsed to a point early, before the test
96  // to collapse to an edge
97  const bool allowEarlyCollapseToPoint_;
98 
99  //- Fraction of maxCollapseFaceToPointSideLengthCoeff_ to use when
100  // allowEarlyCollapseToPoint_ is on
101  const scalar allowEarlyCollapseCoeff_;
102 
103 
104  // Private Member Functions
105 
106  //- Create an edgeList of edges in facei which have both their points
107  // in pointLabels
108  labelList edgesFromPoints
109  (
110  const label& facei,
111  const labelList& pointLabels
112  ) const;
113 
114  //- Collapse a face to an edge, marking the collapsed edges and new
115  // locations for points that will move as a result of the collapse
116  void collapseToEdge
117  (
118  const label facei,
119  const pointField& pts,
120  const labelList& pointPriority,
121  const vector& collapseAxis,
122  const point& fC,
123  const labelList& facePtsNeg,
124  const labelList& facePtsPos,
125  const scalarList& dNeg,
126  const scalarList& dPos,
127  const scalar dShift,
129  Map<point>& collapsePointToLocation
130  ) const;
131 
132  //- Collapse a face to a point, marking the collapsed edges and new
133  // locations for points that will move as a result of the collapse
134  void collapseToPoint
135  (
136  const label& facei,
137  const pointField& pts,
138  const labelList& pointPriority,
139  const point& fC,
140  const labelList& facePts,
142  Map<point>& collapsePointToLocation
143  ) const;
144 
145  //- Do an eigenvector analysis of the face to get its collapse axis
146  // and aspect ratio
147  void faceCollapseAxisAndAspectRatio
148  (
149  const face& f,
150  const point& fC,
151  vector& collapseAxis,
152  scalar& aspectRatio
153  ) const;
154 
155  //- Return the target length scale for each face
156  scalarField calcTargetFaceSizes() const;
157 
158  //- Decides whether a face should be collapsed (and if so it it is to a
159  // point or an edge)
160  collapseType collapseFace
161  (
162  const labelList& pointPriority,
163  const face& f,
164  const label facei,
165  const scalar targetFaceSize,
167  Map<point>& collapsePointToLocation,
168  const scalarField& faceFilterFactor
169  ) const;
170 
171  //- Return label of point that has the highest priority. This will be
172  // the point on the edge that will be collapsed to.
173  label edgeMaster(const labelList& pointPriority, const edge& e) const;
174 
175  //- Decides which points in an edge to collapse, based on their priority
176  void checkBoundaryPointMergeEdges
177  (
178  const label pointi,
179  const label otherPointi,
180  const labelList& pointPriority,
181  Map<point>& collapsePointToLocation
182  ) const;
183 
184  //- Helper function that breaks strings of collapses if an edge is not
185  // labelled to collapse, but its points both collapse to the same
186  // location
187  label breakStringsAtEdges
188  (
189  const bitSet& markedEdges,
191  List<pointEdgeCollapse>& allPointInfo
192  ) const;
193 
194  //- Prevent face pinching by finding points in a face that will be
195  // collapsed to the same location, but that are not ordered
196  // consecutively in the face
197  void determineDuplicatePointsOnFace
198  (
199  const face& f,
200  bitSet& markedPoints,
201  labelHashSet& uniqueCollapses,
202  labelHashSet& duplicateCollapses,
203  List<pointEdgeCollapse>& allPointInfo
204  ) const;
205 
206  //- Count the number of edges on the face that will exist as a result
207  // of the collapse
208  label countEdgesOnFace
209  (
210  const face& f,
211  List<pointEdgeCollapse>& allPointInfo
212  ) const;
213 
214  //- Does the face have fewer than 3 edges as a result of the potential
215  // collapse
216  bool isFaceCollapsed
217  (
218  const face& f,
219  List<pointEdgeCollapse>& allPointInfo
220  ) const;
221 
222  //- Given the collapse information, propagates the information using
223  // PointEdgeWave. Result is a list of new point locations and indices
224  label syncCollapse
225  (
226  const globalIndex& globalPoints,
227  const labelList& boundaryPoint,
228  const bitSet& collapseEdge,
229  const Map<point>& collapsePointToLocation,
230  List<pointEdgeCollapse>& allPointInfo
231  ) const;
232 
233  //- Renumber f with new vertices. Removes consecutive duplicates
234  void filterFace
235  (
236  const Map<DynamicList<label>>& collapseStrings,
237  const List<pointEdgeCollapse>& allPointInfo,
238  face& f
239  ) const;
240 
241  //- No copy construct
242  edgeCollapser(const edgeCollapser&) = delete;
243 
244  //- No copy assignment
245  void operator=(const edgeCollapser&) = delete;
246 
247 
248 public:
249 
250  //- Runtime type information
251  ClassName("edgeCollapser");
252 
253 
254  // Constructors
255 
256  //- Construct from mesh
257  explicit edgeCollapser(const polyMesh& mesh);
258 
259  //- Construct from mesh and dict
260  edgeCollapser(const polyMesh& mesh, const dictionary& dict);
261 
262 
263  // Member Functions
264 
265  // Check
266 
267  //- Calls motionSmoother::checkMesh and returns a set of bad faces
269  (
270  const polyMesh& mesh,
271  const dictionary& meshQualityDict
272  );
273 
274  //- Check mesh and mark points on faces in error
275  // Returns boolList with points in error set
276  static label checkMeshQuality
277  (
278  const polyMesh& mesh,
279  const dictionary& meshQualityDict,
280  bitSet& isErrorPoint
281  );
282 
283  //- Ensure that the collapse is parallel consistent and update
284  // allPointInfo.
285  // Returns a list of edge collapses that is consistent across
286  // coupled boundaries and a list of pointEdgeCollapses.
287  void consistentCollapse
288  (
289  const globalIndex& globalPoints,
290  const labelList& pointPriority,
291  const Map<point>& collapsePointToLocation,
293  List<pointEdgeCollapse>& allPointInfo,
294  const bool allowCellCollapse = false
295  ) const;
296 
297 
298  // Query
299 
300  //- Play commands into polyTopoChange to create mesh.
301  // Return true if anything changed.
302  bool setRefinement
303  (
304  const List<pointEdgeCollapse>& allPointInfo,
305  polyTopoChange& meshMod
306  ) const;
307 
308  //- Mark (in collapseEdge) any edges to collapse
309  label markSmallEdges
310  (
311  const scalarField& minEdgeLen,
312  const labelList& pointPriority,
314  Map<point>& collapsePointToLocation
315  ) const;
316 
317  //- Mark (in collapseEdge) any edges to merge
318  label markMergeEdges
319  (
320  const scalar maxCos,
321  const labelList& pointPriority,
323  Map<point>& collapsePointToLocation
324  ) const;
325 
326  //- Find small faces and sliver faces in the mesh and mark the
327  // edges that need to be collapsed in order to remove these faces.
328  // Also returns a map of new locations for points that will move
329  // as a result of the collapse.
330  // Use in conjunction with edgeCollapser to synchronise the
331  // collapses and modify the mesh
333  (
334  const scalarField& faceFilterFactor,
335  const labelList& pointPriority,
337  Map<point>& collapsePointToLocation
338  ) const;
339 
340  //- Marks edges in the faceZone indirectPatchFaces for collapse
342  (
343  const faceZone& fZone,
344  const scalarField& faceFilterFactor,
345  const labelList& pointPriority,
347  Map<point>& collapsePointToLocation
348  ) const;
349 };
350 
351 
352 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
353 
354 } // End namespace Foam
355 
356 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
357 
358 #endif
359 
360 // ************************************************************************* //
Foam::globalPoints
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:102
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
typeInfo.H
Foam::DynamicList< label >
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:99
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
Foam::edgeCollapser::markFaceZoneEdges
labelPair markFaceZoneEdges(const faceZone &fZone, const scalarField &faceFilterFactor, const labelList &pointPriority, bitSet &collapseEdge, Map< point > &collapsePointToLocation) const
Marks edges in the faceZone indirectPatchFaces for collapse.
Definition: edgeCollapser.C:1999
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:69
Foam::edgeCollapser::collapseType
collapseType
Definition: edgeCollapser.H:73
Foam::HashSet< label, Hash< label > >
Foam::edgeCollapser::toPoint
Definition: edgeCollapser.H:76
pointEdgeCollapse.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::edgeCollapser
Does polyTopoChanges to remove edges. Can remove faces due to edge collapse but can not remove cells ...
Definition: edgeCollapser.H:68
Map.H
Foam::edgeCollapser::checkBadFaces
static labelHashSet checkBadFaces(const polyMesh &mesh, const dictionary &meshQualityDict)
Calls motionSmoother::checkMesh and returns a set of bad faces.
Definition: edgeCollapser.C:51
Foam::edgeCollapser::noCollapse
Definition: edgeCollapser.H:75
Foam::Field< vector >
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
pointFieldFwd.H
Field.H
Switch.H
Foam::edgeCollapser::markSmallEdges
label markSmallEdges(const scalarField &minEdgeLen, const labelList &pointPriority, bitSet &collapseEdge, Map< point > &collapsePointToLocation) const
Mark (in collapseEdge) any edges to collapse.
Definition: edgeCollapser.C:1800
HashSet.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::edgeCollapser::setRefinement
bool setRefinement(const List< pointEdgeCollapse > &allPointInfo, polyTopoChange &meshMod) const
Play commands into polyTopoChange to create mesh.
Definition: edgeCollapser.C:1249
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Foam::edgeCollapser::consistentCollapse
void consistentCollapse(const globalIndex &globalPoints, const labelList &pointPriority, const Map< point > &collapsePointToLocation, bitSet &collapseEdge, List< pointEdgeCollapse > &allPointInfo, const bool allowCellCollapse=false) const
Ensure that the collapse is parallel consistent and update.
Definition: edgeCollapser.C:1610
Foam::Pair< label >
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List< label >
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::edgeCollapser::checkMeshQuality
static label checkMeshQuality(const polyMesh &mesh, const dictionary &meshQualityDict, bitSet &isErrorPoint)
Check mesh and mark points on faces in error.
Definition: edgeCollapser.C:87
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
DynamicList.H
Foam::edgeCollapser::toEdge
Definition: edgeCollapser.H:77
collapseEdge
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
Foam::edgeCollapser::markSmallSliverFaces
labelPair markSmallSliverFaces(const scalarField &faceFilterFactor, const labelList &pointPriority, bitSet &collapseEdge, Map< point > &collapsePointToLocation) const
Find small faces and sliver faces in the mesh and mark the.
Definition: edgeCollapser.C:1938
Foam::edgeCollapser::markMergeEdges
label markMergeEdges(const scalar maxCos, const labelList &pointPriority, bitSet &collapseEdge, Map< point > &collapsePointToLocation) const
Mark (in collapseEdge) any edges to merge.
Definition: edgeCollapser.C:1851
pointLabels
labelList pointLabels(nPoints, -1)
labelPair.H
Foam::edgeCollapser::ClassName
ClassName("edgeCollapser")
Runtime type information.