walkPatch.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-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "walkPatch.H"
29#include "ListOps.H"
30
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
33namespace Foam
34{
36}
37
38
39// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40
41Foam::label Foam::walkPatch::getNeighbour
42(
43 const label facei,
44 const label fp,
45 const label v0,
46 const label v1
47) const
48{
49 const labelList& fEdges = pp_.faceEdges()[facei];
50
51 const edgeList& edges = pp_.edges();
52
53
54 label nbrEdgeI = -1;
55
56 // Shortcut: maybe faceEdges are sorted(?) in which case fEdges[fp] is
57 // edge between v0 and v1.
58 const edge& e = edges[fEdges[fp]];
59
60 if ((e[0] == v0 && e[1] == v1) || (e[0] == v1 && e[1] == v0))
61 {
62 // Correct edge.
63 nbrEdgeI = fEdges[fp];
64 }
65 else
66 {
67 // Loop over all faceEdges.
68 forAll(fEdges, i)
69 {
70 label edgeI = fEdges[i];
71
72 const edge& e = edges[edgeI];
73
74 if
75 (
76 (e[0] == v0 && e[1] == v1)
77 || (e[0] == v1 && e[1] == v0)
78 )
79 {
80 // Found edge on face which uses v0, v1.
81 nbrEdgeI = edgeI;
82
83 break;
84 }
85 }
86 }
87
88
89 if (nbrEdgeI == -1)
90 {
92 << "Did not find edge on face " << facei << " that uses vertices"
93 << v0 << " and " << v1 << abort(FatalError);
94 }
95
96
97 // Get neighbouring face.
98
99 const labelList& eFaces = pp_.edgeFaces()[nbrEdgeI];
100
101 if (eFaces.size() == 1)
102 {
103 return -1;
104 }
105 else if (eFaces.size() == 2)
106 {
107 label nbrFacei = eFaces[0];
108
109 if (nbrFacei == facei)
110 {
111 nbrFacei = eFaces[1];
112 }
113
114 return nbrFacei;
115 }
116 else
117 {
119 << "Illegal surface on patch. Face " << facei
120 << " at vertices " << v0 << ',' << v1
121 << " has fewer than 1 or more than 2 neighbours"
122 << abort(FatalError);
123 return -1;
124 }
125}
126
127
129(
130 const labelList& changedFaces,
131 const labelList& enterVerts,
132
133 labelList& nbrFaces,
134 labelList& nbrEnterVerts
135)
136{
137 nbrFaces.setSize(pp_.size());
138 nbrEnterVerts.setSize(pp_.size());
139 label changedI = 0;
140
141 forAll(changedFaces, i)
142 {
143 label facei = changedFaces[i];
144 label enterVertI = enterVerts[i];
145
146 if (!visited_[facei])
147 {
148 // Do this face
149 visited_[facei] = true;
150 visitOrder_.append(facei);
151
152 const face& f = pp_.localFaces()[facei];
153
154 label fp = f.find(enterVertI);
155
156 indexInFace_.append(fp);
157
158 // Visit neighbouring faces in order, starting at fp.
159 forAll(f, i)
160 {
161 label fp1 = reverse_ ? f.rcIndex(fp) : f.fcIndex(fp);
162 label nbr = getNeighbour(facei, fp, f[fp], f[fp1]);
163
164 if
165 (
166 nbr != -1
167 && !visited_[nbr]
168 && faceZone_[nbr] == faceZone_[facei]
169 )
170 {
171 nbrFaces[changedI] = nbr;
172 nbrEnterVerts[changedI] = f[fp];
173 changedI++;
174 }
175
176 fp = fp1;
177 }
178 }
179 }
180
181 nbrFaces.setSize(changedI);
182 nbrEnterVerts.setSize(changedI);
183}
184
185
186// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
187
189(
190 const primitivePatch& pp,
191 const labelList& faceZone,
192 const bool reverse,
193 const label facei,
194 const label enterVertI,
195 boolList& visited
196)
197:
198 pp_(pp),
199 faceZone_(faceZone),
200 reverse_(reverse),
201 visited_(visited),
202 visitOrder_(pp.size()),
203 indexInFace_(pp.size())
204{
205 // List of faces that have been visited in the current iteration.
206 labelList changedFaces(1, facei);
207 // Corresponding list of entry vertices
208 labelList enterVerts(1, enterVertI);
209
210 while (true)
211 {
212 labelList nbrFaces;
213 labelList nbrEnterVerts;
214
216 (
217 changedFaces,
218 enterVerts,
219
220 nbrFaces,
221 nbrEnterVerts
222 );
223
224
225 if (nbrFaces.empty())
226 {
227 break;
228 }
229
230 changedFaces = nbrFaces;
231 enterVerts = nbrEnterVerts;
232 }
233
234 visitOrder_.shrink();
235 indexInFace_.shrink();
236}
237
238
239// ************************************************************************* //
Various functions to operate on Lists.
DynamicList< T, SizeMin > & shrink()
Shrink the allocated space to the number of elements used.
Definition: DynamicListI.H:434
void setSize(const label n)
Alias for resize()
Definition: List.H:218
A list of faces which address into the list of points.
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
const labelListList & edgeFaces() const
Return edge-face addressing.
const labelListList & faceEdges() const
Return face-edge addressing.
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
label find(const T &val, label pos=0) const
Find index of the first occurrence of the value.
Definition: UList.C:212
label rcIndex(const label i) const noexcept
Definition: UListI.H:67
label fcIndex(const label i) const noexcept
Definition: UListI.H:60
A topoSetFaceSource to select faces based on usage in another faceSet.
Definition: faceToFace.H:162
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:67
Collection of static functions to do various simple patch related things.
Definition: walkPatch.H:52
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
void reverse(UList< T > &list, const label n)
Reverse the first n elements of the list.
Definition: UListI.H:449
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
List< edge > edgeList
A List of edges.
Definition: edgeList.H:63
labelList f(nPoints)
volScalarField & e
Definition: createFields.H:11
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333