OpenFOAM logo
Open Source CFD Toolkit

PrimitivePatch.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 Class
00026     PrimitivePatch
00027 
00028 Description
00029     A PrimitivePatch is a list of faces which address into the list of
00030     points.  The class is templated on the form of the face
00031     (e.g. triangle, polygon etc.)  and one the form of list for faces
00032     and points so that it can refere to existing lists using
00033     UList and const pointField& or hold the storage using
00034     List and pointField.
00035 
00036 SourceFiles
00037     PrimitivePatch.C
00038     PrimitivePatchAddressing.C
00039     PrimitivePatchFaceCells.C
00040     PrimitivePatchBdryPoints.C
00041     PrimitivePatchMeshData.C
00042     PrimitivePatchPointAddressing.C
00043     PrimitivePatchLocalPointOrder.C
00044     PrimitivePatchEdgeLoops.C
00045     PrimitivePatchMeshEdges.C
00046     PrimitivePatchProjectPoints.C
00047     PrimitivePatchClear.C
00048 
00049 \*---------------------------------------------------------------------------*/
00050 
00051 #ifndef PrimitivePatch_H
00052 #define PrimitivePatch_H
00053 
00054 #include "boolList.H"
00055 #include "labelList.H"
00056 #include "edgeList.H"
00057 #include "pointField.H"
00058 #include "vectorField.H"
00059 #include "intersection.H"
00060 #include "labelHashSet.H"
00061 
00062 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00063 
00064 namespace Foam
00065 {
00066 
00067 class face;
00068 class objectHit;
00069 template<class T> class Map;
00070 
00071 /*---------------------------------------------------------------------------*\
00072                         Class PrimitivePatchName Declaration
00073 \*---------------------------------------------------------------------------*/
00074 
00075 TemplateName(PrimitivePatch);
00076 
00077 
00078 /*---------------------------------------------------------------------------*\
00079                            Class PrimitivePatch Declaration
00080 \*---------------------------------------------------------------------------*/
00081 
00082 template<class Face, template<class> class FaceList, class PointField>
00083 class PrimitivePatch
00084 :
00085     public PrimitivePatchName,
00086     public FaceList<Face>
00087 {
00088 
00089 public:
00090 
00091     // Public data types
00092 
00093         //- Enumeration defining the surface type. Used in check routines.
00094         enum surfaceTopo
00095         {
00096             MANIFOLD,
00097             OPEN,
00098             ILLEGAL
00099         };
00100 
00101 private:
00102 
00103     // Private data
00104 
00105         //- Reference to global list of points
00106         PointField points_;
00107 
00108 
00109     // Demand driven private data
00110 
00111         //- Edges of the patch; address into local point list;
00112         //  sorted with internal edges first in upper-triangular order
00113         //  and external edges last.
00114         mutable edgeList* edgesPtr_;
00115 
00116         //- Which part of edgesPtr_ is internal edges.
00117         mutable label nInternalEdges_;
00118 
00119         //- Boundary point labels, addressing into local point list
00120         mutable labelList* boundaryPointsPtr_;
00121 
00122         //- Face-face addressing
00123         mutable labelListList* faceFacesPtr_;
00124 
00125         //- Edge-face addressing
00126         mutable labelListList* edgeFacesPtr_;
00127 
00128         //- Face-edge addressing
00129         mutable labelListList* faceEdgesPtr_;
00130 
00131         //- Point-edge addressing
00132         mutable labelListList* pointEdgesPtr_;
00133 
00134         //- Point-face addressing
00135         mutable labelListList* pointFacesPtr_;
00136 
00137         //- Faces addressing into local point list
00138         mutable List<Face>* localFacesPtr_;
00139 
00140         //- Labels of mesh points
00141         mutable labelList* meshPointsPtr_;
00142 
00143         //- Mesh point map.  Given the global point index find its
00144         //location in the patch
00145         mutable Map<label>* meshPointMapPtr_;
00146 
00147         //- Outside edge loops
00148         mutable labelListList* edgeLoopsPtr_;
00149 
00150         //- Points local to patch
00151         mutable pointField* localPointsPtr_;
00152 
00153         //- Local point order for most efficient search
00154         mutable labelList* localPointOrderPtr_;
00155 
00156         //- Face unit normals
00157         mutable vectorField* faceNormalsPtr_;
00158 
00159         //- Point unit normals
00160         mutable vectorField* pointNormalsPtr_;
00161 
00162 
00163     // Private Member Functions
00164 
00165         //- Calculate edges of the patch
00166         void calcIntBdryEdges() const;
00167 
00168         //- Calculated boundary points on a patch
00169         void calcBdryPoints() const;
00170 
00171         //- Calculate addressing
00172         void calcAddressing() const;
00173 
00174         //- Calculate point-edge addressing
00175         void calcPointEdges() const;
00176 
00177         //- Calculate point-face addressing
00178         void calcPointFaces() const;
00179 
00180         //- Calculate mesh addressing
00181         void calcMeshData() const;
00182 
00183         //- Calculate mesh point map
00184         void calcMeshPointMap() const;
00185 
00186         //- Calculate outside edge loops
00187         void calcEdgeLoops() const;
00188 
00189         //- Calculate local points
00190         void calcLocalPoints() const;
00191 
00192         //- Calculate local point order
00193         void calcLocalPointOrder() const;
00194 
00195         //- Calculate unit face normals
00196         void calcFaceNormals() const;
00197 
00198         //- Calculate unit point normals
00199         void calcPointNormals() const;
00200 
00201 
00202         //- Face-edge-face walk while remaining on a patch point.
00203         // Used to determine if surface multiply connected through point.
00204         void visitPointRegion
00205         (
00206             const label pointI,
00207             const labelList& pFaces,
00208             const label startFaceI,
00209             const label startEdgeI,
00210             boolList& pFacesHad
00211         ) const;
00212 
00213 
00214 public:
00215 
00216     // Constructors
00217 
00218         //- Construct from components
00219         PrimitivePatch
00220         (
00221             const FaceList<Face>& faces,
00222             const pointField& points
00223         );
00224 
00225         //- Construct as copy
00226         PrimitivePatch(const PrimitivePatch<Face, FaceList, PointField>&);
00227 
00228 
00229     // Destructor
00230 
00231         virtual ~PrimitivePatch();
00232 
00233         void clearOut();
00234 
00235         void clearGeom();
00236 
00237         void clearTopology();
00238 
00239         void clearPatchMeshAddr();
00240 
00241 
00242     // Member Functions
00243 
00244         // Access
00245 
00246             //- Return reference to global points
00247             const pointField& points() const
00248             {
00249                 return points_;
00250             }
00251 
00252 
00253         // Access functions for demand driven data
00254 
00255             // Topological data; no mesh required.
00256 
00257                 //- Return number of points supporting patch faces
00258                 label nPoints() const
00259                 {
00260                     return meshPoints().size();
00261                 }
00262 
00263                 //- Return number of edges in patch
00264                 label nEdges() const
00265                 {
00266                     return edges().size();
00267                 }
00268 
00269                 //- Return list of edges, address into LOCAL point list
00270                 const edgeList& edges() const;
00271 
00272                 //- Number of internal edges
00273                 label nInternalEdges() const;
00274 
00275                 //- Is internal edge?
00276                 bool isInternalEdge(const label edgeI) const
00277                 {
00278                     return edgeI < nInternalEdges();
00279                 }
00280 
00281                 //- Return list of boundary points,
00282                 //  address into LOCAL point list
00283                 const labelList& boundaryPoints() const;
00284 
00285                 //- Return face-face addressing
00286                 const labelListList& faceFaces() const;
00287 
00288                 //- Return edge-face addressing
00289                 const labelListList& edgeFaces() const;
00290 
00291                 //- Return face-edge addressing
00292                 const labelListList& faceEdges() const;
00293 
00294                 //- Return point-edge addressing
00295                 const labelListList& pointEdges() const;
00296 
00297                 //- Return point-face addressing
00298                 const labelListList& pointFaces() const;
00299 
00300                 //- Return patch faces addressing into local point list
00301                 const List<Face>& localFaces() const;
00302 
00303 
00304             // Addressing into mesh
00305 
00306                 //- Return labelList of mesh points in patch
00307                 const labelList& meshPoints() const;
00308 
00309                 //- Mesh point map.  Given the global point index find its
00310                 //  location in the patch
00311                 const Map<label>& meshPointMap() const;
00312 
00313                 //- Return pointField of points in patch
00314                 const pointField& localPoints() const;
00315 
00316                 //- Return orders the local points for most efficient search
00317                 const labelList& localPointOrder() const;
00318 
00319                 //- Given a global point index, return the local point
00320                 //index.  If the point is not found, return -1
00321                 label whichPoint(const label gp) const;
00322 
00323                 //- Given an edge in local point labels, return its
00324                 //  index in the edge list.  If the edge is not found, return -1
00325                 label whichEdge(const edge& e) const;
00326 
00327                 //- Return labels of patch edges in the global edge list
00328                 labelList meshEdges
00329                 (
00330                     const edgeList& allEdges,
00331                     const labelListList& cellEdges,
00332                     const labelList& faceCells
00333                 ) const;
00334 
00335                 //- Return face normals for patch
00336                 const vectorField& faceNormals() const;
00337 
00338                 //- Return point normals for patch
00339                 const vectorField& pointNormals() const;
00340 
00341 
00342             // Other patch operations
00343 
00344                 //- Project vertices of patch onto another patch
00345                 template <class ToPatch>
00346                 List<objectHit> projectPoints
00347                 (
00348                     const ToPatch& targetPatch,
00349                     const vectorField& projectionDirection,
00350                     const intersection::algorithm alg = intersection::FULL_RAY,
00351                     const intersection::direction dir = intersection::VECTOR
00352                 ) const;
00353 
00354                 //- Project vertices of patch onto another patch
00355                 template <class ToPatch>
00356                 List<objectHit> projectFaceCentres
00357                 (
00358                     const ToPatch& targetPatch,
00359                     const vectorField& projectionDirection,
00360                     const intersection::algorithm alg = intersection::FULL_RAY,
00361                     const intersection::direction dir = intersection::VECTOR
00362                 ) const;
00363 
00364                 //- Return list of closed loops of boundary vertices.
00365                 //  Edge loops are given as ordered lists of vertices
00366                 //  in local addressing
00367                 const labelListList& edgeLoops() const;
00368 
00369 
00370         // Check
00371 
00372             //- Calculate surface type formed by patch.
00373             //  - all edges have two neighbours (manifold)
00374             //  - some edges have more than two neighbours (illegal)
00375             //  - other (open)
00376             surfaceTopo surfaceType() const;
00377 
00378             //- Check surface formed by patch for manifoldness (see above).
00379             //  Insert vertices of incorrect
00380             //  edges set. Return true if any incorrect edge found.
00381             bool checkTopology
00382             (
00383                 const bool report = false,
00384                 labelHashSet* setPtr = NULL
00385             ) const;
00386 
00387             //- Checks primitivePatch for faces sharing point but not edge.
00388             //  This denotes a surface that is pinched at a single point
00389             //  (test for pinched at single edge is already in PrimitivePatch)
00390             //  Returns true if this situation found and puts conflicting
00391             // (mesh)point in set. Based on all the checking routines in
00392             // primitiveMesh.
00393             bool checkPointManifold
00394             (
00395                 const bool report = false,
00396                 labelHashSet* setPtr = NULL
00397             ) const;
00398 
00399 
00400         // Edit
00401 
00402             //- Correct patch after moving points
00403             virtual void movePoints(const pointField&);
00404 
00405 
00406     // Member operators
00407 
00408         //- Assignment
00409         void operator=(const PrimitivePatch<Face, FaceList, PointField>&);
00410 };
00411 
00412 
00413 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00414 
00415 } // End namespace Foam
00416 
00417 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00418 
00419 #ifdef NoRepository
00420 #   include "PrimitivePatch.C"
00421 #endif
00422 
00423 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00424 
00425 #endif
00426 
00427 // ************************************************************************* //
For further information go to www.openfoam.org