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-2013 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
92 
93  //- Allow a face to be collapsed to a point early, before the test
94  // to collapse to an edge
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
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
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
155 
156  //- Decides whether a face should be collapsed (and if so it it is to a
157  // point or an edge)
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
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
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
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
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
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 // ************************************************************************* //
Foam::PackedBoolList
A bit-packed bool list.
Definition: PackedBoolList.H:63
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::edgeCollapser::calcTargetFaceSizes
scalarField calcTargetFaceSizes() const
Return the target length scale for each face.
Definition: edgeCollapser.C:474
Foam::globalPoints
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:100
Foam::edgeCollapser::countEdgesOnFace
label countEdgesOnFace(const face &f, List< pointEdgeCollapse > &allPointInfo) const
Count the number of edges on the face that will exist as a result.
Definition: edgeCollapser.C:958
Foam::edgeCollapser::markMergeEdges
label markMergeEdges(const scalar maxCos, const labelList &pointPriority, PackedBoolList &collapseEdge, Map< point > &collapsePointToLocation) const
Mark (in collapseEdge) any edges to merge.
Definition: edgeCollapser.C:1880
Foam::edgeCollapser::breakStringsAtEdges
label breakStringsAtEdges(const PackedBoolList &markedEdges, PackedBoolList &collapseEdge, List< pointEdgeCollapse > &allPointInfo) const
Helper function that breaks strings of collapses if an edge is not.
Definition: edgeCollapser.C:856
typeInfo.H
Foam::DynamicList< label >
Foam::edgeCollapser::checkBadFaces
static HashSet< label > checkBadFaces(const polyMesh &mesh, const dictionary &meshQualityDict)
Calls motionSmoother::checkMesh and returns a set of bad faces.
Definition: edgeCollapser.C:46
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:97
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Foam::edgeCollapser::collapseToEdge
void collapseToEdge(const label faceI, const pointField &pts, const labelList &pointPriority, const vector &collapseAxis, const point &fC, const labelList &facePtsNeg, const labelList &facePtsPos, const scalarList &dNeg, const scalarList &dPos, const scalar dShift, PackedBoolList &collapseEdge, Map< point > &collapsePointToLocation) const
Collapse a face to an edge, marking the collapsed edges and new.
Definition: edgeCollapser.C:170
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: PrimitivePatchTemplate.H:68
Foam::edgeCollapser::markFaceZoneEdges
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.
Definition: edgeCollapser.C:2028
Foam::edgeCollapser::filterFace
void filterFace(const Map< DynamicList< label > > &collapseStrings, const List< pointEdgeCollapse > &allPointInfo, face &f) const
Renumber f with new vertices. Removes consecutive duplicates.
Definition: edgeCollapser.C:1122
Foam::edgeCollapser::markSmallEdges
label markSmallEdges(const scalarField &minEdgeLen, const labelList &pointPriority, PackedBoolList &collapseEdge, Map< point > &collapsePointToLocation) const
Mark (in collapseEdge) any edges to collapse.
Definition: edgeCollapser.C:1828
Foam::edgeCollapser::collapseType
collapseType
Definition: edgeCollapser.H:71
Foam::HashSet< label, Hash< label > >
Foam::edgeCollapser::toPoint
@ toPoint
Definition: edgeCollapser.H:74
Foam::edgeCollapser::guardFraction_
const scalar guardFraction_
Controls collapse of a face to an edge.
Definition: edgeCollapser.H:87
pointEdgeCollapse.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::edgeCollapser
Does polyTopoChanges to remove edges. Can remove faces due to edge collapse but can not remove cells ...
Definition: edgeCollapser.H:66
Map.H
Foam::edgeCollapser::determineDuplicatePointsOnFace
void determineDuplicatePointsOnFace(const face &f, PackedBoolList &markedPoints, labelHashSet &uniqueCollapses, labelHashSet &duplicateCollapses, List< pointEdgeCollapse > &allPointInfo) const
Prevent face pinching by finding points in a face that will be.
Definition: edgeCollapser.C:918
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::edgeCollapser::noCollapse
@ noCollapse
Definition: edgeCollapser.H:73
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::edgeCollapser::edgeCollapser
edgeCollapser(const edgeCollapser &)
Disallow default bitwise copy construct.
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
pointFieldFwd.H
Field.H
Switch.H
Foam::edgeCollapser::faceCollapseAxisAndAspectRatio
void faceCollapseAxisAndAspectRatio(const face &f, const point &fC, vector &collapseAxis, scalar &aspectRatio) const
Do an eigenvector analysis of the face to get its collapse axis.
Definition: edgeCollapser.C:390
Foam::edgeCollapser::operator=
void operator=(const edgeCollapser &)
Disallow default bitwise assignment.
Foam::edgeCollapser::consistentCollapse
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.
Definition: edgeCollapser.C:1637
Foam::edgeCollapser::maxCollapseFaceToPointSideLengthCoeff_
const scalar maxCollapseFaceToPointSideLengthCoeff_
Only collapse face to a point if high aspect ratio.
Definition: edgeCollapser.H:90
HashSet.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::edgeCollapser::markSmallSliverFaces
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.
Definition: edgeCollapser.C:1967
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::edgeCollapser::setRefinement
bool setRefinement(const List< pointEdgeCollapse > &allPointInfo, polyTopoChange &meshMod) const
Play commands into polyTopoChange to create mesh.
Definition: edgeCollapser.C:1265
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::edgeCollapser::syncCollapse
label syncCollapse(const globalIndex &globalPoints, const labelList &boundaryPoint, const PackedBoolList &collapseEdge, const Map< point > &collapsePointToLocation, List< pointEdgeCollapse > &allPointInfo) const
Given the collapse information, propagates the information using.
Definition: edgeCollapser.C:1016
Foam::edgeCollapser::allowEarlyCollapseCoeff_
const scalar allowEarlyCollapseCoeff_
Fraction of maxCollapseFaceToPointSideLengthCoeff_ to use when.
Definition: edgeCollapser.H:98
Foam::edgeCollapser::collapseToPoint
void collapseToPoint(const label &faceI, const pointField &pts, const labelList &pointPriority, const point &fC, const labelList &facePts, PackedBoolList &collapseEdge, Map< point > &collapsePointToLocation) const
Collapse a face to a point, marking the collapsed edges and new.
Definition: edgeCollapser.C:288
Foam::edgeCollapser::collapseFace
collapseType collapseFace(const labelList &pointPriority, const face &f, const label faceI, const scalar targetFaceSize, PackedBoolList &collapseEdge, Map< point > &collapsePointToLocation, const scalarField &faceFilterFactor) const
Decides whether a face should be collapsed (and if so it it is to a.
Definition: edgeCollapser.C:563
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
f
labelList f(nPoints)
Foam::edgeCollapser::edgeMaster
label edgeMaster(const labelList &pointPriority, const edge &e) const
Return label of point that has the highest priority. This will be.
Definition: edgeCollapser.C:750
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::edgeCollapser::allowEarlyCollapseToPoint_
const Switch allowEarlyCollapseToPoint_
Allow a face to be collapsed to a point early, before the test.
Definition: edgeCollapser.H:94
Foam::edgeCollapser::isFaceCollapsed
bool isFaceCollapsed(const face &f, List< pointEdgeCollapse > &allPointInfo) const
Does the face have fewer than 3 edges as a result of the potential.
Definition: edgeCollapser.C:992
Foam::edgeCollapser::checkMeshQuality
static label checkMeshQuality(const polyMesh &mesh, const dictionary &meshQualityDict, PackedBoolList &isErrorPoint)
Check mesh and mark points on faces in error.
Definition: edgeCollapser.C:82
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
DynamicList.H
Foam::edgeCollapser::toEdge
@ toEdge
Definition: edgeCollapser.H:75
collapseEdge
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
Foam::edgeCollapser::edgesFromPoints
labelList edgesFromPoints(const label &faceI, const labelList &pointLabels) const
Create an edgeList of edges in faceI which have both their points.
Definition: edgeCollapser.C:121
Foam::edgeCollapser::checkBoundaryPointMergeEdges
void checkBoundaryPointMergeEdges(const label pointI, const label otherPointI, const labelList &pointPriority, Map< point > &collapsePointToLocation) const
Decides which points in an edge to collapse, based on their priority.
Definition: edgeCollapser.C:808
Foam::edgeCollapser::mesh_
const polyMesh & mesh_
Reference to mesh.
Definition: edgeCollapser.H:84
pointLabels
labelList pointLabels(nPoints, -1)
labelPair.H
Foam::edgeCollapser::ClassName
ClassName("edgeCollapser")
Runtime type information.