pointPairs.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 | Copyright (C) 2013-2015 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 \*---------------------------------------------------------------------------*/
25 
26 #include "pointPairs.H"
27 
28 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
29 
30 template<class Triangulation>
33 (
34  const labelPair& vA,
35  const labelPair& vB
36 ) const
37 {
38  return
39  (
40  (vA < vB)
41  ? Pair<labelPair>(vA, vB)
42  : Pair<labelPair>(vB, vA)
43  );
44 }
45 
46 
47 template<class Triangulation>
49 (
50  const labelPair& vA,
51  const labelPair& vB
52 ) const
53 {
54  if (vA == vB)
55  {
56  return false;
57  }
58  else if (find(orderPointPair(vA, vB)) == end())
59  {
60  return false;
61  }
62 
63  return true;
64 }
65 
66 
67 template<class Triangulation>
69 (
70  const labelPair& vA,
71  const labelPair& vB
72 )
73 {
74  if (vA == vB)
75  {
76  return false;
77  }
78 
79  return insert(orderPointPair(vA, vB));
80 }
81 
82 
83 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
84 
85 template<class Triangulation>
86 Foam::pointPairs<Triangulation>::pointPairs(const Triangulation& triangulation)
87 :
88  ptPairTable(),
89  triangulation_(triangulation)
90 {}
91 
92 
93 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
94 
95 template<class Triangulation>
97 {}
98 
99 
100 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
101 
102 template<class Triangulation>
104 (
105  const labelPair& vA,
106  const labelPair& vB
107 )
108 {
109  return insertPointPair(vA, vB);
110 }
111 
112 
113 template<class Triangulation>
115 (
116  const labelPair& master,
117  const DynamicList<labelPair>& slaves
118 )
119 {
120  forAll(slaves, sI)
121  {
122  const labelPair& slave = slaves[sI];
123 
124  addPointPair(master, slave);
125  }
126 
127  return true;
128 }
129 
130 
131 template<class Triangulation>
133 (
134  const label vA,
135  const label vB
136 )
137 {
138  const label procNo = Pstream::myProcNo();
139 
140  labelPair a(vA, procNo);
141  labelPair b(vB, procNo);
142 
143  return addPointPair(a, b);
144 }
145 
146 
147 template<class Triangulation>
149 (
150  const Vertex_handle& vA,
151  const Vertex_handle& vB
152 ) const
153 {
154  if (vA->boundaryPoint() && vB->boundaryPoint())
155  {
156  labelPair a(vA->index(), vA->procIndex());
157  labelPair b(vB->index(), vB->procIndex());
158 
159  return findPointPair(a, b);
160  }
161 
162  return false;
163 }
164 
165 
166 template<class Triangulation>
168 (
169  const labelPair& vA,
170  const labelPair& vB
171 ) const
172 {
173  return findPointPair(vA, vB);
174 }
175 
176 
177 template<class Triangulation>
178 void Foam::pointPairs<Triangulation>::reIndex(const Map<label>& oldToNewIndices)
179 {
180  pointPairs<Triangulation> newTable(triangulation_);
181 
182  forAllConstIter(pointPairs, *this, iter)
183  {
184  Pair<labelPair> e = iter.key();
185 
186  labelPair& start = e.first();
187  labelPair& end = e.second();
188 
189  bool insert = true;
190 
191  if (start.second() == Pstream::myProcNo())
192  {
194  oldToNewIndices.find(start.first());
195 
196  if (iter2 != oldToNewIndices.end())
197  {
198  if (iter2() != -1)
199  {
200  start.first() = iter2();
201  }
202  else
203  {
204  insert = false;
205  }
206  }
207  }
208 
209  if (end.second() == Pstream::myProcNo())
210  {
212  oldToNewIndices.find(end.first());
213 
214  if (iter2 != oldToNewIndices.end())
215  {
216  if (iter2() != -1)
217  {
218  end.first() = iter2();
219  }
220  else
221  {
222  insert = false;
223  }
224  }
225  }
226 
227  if (insert)
228  {
229  if (e.first() < e.second())
230  {
231  newTable.insert(e);
232  }
233  else if (e.first() > e.second())
234  {
235  newTable.insert(reverse(e));
236  }
237  }
238  }
239 
240  this->transfer(newTable);
241 }
242 
243 
244 // ************************************************************************* //
bool isPointPair(const Vertex_handle &vA, const Vertex_handle &vB) const
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:417
void reIndex(const Map< label > &oldToNewIndices)
~pointPairs()
Destructor.
HashTable< label, label, Hash< label > >::const_iterator const_iterator
Definition: Map.H:59
bool addPointPair(const labelPair &vA, const labelPair &vB)
void transfer(dictionary &)
Transfer the contents of the argument and annul the argument.
Definition: dictionary.C:1067
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
timeIndices insert(timeIndex, timeDirs[timeI].value())
Pair< label > labelPair
Label pair.
Definition: labelPair.H:48
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
void reverse(UList< T > &, const label n)
Definition: UListI.H:322
HashSet< Pair< labelPair >, FixedList< labelPair, 2 >::Hash<>> ptPairTable
Definition: pointPairs.H:53
pointPairs(const Triangulation &triangulation)
Construct from triangulation.
HashSet of unique edges. The edges are stored as a pair of pairs:
Definition: pointPairs.H:60