PatchToolsMatch.C
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) 2019-2021 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 \*---------------------------------------------------------------------------*/
28 
29 #include "PatchTools.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template
34 <
35  class FaceList1, class PointField1,
36  class FaceList2, class PointField2
37 >
39 (
42 
43  labelList& p1PointLabels,
44  labelList& p2PointLabels
45 )
46 {
47  p1PointLabels.resize(p1.nPoints());
48  p2PointLabels.resize(p1.nPoints());
49 
50  label nMatches = 0;
51 
52  forAll(p1.meshPoints(), pointi)
53  {
54  const label meshPointi = p1.meshPoints()[pointi];
55 
56  const auto iter = p2.meshPointMap().cfind(meshPointi);
57 
58  if (iter.found())
59  {
60  p1PointLabels[nMatches] = pointi;
61  p2PointLabels[nMatches] = iter.val();
62  ++nMatches;
63  }
64  }
65 
66  p1PointLabels.resize(nMatches);
67  p2PointLabels.resize(nMatches);
68 }
69 
70 
71 template
72 <
73  class FaceList1, class PointField1,
74  class FaceList2, class PointField2
75 >
77 (
80 
81  labelList& p1EdgeLabels,
82  labelList& p2EdgeLabels,
83  bitSet& sameOrientation
84 )
85 {
86  p1EdgeLabels.resize(p1.nEdges());
87  p2EdgeLabels.resize(p1.nEdges());
88  sameOrientation.resize(p1.nEdges());
89  sameOrientation = false;
90 
91  label nMatches = 0;
92 
93  EdgeMap<label> edgeToIndex(2*p1.nEdges());
94  forAll(p1.edges(), edgei)
95  {
96  // Map lookup with globalEdge
97  edgeToIndex.insert(p1.meshEdge(edgei), edgei);
98  }
99 
100  forAll(p2.edges(), edgei)
101  {
102  const edge meshEdge2(p2.meshEdge(edgei));
103 
104  const auto iter = edgeToIndex.cfind(meshEdge2);
105 
106  if (iter.found())
107  {
108  p1EdgeLabels[nMatches] = iter.val();
109  p2EdgeLabels[nMatches] = edgei;
110  sameOrientation.set(nMatches, (meshEdge2[0] == iter.key()[0]));
111  ++nMatches;
112  }
113  }
114 
115  p1EdgeLabels.resize(nMatches);
116  p2EdgeLabels.resize(nMatches);
117  sameOrientation.resize(nMatches);
118 }
119 
120 
121 // ************************************************************************* //
Foam::PackedList::resize
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
Definition: PackedListI.H:409
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::PrimitivePatch::edges
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
Definition: PrimitivePatch.C:183
PatchTools.H
Foam::PrimitivePatch::nEdges
label nEdges() const
Number of edges in patch.
Definition: PrimitivePatch.H:322
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
Foam::bitSet::set
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:574
Foam::PrimitivePatch::meshEdge
edge meshEdge(const label edgei) const
From patch edge to global edge using meshPoints.
Definition: PrimitivePatchMeshEdges.C:35
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
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:77
Foam::PrimitivePatch::nPoints
label nPoints() const
Number of points supporting patch faces.
Definition: PrimitivePatch.H:316
Foam::EdgeMap< label >
Foam::List< label >
Foam::PrimitivePatch::meshPointMap
const Map< label > & meshPointMap() const
Mesh point map.
Definition: PrimitivePatch.C:343
Foam::PrimitivePatch::meshPoints
const labelList & meshPoints() const
Return labelList of mesh points in patch.
Definition: PrimitivePatch.C:330
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:79