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