BUG: potentialFoam/cylinder: indexing into non-existing patch in parallel
[OpenFOAM-2.0.x.git] / src / OpenFOAM / meshes / primitiveMesh / primitiveMesh.H
blob03157bc3373d546289817aa9e2cd37c3898744cf
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::primitiveMesh
27 Description
28     Cell-face mesh analysis engine
30 SourceFiles
31     primitiveMeshI.H
32     primitiveMesh.C
33     primitiveMeshClear.C
34     primitiveMeshCellCells.C
35     primitiveMeshEdgeCells.C
36     primitiveMeshPointCells.C
37     primitiveMeshCells.C
38     primitiveMeshEdgeFaces.C
39     primitiveMeshPointFaces.C
40     primitiveMeshCellEdges.C
41     primitiveMeshPointEdges.C
42     primitiveMeshPointPoints.C
43     primitiveMeshEdges.C
44     primitiveMeshCellCentresAndVols.C
45     primitiveMeshFaceCentresAndAreas.C
46     primitiveMeshEdgeVectors.C
47     primitiveMeshCheck.C
48     primitiveMeshCheckMotion.C
49     primitiveMeshFindCell.C
51 \*---------------------------------------------------------------------------*/
53 #ifndef primitiveMesh_H
54 #define primitiveMesh_H
56 #include "DynamicList.H"
57 #include "edgeList.H"
58 #include "pointField.H"
59 #include "faceList.H"
60 #include "cellList.H"
61 #include "cellShapeList.H"
62 #include "labelList.H"
63 #include "boolList.H"
64 #include "HashSet.H"
65 #include "Map.H"
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 namespace Foam
72 // Forward declaration of classes
73 class treeDataCell;
74 template<class Type> class indexedOctree;
76 /*---------------------------------------------------------------------------*\
77                       Class primitiveMesh Declaration
78 \*---------------------------------------------------------------------------*/
80 class primitiveMesh
82     // Permanent data
84         // Primitive size data
86             //- Number of internal points (or -1 if points not sorted)
87             label nInternalPoints_;
89             //- Number of points
90             label nPoints_;
92             //- Number of internal edges using 0 boundary points
93             mutable label nInternal0Edges_;
95             //- Number of internal edges using 0 or 1 boundary points
96             mutable label nInternal1Edges_;
98             //- Number of internal edges using 0,1 or 2boundary points
99             mutable label nInternalEdges_;
101             //- Number of edges
102             mutable label nEdges_;
104             //- Number of internal faces
105             label nInternalFaces_;
107             //- Number of faces
108             label nFaces_;
110             //- Number of cells
111             label nCells_;
114         // Shapes
116             //- Cell shapes
117             mutable cellShapeList* cellShapesPtr_;
119             //- Edges
120             mutable edgeList* edgesPtr_;
123         // Connectivity
125             //- Cell-cells
126             mutable labelListList* ccPtr_;
128             //- Edge-cells
129             mutable labelListList* ecPtr_;
131             //- Point-cells
132             mutable labelListList* pcPtr_;
134             //- Cell-faces
135             mutable cellList* cfPtr_;
137             //- Edge-faces
138             mutable labelListList* efPtr_;
140             //- Point-faces
141             mutable labelListList* pfPtr_;
143             //- Cell-edges
144             mutable labelListList* cePtr_;
146             //- Face-edges
147             mutable labelListList* fePtr_;
149             //- Point-edges
150             mutable labelListList* pePtr_;
152             //- Point-points
153             mutable labelListList* ppPtr_;
155             //- Cell-points
156             mutable labelListList* cpPtr_;
158             //- Search tree to allow spatial tet searching
159             mutable indexedOctree<treeDataCell>* cellTreePtr_;
162         // On-the-fly edge addresing storage
164             //- Temporary storage for addressing.
165             mutable DynamicList<label> labels_;
167             //- Temporary storage for addressing
168             mutable labelHashSet labelSet_;
171         // Geometric data
173             //- Cell centres
174             mutable vectorField* cellCentresPtr_;
176             //- Face centres
177             mutable vectorField* faceCentresPtr_;
179             //- Cell volumes
180             mutable scalarField* cellVolumesPtr_;
182             //- Face areas
183             mutable vectorField* faceAreasPtr_;
186     // Private Member Functions
188         //- Disallow construct as copy
189         primitiveMesh(const primitiveMesh&);
191         //- Disallow default bitwise assignment
192         void operator=(const primitiveMesh&);
195         // Topological calculations
197             //- Calculate cell shapes
198             void calcCellShapes() const;
200             //- Calculate cell-cell addressing
201             void calcCellCells() const;
203             //- Calculate point-cell addressing
204             void calcPointCells() const;
206             //- Calculate cell-face addressing
207             void calcCells() const;
209             //- Calculate edge list
210             void calcCellEdges() const;
212             //- Calculate point-point addressing
213             void calcPointPoints() const;
215             //- Calculate edges, pointEdges and faceEdges (if doFaceEdges=true)
216             //  During edge calculation, a larger set of data is assembled.
217             //  Create and destroy as a set, using clearOutEdges()
218             void calcEdges(const bool doFaceEdges) const;
219             void clearOutEdges();
220             //- Helper: return (after optional creation) edge between two points
221             static label getEdge
222             (
223                 List<DynamicList<label> >&,
224                 DynamicList<edge>&,
225                 const label,
226                 const label
227             );
228             //- For on-the-fly addressing calculation
229             static label findFirstCommonElementFromSortedLists
230             (
231                 const labelList&,
232                 const labelList&
233             );
236         // Geometrical calculations
238             //- Calculate face centres and areas
239             void calcFaceCentresAndAreas() const;
240             void makeFaceCentresAndAreas
241             (
242                 const pointField& p,
243                 vectorField& fCtrs,
244                 vectorField& fAreas
245             ) const;
247             //- Calculate cell centres and volumes
248             void calcCellCentresAndVols() const;
249             void makeCellCentresAndVols
250             (
251                 const vectorField& fCtrs,
252                 const vectorField& fAreas,
253                 vectorField& cellCtrs,
254                 scalarField& cellVols
255             ) const;
257             //- Calculate edge vectors
258             void calcEdgeVectors() const;
261         // Helper functions for mesh checking
263             //- Check if all points on face are shared with another face.
264             bool checkDuplicateFaces
265             (
266                 const label,
267                 const Map<label>&,
268                 label& nBaffleFaces,
269                 labelHashSet*
270             ) const;
272             //- Check that shared points are in consecutive order.
273             bool checkCommonOrder
274             (
275                 const label,
276                 const Map<label>&,
277                 labelHashSet*
278             ) const;
281     // Static data members
283         //- Static data to control mesh checking
285             //- Cell closedness warning threshold
286             //  set as the fraction of un-closed area to closed area
287             static scalar closedThreshold_;
289             //- Aspect ratio warning threshold
290             static scalar aspectThreshold_;
292             //- Non-orthogonality warning threshold in deg
293             static scalar nonOrthThreshold_;
295             //- Skewness warning threshold
296             static scalar skewThreshold_;
298             //- Threshold where faces are considered coplanar
299             static scalar planarCosAngle_;
302 protected:
304         //- Construct null
305         primitiveMesh();
308 public:
310         // Static data
312             ClassName("primitiveMesh");
314             //- Estimated number of cells per edge
315             static const unsigned cellsPerEdge_ = 4;
317             //- Estimated number of cells per point
318             static const unsigned cellsPerPoint_ = 8;
320             //- Estimated number of faces per cell
321             static const unsigned facesPerCell_ = 6;
323             //- Estimated number of faces per edge
324             static const unsigned facesPerEdge_ = 4;
326             //- Estimated number of faces per point
327             static const unsigned facesPerPoint_ = 12;
329             //- Estimated number of edges per cell
330             static const unsigned edgesPerCell_ = 12;
332             //- Estimated number of edges per cell
333             static const unsigned edgesPerFace_ = 4;
335             //- Estimated number of edges per point
336             static const unsigned edgesPerPoint_ = 6;
338             //- Estimated number of points per cell
339             static const unsigned pointsPerCell_ = 8;
341             //- Estimated number of points per face
342             static const unsigned pointsPerFace_ = 4;
345     // Constructors
347         //- Construct from components
348         primitiveMesh
349         (
350             const label nPoints,
351             const label nInternalFaces,
352             const label nFaces,
353             const label nCells
354         );
357     //- Destructor
358     virtual ~primitiveMesh();
361     // Member Functions
363         //- Reset this primitiveMesh given the primitive array sizes
364         void reset
365         (
366             const label nPoints,
367             const label nInternalFaces,
368             const label nFaces,
369             const label nCells
370         );
372         //- Reset this primitiveMesh given the primitive array sizes and cells
373         void reset
374         (
375             const label nPoints,
376             const label nInternalFaces,
377             const label nFaces,
378             const label nCells,
379             cellList& cells
380         );
383         //- Reset this primitiveMesh given the primitive array sizes and cells
384         void reset
385         (
386             const label nPoints,
387             const label nInternalFaces,
388             const label nFaces,
389             const label nCells,
390             const Xfer<cellList>& cells
391         );
394         // Access
396             // Mesh size parameters
398                 inline label nPoints() const;
399                 inline label nEdges() const;
400                 inline label nInternalFaces() const;
401                 inline label nFaces() const;
402                 inline label nCells() const;
404                 // If points are ordered (nInternalPoints != -1):
406                     //- Points not on boundary
407                     inline label nInternalPoints() const;
409                     //- Internal edges (i.e. not on boundary face) using
410                     //  no boundary point
411                     inline label nInternal0Edges() const;
412                     //- Internal edges using 0 or 1 boundary point
413                     inline label nInternal1Edges() const;
414                     //- Internal edges using 0,1 or 2 boundary points
415                     inline label nInternalEdges() const;
418             // Primitive mesh data
420                 //- Return mesh points
421                 virtual const pointField& points() const = 0;
423                 //- Return faces
424                 virtual const faceList& faces() const = 0;
426                 //- Face face-owner addresing
427                 virtual const labelList& faceOwner() const = 0;
429                 //- Face face-neighbour addressing
430                 virtual const labelList& faceNeighbour() const = 0;
432                 //- Return old points for mesh motion
433                 virtual const pointField& oldPoints() const = 0;
436             // Derived mesh data
438                 //- Return cell shapes
439                 const cellShapeList& cellShapes() const;
441                 //- Return mesh edges. Uses calcEdges.
442                 const edgeList& edges() const;
444                 //- Helper function to calculate cell-face addressing from
445                 //  face-cell addressing. If nCells is not provided it will
446                 //  scan for the maximum.
447                 static void calcCells
448                 (
449                     cellList&,
450                     const labelUList& own,
451                     const labelUList& nei,
452                     const label nCells = -1
453                 );
455                 //- Helper function to calculate point ordering. Returns true
456                 //  if points already ordered, false and fills pointMap (old to
457                 //  new). Map splits points into those not used by any boundary
458                 //  face and those that are.
459                 static bool calcPointOrder
460                 (
461                     label& nInternalPoints,
462                     labelList& pointMap,
463                     const faceList&,
464                     const label nInternalFaces,
465                     const label nPoints
466                 );
468             // Return mesh connectivity
470                 const labelListList& cellCells() const;
471                 // faceCells given as owner and neighbour
472                 const labelListList& edgeCells() const;
473                 const labelListList& pointCells() const;
475                 const cellList& cells() const;
476                 // faceFaces considered unnecessary
477                 const labelListList& edgeFaces() const;
478                 const labelListList& pointFaces() const;
480                 const labelListList& cellEdges() const;
481                 const labelListList& faceEdges() const;
482                 // edgeEdges considered unnecessary
483                 const labelListList& pointEdges() const;
484                 const labelListList& pointPoints() const;
485                 const labelListList& cellPoints() const;
488             //- Build (if necessary) and return the cell search tree
489             const indexedOctree<treeDataCell>& cellTree() const;
492             // Geometric data (raw!)
494                 const vectorField& cellCentres() const;
495                 const vectorField& faceCentres() const;
496                 const scalarField& cellVolumes() const;
497                 const vectorField& faceAreas() const;
500             // Mesh motion
502                 //- Move points, returns volumes swept by faces in motion
503                 tmp<scalarField> movePoints
504                 (
505                     const pointField& p,
506                     const pointField& oldP
507                 );
510             //- Return true if given face label is internal to the mesh
511             inline bool isInternalFace(const label faceIndex) const;
514             // Topological checks
516                 //- Check cell zip-up
517                 bool checkCellsZipUp
518                 (
519                     const bool report = false,
520                     labelHashSet* setPtr = NULL
521                 ) const;
523                 //- Check uniqueness of face vertices
524                 bool checkFaceVertices
525                 (
526                     const bool report = false,
527                     labelHashSet* setPtr = NULL
528                 ) const;
530                 //- Check face-face connectivity
531                 bool checkFaceFaces
532                 (
533                     const bool report = false,
534                     labelHashSet* setPtr = NULL
535                 ) const;
537                 //- Check face ordering
538                 bool checkUpperTriangular
539                 (
540                     const bool report = false,
541                     labelHashSet* setPtr = NULL
542                 ) const;
545             // Geometric checks
547                 //- Check boundary for closedness
548                 bool checkClosedBoundary(const bool report = false) const;
550                 //- Check cells for closedness
551                 bool checkClosedCells
552                 (
553                     const bool report = false,
554                     labelHashSet* setPtr = NULL,
555                     labelHashSet* highAspectSetPtr = NULL,
556                     const Vector<label>& solutionD = Vector<label>::one
557                 ) const;
559                 //- Check for negative face areas
560                 bool checkFaceAreas
561                 (
562                     const bool report = false,
563                     labelHashSet* setPtr = NULL
564                 ) const;
566                 //- Check for negative cell volumes
567                 bool checkCellVolumes
568                 (
569                     const bool report = false,
570                     labelHashSet* setPtr = NULL
571                 ) const;
573                 //- Check for non-orthogonality
574                 bool checkFaceOrthogonality
575                 (
576                     const bool report = false,
577                     labelHashSet* setPtr = NULL
578                 ) const;
580                 //- Check face pyramid volume
581                 bool checkFacePyramids
582                 (
583                     const bool report = false,
584                     const scalar minPyrVol = -SMALL,
585                     labelHashSet* setPtr = NULL
586                 ) const;
588                 //- Check face skewness
589                 bool checkFaceSkewness
590                 (
591                     const bool report = false,
592                     labelHashSet* setPtr = NULL
593                 ) const;
595                 //- Check face angles
596                 bool checkFaceAngles
597                 (
598                     const bool report = false,
599                     const scalar maxSin = 10,    // In degrees
600                     labelHashSet* setPtr = NULL
601                 ) const;
603                 //- Check face warpage: decompose face and check ratio between
604                 //  magnitude of sum of triangle areas and sum of magnitude of
605                 //  triangle areas.
606                 bool checkFaceFlatness
607                 (
608                     const bool report,
609                     const scalar warnFlatness,  // When to include in set.
610                     labelHashSet* setPtr
611                 ) const;
613                 //- Check edge alignment for 1D/2D cases
614                 bool checkEdgeAlignment
615                 (
616                     const bool report,
617                     const Vector<label>& directions,
618                     labelHashSet* setPtr = NULL
619                 ) const;
621                 //- Check for unused points
622                 bool checkPoints
623                 (
624                     const bool report = false,
625                     labelHashSet* setPtr = NULL
626                 ) const;
628                 //- Check for point-point-nearness,
629                 //  e.g. colocated points which may be part of baffles.
630                 bool checkPointNearness
631                 (
632                     const bool report,
633                     const scalar reportDistSqr,
634                     labelHashSet* setPtr = NULL
635                 ) const;
637                 //- Check edge length
638                 bool checkEdgeLength
639                 (
640                     const bool report,
641                     const scalar minLenSqr,
642                     labelHashSet* setPtr = NULL
643                 ) const;
645                 //- Check cell determinant
646                 bool checkCellDeterminant
647                 (
648                     const bool report = false,
649                     labelHashSet* setPtr = NULL,
650                     const Vector<label>& solutionD = Vector<label>::one
651                 ) const;
653                 //- Check for concave cells by the planes of faces
654                 bool checkConcaveCells
655                 (
656                     const bool report = false,
657                     labelHashSet* setPtr = NULL
658                 ) const;
661             //- Check mesh topology for correctness.
662             //  Returns false for no error.
663             bool checkTopology(const bool report = false) const;
665             //- Check mesh geometry (& implicitly topology) for correctness.
666             //  Returns false for no error.
667             bool checkGeometry(const bool report = false) const;
669             //- Check mesh for correctness. Returns false for no error.
670             bool checkMesh(const bool report = false) const;
672             //- Check mesh motion for correctness given motion points
673             bool checkMeshMotion
674             (
675                 const pointField& newPoints,
676                 const bool report = false
677             ) const;
680             //- Set the closedness ratio warning threshold
681             static scalar setClosedThreshold(const scalar);
683             //- Set the aspect ratio warning threshold
684             static scalar setAspectThreshold(const scalar);
686             //- Set the non-orthogonality warning threshold in degrees
687             static scalar setNonOrthThreshold(const scalar);
689             //- Set the skewness warning threshold as percentage
690             //  of the face area vector
691             static scalar setSkewThreshold(const scalar);
694         // Useful derived info
696             //- Is the point in the cell bounding box, option relative
697             //  tolerance to increase the effective size of the boundBox
698             bool pointInCellBB
699             (
700                 const point& p,
701                 label celli,
702                 scalar tol = 0
703             ) const;
705             //- Is the point in the cell
706             bool pointInCell(const point& p, label celli) const;
708             //- Find the cell with the nearest cell centre to location
709             label findNearestCell(const point& location) const;
711             //- Find cell enclosing this location (-1 if not in mesh)
712             label findCell(const point& location) const;
715         //  Storage management
717             //- Print a list of all the currently allocated mesh data
718             void printAllocated() const;
720             // Per storage whether allocated
721             inline bool hasCellShapes() const;
722             inline bool hasEdges() const;
723             inline bool hasCellCells() const;
724             inline bool hasEdgeCells() const;
725             inline bool hasPointCells() const;
726             inline bool hasCells() const;
727             inline bool hasEdgeFaces() const;
728             inline bool hasPointFaces() const;
729             inline bool hasCellEdges() const;
730             inline bool hasFaceEdges() const;
731             inline bool hasPointEdges() const;
732             inline bool hasPointPoints() const;
733             inline bool hasCellPoints() const;
734             inline bool hasCellCentres() const;
735             inline bool hasFaceCentres() const;
736             inline bool hasCellVolumes() const;
737             inline bool hasFaceAreas() const;
739             // On-the-fly addressing calculation. These functions return either
740             // a reference to the full addressing (if already calculated) or
741             // a reference to the supplied storage. The one-argument ones
742             // use member DynamicList labels_ so be careful when not storing
743             // result.
745             //- cellCells using cells.
746             const labelList& cellCells
747             (
748                 const label cellI,
749                 DynamicList<label>&
750             ) const;
752             const labelList& cellCells(const label cellI) const;
754             //- cellPoints using cells
755             const labelList& cellPoints
756             (
757                 const label cellI,
758                 DynamicList<label>&
759             ) const;
761             const labelList& cellPoints(const label cellI) const;
763             //- pointCells using pointFaces
764             const labelList& pointCells
765             (
766                 const label pointI,
767                 DynamicList<label>&
768             ) const;
770             const labelList& pointCells(const label pointI) const;
772             //- pointPoints using edges, pointEdges
773             const labelList& pointPoints
774             (
775                 const label pointI,
776                 DynamicList<label>&
777             ) const;
779             const labelList& pointPoints(const label pointI) const;
781             //- faceEdges using pointFaces, edges, pointEdges
782             const labelList& faceEdges
783             (
784                 const label faceI,
785                 DynamicList<label>&
786             ) const;
788             const labelList& faceEdges(const label faceI) const;
790             //- edgeFaces using pointFaces, edges, pointEdges
791             const labelList& edgeFaces
792             (
793                 const label edgeI,
794                 DynamicList<label>&
795             ) const;
797             const labelList& edgeFaces(const label edgeI) const;
799             //- edgeCells using pointFaces, edges, pointEdges
800             const labelList& edgeCells
801             (
802                 const label edgeI,
803                 DynamicList<label>&
804             ) const;
806             const labelList& edgeCells(const label edgeI) const;
808             //- cellEdges using cells, pointFaces, edges, pointEdges
809             const labelList& cellEdges
810             (
811                 const label cellI,
812                 DynamicList<label>&
813             ) const;
815             const labelList& cellEdges(const label cellI) const;
818             //- Clear geometry
819             void clearGeom();
821             //- Clear topological data
822             void clearAddressing();
824             //- Clear cell tree data
825             void clearCellTree();
827             //- Clear all geometry and addressing unnecessary for CFD
828             void clearOut();
832 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
834 } // End namespace Foam
836 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
838 #include "primitiveMeshI.H"
840 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
842 #endif
844 // ************************************************************************* //