OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

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