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

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