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/>.
25 \*---------------------------------------------------------------------------*/
27 #include "directionInfo.H"
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 // Find edge among edgeLabels that uses v0 and v1
33 Foam::label Foam::directionInfo::findEdge
35 const primitiveMesh& mesh,
36 const labelList& edgeLabels,
41 forAll(edgeLabels, edgeLabelI)
43 label edgeI = edgeLabels[edgeLabelI];
45 if (mesh.edges()[edgeI] == edge(v0, v1))
51 FatalErrorIn("directionInfo::findEdge")
52 << "Cannot find an edge among " << edgeLabels << endl
53 << "that uses vertices " << v0
61 Foam::label Foam::directionInfo::lowest
69 label a1 = (a + 1) % size;
77 label b1 = (b + 1) % size;
81 FatalErrorIn("directionInfo::lowest")
82 << "Problem : a:" << a << " b:" << b << " size:" << size
91 // Have edge on hex cell. Find corresponding edge on face. Return -1 if none
93 Foam::label Foam::directionInfo::edgeToFaceIndex
95 const primitiveMesh& mesh,
101 if ((edgeI < 0) || (edgeI >= mesh.nEdges()))
103 FatalErrorIn("directionInfo::edgeToFaceIndex")
104 << "Illegal edge label:" << edgeI
105 << " when projecting cut edge from cell " << cellI
106 << " to face " << faceI
107 << abort(FatalError);
110 const edge& e = mesh.edges()[edgeI];
112 const face& f = mesh.faces()[faceI];
115 // - in faceI. Convert into index in face.
116 // - connected (but not in) to face. Return -1.
117 // - in face opposite faceI. Convert into index in face.
119 label fpA = findIndex(f, e.start());
120 label fpB = findIndex(f, e.end());
126 return lowest(f.size(), fpA, fpB);
130 // e.start() in face, e.end() not
138 // e.end() in face, e.start() not
144 // e is on opposite face. Determine corresponding edge on this face:
145 // - determine two faces using edge (one is the opposite face,
146 // one is 'side' face
147 // - walk on both these faces to opposite edge
148 // - check if this opposite edge is on faceI
152 meshTools::getEdgeFaces(mesh, cellI, edgeI, f0I, f1I);
154 // Walk to opposite edge on face f0
156 meshTools::walkFace(mesh, f0I, edgeI, e.start(), 2);
158 // Check if edge on faceI.
160 const edge& e0 = mesh.edges()[edge0I];
162 fpA = findIndex(f, e0.start());
163 fpB = findIndex(f, e0.end());
165 if ((fpA != -1) && (fpB != -1))
167 return lowest(f.size(), fpA, fpB);
170 // Face0 is doesn't have an edge on faceI (so must be the opposite
171 // face) so try face1.
173 // Walk to opposite edge on face f1
175 meshTools::walkFace(mesh, f1I, edgeI, e.start(), 2);
177 // Check if edge on faceI.
178 const edge& e1 = mesh.edges()[edge1I];
180 fpA = findIndex(f, e1.start());
181 fpB = findIndex(f, e1.end());
183 if ((fpA != -1) && (fpB != -1))
185 return lowest(f.size(), fpA, fpB);
188 FatalErrorIn("directionInfo::edgeToFaceIndex")
189 << "Found connected faces " << mesh.faces()[f0I] << " and "
190 << mesh.faces()[f1I] << " sharing edge " << edgeI << endl
191 << "But none seems to be connected to face " << faceI
193 << abort(FatalError);
201 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
203 Foam::Ostream& Foam::operator<<
206 const Foam::directionInfo& wDist
209 if (os.format() == IOstream::ASCII)
211 os << wDist.index_ << wDist.n_;
217 reinterpret_cast<const char*>(&wDist.index_),
218 sizeof(directionInfo)
222 // Check state of Ostream
223 os.check("Ostream& operator<<(Ostream&, const directionInfo&)");
229 Foam::Istream& Foam::operator>>(Foam::Istream& is, Foam::directionInfo& wDist)
231 if (is.format() == IOstream::ASCII)
233 is >> wDist.index_ >> wDist.n_;
239 reinterpret_cast<char*>(&wDist.index_),
240 sizeof(directionInfo)
244 // Check state of Istream
245 is.check("Istream& operator>>(Istream&, directionInfo&)");
249 // ************************************************************************* //