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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::PatchTools
29 
30 Description
31  A collection of tools for searching, sorting PrimitivePatch information.
32 
33  The class could also be extended to include more that just static methods.
34 
35 SourceFiles
36  PatchTools.C
37  PatchToolsCheck.C
38  PatchToolsEdgeOwner.C
39  PatchToolsGatherAndMerge.C
40  PatchToolsMatch.C
41  PatchToolsNormals.C
42  PatchToolsSearch.C
43  PatchToolsSortEdges.C
44  PatchToolsSortPoints.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef Foam_PatchTools_H
49 #define Foam_PatchTools_H
50 
51 #include "autoPtr.H"
52 #include "globalIndex.H"
53 #include "primitivePatch.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 // Forward Declarations
61 class polyMesh;
62 class bitSet;
63 class boundBox;
64 
65 /*---------------------------------------------------------------------------*\
66  Class PatchTools Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class PatchTools
70 {
71 public:
72 
73  //- Check for orientation issues.
74  // Returns true if problems were found.
75  // If a normal flips across an edge, places it in the HashSet
76  template<class FaceList, class PointField>
77  static bool checkOrientation
78  (
80  const bool report = false,
81  labelHashSet* marked = 0
82  );
83 
84 
85  //- Fill faceZone with currentZone for every face reachable
86  // from facei without crossing edge marked in borderEdge.
87  // Note: faceZone has to be sized nFaces before calling.
88  template<class BoolListType, class FaceList, class PointField>
89  static void markZone
90  (
92  const BoolListType& borderEdge,
93  const label facei,
94  const label currentZone,
96  );
97 
98  //- Size and fills faceZone with zone of face.
99  // Zone is area reachable by edge crossing without crossing borderEdge.
100  // Returns number of zones.
101  template<class BoolListType, class FaceList, class PointField>
102  static label markZones
103  (
105  const BoolListType& borderEdge,
107  );
108 
109  //- Determine the mapping for a sub-patch.
110  // Only include faces for which bool-list entry is true.
111  // \param[in] p patch to be searched on
112  // \param[in] includeFaces faces to include
113  // \param[out] pointMap mapping new to old localPoints
114  // \param[out] faceMap mapping new to old faces
115  template<class BoolListType, class FaceList, class PointField>
116  static void subsetMap
117  (
119  const BoolListType& includeFaces,
120  labelList& pointMap,
122  );
123 
124  //-
125  template<class FaceList, class PointField>
126  static void calcBounds
127  (
129  boundBox& bb,
130  label& nPoints
131  );
132 
133  //- Return edge-face addressing sorted by angle around the edge.
134  // Orientation is anticlockwise looking from edge.vec(localPoints())
135  template<class FaceList, class PointField>
137  (
139  );
140 
141  //- Return point-edge addressing sorted by order around the point.
142  template<class FaceList, class PointField>
144  (
146  );
147 
148  //- If 2 face neighbours: label of face where ordering of edge
149  // is consistent with righthand walk.
150  // If 1 neighbour: label of only face.
151  // If >2 neighbours: undetermined.
152  template<class FaceList, class PointField>
153  static labelList edgeOwner
154  (
156  );
157 
158 
159  //- Find corresponding points on patches sharing the same points
160  // p1PointLabels : points on p1 that were matched
161  // p2PointLabels : corresponding points on p2
162  template
163  <
164  class FaceList1, class PointField1,
165  class FaceList2, class PointField2
166  >
167  static void matchPoints
168  (
171 
172  labelList& p1PointLabels,
173  labelList& p2PointLabels
174  );
175 
176  //- Find corresponding edges on patches sharing the same points
177  // p1EdgeLabels : edges on p1 that were matched
178  // p2EdgeLabels : corresponding edges on p2
179  // sameOrientation : same orientation?
180  template
181  <
182  class FaceList1, class PointField1,
183  class FaceList2, class PointField2
184  >
185  static void matchEdges
186  (
189 
190  labelList& p1EdgeLabels,
191  labelList& p2EdgeLabels,
192  bitSet& sameOrientation
193  );
194 
195 
196  //- Return parallel consistent point normals for patches using mesh points.
197  template<class FaceList, class PointField>
199  (
200  const polyMesh&,
202  const bitSet& flipMap = bitSet::null()
203  );
204 
205 
206  //- Return parallel consistent edge normals for patches using mesh points.
207  // Supply with patch matching info from matchEdges.
208  template<class FaceList, class PointField>
210  (
211  const polyMesh&,
213  const labelList& patchEdges,
214  const labelList& coupledEdges,
215  const bitSet& flipMap = bitSet::null()
216  );
217 
218 
219  //- Gather points and faces onto master and merge into single patch.
220  // Note: Normally uses faces/points (not localFaces/localPoints)
221  //
222  // \param[in] mergeDist Geometric merge tolerance for Foam::mergePoints
223  // \param[in] pp The patch to merge
224  // \param[out] mergedPoints merged points (master only, empty elsewhere)
225  // \param[out] mergedFaces merged faces (master only, empty elsewhere)
226  // \param[out] pointAddr Points globalIndex gather addressing
227  // (master only, empty elsewhere)
228  // \param[out] faceAddr Faces globalIndex gather addressing
229  // (master only, empty elsewhere)
230  // \param[out] pointMergeMap An old-to-new mapping from original
231  // point index to the index into merged points.
232  // \param[in] useLocal gather/merge patch localFaces/localPoints
233  // instead of faces/points
234  //
235  // \note
236  // - OpenFOAM-v2112 and earlier: geometric merge on all patch points.
237  // - OpenFOAM-v2206 and later: geometric merge on patch boundary points.
238  template<class FaceList, class PointField>
239  static void gatherAndMerge
240  (
241  const scalar mergeDist,
243  Field
244  <
246  >& mergedPoints,
247  List
248  <
250  >& mergedFaces,
251  globalIndex& pointAddr,
252  globalIndex& faceAddr,
253  labelList& pointMergeMap = const_cast<labelList&>(labelList::null()),
254  const bool useLocal = false
255  );
256 
257  //- Gather points and faces onto master and merge into single patch.
258  // Note: Normally uses faces/points (not localFaces/localPoints)
259  //
260  // \param[in] mergeDist Geometric merge tolerance for Foam::mergePoints
261  // \param[in] pp The patch to merge
262  // \param[out] mergedPoints merged points (master only, empty elsewhere)
263  // \param[out] mergedFaces merged faces (master only, empty elsewhere)
264  // \param[out] pointMergeMap An old-to-new mapping from original
265  // point index to the index into merged points.
266  // \param[in] useLocal gather/merge patch localFaces/localPoints
267  // instead of faces/points
268  //
269  // \note
270  // - OpenFOAM-v2112 and earlier: geometric merge on all patch points.
271  // - OpenFOAM-v2206 and later: geometric merge on patch boundary points.
272  template<class FaceList, class PointField>
273  static void gatherAndMerge
274  (
275  const scalar mergeDist,
277  Field
278  <
280  >& mergedPoints,
281  List
282  <
284  >& mergedFaces,
285  labelList& pointMergeMap = const_cast<labelList&>(labelList::null()),
286  const bool useLocal = false
287  );
288 
289  //- Gather (mesh!) points and faces onto master and merge collocated
290  // points into a single patch. Uses coupled point mesh
291  // structure so does not need tolerances.
292  // On master and sub-ranks returns:
293  // - pointToGlobal : for every local point index the global point index
294  // - uniqueMeshPointLabels : my local mesh points
295  // - globalPoints : global numbering for the global points
296  // - globalFaces : global numbering for the faces
297  // .
298  // On master only returns:
299  // - mergedFaces : the merged faces
300  // - mergedPoints : the merged points
301  template<class FaceList>
302  static void gatherAndMerge
303  (
304  const polyMesh& mesh,
305  const FaceList& faces,
306  const labelList& meshPoints,
307  const Map<label>& meshPointMap,
308 
309  labelList& pointToGlobal,
310  labelList& uniqueMeshPointLabels,
312  autoPtr<globalIndex>& globalFaces,
314  pointField& mergedPoints
315  );
316 };
317 
318 
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320 
321 } // End namespace Foam
322 
323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
324 
325 #ifdef NoRepository
326  #include "PatchTools.C"
327 #endif
328 
329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 
331 #endif
332 
333 // ************************************************************************* //
std::remove_reference< PointField >::type::value_type point_type
The point type.
static bool checkOrientation(const PrimitivePatch< FaceList, PointField > &, const bool report=false, labelHashSet *marked=0)
Check for orientation issues.
static labelList edgeOwner(const PrimitivePatch< FaceList, PointField > &)
If 2 face neighbours: label of face where ordering of edge.
A collection of tools for searching, sorting PrimitivePatch information.
Definition: PatchTools.H:64
static void markZone(const PrimitivePatch< FaceList, PointField > &, const BoolListType &borderEdge, const label facei, const label currentZone, labelList &faceZone)
Fill faceZone with currentZone for every face reachable.
static void matchEdges(const PrimitivePatch< FaceList1, PointField1 > &p1, const PrimitivePatch< FaceList2, PointField2 > &p2, labelList &p1EdgeLabels, labelList &p2EdgeLabels, bitSet &sameOrientation)
Find corresponding edges on patches sharing the same points.
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
static const List< label > & null()
Return a null List.
Definition: ListI.H:130
std::remove_reference< FaceList >::type::value_type face_type
The face type.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
static label markZones(const PrimitivePatch< FaceList, PointField > &, const BoolListType &borderEdge, labelList &faceZone)
Size and fills faceZone with zone of face.
static void gatherAndMerge(const scalar mergeDist, const PrimitivePatch< FaceList, PointField > &pp, Field< typename PrimitivePatch< FaceList, PointField >::point_type > &mergedPoints, List< typename PrimitivePatch< FaceList, PointField >::face_type > &mergedFaces, globalIndex &pointAddr, globalIndex &faceAddr, labelList &pointMergeMap=const_cast< labelList &>(labelList::null()), const bool useLocal=false)
Gather points and faces onto master and merge into single patch.
A list of faces which address into the list of points.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:61
static void calcBounds(const PrimitivePatch< FaceList, PointField > &p, boundBox &bb, label &nPoints)
dynamicFvMesh & mesh
Generic templated field type.
Definition: Field.H:62
label nPoints
static const bitSet & null()
Return a null bitSet reference.
Definition: bitSetI.H:401
static tmp< pointField > edgeNormals(const polyMesh &, const PrimitivePatch< FaceList, PointField > &, const labelList &patchEdges, const labelList &coupledEdges, const bitSet &flipMap=bitSet::null())
Return parallel consistent edge normals for patches using mesh points.
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:98
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
static void subsetMap(const PrimitivePatch< FaceList, PointField > &p, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:60
static labelListList sortedEdgeFaces(const PrimitivePatch< FaceList, PointField > &)
Return edge-face addressing sorted by angle around the edge.
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
static tmp< pointField > pointNormals(const polyMesh &, const PrimitivePatch< FaceList, PointField > &, const bitSet &flipMap=bitSet::null())
Return parallel consistent point normals for patches using mesh points.
static void matchPoints(const PrimitivePatch< FaceList1, PointField1 > &p1, const PrimitivePatch< FaceList2, PointField2 > &p2, labelList &p1PointLabels, labelList &p2PointLabels)
Find corresponding points on patches sharing the same points.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
static labelListList sortedPointEdges(const PrimitivePatch< FaceList, PointField > &)
Return point-edge addressing sorted by order around the point.