1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
28 #include "walkPatch.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(Foam::walkPatch, 0);
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 // Get other face using v0, v1 (in localFaces numbering). Or -1.
38 Foam::label Foam::walkPatch::getNeighbour
46 const labelList& fEdges = pp_.faceEdges()[faceI];
48 const edgeList& edges = pp_.edges();
53 // Shortcut: maybe faceEdges are sorted(?) in which case fEdges[fp] is
54 // edge between v0 and v1.
55 const edge& e = edges[fEdges[fp]];
57 if ((e[0] == v0 && e[1] == v1) || (e[0] == v1 && e[1] == v0))
60 nbrEdgeI = fEdges[fp];
64 // Loop over all faceEdges.
67 label edgeI = fEdges[i];
69 const edge& e = edges[edgeI];
73 (e[0] == v0 && e[1] == v1)
74 || (e[0] == v1 && e[1] == v0)
77 // Found edge on face which uses v0, v1.
88 FatalErrorIn("getNeighbour")
89 << "Did not find edge on face " << faceI << " that uses vertices"
90 << v0 << " and " << v1 << abort(FatalError);
94 // Get neighbouring face.
96 const labelList& eFaces = pp_.edgeFaces()[nbrEdgeI];
98 if (eFaces.size() == 1)
102 else if (eFaces.size() == 2)
104 label nbrFaceI = eFaces[0];
106 if (nbrFaceI == faceI)
108 nbrFaceI = eFaces[1];
115 FatalErrorIn("getNeighbour")
116 << "Illegal surface on patch. Face " << faceI
117 << " at vertices " << v0 << ',' << v1
118 << " has fewer than 1 or more than 2 neighbours"
119 << abort(FatalError);
125 // Gets labels of changed faces and enterVertices on faces.
126 // Returns labels of faces changed and enterVertices on them.
127 void Foam::walkPatch::faceToFace
129 const labelList& changedFaces,
130 const labelList& enterVerts,
133 labelList& nbrEnterVerts
136 nbrFaces.setSize(pp_.size());
137 nbrEnterVerts.setSize(pp_.size());
140 forAll(changedFaces, i)
142 label faceI = changedFaces[i];
143 label enterVertI = enterVerts[i];
145 if (!visited_[faceI])
148 visited_[faceI] = true;
149 visitOrder_.append(faceI);
151 const face& f = pp_.localFaces()[faceI];
153 label fp = findIndex(f, enterVertI);
155 indexInFace_.append(fp);
157 // Visit neighbouring faces in order, starting at fp.
158 for (label i = 0; i < f.size(); i++)
160 label fp1 = reverse_ ? f.rcIndex(fp) : f.fcIndex(fp);
161 label nbr = getNeighbour(faceI, fp, f[fp], f[fp1]);
167 && faceZone_[nbr] == faceZone_[faceI]
170 nbrFaces[changedI] = nbr;
171 nbrEnterVerts[changedI] = f[fp];
180 nbrFaces.setSize(changedI);
181 nbrEnterVerts.setSize(changedI);
185 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
187 // Construct from components
188 Foam::walkPatch::walkPatch
190 const primitivePatch& pp,
191 const labelList& faceZone,
194 const label enterVertI,
202 visitOrder_(pp.size()),
203 indexInFace_(pp.size())
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);
213 labelList nbrEnterVerts;
225 if (nbrFaces.empty())
230 changedFaces = nbrFaces;
231 enterVerts = nbrEnterVerts;
234 visitOrder_.shrink();
235 indexInFace_.shrink();
239 // ************************************************************************* //