Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::PatchTools
29
30Description
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
35SourceFiles
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
57namespace Foam
58{
59
60// Forward Declarations
61class polyMesh;
62class bitSet;
63class boundBox;
65/*---------------------------------------------------------------------------*\
66 Class PatchTools Declaration
67\*---------------------------------------------------------------------------*/
68
69class PatchTools
70{
71public:
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 );
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 //- Return parallel consistent point normals for patches using mesh points.
206 // Get all geometry from provided patch local points. (assumed to be
207 // consistent across coupled patches)
208 template<class FaceList, class PointField>
210 (
211 const polyMesh&,
213 const pointField& localPoints,
214 const bitSet& flipMap = bitSet::null()
215 );
216
217 //- Return parallel consistent edge normals for patches using mesh points.
218 // Supply with patch matching info from matchEdges.
219 template<class FaceList, class PointField>
221 (
222 const polyMesh&,
224 const labelList& patchEdges,
225 const labelList& coupledEdges,
226 const bitSet& flipMap = bitSet::null()
227 );
228
229 //- Return parallel consistent edge normals for patches using mesh points.
230 // Get all geometry from provided patch local points. (assumed to be
231 // consistent across coupled patches)
232 // Supply with patch matching info from matchEdges.
233 template<class FaceList, class PointField>
235 (
236 const polyMesh&,
238 const pointField& localPoints,
239 const labelList& patchEdges,
240 const labelList& coupledEdges,
241 const bitSet& flipMap = bitSet::null()
242 );
243
244
245 //- Gather points and faces onto master and merge into single patch.
246 // Note: Normally uses faces/points (not localFaces/localPoints)
247 //
248 // \param[in] mergeDist Geometric merge tolerance for Foam::mergePoints
249 // \param[in] pp The patch to merge
250 // \param[out] mergedPoints merged points (master only, empty elsewhere)
251 // \param[out] mergedFaces merged faces (master only, empty elsewhere)
252 // \param[out] pointAddr Points globalIndex gather addressing
253 // (master only, empty elsewhere)
254 // \param[out] faceAddr Faces globalIndex gather addressing
255 // (master only, empty elsewhere)
256 // \param[out] pointMergeMap An old-to-new mapping from original
257 // point index to the index into merged points.
258 // \param[in] useLocal gather/merge patch localFaces/localPoints
259 // instead of faces/points
260 //
261 // \note
262 // - OpenFOAM-v2112 and earlier: geometric merge on all patch points.
263 // - OpenFOAM-v2206 and later: geometric merge on patch boundary points.
264 template<class FaceList, class PointField>
265 static void gatherAndMerge
266 (
267 const scalar mergeDist,
269 Field
270 <
272 >& mergedPoints,
273 List
274 <
276 >& mergedFaces,
277 globalIndex& pointAddr,
278 globalIndex& faceAddr,
279 labelList& pointMergeMap = const_cast<labelList&>(labelList::null()),
280 const bool useLocal = false
281 );
282
283 //- Gather points and faces onto master and merge into single patch.
284 // Note: Normally uses faces/points (not localFaces/localPoints)
285 //
286 // \param[in] mergeDist Geometric merge tolerance for Foam::mergePoints
287 // \param[in] pp The patch to merge
288 // \param[out] mergedPoints merged points (master only, empty elsewhere)
289 // \param[out] mergedFaces merged faces (master only, empty elsewhere)
290 // \param[out] pointMergeMap An old-to-new mapping from original
291 // point index to the index into merged points.
292 // \param[in] useLocal gather/merge patch localFaces/localPoints
293 // instead of faces/points
294 //
295 // \note
296 // - OpenFOAM-v2112 and earlier: geometric merge on all patch points.
297 // - OpenFOAM-v2206 and later: geometric merge on patch boundary points.
298 template<class FaceList, class PointField>
299 static void gatherAndMerge
300 (
301 const scalar mergeDist,
303 Field
304 <
306 >& mergedPoints,
307 List
308 <
310 >& mergedFaces,
311 labelList& pointMergeMap = const_cast<labelList&>(labelList::null()),
312 const bool useLocal = false
313 );
314
315 //- Gather (mesh!) points and faces onto master and merge collocated
316 // points into a single patch. Uses coupled point mesh
317 // structure so does not need tolerances.
318 // On master and sub-ranks returns:
319 // - pointToGlobal : for every local point index the global point index
320 // - uniqueMeshPointLabels : my local mesh points
321 // - globalPoints : global numbering for the global points
322 // - globalFaces : global numbering for the faces
323 // .
324 // On master only returns:
325 // - mergedFaces : the merged faces
326 // - mergedPoints : the merged points
327 template<class FaceList>
328 static void gatherAndMerge
329 (
330 const polyMesh& mesh,
331 const FaceList& faces,
332 const labelList& meshPoints,
333 const Map<label>& meshPointMap,
334
335 labelList& pointToGlobal,
336 labelList& uniqueMeshPointLabels,
338 autoPtr<globalIndex>& globalFaces,
340 pointField& mergedPoints
341 );
342};
343
344
345// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
346
347} // End namespace Foam
348
349// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
350
351#ifdef NoRepository
352 #include "PatchTools.C"
353#endif
354
355// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356
357#endif
358
359// ************************************************************************* //
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
static const List< label > & null() noexcept
Definition List.H:138
A HashTable to objects of type <T> with a label key.
Definition Map.H:54
A collection of tools for searching, sorting PrimitivePatch information.
Definition PatchTools.H:65
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 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.
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.
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 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.
static labelListList sortedPointEdges(const PrimitivePatch< FaceList, PointField > &)
Return point-edge addressing sorted by order around the point.
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 tmp< pointField > pointNormals(const polyMesh &, const PrimitivePatch< FaceList, PointField > &, const pointField &localPoints, const bitSet &flipMap=bitSet::null())
Return parallel consistent point normals for patches using mesh points.
static tmp< pointField > edgeNormals(const polyMesh &, const PrimitivePatch< FaceList, PointField > &, const pointField &localPoints, const labelList &patchEdges, const labelList &coupledEdges, const bitSet &flipMap=bitSet::null())
Return parallel consistent edge normals for patches using mesh 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)
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.
A list of faces which address into the list of points.
std::remove_reference< PointField >::type::value_type point_type
The point type.
std::remove_reference< FaceList >::type::value_type face_type
The face type.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
static const bitSet & null() noexcept
Return a null bitSet (reference to a nullObject).
Definition bitSet.H:138
A bounding box defined in terms of min/max extrema points.
Definition boundBox.H:71
A subset of mesh faces organised as a primitive patch.
Definition faceZone.H:63
Calculates a non-overlapping list of offsets based on an input size (eg, number of cells) from differ...
Definition globalIndex.H:77
Calculates points shared by more than two processor patches or cyclic patches.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A class for managing temporary objects.
Definition tmp.H:75
volScalarField & p
dynamicFvMesh & mesh
label nPoints
Namespace for OpenFOAM.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition HashSet.H:85
vectorField pointField
pointField is a vectorField.