OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

triFaceI.H

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-2007 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 "IOstreams.H"
00028 #include "face.H"
00029 #include "triPointRef.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00037 
00038 //- Construct null
00039 inline triFace::triFace()
00040 {}
00041 
00042 
00043 //- Construct from components
00044 inline triFace::triFace
00045 (
00046     const label a,
00047     const label b,
00048     const label c
00049 )
00050 {
00051     operator[](0) = a;
00052     operator[](1) = b;
00053     operator[](2) = c;
00054 }
00055 
00056 
00057 inline triFace::triFace(Istream& is)
00058 :
00059     FixedList<label, 3>(is)
00060 {}
00061 
00062 
00063 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00064 
00065 // Return the points associated with this face
00066 inline pointField triFace::points(const pointField& points) const
00067 {
00068     pointField p(3);
00069 
00070     p[0] = points[operator[](0)];
00071     p[1] = points[operator[](1)];
00072     p[2] = points[operator[](2)];
00073 
00074     return p;
00075 }
00076 
00077 
00078 // Return triagle as a face
00079 inline face triFace::triFaceFace() const
00080 {
00081     face f(3);
00082 
00083     f[0] = operator[](0);
00084     f[1] = operator[](1);
00085     f[2] = operator[](2);
00086 
00087     return f;
00088 }
00089 
00090 
00091 inline label triFace::nEdges() const
00092 {
00093     return 3;
00094 }
00095 
00096 
00097 inline edgeList triFace::edges() const
00098 {
00099     edgeList e(3);
00100 
00101     e[0].start() = operator[](0);
00102     e[0].end() = operator[](1);
00103 
00104     e[1].start() = operator[](1);
00105     e[1].end() = operator[](2);
00106 
00107     e[2].start() = operator[](2);
00108     e[2].end() = operator[](0);
00109 
00110     return e;
00111 }
00112 
00113 
00114 inline point triFace::centre(const pointField& points) const
00115 {
00116     return (1.0/3.0)*
00117     (
00118         points[operator[](0)]
00119       + points[operator[](1)]
00120       + points[operator[](2)]
00121     );
00122 }
00123 
00124 
00125 inline scalar triFace::mag(const pointField& points) const
00126 {
00127     return ::Foam::mag(normal(points));
00128 }
00129 
00130 
00131 inline vector triFace::normal(const pointField& points) const
00132 {
00133     return 0.5*
00134     (
00135         (points[operator[](1)] - points[operator[](0)])
00136        ^(points[operator[](2)] - points[operator[](0)])
00137     );
00138 }
00139 
00140 
00141 inline scalar triFace::sweptVol
00142 (
00143     const pointField& opts,
00144     const pointField& npts
00145 ) const
00146 {
00147     return (1.0/6.0)*
00148     (
00149         (
00150             (npts[operator[](0)] - opts[operator[](0)])
00151           & (
00152                 (opts[operator[](1)] - opts[operator[](0)])
00153               ^ (opts[operator[](2)] - opts[operator[](0)])
00154             )
00155         )
00156       + (
00157             (npts[operator[](1)] - opts[operator[](1)])
00158           & (
00159                 (opts[operator[](2)] - opts[operator[](1)])
00160               ^ (npts[operator[](0)] - opts[operator[](1)])
00161             )
00162         )
00163       + (
00164             (opts[operator[](2)] - npts[operator[](2)])
00165           & (
00166                 (npts[operator[](1)] - npts[operator[](2)])
00167               ^ (npts[operator[](0)] - npts[operator[](2)])
00168             )
00169         )
00170     );
00171 }
00172 
00173 
00174 inline pointHit triFace::ray
00175 (
00176     const point& p,
00177     const vector& q,
00178     const pointField& points,
00179     const intersection::algorithm alg,
00180     const intersection::direction dir
00181 ) const
00182 {
00183     return triPointRef
00184     (
00185         points[operator[](0)],
00186         points[operator[](1)],
00187         points[operator[](2)]
00188     ).ray(p, q, alg, dir);
00189 }
00190 
00191 
00192 inline triPointRef triFace::tri(const pointField& points) const
00193 {
00194     return triPointRef
00195     (
00196         points[operator[](0)],
00197         points[operator[](1)],
00198         points[operator[](2)]
00199     );
00200 }
00201 
00202 
00203 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00204 
00205 inline bool operator==(const triFace& tf1, const triFace& tf2)
00206 {
00207     return
00208     (
00209         (tf1[0] == tf2[0] && tf1[1] == tf2[1] && tf1[2] == tf2[2])
00210      || (tf1[0] == tf2[1] && tf1[1] == tf2[2] && tf1[2] == tf2[0])
00211      || (tf1[0] == tf2[2] && tf1[1] == tf2[0] && tf1[2] == tf2[1])
00212      || (tf1[0] == tf2[2] && tf1[1] == tf2[1] && tf1[2] == tf2[0])
00213      || (tf1[0] == tf2[1] && tf1[1] == tf2[0] && tf1[2] == tf2[2])
00214      || (tf1[0] == tf2[0] && tf1[1] == tf2[2] && tf1[2] == tf2[1])
00215     );
00216 }
00217 
00218 
00219 inline bool operator!=(const triFace& tf1, const triFace& tf2)
00220 {
00221     return !(tf1 == tf2);
00222 }
00223 
00224 
00225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00226 
00227 } // End namespace Foam
00228 
00229 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd