edgeCollapser.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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  (
188  List<pointEdgeCollapse>& allPointInfo
189  ) const;
190 
191  //- Prevent face pinching by finding points in a face that will be
192  // collapsed to the same location, but that are not ordered
193  // consecutively in the face
194  void determineDuplicatePointsOnFace
195  (
196  const face& f,
197  PackedBoolList& markedPoints,
198  labelHashSet& uniqueCollapses,
199  labelHashSet& duplicateCollapses,
200  List<pointEdgeCollapse>& allPointInfo
201  ) const;
202 
203  //- Count the number of edges on the face that will exist as a result
204  // of the collapse
205  label countEdgesOnFace
206  (
207  const face& f,
208  List<pointEdgeCollapse>& allPointInfo
209  ) const;
210 
211  //- Does the face have fewer than 3 edges as a result of the potential
212  // collapse
213  bool isFaceCollapsed
214  (
215  const face& f,
216  List<pointEdgeCollapse>& allPointInfo
217  ) const;
218 
219  //- Given the collapse information, propagates the information using
220  // PointEdgeWave. Result is a list of new point locations and indices
221  label syncCollapse
222  (
223  const globalIndex& globalPoints,
224  const labelList& boundaryPoint,
226  const Map<point>& collapsePointToLocation,
227  List<pointEdgeCollapse>& allPointInfo
228  ) const;
229 
230  //- Renumber f with new vertices. Removes consecutive duplicates
231  void filterFace
232  (
233  const Map<DynamicList<label>>& collapseStrings,
234  const List<pointEdgeCollapse>& allPointInfo,
235  face& f
236  ) const;
237 
238  //- Disallow default bitwise copy construct
240 
241  //- Disallow default bitwise assignment
242  void operator=(const edgeCollapser&);
243 
244 
245 public:
246 
247  //- Runtime type information
248  ClassName("edgeCollapser");
249 
250 
251  // Constructors
252 
253  //- Construct from mesh
254  edgeCollapser(const polyMesh& mesh);
255 
256  //- Construct from mesh and dict
257  edgeCollapser(const polyMesh& mesh, const dictionary& dict);
258 
259 
260  // Member Functions
261 
262  // Check
263 
264  //- Calls motionSmoother::checkMesh and returns a set of bad faces
266  (
267  const polyMesh& mesh,
268  const dictionary& meshQualityDict
269  );
270 
271  //- Check mesh and mark points on faces in error
272  // Returns boolList with points in error set
273  static label checkMeshQuality
274  (
275  const polyMesh& mesh,
276  const dictionary& meshQualityDict,
277  PackedBoolList& isErrorPoint
278  );
279 
280  //- Ensure that the collapse is parallel consistent and update
281  // allPointInfo.
282  // Returns a list of edge collapses that is consistent across
283  // coupled boundaries and a list of pointEdgeCollapses.
284  void consistentCollapse
285  (
286  const globalIndex& globalPoints,
287  const labelList& pointPriority,
288  const Map<point>& collapsePointToLocation,
290  List<pointEdgeCollapse>& allPointInfo,
291  const bool allowCellCollapse = false
292  ) const;
293 
294 
295  // Query
296 
297  //- Play commands into polyTopoChange to create mesh.
298  // Return true if anything changed.
299  bool setRefinement
300  (
301  const List<pointEdgeCollapse>& allPointInfo,
302  polyTopoChange& meshMod
303  ) const;
304 
305  //- Mark (in collapseEdge) any edges to collapse
307  (
308  const scalarField& minEdgeLen,
309  const labelList& pointPriority,
311  Map<point>& collapsePointToLocation
312  ) const;
313 
314  //- Mark (in collapseEdge) any edges to merge
316  (
317  const scalar maxCos,
318  const labelList& pointPriority,
320  Map<point>& collapsePointToLocation
321  ) const;
322 
323  //- Find small faces and sliver faces in the mesh and mark the
324  // edges that need to be collapsed in order to remove these faces.
325  // Also returns a map of new locations for points that will move
326  // as a result of the collapse.
327  // Use in conjuctions with edgeCollapser to synchronise the
328  // collapses and modify the mesh
330  (
331  const scalarField& faceFilterFactor,
332  const labelList& pointPriority,
334  Map<point>& collapsePointToLocation
335  ) const;
336 
337  //- Marks edges in the faceZone indirectPatchFaces for collapse
339  (
340  const faceZone& fZone,
341  const scalarField& faceFilterFactor,
342  const labelList& pointPriority,
344  Map<point>& collapsePointToLocation
345  ) const;
346 };
347 
348 
349 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
350 
351 } // End namespace Foam
352 
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354 
355 #endif
356 
357 // ************************************************************************* //
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
labelList pointLabels(nPoints, -1)
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
Does polyTopoChanges to remove edges. Can remove faces due to edge collapse but can not remove cells ...
Definition: edgeCollapser.H:66
label markMergeEdges(const scalar maxCos, const labelList &pointPriority, PackedBoolList &collapseEdge, Map< point > &collapsePointToLocation) const
Mark (in collapseEdge) any edges to merge.
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.
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
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.
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)
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.
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:100
A bit-packed bool list.
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.
label markSmallEdges(const scalarField &minEdgeLen, const labelList &pointPriority, PackedBoolList &collapseEdge, Map< point > &collapsePointToLocation) const
Mark (in collapseEdge) any edges to collapse.
bool setRefinement(const List< pointEdgeCollapse > &allPointInfo, polyTopoChange &meshMod) const
Play commands into polyTopoChange to create mesh.
Direct mesh changes based on v1.3 polyTopoChange syntax.
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:98
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Namespace for OpenFOAM.
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49