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 "surfaceLocation.H"
27 #include "triSurface.H"
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 Foam::vector Foam::surfaceLocation::normal(const triSurface& s) const
33 const vectorField& n = s.faceNormals();
35 if (elementType_ == triPointRef::NONE)
39 else if (elementType_ == triPointRef::EDGE)
41 const labelList& eFaces = s.edgeFaces()[index()];
43 if (eFaces.size() == 1)
49 vector edgeNormal(vector::zero);
53 edgeNormal += n[eFaces[i]];
55 return edgeNormal/(mag(edgeNormal) + VSMALL);
60 return s.pointNormals()[index()];
65 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
67 void Foam::surfaceLocation::write(Ostream& os, const triSurface& s) const
69 if (elementType_ == triPointRef::NONE)
71 os << "trianglecoords:" << s[index()].tri(s.points());
73 else if (elementType() == triPointRef::EDGE)
75 const edge& e = s.edges()[index()];
77 os << "edgecoords:" << e.line(s.localPoints());
81 os << "pointcoord:" << s.localPoints()[index()];
86 Foam::Istream& Foam::operator>>(Istream& is, surfaceLocation& sl)
89 is >> static_cast<pointIndexHit&>(sl)
90 >> elType >> sl.triangle_;
91 sl.elementType_ = triPointRef::proxType(elType);
96 Foam::Ostream& Foam::operator<<(Ostream& os, const surfaceLocation& sl)
99 << static_cast<const pointIndexHit&>(sl)
100 << token::SPACE << label(sl.elementType_)
101 << token::SPACE << sl.triangle_;
105 Foam::Ostream& Foam::operator<<
108 const InfoProxy<surfaceLocation>& ip
111 const surfaceLocation& sl = ip.t_;
113 if (sl.elementType() == triPointRef::NONE)
115 os << "coord:" << sl.rawPoint()
116 << " inside triangle:" << sl.index()
117 << " excludeTriangle:" << sl.triangle();
119 else if (sl.elementType() == triPointRef::EDGE)
121 os << "coord:" << sl.rawPoint()
122 << " on edge:" << sl.index()
123 << " excludeTriangle:" << sl.triangle();
127 os << "coord:" << sl.rawPoint()
128 << " on point:" << sl.index()
129 << " excludeTriangle:" << sl.triangle();
145 // ************************************************************************* //