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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2013-2015 OpenFOAM Foundation
9 Copyright (C) 2019 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
27\*---------------------------------------------------------------------------*/
28
29#include "pointPairs.H"
30
31// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
32
33template<class Triangulation>
36(
37 const labelPair& vA,
38 const labelPair& vB
39) const
40{
41 return
42 (
43 (vA < vB)
44 ? labelPairPair(vA, vB)
45 : labelPairPair(vB, vA)
46 );
47}
48
49
50template<class Triangulation>
52(
53 const labelPair& vA,
54 const labelPair& vB
55) const
56{
57 if (vA == vB)
58 {
59 return false;
60 }
61 else if (find(orderPointPair(vA, vB)) == end())
62 {
63 return false;
64 }
65
66 return true;
67}
68
69
70template<class Triangulation>
72(
73 const labelPair& vA,
74 const labelPair& vB
75)
76{
77 if (vA == vB)
78 {
79 return false;
80 }
81
82 return insert(orderPointPair(vA, vB));
83}
84
85
86// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
87
88template<class Triangulation>
89Foam::pointPairs<Triangulation>::pointPairs(const Triangulation& triangulation)
90:
91 StorageContainer(),
92 triangulation_(triangulation)
93{}
94
95
96// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
97
98template<class Triangulation>
100{}
101
102
103// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
104
105template<class Triangulation>
107(
108 const labelPair& vA,
109 const labelPair& vB
110)
111{
112 return insertPointPair(vA, vB);
113}
114
115
116template<class Triangulation>
118(
119 const labelPair& master,
120 const DynamicList<labelPair>& slaves
121)
122{
123 for (const labelPair& slave : slaves)
124 {
125 addPointPair(master, slave);
126 }
127
128 return true;
129}
130
131
132template<class Triangulation>
134(
135 const label vA,
136 const label vB
137)
138{
139 const label procNo = Pstream::myProcNo();
140
141 labelPair a(vA, procNo);
142 labelPair b(vB, procNo);
143
144 return addPointPair(a, b);
145}
146
147
148template<class Triangulation>
150(
151 const Vertex_handle& vA,
152 const Vertex_handle& vB
153) const
154{
155 if (vA->boundaryPoint() && vB->boundaryPoint())
156 {
157 labelPair a(vA->index(), vA->procIndex());
158 labelPair b(vB->index(), vB->procIndex());
159
160 return findPointPair(a, b);
161 }
162
163 return false;
164}
165
166
167template<class Triangulation>
169(
170 const labelPair& vA,
171 const labelPair& vB
172) const
173{
174 return findPointPair(vA, vB);
175}
176
177
178template<class Triangulation>
179void Foam::pointPairs<Triangulation>::reIndex(const Map<label>& oldToNewIndices)
180{
181 pointPairs<Triangulation> newTable(triangulation_);
182
183 forAllConstIters(*this, iter)
184 {
185 labelPairPair e = iter.key();
186
187 labelPair& start = e.first();
188 labelPair& end = e.second();
189
190 bool insert = true;
191
192 if (start.second() == Pstream::myProcNo())
193 {
194 const auto iter2 = oldToNewIndices.cfind(start.first());
195
196 if (iter2.found())
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 {
211 const auto iter2 = oldToNewIndices.cfind(end.first());
212
213 if (iter2.found())
214 {
215 if (iter2() != -1)
216 {
217 end.first() = iter2();
218 }
219 else
220 {
221 insert = false;
222 }
223 }
224 }
225
226 if (insert)
227 {
228 if (e.first() < e.second())
229 {
230 newTable.insert(e);
231 }
232 else if (e.first() > e.second())
233 {
234 newTable.insert(reverse(e));
235 }
236 }
237 }
238
239 this->transfer(newTable);
240}
241
242
243// ************************************************************************* //
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:69
HashSet of unique edges. The edges are stored as a pair of pairs:
Definition: pointPairs.H:59
bool addPointPair(const labelPair &vA, const labelPair &vB)
bool isPointPair(const Vertex_handle &vA, const Vertex_handle &vB) const
~pointPairs()
Destructor.
void reIndex(const Map< label > &oldToNewIndices)
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Same as ListOps::find_if.
Definition: ListOps.H:653
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:57
void reverse(UList< T > &list, const label n)
Reverse the first n elements of the list.
Definition: UListI.H:449
Pair< labelPair > labelPairPair
A pair of labelPairs.
Definition: labelPair.H:63
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:158
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
volScalarField & b
Definition: createFields.H:27
volScalarField & e
Definition: createFields.H:11
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278