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 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 PatchTools_H
49 #define PatchTools_H
50 
51 #include "PrimitivePatch.H"
52 #include "HashSet.H"
53 #include "globalIndex.H"
54 #include "autoPtr.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 // Forward Declarations
62 class polyMesh;
63 class bitSet;
64 class boundBox;
65 
66 /*---------------------------------------------------------------------------*\
67  Class PatchTools Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 class PatchTools
71 {
72 public:
73 
74  //- Check for orientation issues.
75  // Returns true if problems were found.
76  // If a normal flips across an edge, places it in the HashSet
77  template<class FaceList, class PointField>
78  static bool checkOrientation
79  (
81  const bool report = false,
82  labelHashSet* marked = 0
83  );
84 
85 
86  //- Fill faceZone with currentZone for every face reachable
87  // from facei without crossing edge marked in borderEdge.
88  // Note: faceZone has to be sized nFaces before calling.
89  template<class BoolListType, class FaceList, class PointField>
90  static void markZone
91  (
93  const BoolListType& borderEdge,
94  const label facei,
95  const label currentZone,
97  );
98 
99  //- Size and fills faceZone with zone of face.
100  // Zone is area reachable by edge crossing without crossing borderEdge.
101  // Returns number of zones.
102  template<class BoolListType, class FaceList, class PointField>
103  static label markZones
104  (
106  const BoolListType& borderEdge,
108  );
109 
110  //- Determine the mapping for a sub-patch.
111  // Only include faces for which bool-list entry is true.
112  // \param[in] p patch to be searched on
113  // \param[in] includeFaces faces to include
114  // \param[out] pointMap mapping new to old localPoints
115  // \param[out] faceMap mapping new to old faces
116  template<class BoolListType, class FaceList, class PointField>
117  static void subsetMap
118  (
120  const BoolListType& includeFaces,
121  labelList& pointMap,
123  );
124 
125  //-
126  template<class FaceList, class PointField>
127  static void calcBounds
128  (
130  boundBox& bb,
131  label& nPoints
132  );
133 
134  //- Return edge-face addressing sorted by angle around the edge.
135  // Orientation is anticlockwise looking from edge.vec(localPoints())
136  template<class FaceList, class PointField>
138  (
140  );
141 
142  //- Return point-edge addressing sorted by order around the point.
143  template<class FaceList, class PointField>
145  (
147  );
148 
149  //- If 2 face neighbours: label of face where ordering of edge
150  // is consistent with righthand walk.
151  // If 1 neighbour: label of only face.
152  // If >2 neighbours: undetermined.
153  template<class FaceList, class PointField>
154  static labelList edgeOwner
155  (
157  );
158 
159 
160  //- Find corresponding points on patches sharing the same points
161  // p1PointLabels : points on p1 that were matched
162  // p2PointLabels : corresponding points on p2
163  template
164  <
165  class FaceList1, class PointField1,
166  class FaceList2, class PointField2
167  >
168  static void matchPoints
169  (
172 
173  labelList& p1PointLabels,
174  labelList& p2PointLabels
175  );
176 
177  //- Find corresponding edges on patches sharing the same points
178  // p1EdgeLabels : edges on p1 that were matched
179  // p2EdgeLabels : corresponding edges on p2
180  // sameOrientation : same orientation?
181  template
182  <
183  class FaceList1, class PointField1,
184  class FaceList2, class PointField2
185  >
186  static void matchEdges
187  (
190 
191  labelList& p1EdgeLabels,
192  labelList& p2EdgeLabels,
193  bitSet& 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,
225  Field
226  <
228  >& mergedPoints,
229  List
230  <
232  >& mergedFaces,
233  labelList& pointMergeMap
234  );
235 
236  //- Gather (mesh!) points and faces onto master and merge collocated
237  // points into a single patch. Uses coupled point mesh
238  // structure so does not need tolerances.
239  // On master and slave returns:
240  // - pointToGlobal : for every local point index the global point index
241  // - uniqueMeshPointLabels : my local mesh points
242  // - globalPoints : global numbering for the global points
243  // - globalFaces : global numbering for the faces
244  // On master only:
245  // - mergedFaces : the merged faces
246  // - mergedPoints : the merged points
247  template<class FaceList>
248  static void gatherAndMerge
249  (
250  const polyMesh& mesh,
251  const FaceList& faces,
252  const labelList& meshPoints,
253  const Map<label>& meshPointMap,
254 
255  labelList& pointToGlobal,
256  labelList& uniqueMeshPointLabels,
258  autoPtr<globalIndex>& globalFaces,
260  pointField& mergedPoints
261  );
262 };
263 
264 
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 
267 } // End namespace Foam
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 #ifdef NoRepository
272  #include "PatchTools.C"
273 #endif
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 #endif
278 
279 // ************************************************************************* //
Foam::PatchTools::markZone
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.
Definition: PatchToolsSearch.C:40
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::PatchTools::pointNormals
static tmp< pointField > pointNormals(const polyMesh &, const PrimitivePatch< FaceList, PointField > &)
Return parallel consistent point normals for patches using mesh points.
Foam::globalPoints
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:102
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::PatchTools::gatherAndMerge
static void gatherAndMerge(const scalar mergeDist, const PrimitivePatch< FaceList, PointField > &p, Field< typename PrimitivePatch< FaceList, PointField >::point_type > &mergedPoints, List< typename PrimitivePatch< FaceList, PointField >::face_type > &mergedFaces, labelList &pointMergeMap)
Gather points and faces onto master and merge into single patch.
Definition: PatchToolsGatherAndMerge.C:38
globalIndex.H
Foam::Map< label >
Foam::PatchTools::calcBounds
static void calcBounds(const PrimitivePatch< FaceList, PointField > &p, boundBox &bb, label &nPoints)
Definition: PatchToolsSearch.C:178
Foam::PatchTools::sortedPointEdges
static labelListList sortedPointEdges(const PrimitivePatch< FaceList, PointField > &)
Return point-edge addressing sorted by order around the point.
Foam::HashSet< label, Hash< label > >
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::PatchTools::sortedEdgeFaces
static labelListList sortedEdgeFaces(const PrimitivePatch< FaceList, PointField > &)
Return edge-face addressing sorted by angle around the edge.
Foam::PatchTools::edgeOwner
static labelList edgeOwner(const PrimitivePatch< FaceList, PointField > &)
If 2 face neighbours: label of face where ordering of edge.
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::Field
Generic templated field type.
Definition: Field.H:63
PrimitivePatch.H
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:65
Foam::PrimitivePatch::point_type
std::remove_reference< PointField >::type::value_type point_type
The point type.
Definition: PrimitivePatch.H:100
PatchTools.C
Foam::PatchTools
A collection of tools for searching, sorting PrimitivePatch information.
Definition: PatchTools.H:69
Foam::PatchTools::matchEdges
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.
Definition: PatchToolsMatch.C:76
HashSet.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::List< label >
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::PrimitivePatch::face_type
std::remove_reference< FaceList >::type::value_type face_type
The face type.
Definition: PrimitivePatch.H:96
Foam::PatchTools::markZones
static label markZones(const PrimitivePatch< FaceList, PointField > &, const BoolListType &borderEdge, labelList &faceZone)
Size and fills faceZone with zone of face.
Foam::PatchTools::checkOrientation
static bool checkOrientation(const PrimitivePatch< FaceList, PointField > &, const bool report=false, labelHashSet *marked=0)
Check for orientation issues.
Definition: PatchToolsCheck.C:36
Foam::PatchTools::subsetMap
static void subsetMap(const PrimitivePatch< FaceList, PointField > &p, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
Definition: PatchToolsSearch.C:142
Foam::PatchTools::edgeNormals
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.
Foam::PatchTools::matchPoints
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.
Definition: PatchToolsMatch.C:39
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:85
autoPtr.H