PatchTools.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::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<class FaceList, class PointField>
74  static bool checkOrientation
75  (
77  const bool report = false,
78  labelHashSet* marked = 0
79  );
80 
81 
82  //- Fill faceZone with currentZone for every face reachable
83  // from facei without crossing edge marked in borderEdge.
84  // Note: faceZone has to be sized nFaces before calling.
85  template<class BoolListType, class FaceList, class PointField>
86  static void markZone
87  (
89  const BoolListType& borderEdge,
90  const label facei,
91  const label currentZone,
93  );
94 
95  //- Size and fills faceZone with zone of face.
96  // Zone is area reachable by edge crossing without crossing borderEdge.
97  // Returns number of zones.
98  template<class BoolListType, class FaceList, class PointField>
99  static label markZones
100  (
102  const BoolListType& borderEdge,
104  );
105 
106  //- Determine the mapping for a sub-patch.
107  // Only include faces for which bool-list entry is true.
108  // \param[in] p patch to be searched on
109  // \param[in] includeFaces faces to include
110  // \param[out] pointMap mapping new to old localPoints
111  // \param[out] faceMap mapping new to old faces
112  template<class BoolListType, class FaceList, class PointField>
113  static void subsetMap
114  (
116  const BoolListType& includeFaces,
117  labelList& pointMap,
119  );
120 
121  //-
122  template<class FaceList, class PointField>
123  static void calcBounds
124  (
126  boundBox& bb,
127  label& nPoints
128  );
129 
130  //- Return edge-face addressing sorted by angle around the edge.
131  // Orientation is anticlockwise looking from edge.vec(localPoints())
132  template<class FaceList, class PointField>
134  (
136  );
137 
138  //- Return point-edge addressing sorted by order around the point.
139  template<class FaceList, class PointField>
141  (
143  );
144 
145  //- If 2 face neighbours: label of face where ordering of edge
146  // is consistent with righthand walk.
147  // If 1 neighbour: label of only face.
148  // If >2 neighbours: undetermined.
149  template<class FaceList, class PointField>
150  static labelList edgeOwner
151  (
153  );
154 
155 
156  //- Find corresponding points on patches sharing the same points
157  // p1PointLabels : points on p1 that were matched
158  // p2PointLabels : corresponding points on p2
159  template
160  <
161  class FaceList1,
162  class PointField1,
163  class FaceList2,
164  class PointField2
165  >
166  static void matchPoints
167  (
170 
171  labelList& p1PointLabels,
172  labelList& p2PointLabels
173  );
174 
175  //- Find corresponding edges on patches sharing the same points
176  // p1EdgeLabels : edges on p1 that were matched
177  // p2EdgeLabels : corresponding edges on p2
178  // sameOrientation : same orientation?
179  template
180  <
181  class FaceList1,
182  class PointField1,
183  class FaceList2,
184  class PointField2
185  >
186  static void matchEdges
187  (
190 
191  labelList& p1EdgeLabels,
192  labelList& p2EdgeLabels,
193  PackedBoolList& sameOrientation
194  );
195 
196 
197  //- Return parallel consistent point normals for patches using mesh points.
198  template<class FaceList, class PointField>
200  (
201  const polyMesh&,
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  );
216 
217 
218  //- Gather points and faces onto master and merge into single patch.
219  // Note: uses faces/points, not localFaces/localPoints.
220  template<class FaceList, class PointField>
221  static void gatherAndMerge
222  (
223  const scalar mergeDist,
226  mergedPoints,
228  mergedFaces,
229  labelList& pointMergeMap
230  );
231 
232  //- Gather (mesh!) points and faces onto master and merge collocated
233  // points into a single patch. Uses coupled point mesh
234  // structure so does not need tolerances.
235  // On master and slave returns:
236  // - pointToGlobal : for every local point index the global point index
237  // - uniqueMeshPointLabels : my local mesh points
238  // - globalPoints : global numbering for the global points
239  // - globalFaces : global numbering for the faces
240  // On master only:
241  // - mergedFaces : the merged faces
242  // - mergedPoints : the merged points
243  template<class FaceList>
244  static void gatherAndMerge
245  (
246  const polyMesh& mesh,
247  const FaceList& faces,
248  const labelList& meshPoints,
249  const Map<label>& meshPointMap,
250 
251  labelList& pointToGlobal,
252  labelList& uniqueMeshPointLabels,
254  autoPtr<globalIndex>& globalFaces,
256  pointField& mergedPoints
257  );
258 };
259 
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 } // End namespace Foam
264 
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 
267 #ifdef NoRepository
268  #include "PatchTools.C"
269 #endif
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 #endif
274 
275 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:83
A bit-packed bool list.
A collection of tools for searching, sorting PrimitivePatch information.
Definition: PatchTools.H:66
static labelList edgeOwner(const PrimitivePatch< FaceList, PointField > &)
If 2 face neighbours: label of face where ordering of edge.
static void subsetMap(const PrimitivePatch< FaceList, PointField > &p, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
static void gatherAndMerge(const scalar mergeDist, const PrimitivePatch< FaceList, PointField > &p, Field< typename PrimitivePatch< FaceList, PointField >::PointType > &mergedPoints, List< typename PrimitivePatch< FaceList, PointField >::FaceType > &mergedFaces, labelList &pointMergeMap)
Gather points and faces onto master and merge into single patch.
static tmp< pointField > edgeNormals(const polyMesh &, const PrimitivePatch< FaceList, PointField > &, const labelList &patchEdges, const labelList &coupledEdges)
Return parallel consistent edge normals for patches using mesh points.
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 labelListList sortedPointEdges(const PrimitivePatch< FaceList, PointField > &)
Return point-edge addressing sorted by order around the point.
static tmp< pointField > pointNormals(const polyMesh &, const PrimitivePatch< FaceList, PointField > &)
Return parallel consistent point normals for patches using mesh points.
static labelListList sortedEdgeFaces(const PrimitivePatch< FaceList, PointField > &)
Return edge-face addressing sorted by angle around the edge.
static bool checkOrientation(const PrimitivePatch< FaceList, PointField > &, const bool report=false, labelHashSet *marked=0)
Check for orientation issues.
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.
static void matchEdges(const PrimitivePatch< FaceList1, PointField1 > &p1, const PrimitivePatch< FaceList2, PointField2 > &p2, labelList &p1EdgeLabels, labelList &p2EdgeLabels, PackedBoolList &sameOrientation)
Find corresponding edges on patches sharing the same points.
static label markZones(const PrimitivePatch< FaceList, PointField > &, const BoolListType &borderEdge, labelList &faceZone)
Size and fills faceZone with zone of face.
static void calcBounds(const PrimitivePatch< FaceList, PointField > &p, boundBox &bb, label &nPoints)
A list of faces which address into the list of points.
std::remove_reference< PointField >::type::value_type PointType
std::remove_reference< FaceList >::type::value_type FaceType
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:59
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:59
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:101
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
A class for managing temporary objects.
Definition: tmp.H:55
label nPoints
Namespace for OpenFOAM.
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
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
volScalarField & p