OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

surfaceLocation.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*----------------------------------------------------------------------------*/
00026 
00027 #include "surfaceLocation.H"
00028 #include "triSurface.H"
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 
00033 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00034 
00035 
00036 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00037 
00038 
00039 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00040 
00041 Foam::vector Foam::surfaceLocation::normal(const triSurface& s) const
00042 {
00043     const vectorField& n = s.faceNormals();
00044 
00045     if (elementType_ == triPointRef::NONE)
00046     {
00047         return n[index()];
00048     }
00049     else if (elementType_ == triPointRef::EDGE)
00050     {
00051         const labelList& eFaces = s.edgeFaces()[index()];
00052 
00053         if (eFaces.size() == 1)
00054         {
00055             return n[eFaces[0]];
00056         }
00057         else
00058         {
00059             vector edgeNormal(vector::zero);
00060 
00061             forAll(eFaces, i)
00062             {
00063                 edgeNormal += n[eFaces[i]];
00064             }
00065             return edgeNormal/(mag(edgeNormal) + VSMALL);
00066         }
00067     }
00068     else
00069     {
00070         return s.pointNormals()[index()];
00071     }
00072 }
00073 
00074 
00075 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00076 
00077 
00078 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
00079 
00080 
00081 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00082 
00083 void Foam::surfaceLocation::write(Ostream& os, const triSurface& s) const
00084 {
00085     if (elementType_ == triPointRef::NONE)
00086     {
00087         os  << "trianglecoords:" << s[index()].tri(s.points());
00088     }
00089     else if (elementType() == triPointRef::EDGE)
00090     {
00091         const edge& e = s.edges()[index()];
00092 
00093         os  << "edgecoords:" << e.line(s.localPoints());
00094     }
00095     else
00096     {
00097         os  << "pointcoord:" << s.localPoints()[index()];
00098     }
00099 }
00100 
00101 
00102 Foam::Istream& Foam::operator>>(Istream& is, surfaceLocation& sl)
00103 {
00104     label elType;
00105     is  >> static_cast<pointIndexHit&>(sl)
00106         >> elType >> sl.triangle_;
00107     sl.elementType_ = triPointRef::proxType(elType);
00108     return is;
00109 }
00110 
00111 
00112 Foam::Ostream& Foam::operator<<(Ostream& os, const surfaceLocation& sl)
00113 {
00114     return os
00115         << static_cast<const pointIndexHit&>(sl)
00116         << token::SPACE << label(sl.elementType_)
00117         << token::SPACE << sl.triangle_;
00118 }
00119 
00120 
00121 Foam::Ostream& Foam::operator<<
00122 (
00123     Ostream& os,
00124     const InfoProxy<surfaceLocation>& ip
00125 )
00126 {
00127     const surfaceLocation& sl = ip.t_;
00128 
00129     if (sl.elementType() == triPointRef::NONE)
00130     {
00131         os  << "coord:" << sl.rawPoint()
00132             << " inside triangle:" << sl.index()
00133             << " excludeTriangle:" << sl.triangle();
00134     }
00135     else if (sl.elementType() == triPointRef::EDGE)
00136     {
00137         os  << "coord:" << sl.rawPoint()
00138             << " on edge:" << sl.index()
00139             << " excludeTriangle:" << sl.triangle();
00140     }
00141     else
00142     {
00143         os  << "coord:" << sl.rawPoint()
00144             << " on point:" << sl.index()
00145             << " excludeTriangle:" << sl.triangle();
00146     }
00147 
00148     if (sl.hit())
00149     {
00150         os  << " (hit)";
00151     }
00152     else
00153     {
00154         os  << " (miss)";
00155     }
00156 
00157     return os;
00158 }
00159 
00160 
00161 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd