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-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 \*---------------------------------------------------------------------------*/
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.setSize(p1.nPoints());
48  p2PointLabels.setSize(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  p1PointLabels.setSize(nMatches);
66  p2PointLabels.setSize(nMatches);
67 }
68 
69 
70 template
71 <
72  class FaceList1, class PointField1,
73  class FaceList2, class PointField2
74 >
76 (
79 
80  labelList& p1EdgeLabels,
81  labelList& p2EdgeLabels,
82  bitSet& sameOrientation
83 )
84 {
85  p1EdgeLabels.setSize(p1.nEdges());
86  p2EdgeLabels.setSize(p1.nEdges());
87  sameOrientation.setSize(p1.nEdges());
88  sameOrientation = false;
89 
90  label nMatches = 0;
91 
92  EdgeMap<label> edgeToIndex(2*p1.nEdges());
93  forAll(p1.edges(), edgeI)
94  {
95  const edge& e = p1.edges()[edgeI];
96  const edge meshE
97  (
98  p1.meshPoints()[e[0]],
99  p1.meshPoints()[e[1]]
100  );
101  edgeToIndex.insert(meshE, edgeI);
102  }
103 
104  forAll(p2.edges(), edgeI)
105  {
106  const edge& e = p2.edges()[edgeI];
107  const edge meshE(p2.meshPoints()[e[0]], p2.meshPoints()[e[1]]);
108 
109  const auto iter = edgeToIndex.cfind(meshE);
110 
111  if (iter.found())
112  {
113  p1EdgeLabels[nMatches] = iter.val();
114  p2EdgeLabels[nMatches] = edgeI;
115  sameOrientation.set(nMatches, (meshE[0] == iter.key()[0]));
116  ++nMatches;
117  }
118  }
119  p1EdgeLabels.setSize(nMatches);
120  p2EdgeLabels.setSize(nMatches);
121  sameOrientation.setSize(nMatches);
122 }
123 
124 
125 // ************************************************************************* //
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::PrimitivePatch::edges
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
Definition: PrimitivePatch.C:190
PatchTools.H
Foam::PrimitivePatch::nEdges
label nEdges() const
Return 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:563
Foam::edge::insert
bool insert(const label index)
Fill any open slot with the index if it did not previously exist.
Definition: edgeI.H:260
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:76
Foam::PrimitivePatch::nPoints
label nPoints() const
Return number of points supporting patch faces.
Definition: PrimitivePatch.H:316
Foam::EdgeMap< label >
Foam::PackedList::setSize
void setSize(const label nElem, const unsigned int val=0u)
Alias for resize()
Definition: PackedListI.H:451
Foam::List< label >
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::PrimitivePatch::meshPointMap
const Map< label > & meshPointMap() const
Mesh point map.
Definition: PrimitivePatch.C:323
Foam::PrimitivePatch::meshPoints
const labelList & meshPoints() const
Return labelList of mesh points in patch.
Definition: PrimitivePatch.C:310
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
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