FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*----------------------------------------------------------------------------*/
00025 
00026 #include "surfaceLocation.H"
00027 #include <triSurface/triSurface.H>
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 
00032 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00033 
00034 
00035 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00036 
00037 
00038 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00039 
00040 Foam::vector Foam::surfaceLocation::normal(const triSurface& s) const
00041 {
00042     const vectorField& n = s.faceNormals();
00043 
00044     if (elementType_ == triPointRef::NONE)
00045     {
00046         return n[index()];
00047     }
00048     else if (elementType_ == triPointRef::EDGE)
00049     {
00050         const labelList& eFaces = s.edgeFaces()[index()];
00051 
00052         if (eFaces.size() == 1)
00053         {
00054             return n[eFaces[0]];
00055         }
00056         else
00057         {
00058             vector edgeNormal(vector::zero);
00059 
00060             forAll(eFaces, i)
00061             {
00062                 edgeNormal += n[eFaces[i]];
00063             }
00064             return edgeNormal/(mag(edgeNormal) + VSMALL);
00065         }
00066     }
00067     else
00068     {
00069         return s.pointNormals()[index()];
00070     }
00071 }
00072 
00073 
00074 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00075 
00076 
00077 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
00078 
00079 
00080 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00081 
00082 void Foam::surfaceLocation::write(Ostream& os, const triSurface& s) const
00083 {
00084     if (elementType_ == triPointRef::NONE)
00085     {
00086         os  << "trianglecoords:" << s[index()].tri(s.points());
00087     }
00088     else if (elementType() == triPointRef::EDGE)
00089     {
00090         const edge& e = s.edges()[index()];
00091 
00092         os  << "edgecoords:" << e.line(s.localPoints());
00093     }
00094     else
00095     {
00096         os  << "pointcoord:" << s.localPoints()[index()];
00097     }
00098 }
00099 
00100 
00101 Foam::Istream& Foam::operator>>(Istream& is, surfaceLocation& sl)
00102 {
00103     label elType;
00104     is  >> static_cast<pointIndexHit&>(sl)
00105         >> elType >> sl.triangle_;
00106     sl.elementType_ = triPointRef::proxType(elType);
00107     return is;
00108 }
00109 
00110 
00111 Foam::Ostream& Foam::operator<<(Ostream& os, const surfaceLocation& sl)
00112 {
00113     return os
00114         << static_cast<const pointIndexHit&>(sl)
00115         << token::SPACE << label(sl.elementType_)
00116         << token::SPACE << sl.triangle_;
00117 }
00118 
00119 
00120 Foam::Ostream& Foam::operator<<
00121 (
00122     Ostream& os,
00123     const InfoProxy<surfaceLocation>& ip
00124 )
00125 {
00126     const surfaceLocation& sl = ip.t_;
00127 
00128     if (sl.elementType() == triPointRef::NONE)
00129     {
00130         os  << "coord:" << sl.rawPoint()
00131             << " inside triangle:" << sl.index()
00132             << " excludeTriangle:" << sl.triangle();
00133     }
00134     else if (sl.elementType() == triPointRef::EDGE)
00135     {
00136         os  << "coord:" << sl.rawPoint()
00137             << " on edge:" << sl.index()
00138             << " excludeTriangle:" << sl.triangle();
00139     }
00140     else
00141     {
00142         os  << "coord:" << sl.rawPoint()
00143             << " on point:" << sl.index()
00144             << " excludeTriangle:" << sl.triangle();
00145     }
00146 
00147     if (sl.hit())
00148     {
00149         os  << " (hit)";
00150     }
00151     else
00152     {
00153         os  << " (miss)";
00154     }
00155 
00156     return os;
00157 }
00158 
00159 
00160 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines