OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide 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-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 "IOstreams.H"
00028 #include "face.H"
00029 #include "triPointRef.H"
00030 
00031 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
00032 
00033 inline int Foam::triFace::compare(const triFace& a, const triFace& b)
00034 {
00035     if
00036     (
00037         (a[0] == b[0] && a[1] == b[1] && a[2] == b[2])
00038      || (a[0] == b[1] && a[1] == b[2] && a[2] == b[0])
00039      || (a[0] == b[2] && a[1] == b[0] && a[2] == b[1])
00040     )
00041     {
00042         // identical
00043         return 1;
00044     }
00045     else if
00046     (
00047         (a[0] == b[2] && a[1] == b[1] && a[2] == b[0])
00048      || (a[0] == b[1] && a[1] == b[0] && a[2] == b[2])
00049      || (a[0] == b[0] && a[1] == b[2] && a[2] == b[1])
00050     )
00051     {
00052         // same face, but reversed orientation
00053         return -1;
00054     }
00055     else
00056     {
00057         return 0;
00058     }
00059 }
00060 
00061 
00062 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00063 
00064 inline Foam::triFace::triFace()
00065 {}
00066 
00067 
00068 inline Foam::triFace::triFace
00069 (
00070     const label a,
00071     const label b,
00072     const label c
00073 )
00074 {
00075     operator[](0) = a;
00076     operator[](1) = b;
00077     operator[](2) = c;
00078 }
00079 
00080 
00081 inline Foam::triFace::triFace(const UList<label>& lst)
00082 :
00083     FixedList<label, 3>(lst)
00084 {}
00085 
00086 
00087 inline Foam::triFace::triFace(Istream& is)
00088 :
00089     FixedList<label, 3>(is)
00090 {}
00091 
00092 
00093 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00094 
00095 inline Foam::label Foam::triFace::collapse()
00096 {
00097     // we cannot resize a FixedList, so mark duplicates with '-1'
00098     // (the lower vertex is retained)
00099     // catch any '-1' (eg, if called twice)
00100 
00101     label n = 3;
00102     if (operator[](0) == operator[](1) || operator[](1) == -1)
00103     {
00104         operator[](1) = -1;
00105         n--;
00106     }
00107     else if (operator[](1) == operator[](2) || operator[](2) == -1)
00108     {
00109         operator[](2) = -1;
00110         n--;
00111     }
00112     if (operator[](0) == operator[](2))
00113     {
00114         operator[](2) = -1;
00115         n--;
00116     }
00117 
00118     return n;
00119 }
00120 
00121 
00122 inline Foam::pointField Foam::triFace::points(const pointField& points) const
00123 {
00124     pointField p(3);
00125 
00126     p[0] = points[operator[](0)];
00127     p[1] = points[operator[](1)];
00128     p[2] = points[operator[](2)];
00129 
00130     return p;
00131 }
00132 
00133 
00134 inline Foam::face Foam::triFace::triFaceFace() const
00135 {
00136     Foam::face f(3);
00137 
00138     f[0] = operator[](0);
00139     f[1] = operator[](1);
00140     f[2] = operator[](2);
00141 
00142     return f;
00143 }
00144 
00145 
00146 inline Foam::label Foam::triFace::nEdges() const
00147 {
00148     return 3;
00149 }
00150 
00151 
00152 inline Foam::edgeList Foam::triFace::edges() const
00153 {
00154     edgeList e(3);
00155 
00156     e[0].start() = operator[](0);
00157     e[0].end()   = operator[](1);
00158 
00159     e[1].start() = operator[](1);
00160     e[1].end()   = operator[](2);
00161 
00162     e[2].start() = operator[](2);
00163     e[2].end()   = operator[](0);
00164 
00165     return e;
00166 }
00167 
00168 
00169 // return
00170 //  - +1: forward (counter-clockwise) on the face
00171 //  - -1: reverse (clockwise) on the face
00172 //  -  0: edge not found on the face
00173 inline int Foam::triFace::edgeDirection(const edge& e) const
00174 {
00175     if
00176     (
00177         (operator[](0) == e.start() && operator[](1) == e.end())
00178      || (operator[](1) == e.start() && operator[](2) == e.end())
00179      || (operator[](2) == e.start() && operator[](0) == e.end())
00180     )
00181     {
00182         return 1;
00183     }
00184     else if
00185     (
00186         (operator[](0) == e.end() && operator[](1) == e.start())
00187      || (operator[](1) == e.end() && operator[](2) == e.start())
00188      || (operator[](2) == e.end() && operator[](0) == e.start())
00189     )
00190     {
00191         return -1;
00192     }
00193     else
00194     {
00195         return 0;
00196     }
00197 }
00198 
00199 
00200 inline Foam::point Foam::triFace::centre(const pointField& points) const
00201 {
00202     return (1.0/3.0)*
00203     (
00204         points[operator[](0)]
00205       + points[operator[](1)]
00206       + points[operator[](2)]
00207     );
00208 }
00209 
00210 
00211 inline Foam::scalar Foam::triFace::mag(const pointField& points) const
00212 {
00213     return ::Foam::mag(normal(points));
00214 }
00215 
00216 // could also delegate to triPointRef(...).normal()
00217 inline Foam::vector Foam::triFace::normal(const pointField& points) const
00218 {
00219     return 0.5*
00220     (
00221         (points[operator[](1)] - points[operator[](0)])
00222        ^(points[operator[](2)] - points[operator[](0)])
00223     );
00224 }
00225 
00226 
00227 inline Foam::label Foam::triFace::nTriangles() const
00228 {
00229     return 1;
00230 }
00231 
00232 
00233 inline Foam::triFace Foam::triFace::reverseFace() const
00234 {
00235     // The starting points of the original and reverse face are identical.
00236     return triFace(operator[](0), operator[](2), operator[](1));
00237 }
00238 
00239 
00240 inline Foam::scalar Foam::triFace::sweptVol
00241 (
00242     const pointField& opts,
00243     const pointField& npts
00244 ) const
00245 {
00246     return (1.0/6.0)*
00247     (
00248         (
00249             (npts[operator[](0)] - opts[operator[](0)])
00250           & (
00251                 (opts[operator[](1)] - opts[operator[](0)])
00252               ^ (opts[operator[](2)] - opts[operator[](0)])
00253             )
00254         )
00255       + (
00256             (npts[operator[](1)] - opts[operator[](1)])
00257           & (
00258                 (opts[operator[](2)] - opts[operator[](1)])
00259               ^ (npts[operator[](0)] - opts[operator[](1)])
00260             )
00261         )
00262       + (
00263             (opts[operator[](2)] - npts[operator[](2)])
00264           & (
00265                 (npts[operator[](1)] - npts[operator[](2)])
00266               ^ (npts[operator[](0)] - npts[operator[](2)])
00267             )
00268         )
00269     );
00270 }
00271 
00272 
00273 inline Foam::pointHit Foam::triFace::ray
00274 (
00275     const point& p,
00276     const vector& q,
00277     const pointField& points,
00278     const intersection::algorithm alg,
00279     const intersection::direction dir
00280 ) const
00281 {
00282     return triPointRef
00283     (
00284         points[operator[](0)],
00285         points[operator[](1)],
00286         points[operator[](2)]
00287     ).ray(p, q, alg, dir);
00288 }
00289 
00290 
00291 inline Foam::triPointRef Foam::triFace::tri(const pointField& points) const
00292 {
00293     return triPointRef
00294     (
00295         points[operator[](0)],
00296         points[operator[](1)],
00297         points[operator[](2)]
00298     );
00299 }
00300 
00301 
00302 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00303 
00304 inline bool Foam::operator==(const triFace& a, const triFace& b)
00305 {
00306     return triFace::compare(a,b) != 0;
00307 }
00308 
00309 
00310 inline bool Foam::operator!=(const triFace& a, const triFace& b)
00311 {
00312     return triFace::compare(a,b) == 0;
00313 }
00314 
00315 
00316 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd