OpenFOAM logo
Open Source CFD Toolkit

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