PatchTools.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::PatchTools
26 
27 Description
28  A collection of tools for searching, sorting PrimitivePatch information.
29 
30  The class could also be extended to include more that just static methods.
31 
32 SourceFiles
33  PatchTools.C
34  PatchToolsCheck.C
35  PatchToolsEdgeOwner.C
36  PatchToolsGatherAndMerge.C
37  PatchToolsMatch.C
38  PatchToolsNormals.C
39  PatchToolsSearch.C
40  PatchToolsSortEdges.C
41  PatchToolsSortPoints.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef PatchTools_H
46 #define PatchTools_H
47 
48 #include "PrimitivePatch.H"
49 #include "HashSet.H"
50 #include "globalIndex.H"
51 #include "autoPtr.H"
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 class polyMesh;
59 class PackedBoolList;
60 class boundBox;
61 
62 /*---------------------------------------------------------------------------*\
63  Class PatchTools Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class PatchTools
67 {
68 public:
69 
70  //- Check for orientation issues.
71  // Returns true if problems were found.
72  // If a normal flips across an edge, places it in the HashSet
73  template
74  <
75  class Face,
76  template<class> class FaceList,
77  class PointField,
78  class PointType
79  >
80  static bool checkOrientation
81  (
83  const bool report = false,
84  labelHashSet* marked = 0
85  );
86 
87 
88  //- Fill faceZone with currentZone for every face reachable
89  // from facei without crossing edge marked in borderEdge.
90  // Note: faceZone has to be sized nFaces before calling.
91  template
92  <
93  class BoolListType,
94  class Face,
95  template<class> class FaceList,
96  class PointField,
97  class PointType
98  >
99  static void markZone
100  (
102  const BoolListType& borderEdge,
103  const label facei,
104  const label currentZone,
106  );
107 
108  //- Size and fills faceZone with zone of face.
109  // Zone is area reachable by edge crossing without crossing borderEdge.
110  // Returns number of zones.
111  template
112  <
113  class BoolListType,
114  class Face,
115  template<class> class FaceList,
116  class PointField,
117  class PointType
118  >
119  static label markZones
120  (
122  const BoolListType& borderEdge,
123  labelList& faceZone
124  );
125 
126  //- Determine the mapping for a sub-patch.
127  // Only include faces for which bool-list entry is true.
128  // \param[in] p patch to be searched on
129  // \param[in] includeFaces faces to include
130  // \param[out] pointMap mapping new to old localPoints
131  // \param[out] faceMap mapping new to old faces
132  template
133  <
134  class BoolListType,
135  class Face,
136  template<class> class FaceList,
137  class PointField,
138  class PointType
139  >
140  static void subsetMap
141  (
143  const BoolListType& includeFaces,
144  labelList& pointMap,
146  );
147 
148  //-
149  template
150  <
151  class Face,
152  template<class> class FaceList,
153  class PointField,
154  class PointType
155  >
156  static void calcBounds
157  (
159  boundBox& bb,
160  label& nPoints
161  );
162 
163  //- Return edge-face addressing sorted by angle around the edge.
164  // Orientation is anticlockwise looking from edge.vec(localPoints())
165  template
166  <
167  class Face,
168  template<class> class FaceList,
169  class PointField,
170  class PointType
171  >
173  (
175  );
176 
177  //- Return point-edge addressing sorted by order around the point.
178  template
179  <
180  class Face,
181  template<class> class FaceList,
182  class PointField,
183  class PointType
184  >
186  (
188  );
189 
190  //- If 2 face neighbours: label of face where ordering of edge
191  // is consistent with righthand walk.
192  // If 1 neighbour: label of only face.
193  // If >2 neighbours: undetermined.
194  template
195  <
196  class Face,
197  template<class> class FaceList,
198  class PointField,
199  class PointType
200  >
201  static labelList edgeOwner
202  (
204  );
205 
206 
207  //- Find corresponding points on patches sharing the same points
208  // p1PointLabels : points on p1 that were matched
209  // p2PointLabels : corresponding points on p2
210  template
211  <
212  class Face1,
213  template<class> class FaceList1,
214  class PointField1,
215  class PointType1,
216  class Face2,
217  template<class> class FaceList2,
218  class PointField2,
219  class PointType2
220  >
221  static void matchPoints
222  (
225 
226  labelList& p1PointLabels,
227  labelList& p2PointLabels
228  );
229 
230  //- Find corresponding edges on patches sharing the same points
231  // p1EdgeLabels : edges on p1 that were matched
232  // p2EdgeLabels : corresponding edges on p2
233  // sameOrientation : same orientation?
234  template
235  <
236  class Face1,
237  template<class> class FaceList1,
238  class PointField1,
239  class PointType1,
240  class Face2,
241  template<class> class FaceList2,
242  class PointField2,
243  class PointType2
244  >
245  static void matchEdges
246  (
249 
250  labelList& p1EdgeLabels,
251  labelList& p2EdgeLabels,
252  PackedBoolList& sameOrientation
253  );
254 
255 
256  //- Return parallel consistent point normals for patches using mesh points.
257  template
258  <
259  class Face,
260  template<class> class FaceList,
261  class PointField,
262  class PointType
263  >
265  (
266  const polyMesh&,
268  );
269 
270 
271  //- Return parallel consistent edge normals for patches using mesh points.
272  // Supply with patch matching info from matchEdges.
273  template
274  <
275  class Face,
276  template<class> class FaceList,
277  class PointField,
278  class PointType
279  >
281  (
282  const polyMesh&,
284  const labelList& patchEdges,
285  const labelList& coupledEdges
286  );
287 
288 
289  //- Gather points and faces onto master and merge into single patch.
290  // Note: uses faces/points, not localFaces/localPoints.
291  template
292  <
293  class Face,
294  template<class> class FaceList,
295  class PointField,
296  class PointType
297  >
298  static void gatherAndMerge
299  (
300  const scalar mergeDist,
302  Field<PointType>& mergedPoints,
303  List<Face>& mergedFaces,
304  labelList& pointMergeMap
305  );
306 
307  //- Gather (mesh!) points and faces onto master and merge collocated
308  // points into a single patch. Uses coupled point mesh
309  // structure so does not need tolerances.
310  // On master and slave returns:
311  // - pointToGlobal : for every local point index the global point index
312  // - uniqueMeshPointLabels : my local mesh points
313  // - globalPoints : global numbering for the global points
314  // - globalFaces : global numbering for the faces
315  // On master only:
316  // - mergedFaces : the merged faces
317  // - mergedPoints : the merged points
318  template<class FaceList>
319  static void gatherAndMerge
320  (
321  const polyMesh& mesh,
322  const FaceList& faces,
323  const labelList& meshPoints,
324  const Map<label>& meshPointMap,
325 
326  labelList& pointToGlobal,
327  labelList& uniqueMeshPointLabels,
329  autoPtr<globalIndex>& globalFaces,
331  pointField& mergedPoints
332  );
333 };
334 
335 
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
337 
338 } // End namespace Foam
339 
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 
342 #ifdef NoRepository
343  #include "PatchTools.C"
344 #endif
345 
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
347 
348 #endif
349 
350 // ************************************************************************* //
static void gatherAndMerge(const scalar mergeDist, const PrimitivePatch< Face, FaceList, PointField, PointType > &p, Field< PointType > &mergedPoints, List< Face > &mergedFaces, labelList &pointMergeMap)
Gather points and faces onto master and merge into single patch.
static labelListList sortedEdgeFaces(const PrimitivePatch< Face, FaceList, PointField, PointType > &)
Return edge-face addressing sorted by angle around the edge.
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 collection of tools for searching, sorting PrimitivePatch information.
Definition: PatchTools.H:65
static void matchEdges(const PrimitivePatch< Face1, FaceList1, PointField1, PointType1 > &p1, const PrimitivePatch< Face2, FaceList2, PointField2, PointType2 > &p2, labelList &p1EdgeLabels, labelList &p2EdgeLabels, PackedBoolList &sameOrientation)
Find corresponding edges on patches sharing the same points.
static labelListList sortedPointEdges(const PrimitivePatch< Face, FaceList, PointField, PointType > &)
Return point-edge addressing sorted by order around the point.
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
static void subsetMap(const PrimitivePatch< Face, FaceList, PointField, PointType > &p, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
A list of faces which address into the list of points.
dynamicFvMesh & mesh
static label markZones(const PrimitivePatch< Face, FaceList, PointField, PointType > &, const BoolListType &borderEdge, labelList &faceZone)
Size and fills faceZone with zone of face.
label nPoints
static labelList edgeOwner(const PrimitivePatch< Face, FaceList, PointField, PointType > &)
If 2 face neighbours: label of face where ordering of edge.
static bool checkOrientation(const PrimitivePatch< Face, FaceList, PointField, PointType > &, const bool report=false, labelHashSet *marked=0)
Check for orientation issues.
static void calcBounds(const PrimitivePatch< Face, FaceList, PointField, PointType > &p, boundBox &bb, label &nPoints)
static tmp< pointField > pointNormals(const polyMesh &, const PrimitivePatch< Face, FaceList, PointField, PointType > &)
Return parallel consistent point normals for patches using mesh points.
static void markZone(const PrimitivePatch< Face, FaceList, PointField, PointType > &, const BoolListType &borderEdge, const label facei, const label currentZone, labelList &faceZone)
Fill faceZone with currentZone for every face reachable.
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:100
A bit-packed bool list.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
static void matchPoints(const PrimitivePatch< Face1, FaceList1, PointField1, PointType1 > &p1, const PrimitivePatch< Face2, FaceList2, PointField2, PointType2 > &p2, labelList &p1PointLabels, labelList &p2PointLabels)
Find corresponding points on patches sharing the same points.
Namespace for OpenFOAM.
static tmp< pointField > edgeNormals(const polyMesh &, const PrimitivePatch< Face, FaceList, PointField, PointType > &, const labelList &patchEdges, const labelList &coupledEdges)
Return parallel consistent edge normals for patches using mesh points.