Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / meshes / primitiveMesh / primitiveMesh.H
blob7d3bffa58a11b0b2a6b4a5322b95aac6cb549c17
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  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 "SubField.H"
60 #include "SubList.H"
61 #include "faceList.H"
62 #include "cellList.H"
63 #include "cellShapeList.H"
64 #include "labelList.H"
65 #include "boolList.H"
66 #include "HashSet.H"
67 #include "Map.H"
68 #include "EdgeMap.H"
69 #include "tolerancesSwitch.H"
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 namespace Foam
76 /*---------------------------------------------------------------------------*\
77                       Class primitiveMesh Declaration
78 \*---------------------------------------------------------------------------*/
80 class primitiveMesh
82     // Permanent data
84         // Primitive size data
86             //- Number of points
87             label nPoints_;
89             //- Number of edges
90             mutable label nEdges_;
92             //- Number of internal faces
93             label nInternalFaces_;
95             //- Number of faces
96             label nFaces_;
98             //- Number of cells
99             label nCells_;
102         // Shapes
104             //- Cell shapes
105             mutable cellShapeList* cellShapesPtr_;
107             //- Edges are ordered in upper triangular order
108             //  Note: inconsistency with 1.6.x to re-instate
109             //  parallelisation of point-based operations
110             // HJ, 9/Jul/2010
111             mutable edgeList* edgesPtr_;
114         // Connectivity
116             //- Cell-cells
117             mutable labelListList* ccPtr_;
119             //- Edge-cells
120             mutable labelListList* ecPtr_;
122             //- Point-cells
123             mutable labelListList* pcPtr_;
125             //- Cell-faces
126             mutable cellList* cfPtr_;
128             //- Edge-faces
129             mutable labelListList* efPtr_;
131             //- Point-faces
132             mutable labelListList* pfPtr_;
134             //- Cell-edges
135             mutable labelListList* cePtr_;
137             //- Face-edges
138             mutable labelListList* fePtr_;
140             //- Point-edges
141             mutable labelListList* pePtr_;
143             //- Point-points
144             mutable labelListList* ppPtr_;
146             //- Cell-points
147             mutable labelListList* cpPtr_;
150         // On-the-fly edge addresing storage
152             //- Temporary storage for addressing.
153             mutable dynamicLabelList labels_;
155             //- Temporary storage for addressing
156             mutable labelHashSet labelSet_;
159         // Geometric data
161             //- Cell centres
162             mutable vectorField* cellCentresPtr_;
164             //- Face centres
165             mutable vectorField* faceCentresPtr_;
167             //- Cell volumes
168             mutable scalarField* cellVolumesPtr_;
170             //- Face areas
171             mutable vectorField* faceAreasPtr_;
174     // Private member functions
176         //- Disallow construct as copy
177         primitiveMesh(const primitiveMesh&);
179         //- Disallow default bitwise assignment
180         void operator=(const primitiveMesh&);
183         // Topological calculations
185             //- Calculate cell shapes
186             void calcCellShapes() const;
188             //- Calculate cell-cell addressing
189             void calcCellCells() const;
191             //- Calculate point-cell addressing
192             void calcPointCells() const;
194             //- Calculate cell-face addressing
195             void calcCells() const;
197             //- Calculate edge list
198             void calcCellEdges() const;
200             //- Calculate point-edge addressing
201             void calcPointEdges() const;
203             //- Calculate point-point addressing
204             void calcPointPoints() const;
206             //- Calculate edges, pointEdges and faceEdges
207             void calcEdges() const;
209             //- During edge calculation, a larger set of data is assembled.
210             // Create and destroy as a set, using clearOutEdges()
211             void clearOutEdges();
213             //- Helper:
214             //  return (after optional creation) edge between two points
215             static label getEdge
216             (
217                 List<dynamicLabelList >&,
218                 DynamicList<edge>&,
219                 const label,
220                 const label
221             );
222             //- For on-the-fly addressing calculation
223             static label findFirstCommonElementFromSortedLists
224             (
225                 const labelList&,
226                 const labelList&
227             );
230         // Geometrical calculations
232             //- Calculate face centres and areas
233             void calcFaceCentresAndAreas() const;
235             void makeFaceCentresAndAreas
236             (
237                 const pointField& p,
238                 vectorField& fCtrs,
239                 vectorField& fAreas
240             ) const;
242             //- Calculate cell centres and volumes
243             void calcCellCentresAndVols() const;
244             void makeCellCentresAndVols
245             (
246                 const vectorField& fCtrs,
247                 const vectorField& fAreas,
248                 vectorField& cellCtrs,
249                 scalarField& cellVols
250             ) const;
252             //- Calculate edge vectors
253             void calcEdgeVectors() const;
256         // Helper functions for mesh checking
258             //- Check if all points on face are shared with another face.
259             bool checkDuplicateFaces
260             (
261                 const label,
262                 const Map<label>&,
263                 label& nBaffleFaces,
264                 labelHashSet*
265             ) const;
267             //- Check that shared points are in consecutive order.
268             bool checkCommonOrder
269             (
270                 const label,
271                 const Map<label>&,
272                 labelHashSet*
273             ) const;
276 protected:
278         //- Construct null
279         primitiveMesh();
282 public:
284     // Static data
286         ClassName("primitiveMesh");
289     // Static mesh analysis data
291             //- Estimated number of cells per edge
292             static const unsigned cellsPerEdge_ = 4;
294             //- Estimated number of cells per point
295             static const unsigned cellsPerPoint_ = 8;
297             //- Estimated number of faces per cell
298             static const unsigned facesPerCell_ = 6;
300             //- Estimated number of faces per edge
301             static const unsigned facesPerEdge_ = 4;
303             //- Estimated number of faces per point
304             static const unsigned facesPerPoint_ = 12;
306             //- Estimated number of edges per cell
307             static const unsigned edgesPerCell_ = 12;
309             //- Estimated number of edges per cell
310             static const unsigned edgesPerFace_ = 4;
312             //- Estimated number of edges per point
313             static const unsigned edgesPerPoint_ = 6;
315             //- Estimated number of points per cell
316             static const unsigned pointsPerCell_ = 8;
318             //- Estimated number of points per face
319             static const unsigned pointsPerFace_ = 4;
321         //- Static data to control mesh checking
323             //- Cell closedness warning threshold
324             //  set as the fraction of un-closed area to closed area
325             static const debug::tolerancesSwitch closedThreshold_;
327             //- Aspect ratio warning threshold
328             static const debug::tolerancesSwitch aspectThreshold_;
330             //- Non-orthogonality warning threshold in deg
331             static Foam::debug::tolerancesSwitch nonOrthThreshold_;
333             //- Skewness warning threshold
334             static const debug::tolerancesSwitch skewThreshold_;
336             //- Face angle threshold
337             static Foam::debug::tolerancesSwitch faceAngleThreshold_;
339             //- Face flatness threshold
340             static const debug::tolerancesSwitch faceFlatnessThreshold_;
343     // Constructors
345         //- Construct from components
346         primitiveMesh
347         (
348             const label nPoints,
349             const label nInternalFaces,
350             const label nFaces,
351             const label nCells
352         );
355     // Destructor
357         virtual ~primitiveMesh();
360     // Member Functions
362         //- Reset this primitiveMesh given the primitive array sizes
363         void reset
364         (
365             const label nPoints,
366             const label nInternalFaces,
367             const label nFaces,
368             const label nCells
369         );
371         //- Reset this primitiveMesh given the primitive array sizes and cells
372         void reset
373         (
374             const label nPoints,
375             const label nInternalFaces,
376             const label nFaces,
377             const label nCells,
378             cellList& cells
379         );
382         //- Reset this primitiveMesh given the primitive array sizes and cells
383         void reset
384         (
385             const label nPoints,
386             const label nInternalFaces,
387             const label nFaces,
388             const label nCells,
389             const Xfer<cellList>& cells
390         );
393         // Access
395             // Mesh size parameters
397                 inline label nPoints() const;
398                 inline label nEdges() const;
399                 inline label nInternalFaces() const;
400                 inline label nFaces() const;
401                 inline label nCells() const;
404             // Primitive mesh data
406                 //- Return mesh points
407                 virtual const pointField& points() const = 0;
409                 //- Return faces
410                 virtual const faceList& faces() const = 0;
412                 //- Face face-owner addresing
413                 virtual const labelList& faceOwner() const = 0;
415                 //- Face face-neighbour addressing
416                 virtual const labelList& faceNeighbour() const = 0;
418                 //- Return old points for mesh motion
419                 virtual const pointField& oldPoints() const = 0;
422             // Derived mesh data
424                 //- Return cell shapes
425                 const cellShapeList& cellShapes() const;
427                 //- Return mesh edges. Uses calcEdges.
428                 const edgeList& edges() const;
430                 //- Helper function to calculate cell-face addressing from
431                 //  face-cell addressing. If nCells is not provided it will
432                 //  scan for the maximum.
433                 static void calcCells
434                 (
435                     cellList&,
436                     const unallocLabelList& own,
437                     const unallocLabelList& nei,
438                     const label nCells = -1
439                 );
441             // Removed calcPointOrder - garbage.  HJ, 27/Aug/2010
444             // Return mesh connectivity
446                 const labelListList& cellCells() const;
447                 // faceCells given as owner and neighbour
448                 const labelListList& edgeCells() const;
449                 const labelListList& pointCells() const;
451                 const cellList& cells() const;
452                 // faceFaces considered unnecessary
453                 const labelListList& edgeFaces() const;
454                 const labelListList& pointFaces() const;
456                 const labelListList& cellEdges() const;
457                 const labelListList& faceEdges() const;
458                 // edgeEdges considered unnecessary
459                 const labelListList& pointEdges() const;
460                 const labelListList& pointPoints() const;
461                 const labelListList& cellPoints() const;
464             // Geometric data (raw!)
466                 const vectorField& cellCentres() const;
467                 const vectorField& faceCentres() const;
468                 const scalarField& cellVolumes() const;
469                 const vectorField& faceAreas() const;
472             // Mesh motion
474                 //- Move points, returns volumes swept by faces in motion
475                 tmp<scalarField> movePoints
476                 (
477                     const pointField& p,
478                     const pointField& oldP
479                 );
482             //- Return true if given face label is internal to the mesh
483             inline bool isInternalFace(const label faceIndex) const;
486             // Topological checks
488                 //- Check cell zip-up
489                 bool checkCellsZipUp
490                 (
491                     const bool report = false,
492                     labelHashSet* setPtr = NULL
493                 ) const;
495                 //- Check uniqueness of face vertices
496                 bool checkFaceVertices
497                 (
498                     const bool report = false,
499                     labelHashSet* setPtr = NULL
500                 ) const;
502                 //- Check face-face connectivity
503                 bool checkFaceFaces
504                 (
505                     const bool report = false,
506                     labelHashSet* setPtr = NULL
507                 ) const;
509                 //- Check face ordering
510                 bool checkUpperTriangular
511                 (
512                     const bool report = false,
513                     labelHashSet* setPtr = NULL
514                 ) const;
517             // Geometric checks
519                 //- Check boundary for closedness
520                 bool checkClosedBoundary(const bool report = false) const;
522                 //- Check cells for closedness
523                 bool checkClosedCells
524                 (
525                     const bool report = false,
526                     labelHashSet* setPtr = NULL,
527                     labelHashSet* highAspectSetPtr = NULL
528                 ) const;
530                 //- Check for negative face areas
531                 bool checkFaceAreas
532                 (
533                     const bool report = false,
534                     labelHashSet* setPtr = NULL
535                 ) const;
537                 //- Check for negative cell volumes
538                 bool checkCellVolumes
539                 (
540                     const bool report = false,
541                     labelHashSet* setPtr = NULL
542                 ) const;
544                 //- Check for non-orthogonality
545                 bool checkFaceOrthogonality
546                 (
547                     const bool report = false,
548                     labelHashSet* setPtr = NULL
549                 ) const;
551                 //- Check face pyramid volume
552                 bool checkFacePyramids
553                 (
554                     const bool report = false,
555                     const scalar minPyrVol = -SMALL,
556                     labelHashSet* setPtr = NULL
557                 ) const;
559                 //- Check face skewness
560                 bool checkFaceSkewness
561                 (
562                     const bool report = false,
563                     labelHashSet* setPtr = NULL
564                 ) const;
566                 //- Check face angles
567                 bool checkFaceAngles
568                 (
569                     const bool report = false,
570                     labelHashSet* setPtr = NULL
571                 ) const;
573                 //- Check face warpage: decompose face and check ratio between
574                 //  magnitude of sum of triangle areas and sum of magnitude of
575                 //  triangle areas.
576                 bool checkFaceFlatness
577                 (
578                     const bool report,
579                     labelHashSet* setPtr
580                 ) const;
582                 //- Check edge alignment for 1D/2D cases
583                 bool checkEdgeAlignment
584                 (
585                     const bool report,
586                     const Vector<label>& directions,
587                     labelHashSet* setPtr = NULL
588                 ) const;
590                 //- Check for unused points
591                 bool checkPoints
592                 (
593                     const bool report = false,
594                     labelHashSet* setPtr = NULL
595                 ) const;
597                 //- Check for point-point-nearness,
598                 //  e.g. colocated points which may be part of baffles.
599                 bool checkPointNearness
600                 (
601                     const bool report,
602                     const scalar reportDistSqr,
603                     labelHashSet* setPtr = NULL
604                 ) const;
606                 //- Check edge length
607                 bool checkEdgeLength
608                 (
609                     const bool report,
610                     const scalar minLenSqr,
611                     labelHashSet* setPtr = NULL
612                 ) const;
614                 //- Check cell determinant
615                 bool checkCellDeterminant
616                 (
617                     const bool report = false,
618                     labelHashSet* setPtr = NULL
619                 ) const;
622             //- Check mesh topology for correctness.
623             //  Returns false for no error.
624             bool checkTopology(const bool report = false) const;
626             //- Check mesh geometry (& implicitly topology) for correctness.
627             //  Returns false for no error.
628             bool checkGeometry(const bool report = false) const;
630             //- Check mesh for correctness. Returns false for no error.
631             bool checkMesh(const bool report = false) const;
633             //- Check mesh motion for correctness given motion points
634             bool checkMeshMotion
635             (
636                 const pointField& newPoints,
637                 const bool report = false
638             ) const;
641         // Useful derived info
643             //- Is the point in the cell bounding box
644             bool pointInCellBB(const point& p, label celli) const;
646             //- Is the point in the cell
647             bool pointInCell(const point& p, label celli) const;
649             //- Find the cell with the nearest cell centre to location
650             label findNearestCell(const point& location) const;
652             //- Find cell enclosing this location (-1 if not in mesh)
653             label findCell(const point& location) const;
656         //  Storage management
658             //- Print a list of all the currently allocated mesh data
659             void printAllocated() const;
661             // Per storage whether allocated
662             inline bool hasCellShapes() const;
663             inline bool hasEdges() const;
664             inline bool hasCellCells() const;
665             inline bool hasEdgeCells() const;
666             inline bool hasPointCells() const;
667             inline bool hasCells() const;
668             inline bool hasEdgeFaces() const;
669             inline bool hasPointFaces() const;
670             inline bool hasCellEdges() const;
671             inline bool hasFaceEdges() const;
672             inline bool hasPointEdges() const;
673             inline bool hasPointPoints() const;
674             inline bool hasCellPoints() const;
675             inline bool hasCellCentres() const;
676             inline bool hasFaceCentres() const;
677             inline bool hasCellVolumes() const;
678             inline bool hasFaceAreas() const;
680             // On-the-fly addressing calculation. These functions return either
681             // a reference to the full addressing (if already calculated) or
682             // a reference to the supplied storage. The one-argument ones
683             // use member DynamicList labels_ so be careful when not storing
684             // result.
686             //- cellCells using cells.
687             const labelList& cellCells
688             (
689                 const label cellI,
690                 dynamicLabelList&
691             ) const;
693             const labelList& cellCells(const label cellI) const;
695             //- cellPoints using cells
696             const labelList& cellPoints
697             (
698                 const label cellI,
699                 dynamicLabelList&
700             ) const;
702             const labelList& cellPoints(const label cellI) const;
704             //- pointCells using pointFaces
705             const labelList& pointCells
706             (
707                 const label pointI,
708                 dynamicLabelList&
709             ) const;
711             const labelList& pointCells(const label pointI) const;
713             //- pointPoints using edges, pointEdges
714             const labelList& pointPoints
715             (
716                 const label pointI,
717                 dynamicLabelList&
718             ) const;
720             const labelList& pointPoints(const label pointI) const;
722             //- faceEdges using pointFaces, edges, pointEdges
723             const labelList& faceEdges
724             (
725                 const label faceI,
726                 dynamicLabelList&
727             ) const;
729             const labelList& faceEdges(const label faceI) const;
731             //- edgeFaces using pointFaces, edges, pointEdges
732             const labelList& edgeFaces
733             (
734                 const label edgeI,
735                 dynamicLabelList&
736             ) const;
738             const labelList& edgeFaces(const label edgeI) const;
740             //- edgeCells using pointFaces, edges, pointEdges
741             const labelList& edgeCells
742             (
743                 const label edgeI,
744                 dynamicLabelList&
745             ) const;
747             const labelList& edgeCells(const label edgeI) const;
749             //- cellEdges using cells, pointFaces, edges, pointEdges
750             const labelList& cellEdges
751             (
752                 const label cellI,
753                 dynamicLabelList&
754             ) const;
756             const labelList& cellEdges(const label cellI) const;
759             //- Clear geometry
760             void clearGeom();
762             //- Clear topological data
763             void clearAddressing();
765             //- Clear all geometry and addressing unnecessary for CFD
766             void clearOut();
770 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
772 } // End namespace Foam
774 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
776 #include "primitiveMeshI.H"
778 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
780 #endif
782 // ************************************************************************* //