OpenFOAM logo
Open Source CFD Toolkit

primitiveMesh.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     primitiveMesh
00027 
00028 Description
00029     Cell-face mesh analysis engine
00030 
00031 SourceFiles
00032     primitiveMeshI.H
00033     primitiveMesh.C
00034     primitiveMeshClear.C
00035     primitiveMeshCellCells.C
00036     primitiveMeshEdgeCells.C
00037     primitiveMeshPointCells.C
00038     primitiveMeshCells.C
00039     primitiveMeshEdgeFaces.C
00040     primitiveMeshPointFaces.C
00041     primitiveMeshCellEdges.C
00042     primitiveMeshPointEdges.C
00043     primitiveMeshPointPoints.C
00044     primitiveMeshEdges.C
00045     primitiveMeshCellCentresAndVols.C
00046     primitiveMeshFaceCentresAndAreas.C
00047     primitiveMeshEdgeVectors.C
00048     primitiveMeshCheck.C
00049     primitiveMeshCheckMotion.C
00050     primitiveMeshFindCell.C
00051 
00052 \*---------------------------------------------------------------------------*/
00053 
00054 #ifndef primitiveMesh_H
00055 #define primitiveMesh_H
00056 
00057 #include "edgeList.H"
00058 #include "boundBox.H"
00059 #include "pointField.H"
00060 #include "SubField.H"
00061 #include "SubList.H"
00062 #include "faceList.H"
00063 #include "cellList.H"
00064 #include "cellShapeList.H"
00065 #include "labelList.H"
00066 #include "boolList.H"
00067 #include "labelHashSet.H"
00068 #include "Map.H"
00069 
00070 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00071 
00072 namespace Foam
00073 {
00074 
00075 /*---------------------------------------------------------------------------*\
00076                       Class primitiveMesh Declaration
00077 \*---------------------------------------------------------------------------*/
00078 
00079 class primitiveMesh
00080 {
00081     // Permanent data
00082 
00083         // Primitive size data
00084 
00085             //- Number of points
00086             label nPoints_;
00087 
00088             //- Number of edges
00089             mutable label nEdges_;
00090 
00091             //- Number of internal faces
00092             label nInternalFaces_;
00093 
00094             //- Number of faces
00095             label nFaces_;
00096 
00097             //- Number of cells
00098             label nCells_;
00099 
00100 
00101         // Minimum mesh data
00102 
00103             //- Points
00104             pointField::subField points_;
00105 
00106             //- Faces
00107             faceList::subList faces_;
00108 
00109             //- Face-owner cells
00110             labelList::subList faceOwner_;
00111 
00112             //- Face-neighbour cells
00113             labelList::subList faceNeighbour_;
00114 
00115             //- Have the primitives been cleared
00116             bool clearedPrimitives_;
00117 
00118 
00119         // Mesh motion
00120 
00121             //- Old points
00122             mutable pointField::subField* oldPointsPtr_;
00123 
00124 
00125         // Shapes
00126 
00127             //- Cell shapes
00128             mutable cellShapeList* cellShapesPtr_;
00129 
00130             //- Edges
00131             mutable edgeList* edgesPtr_;
00132 
00133 
00134         // Connectivity
00135 
00136             //- Cell-cells
00137             mutable labelListList* ccPtr_;
00138 
00139             //- Edge-cells
00140             mutable labelListList* ecPtr_;
00141 
00142             //- Point-cells
00143             mutable labelListList* pcPtr_;
00144 
00145             //- Cell-faces
00146             mutable cellList* cfPtr_;
00147 
00148             //- Edge-faces
00149             mutable labelListList* efPtr_;
00150 
00151             //- Point-faces
00152             mutable labelListList* pfPtr_;
00153 
00154             //- Cell-edges
00155             mutable labelListList* cePtr_;
00156 
00157             //- Face-edges
00158             mutable labelListList* fePtr_;
00159 
00160             //- Point-edges
00161             mutable labelListList* pePtr_;
00162 
00163             //- Point-points
00164             mutable labelListList* ppPtr_;
00165 
00166             //- Cell-points
00167             mutable labelListList* cpPtr_;
00168 
00169 
00170         // Geometric data
00171 
00172             //- Cell centres
00173             mutable vectorField* cellCentresPtr_;
00174 
00175             //- Face centres
00176             mutable vectorField* faceCentresPtr_;
00177 
00178             //- Cell volumes
00179             mutable scalarField* cellVolumesPtr_;
00180 
00181             //- Face areas
00182             mutable vectorField* faceAreasPtr_;
00183 
00184 
00185     // Private member functions
00186 
00187         //- Disallow construct as copy
00188         primitiveMesh(const primitiveMesh&);
00189 
00190         //- Disallow default bitwise assignment
00191         void operator=(const primitiveMesh&);
00192 
00193 
00194         // Private member functions to calculate demand driven data
00195 
00196         // Topological calculations
00197 
00198             //- Calculate cell shapes
00199             void calcCellShapes() const;
00200 
00201             //- Calculate cell-cell addressing
00202             void calcCellCells() const;
00203 
00204             //- Calculate cell-edge addressing
00205             void calcEdgeCells() const;
00206 
00207             //- Calculate point-cell addressing
00208             void calcPointCells() const;
00209 
00210             //- Calculate cell-face addressing
00211             void calcCells() const;
00212 
00213             //- Calculate face-edge addressing
00214             void calcEdgeFaces() const;
00215 
00216             //- Calculate point-face addressing
00217             void calcPointFaces() const;
00218 
00219             //- Calculate edge list
00220             void calcCellEdges() const;
00221 
00222             //- Calculate point-edge addressing
00223             void calcPointEdges() const;
00224 
00225             //- Calculate point-point addressing
00226             void calcPointPoints() const;
00227 
00228             //- Calculate cell-point addressing
00229             void calcCellPoints() const;
00230 
00231             //- During edge calculation, a larger set of data is assembled.
00232             // Create and destroy as a set, using clearOutEdges()
00233             void calcEdges() const;
00234             void clearOutEdges();
00235 
00236 
00237         // Geometrical calculations
00238 
00239             //- Calculate face centres and areas
00240             void calcFaceCentresAndAreas() const;
00241             void makeFaceCentresAndAreas
00242             (
00243                 const pointField& p,
00244                 vectorField& fCtrs,
00245                 vectorField& fAreas
00246             ) const;
00247 
00248             //- Calculate cell centres and volumes
00249             void calcCellCentresAndVols() const;
00250             void makeCellCentresAndVols
00251             (
00252                 const vectorField& fCtrs,
00253                 const vectorField& fAreas,
00254                 vectorField& cellCtrs,
00255                 scalarField& cellVols
00256             ) const;
00257 
00258             //- Calculate edge vectors
00259             void calcEdgeVectors() const;
00260 
00261 
00262     // Helper functions for mesh checking
00263 
00264             //- Check for more than 2 shared points between two faces
00265             void warnCommonPoints
00266             (
00267                 const label,
00268                 const Map<label>&,
00269                 bool& hasWarned
00270             ) const;
00271 
00272             //- Check if all points on face are shared with another face.
00273             bool checkDuplicateFaces
00274             (
00275                 const label,
00276                 const Map<label>&,
00277                 labelHashSet*
00278             ) const;
00279 
00280             //- Check that shared points are in consecutive order.
00281             bool checkCommonOrder
00282             (
00283                 const label,
00284                 const Map<label>&,
00285                 labelHashSet*
00286             ) const;
00287 
00288 
00289     // Static data members
00290 
00291         //- Static data to control mesh checking
00292 
00293             //- Orthogonality warning threshold
00294             static scalar orthWarn_;
00295 
00296             //- Skewness warning threshold
00297             static scalar skewWarn_;
00298 
00299             //- Aspect ratio warning threshold
00300             static scalar aspectWarn_;
00301 
00302 
00303 protected:
00304 
00305         //- Construct null
00306         primitiveMesh();
00307 
00308 
00309 public:
00310 
00311         // Static data
00312 
00313             ClassName("primitiveMesh");
00314 
00315             //- Estimated number of cells per edge
00316             static const unsigned cellsPerEdge_ = 4;
00317 
00318             //- Estimated number of cells per point
00319             static const unsigned cellsPerPoint_ = 8;
00320 
00321             //- Estimated number of faces per cell
00322             static const unsigned facesPerCell_ = 6;
00323 
00324             //- Estimated number of faces per edge
00325             static const unsigned facesPerEdge_ = 4;
00326 
00327             //- Estimated number of faces per point
00328             static const unsigned facesPerPoint_ = 12;
00329 
00330             //- Estimated number of edges per cell
00331             static const unsigned edgesPerCell_ = 12;
00332 
00333             //- Estimated number of edges per cell
00334             static const unsigned edgesPerFace_ = 4;
00335 
00336             //- Estimated number of edges per point
00337             static const unsigned edgesPerPoint_ = 6;
00338 
00339             //- Estimated number of points per cell
00340             static const unsigned pointsPerCell_ = 8;
00341 
00342             //- Estimated number of points per face
00343             static const unsigned pointsPerFace_ = 4;
00344 
00345             //- Tolerance for mesh and cell closedness
00346             static const scalar closedTolerance_;
00347 
00348 
00349     // Constructors
00350 
00351         //- Construct from components
00352         primitiveMesh
00353         (
00354             const label nPoints,
00355             const label nInternalFaces,
00356             const label nFaces,
00357             const label nCells,
00358             const pointField& points,
00359             const faceList& faces,
00360             const labelList& faceOwner,
00361             const labelList& faceNeighbour
00362         );
00363 
00364 
00365     // Destructor
00366 
00367         virtual ~primitiveMesh();
00368 
00369 
00370     // Member Functions
00371 
00372         //- Reset this primitiveMesh given a complete set of data
00373         void reset
00374         (
00375             const label nPoints,
00376             const label nInternalFaces,
00377             const label nFaces,
00378             const label nCells,
00379             const pointField& points,
00380             const faceList& faces,
00381             const labelList& faceOwner,
00382             const labelList& faceNeighbour
00383         );
00384 
00385         //- Reset this primitiveMesh given a complete set of data and cells
00386         void reset
00387         (
00388             const label nPoints,
00389             const label nInternalFaces,
00390             const label nFaces,
00391             const label nCells,
00392             const pointField& points,
00393             const faceList& faces,
00394             const labelList& faceOwner,
00395             const labelList& faceNeighbour,
00396             cellList& cells
00397         );
00398 
00399 
00400         // Access
00401 
00402             // Mesh size parameters
00403 
00404                 inline label nPoints() const;
00405                 inline label nEdges() const;
00406                 inline label nInternalFaces() const;
00407                 inline label nFaces() const;
00408                 inline label nCells() const;
00409 
00410 
00411             // Primitive mesh data
00412 
00413                 //- Return mesh points
00414                 const pointField& points() const;
00415 
00416                 //- Return faces
00417                 const faceList& faces() const;
00418 
00419                 //- Face owner addresing
00420                 inline const labelList& faceOwner() const;
00421 
00422                 //- Face neighbour addressing
00423                 inline const labelList& faceNeighbour() const;
00424 
00425                 //- Return cell shapes
00426                 const cellShapeList& cellShapes() const;
00427 
00428                 //- Return mesh edges
00429                 const edgeList& edges() const;
00430 
00431                 //- Helper function to calculate cell-face addressing from
00432                 //  face-cell addressing. If nCells is not provided it will
00433                 //  scan for the maximum.
00434                 static void calcCells
00435                 (
00436                     cellList&,
00437                     const unallocLabelList& own,
00438                     const unallocLabelList& nei,
00439                     const label nCells = -1
00440                 );
00441 
00442 
00443             // Mesh motion
00444 
00445                 //- Return old points
00446                 const pointField& oldPoints() const;
00447 
00448 
00449             // Return mesh connectivity
00450 
00451                 const labelListList& cellCells() const;
00452                 // faceCells given as faceOwner and faceNeighbour
00453                 const labelListList& edgeCells() const;
00454                 const labelListList& pointCells() const;
00455 
00456                 const cellList& cells() const;
00457                 // faceFaces considered unnecessary
00458                 const labelListList& edgeFaces() const;
00459                 const labelListList& pointFaces() const;
00460 
00461                 const labelListList& cellEdges() const;
00462                 const labelListList& faceEdges() const;
00463                 // edgeEdges considered unnecessary
00464                 const labelListList& pointEdges() const;
00465                 const labelListList& pointPoints() const;
00466                 const labelListList& cellPoints() const;
00467 
00468 
00469             // Geometric data (raw!)
00470 
00471                 const vectorField& cellCentres() const;
00472                 const vectorField& faceCentres() const;
00473                 const scalarField& cellVolumes() const;
00474                 const vectorField& faceAreas() const;
00475 
00476 
00477             // Mesh motion
00478 
00479                 //- Move points, returns volumes swept by faces in motion
00480                 tmp<scalarField> movePoints
00481                 (
00482                     const pointField& p,
00483                     const pointField& oldP
00484                 );
00485 
00486 
00487             //- Return true if given face label is internal to the mesh
00488             inline bool isInternalFace(const label faceIndex) const;
00489 
00490 
00491             // Mesh checking tools
00492 
00493                 // Checks using geometry
00494 
00495                 //- Check boundary for closedness
00496                 bool checkClosedBoundary(const bool report = false) const;
00497 
00498                 //- Check cells for closedness
00499                 bool checkClosedCells
00500                 (
00501                     const bool report = false,
00502                     labelHashSet* setPtr = NULL
00503                 ) const;
00504 
00505                 //- Check for negative face areas
00506                 bool checkFaceAreas
00507                 (
00508                     const bool report = false,
00509                     labelHashSet* setPtr = NULL
00510                 ) const;
00511 
00512                 //- Check for negative cell volumes
00513                 bool checkCellVolumes
00514                 (
00515                     
00516                     const bool report = false,
00517                     labelHashSet* setPtr = NULL
00518                 ) const;
00519 
00520                 //- Check for non-orthogonality
00521                 bool checkFaceDotProduct
00522                 (
00523                     const bool report = false,
00524                     labelHashSet* setPtr = NULL
00525                 ) const;
00526 
00527                 //- Check face pyramid volume
00528                 bool checkFacePyramids
00529                 (
00530                     const bool report = false,
00531                     const scalar minPyrVol = -SMALL,
00532                     labelHashSet* setPtr = NULL
00533                 ) const;
00534 
00535                 //- Check face skewness
00536                 bool checkFaceSkewness
00537                 (
00538                     const bool report = false,
00539                     labelHashSet* setPtr = NULL
00540                 ) const;
00541 
00542                 //- Check face angles
00543                 bool checkFaceAngles
00544                 (
00545                     const bool report = false,
00546                     const scalar maxSin = 10,    // In degrees
00547                     labelHashSet* setPtr = NULL
00548                 ) const;
00549 
00550                 //- Check face warpage: decompose face and check ratio between
00551                 //  magnitude of sum of triangle areas and sum of magnitude of
00552                 //  triangle areas.
00553                 bool checkFaceFlatness
00554                 (
00555                     const bool report,
00556                     const scalar warnFlatness,  // When to include in set.
00557                     labelHashSet* setPtr
00558                 ) const;
00559 
00560                 //- Check for unused points
00561                 bool checkPoints
00562                 (
00563                     const bool report = false,
00564                     labelHashSet* setPtr = NULL
00565                 ) const;
00566 
00567                 //- Check face ordering
00568                 bool checkUpperTriangular
00569                 (
00570                     const bool report = false,
00571                     labelHashSet* setPtr = NULL
00572                 ) const;
00573 
00574                 // Checks using topology only
00575 
00576                 //- Check cell zip-up
00577                 bool checkCellsZipUp
00578                 (
00579                     const bool report = false,
00580                     labelHashSet* setPtr = NULL
00581                 ) const;
00582 
00583                 //- Check uniqueness of face vertices
00584                 bool checkFaceVertices
00585                 (
00586                     const bool report = false,
00587                     labelHashSet* setPtr = NULL
00588                 ) const;
00589 
00590                 //- Check face-face connectivity
00591                 bool checkFaceFaces
00592                 (
00593                     const bool report = false,
00594                     labelHashSet* setPtr = NULL
00595                 ) const;
00596 
00597                 //- Check unconnected cells
00598                 bool checkFloatingCells
00599                 (
00600                     const bool report = false,
00601                     labelHashSet* setPtr = NULL
00602                 ) const;
00603 
00604 
00605             //- Check mesh topology for correctness. Returns false for no error.
00606             bool checkTopology(const bool report = false) const;
00607 
00608             //- Check mesh geometry (& implicitly topology) for correctness. 
00609             //  Returns false for no error.
00610             bool checkGeometry(const bool report = false) const;
00611 
00612             //- Check mesh for correctness. Returns false for no error.
00613             bool checkMesh(const bool report = false) const;
00614 
00615             //- Check mesh motion for correctness given motion points
00616             bool checkMeshMotion
00617             (
00618                 const pointField& newPoints,
00619                 const bool report = false
00620             ) const;
00621 
00622             //- Set the non-orthogonality warning threshold in degrees
00623             static scalar setOrthWarn(const scalar);
00624 
00625             //- Set the skewness warning threshold as percentage
00626             //  of the face area vector
00627             static scalar setSkewWarn(const scalar);
00628 
00629             //- Set the aspect ratio warning threshold
00630             static scalar setAspectWarn(const scalar);
00631 
00632 
00633         // Useful derived info
00634 
00635             //- Return mesh bounding box
00636             boundBox bounds() const
00637             {
00638                 return boundBox(points());
00639             }
00640 
00641             //- Is the point in the cell bounding box
00642             bool pointInCellBB(const point& p, label celli) const;
00643 
00644             //- Is the point in the cell
00645             bool pointInCell(const point& p, label celli) const;
00646 
00647             //- Find the cell with the nearest cell centre to location
00648             label findNearestCell(const point& location) const;
00649 
00650             //- Find cell enclosing this location (-1 if not in mesh)
00651             label findCell(const point& location) const;
00652 
00653 
00654         //  Storage management
00655 
00656             //- Print a list of all the currently allocated mesh data
00657             void printAllocated() const;
00658 
00659             //- Clear geometry
00660             void clearGeom();
00661 
00662             //- Clear topological data
00663             void clearAddressing();
00664 
00665             //- Clear all geometry and addressing unnecessary for CFD
00666             void clearOut();
00667 
00668             //- Clear primitive data.  Access to points and faces
00669             //  will be denied
00670             void clearPrimitives();
00671 
00672             //- Clear everyting primitive, geometry and addressing
00673             void clearAll();
00674 };
00675 
00676 
00677 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00678 
00679 } // End namespace Foam
00680 
00681 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00682 
00683 #include "primitiveMeshI.H"
00684 
00685 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00686 
00687 #endif
00688 
00689 // ************************************************************************* //
For further information go to www.openfoam.org