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-2019 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 
239 public:
240 
241  //- Runtime type information
242  ClassName("edgeCollapser");
243 
244 
245  // Constructors
246 
247  //- Construct from mesh
248  edgeCollapser(const polyMesh& mesh);
249 
250  //- Construct from mesh and dict
251  edgeCollapser(const polyMesh& mesh, const dictionary& dict);
252 
253  //- Disallow default bitwise copy construction
254  edgeCollapser(const edgeCollapser&) = delete;
255 
256 
257  // Member Functions
258 
259  // Check
260 
261  //- Calls motionSmoother::checkMesh and returns a set of bad faces
263  (
264  const polyMesh& mesh,
265  const dictionary& meshQualityDict
266  );
267 
268  //- Check mesh and mark points on faces in error
269  // Returns boolList with points in error set
270  static label checkMeshQuality
271  (
272  const polyMesh& mesh,
273  const dictionary& meshQualityDict,
274  PackedBoolList& isErrorPoint
275  );
276 
277  //- Ensure that the collapse is parallel consistent and update
278  // allPointInfo.
279  // Returns a list of edge collapses that is consistent across
280  // coupled boundaries and a list of pointEdgeCollapses.
281  void consistentCollapse
282  (
283  const globalIndex& globalPoints,
284  const labelList& pointPriority,
285  const Map<point>& collapsePointToLocation,
287  List<pointEdgeCollapse>& allPointInfo,
288  const bool allowCellCollapse = false
289  ) const;
290 
291 
292  // Query
293 
294  //- Play commands into polyTopoChange to create mesh.
295  // Return true if anything changed.
296  bool setRefinement
297  (
298  const List<pointEdgeCollapse>& allPointInfo,
299  polyTopoChange& meshMod
300  ) const;
301 
302  //- Mark (in collapseEdge) any edges to collapse
304  (
305  const scalarField& minEdgeLen,
306  const labelList& pointPriority,
308  Map<point>& collapsePointToLocation
309  ) const;
310 
311  //- Mark (in collapseEdge) any edges to merge
313  (
314  const scalar maxCos,
315  const labelList& pointPriority,
317  Map<point>& collapsePointToLocation
318  ) const;
319 
320  //- Find small faces and sliver faces in the mesh and mark the
321  // edges that need to be collapsed in order to remove these faces.
322  // Also returns a map of new locations for points that will move
323  // as a result of the collapse.
324  // Use in conjunctions with edgeCollapser to synchronise the
325  // collapses and modify the mesh
327  (
328  const scalarField& faceFilterFactor,
329  const labelList& pointPriority,
331  Map<point>& collapsePointToLocation
332  ) const;
333 
334  //- Marks edges in the faceZone indirectPatchFaces for collapse
336  (
337  const faceZone& fZone,
338  const scalarField& faceFilterFactor,
339  const labelList& pointPriority,
341  Map<point>& collapsePointToLocation
342  ) const;
343 
344 
345  // Member Operators
346 
347  //- Disallow default bitwise assignment
348  void operator=(const edgeCollapser&) = delete;
349 };
350 
351 
352 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
353 
354 } // End namespace Foam
355 
356 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
357 
358 #endif
359 
360 // ************************************************************************* //
dictionary dict
edgeCollapser(const polyMesh &mesh)
Construct from mesh.
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:156
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/any.
Definition: Switch.H:60
void operator=(const edgeCollapser &)=delete
Disallow default bitwise assignment.
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
fvMesh & mesh
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
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
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:105
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:65
Namespace for OpenFOAM.
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49