1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 \*---------------------------------------------------------------------------*/
29 #include "walkPatch.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(Foam::walkPatch, 0);
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 // Get other face using v0, v1 (in localFaces numbering). Or -1.
39 Foam::label Foam::walkPatch::getNeighbour
47 const labelList& fEdges = pp_.faceEdges()[faceI];
49 const edgeList& edges = pp_.edges();
54 // Shortcut: maybe faceEdges are sorted(?) in which case fEdges[fp] is
55 // edge between v0 and v1.
56 const edge& e = edges[fEdges[fp]];
58 if ((e[0] == v0 && e[1] == v1) || (e[0] == v1 && e[1] == v0))
61 nbrEdgeI = fEdges[fp];
65 // Loop over all faceEdges.
68 label edgeI = fEdges[i];
70 const edge& e = edges[edgeI];
74 (e[0] == v0 && e[1] == v1)
75 || (e[0] == v1 && e[1] == v0)
78 // Found edge on face which uses v0, v1.
89 FatalErrorIn("getNeighbour")
90 << "Did not find edge on face " << faceI << " that uses vertices"
91 << v0 << " and " << v1 << abort(FatalError);
95 // Get neighbouring face.
97 const labelList& eFaces = pp_.edgeFaces()[nbrEdgeI];
99 if (eFaces.size() == 1)
103 else if (eFaces.size() == 2)
105 label nbrFaceI = eFaces[0];
107 if (nbrFaceI == faceI)
109 nbrFaceI = eFaces[1];
116 FatalErrorIn("getNeighbour")
117 << "Illegal surface on patch. Face " << faceI
118 << " at vertices " << v0 << ',' << v1
119 << " has fewer than 1 or more than 2 neighbours"
120 << abort(FatalError);
126 // Gets labels of changed faces and enterVertices on faces.
127 // Returns labels of faces changed and enterVertices on them.
128 void Foam::walkPatch::faceToFace
130 const labelList& changedFaces,
131 const labelList& enterVerts,
134 labelList& nbrEnterVerts
137 nbrFaces.setSize(pp_.size());
138 nbrEnterVerts.setSize(pp_.size());
141 forAll(changedFaces, i)
143 label faceI = changedFaces[i];
144 label enterVertI = enterVerts[i];
146 if (!visited_[faceI])
149 visited_[faceI] = true;
150 visitOrder_.append(faceI);
152 const face& f = pp_.localFaces()[faceI];
154 label fp = findIndex(f, enterVertI);
156 indexInFace_.append(fp);
158 // Visit neighbouring faces in order, starting at fp.
159 for (label i = 0; i < f.size(); i++)
161 label fp1 = reverse_ ? f.rcIndex(fp) : f.fcIndex(fp);
162 label nbr = getNeighbour(faceI, fp, f[fp], f[fp1]);
168 && faceZone_[nbr] == faceZone_[faceI]
171 nbrFaces[changedI] = nbr;
172 nbrEnterVerts[changedI] = f[fp];
181 nbrFaces.setSize(changedI);
182 nbrEnterVerts.setSize(changedI);
186 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
188 // Construct from components
189 Foam::walkPatch::walkPatch
191 const primitivePatch& pp,
192 const labelList& faceZone,
195 const label enterVertI,
203 visitOrder_(pp.size()),
204 indexInFace_(pp.size())
206 // List of faces that have been visited in the current iteration.
207 labelList changedFaces(1, faceI);
208 // Corresponding list of entry vertices
209 labelList enterVerts(1, enterVertI);
214 labelList nbrEnterVerts;
226 if (nbrFaces.empty())
231 changedFaces = nbrFaces;
232 enterVerts = nbrEnterVerts;
235 visitOrder_.shrink();
236 indexInFace_.shrink();
240 // ************************************************************************* //