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

face.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 Class
00026     Foam::face
00027 
00028 Description
00029     A face is a list of labels corresponding to mesh vertices.
00030 
00031 SourceFiles
00032     faceI.H
00033     face.C
00034     faceIntersection.C
00035     faceContactSphere.C
00036     faceAreaInContact.C
00037 
00038 \*---------------------------------------------------------------------------*/
00039 
00040 #ifndef face_H
00041 #define face_H
00042 
00043 #include "pointField.H"
00044 #include "labelList.H"
00045 #include "edgeList.H"
00046 #include "vectorField.H"
00047 #include "faceListFwd.H"
00048 #include "intersection.H"
00049 #include "pointHit.H"
00050 
00051 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00052 
00053 namespace Foam
00054 {
00055 
00056 // Forward declaration of friend functions and operators
00057 
00058 class face;
00059 class triFace;
00060 
00061 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00062 class DynamicList;
00063 
00064 inline bool operator==(const face& a, const face& b);
00065 inline bool operator!=(const face& a, const face& b);
00066 inline Istream& operator>>(Istream&, face&);
00067 
00068 /*---------------------------------------------------------------------------*\
00069                            Class face Declaration
00070 \*---------------------------------------------------------------------------*/
00071 
00072 class face
00073 :
00074     public labelList
00075 {
00076     // Private Member Functions
00077 
00078         //- Edge to the right of face vertex i
00079         inline label right(const label i) const;
00080 
00081         //- Edge to the left of face vertex i
00082         inline label left(const label i) const;
00083 
00084         //- Construct list of edge vectors for face
00085         tmp<vectorField> calcEdges
00086         (
00087             const pointField& points
00088         ) const;
00089 
00090         //- Cos between neighbouring edges
00091         scalar edgeCos
00092         (
00093             const vectorField& edges,
00094             const label index
00095         ) const;
00096 
00097         //- Find index of largest internal angle on face
00098         label mostConcaveAngle
00099         (
00100             const pointField& points,
00101             const vectorField& edges,
00102             scalar& edgeCos
00103         ) const;
00104 
00105         //- Enumeration listing the modes for split()
00106         enum splitMode
00107         {
00108             COUNTTRIANGLE,  // count if split into triangles
00109             COUNTQUAD,      // count if split into triangles&quads
00110             SPLITTRIANGLE,  // split into triangles
00111             SPLITQUAD       // split into triangles&quads
00112         };
00113 
00114         //- Split face into triangles or triangles&quads.
00115         //  Stores results quadFaces[quadI], triFaces[triI]
00116         //  Returns number of new faces created
00117         label split
00118         (
00119             const splitMode mode,
00120             const pointField& points,
00121             label& triI,
00122             label& quadI,
00123             faceList& triFaces,
00124             faceList& quadFaces
00125         ) const;
00126 
00127 
00128 public:
00129 
00130     // Static data members
00131 
00132         static const char* const typeName;
00133 
00134 
00135     // Constructors
00136 
00137         //- Construct null
00138         inline face();
00139 
00140         //- Construct given size
00141         explicit inline face(label);
00142 
00143         //- Construct from list of labels
00144         explicit inline face(const UList<label>&);
00145 
00146         //- Construct from list of labels
00147         explicit inline face(const labelList&);
00148 
00149         //- Construct by transferring the parameter contents
00150         explicit inline face(const Xfer<labelList>&);
00151 
00152         //- Copy construct from triFace
00153         face(const triFace&);
00154 
00155         //- Construct from Istream
00156         inline face(Istream&);
00157 
00158 
00159     // Member Functions
00160 
00161         //- Collapse face by removing duplicate point labels
00162         //  return the collapsed size
00163         label collapse();
00164 
00165         //- Return the points corresponding to this face
00166         inline pointField points(const pointField& meshPoints) const;
00167 
00168         //- Centre point of face
00169         point centre(const pointField&) const;
00170 
00171         //- Calculate average value at centroid of face
00172         template<class Type>
00173         Type average(const pointField&, const Field<Type>&) const;
00174 
00175         //- Scalar magnitude
00176         inline scalar mag(const pointField&) const;
00177 
00178         //- Vector normal; magnitude is equal to area of face
00179         vector normal(const pointField&) const;
00180 
00181         //- Return face with reverse direction
00182         face reverseFace() const;
00183 
00184         //- Navigation through face vertices
00185 
00186             //- Which vertex on face (face index given a global index)
00187             label which(const label globalIndex) const;
00188 
00189             //- Next vertex on face
00190             inline label nextLabel(const label i) const;
00191 
00192             //- Previous vertex on face
00193             inline label prevLabel(const label i) const;
00194 
00195 
00196         //- Return the volume swept out by the face when its points move
00197         scalar sweptVol
00198         (
00199             const pointField& oldPoints,
00200             const pointField& newPoints
00201         ) const;
00202 
00203         //- Return potential intersection with face with a ray starting
00204         //  at p, direction n (does not need to be normalized)
00205         //  Does face-center decomposition and returns triangle intersection
00206         //  point closest to p. Face-center is calculated from point average.
00207         //  For a hit, the distance is signed.  Positive number
00208         //  represents the point in front of triangle
00209         //  In case of miss the point is the nearest point on the face
00210         //  and the distance is the distance between the intersection point
00211         //  and the original point.
00212         //  The half-ray or full-ray intersection and the contact
00213         //  sphere adjustment of the projection vector is set by the
00214         //  intersection parameters
00215         pointHit ray
00216         (
00217             const point& p,
00218             const vector& n,
00219             const pointField& meshPoints,
00220             const intersection::algorithm alg = intersection::FULL_RAY,
00221             const intersection::direction dir = intersection::VECTOR
00222         ) const;
00223 
00224         //- Fast intersection with a ray.
00225         //  Does face-center decomposition and returns triangle intersection
00226         //  point closest to p. See triangle::intersection for details.
00227         pointHit intersection
00228         (
00229             const point& p,
00230             const vector& q,
00231             const point& ctr,
00232             const pointField& meshPoints,
00233             const intersection::algorithm alg,
00234             const scalar tol = 0.0
00235         ) const;
00236 
00237         //- Return nearest point to face
00238         pointHit nearestPoint
00239         (
00240             const point& p,
00241             const pointField& meshPoints
00242         ) const;
00243 
00244         //- Return contact sphere diameter
00245         scalar contactSphereDiameter
00246         (
00247             const point& p,
00248             const vector& n,
00249             const pointField& meshPoints
00250         ) const;
00251 
00252         //- Return area in contact, given the displacement in vertices
00253         scalar areaInContact
00254         (
00255             const pointField& points,
00256             const scalarField& v
00257         ) const;
00258 
00259         //- Return number of edges
00260         inline label nEdges() const;
00261 
00262         //- Return edges in face point ordering, i.e. edges()[0] is edge
00263         //  between [0] and [1]
00264         edgeList edges() const;
00265 
00266         //- Return n-th face edge
00267         inline edge faceEdge(const label n) const;
00268 
00269         //- Return the edge direction on the face
00270         //  -  0: edge not found on the face
00271         //  - +1: forward (counter-clockwise) on the face
00272         //  - -1: reverse (clockwise) on the face
00273         int edgeDirection(const edge&) const;
00274 
00275         // Face splitting utilities
00276 
00277             //- Number of triangles after splitting
00278             inline label nTriangles() const;
00279 
00280             //- Number of triangles after splitting
00281             label nTriangles(const pointField& points) const;
00282 
00283             //- Split into triangles using existing points.
00284             //  Result in triFaces[triI..triI+nTri].
00285             //  Splits intelligently to maximize triangle quality.
00286             //  Returns number of faces created.
00287             label triangles
00288             (
00289                 const pointField& points,
00290                 label& triI,
00291                 faceList& triFaces
00292             ) const;
00293 
00294             //- Split into triangles using existing points.
00295             //  Append to DynamicList.
00296             //  Returns number of faces created.
00297             template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00298             label triangles
00299             (
00300                 const pointField& points,
00301                 DynamicList<face, SizeInc, SizeMult, SizeDiv>& triFaces
00302             ) const;
00303 
00304             //- Number of triangles and quads after splitting
00305             //  Returns the sum of both
00306             label nTrianglesQuads
00307             (
00308                 const pointField& points,
00309                 label& nTris,
00310                 label& nQuads
00311             ) const;
00312 
00313             //- Split into triangles and quads.
00314             //  Results in triFaces (starting at triI) and quadFaces
00315             //  (starting at quadI).
00316             //  Returns number of new faces created.
00317             label trianglesQuads
00318             (
00319                 const pointField& points,
00320                 label& triI,
00321                 label& quadI,
00322                 faceList& triFaces,
00323                 faceList& quadFaces
00324             ) const;
00325 
00326         //- compare faces
00327         //   0: different
00328         //  +1: identical
00329         //  -1: same face, but different orientation
00330         static int compare(const face&, const face&);
00331 
00332 
00333     // Friend Operators
00334 
00335         friend bool operator==(const face& a, const face& b);
00336         friend bool operator!=(const face& a, const face& b);
00337 
00338 
00339     // Istream Operator
00340 
00341         friend Istream& operator>>(Istream&, face&);
00342 };
00343 
00344 
00345 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00346 
00347 } // End namespace Foam
00348 
00349 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00350 
00351 #include "faceI.H"
00352 
00353 #ifdef NoRepository
00354 #   include "faceTemplates.C"
00355 #endif
00356 
00357 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00358 
00359 #endif
00360 
00361 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd