1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "walkPatch.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 defineTypeNameAndDebug(Foam::walkPatch, 0);
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 // Get other face using v0, v1 (in localFaces numbering). Or -1.
36 Foam::label Foam::walkPatch::getNeighbour
44 const labelList& fEdges = pp_.faceEdges()[faceI];
46 const edgeList& edges = pp_.edges();
51 // Shortcut: maybe faceEdges are sorted(?) in which case fEdges[fp] is
52 // edge between v0 and v1.
53 const edge& e = edges[fEdges[fp]];
55 if ((e[0] == v0 && e[1] == v1) || (e[0] == v1 && e[1] == v0))
58 nbrEdgeI = fEdges[fp];
62 // Loop over all faceEdges.
65 label edgeI = fEdges[i];
67 const edge& e = edges[edgeI];
71 (e[0] == v0 && e[1] == v1)
72 || (e[0] == v1 && e[1] == v0)
75 // Found edge on face which uses v0, v1.
86 FatalErrorIn("getNeighbour")
87 << "Did not find edge on face " << faceI << " that uses vertices"
88 << v0 << " and " << v1 << abort(FatalError);
92 // Get neighbouring face.
94 const labelList& eFaces = pp_.edgeFaces()[nbrEdgeI];
96 if (eFaces.size() == 1)
100 else if (eFaces.size() == 2)
102 label nbrFaceI = eFaces[0];
104 if (nbrFaceI == faceI)
106 nbrFaceI = eFaces[1];
113 FatalErrorIn("getNeighbour")
114 << "Illegal surface on patch. Face " << faceI
115 << " at vertices " << v0 << ',' << v1
116 << " has fewer than 1 or more than 2 neighbours"
117 << abort(FatalError);
123 // Gets labels of changed faces and enterVertices on faces.
124 // Returns labels of faces changed and enterVertices on them.
125 void Foam::walkPatch::faceToFace
127 const labelList& changedFaces,
128 const labelList& enterVerts,
131 labelList& nbrEnterVerts
134 nbrFaces.setSize(pp_.size());
135 nbrEnterVerts.setSize(pp_.size());
138 forAll(changedFaces, i)
140 label faceI = changedFaces[i];
141 label enterVertI = enterVerts[i];
143 if (!visited_[faceI])
146 visited_[faceI] = true;
147 visitOrder_.append(faceI);
149 const face& f = pp_.localFaces()[faceI];
151 label fp = findIndex(f, enterVertI);
153 indexInFace_.append(fp);
155 // Visit neighbouring faces in order, starting at fp.
158 label fp1 = reverse_ ? f.rcIndex(fp) : f.fcIndex(fp);
159 label nbr = getNeighbour(faceI, fp, f[fp], f[fp1]);
165 && faceZone_[nbr] == faceZone_[faceI]
168 nbrFaces[changedI] = nbr;
169 nbrEnterVerts[changedI] = f[fp];
178 nbrFaces.setSize(changedI);
179 nbrEnterVerts.setSize(changedI);
183 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
185 // Construct from components
186 Foam::walkPatch::walkPatch
188 const primitivePatch& pp,
189 const labelList& faceZone,
192 const label enterVertI,
200 visitOrder_(pp.size()),
201 indexInFace_(pp.size())
203 // List of faces that have been visited in the current iteration.
204 labelList changedFaces(1, faceI);
205 // Corresponding list of entry vertices
206 labelList enterVerts(1, enterVertI);
211 labelList nbrEnterVerts;
223 if (nbrFaces.empty())
228 changedFaces = nbrFaces;
229 enterVerts = nbrEnterVerts;
232 visitOrder_.shrink();
233 indexInFace_.shrink();
237 // ************************************************************************* //