1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
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/>.
28 Cell-face mesh analysis engine
34 primitiveMeshCellCells.C
35 primitiveMeshEdgeCells.C
36 primitiveMeshPointCells.C
38 primitiveMeshEdgeFaces.C
39 primitiveMeshPointFaces.C
40 primitiveMeshCellEdges.C
41 primitiveMeshPointEdges.C
42 primitiveMeshPointPoints.C
44 primitiveMeshCellCentresAndVols.C
45 primitiveMeshFaceCentresAndAreas.C
46 primitiveMeshEdgeVectors.C
48 primitiveMeshCheckMotion.C
49 primitiveMeshFindCell.C
51 \*---------------------------------------------------------------------------*/
53 #ifndef primitiveMesh_H
54 #define primitiveMesh_H
56 #include "DynamicList.H"
58 #include "pointField.H"
61 #include "cellShapeList.H"
62 #include "labelList.H"
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 // Forward declaration of classes
74 template<class Type> class indexedOctree;
76 /*---------------------------------------------------------------------------*\
77 Class primitiveMesh Declaration
78 \*---------------------------------------------------------------------------*/
84 // Primitive size data
86 //- Number of internal points (or -1 if points not sorted)
87 label nInternalPoints_;
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_;
102 mutable label nEdges_;
104 //- Number of internal faces
105 label nInternalFaces_;
117 mutable cellShapeList* cellShapesPtr_;
120 mutable edgeList* edgesPtr_;
126 mutable labelListList* ccPtr_;
129 mutable labelListList* ecPtr_;
132 mutable labelListList* pcPtr_;
135 mutable cellList* cfPtr_;
138 mutable labelListList* efPtr_;
141 mutable labelListList* pfPtr_;
144 mutable labelListList* cePtr_;
147 mutable labelListList* fePtr_;
150 mutable labelListList* pePtr_;
153 mutable labelListList* ppPtr_;
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_;
174 mutable vectorField* cellCentresPtr_;
177 mutable vectorField* faceCentresPtr_;
180 mutable scalarField* cellVolumesPtr_;
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
223 List<DynamicList<label> >&,
228 //- For on-the-fly addressing calculation
229 static label findFirstCommonElementFromSortedLists
236 // Geometrical calculations
238 //- Calculate face centres and areas
239 void calcFaceCentresAndAreas() const;
240 void makeFaceCentresAndAreas
247 //- Calculate cell centres and volumes
248 void calcCellCentresAndVols() const;
249 void makeCellCentresAndVols
251 const vectorField& fCtrs,
252 const vectorField& fAreas,
253 vectorField& cellCtrs,
254 scalarField& cellVols
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
272 //- Check that shared points are in consecutive order.
273 bool checkCommonOrder
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_;
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;
347 //- Construct from components
351 const label nInternalFaces,
358 virtual ~primitiveMesh();
363 //- Reset this primitiveMesh given the primitive array sizes
367 const label nInternalFaces,
372 //- Reset this primitiveMesh given the primitive array sizes and cells
376 const label nInternalFaces,
383 //- Reset this primitiveMesh given the primitive array sizes and cells
387 const label nInternalFaces,
390 const Xfer<cellList>& cells
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
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;
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;
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
450 const labelUList& own,
451 const labelUList& nei,
452 const label nCells = -1
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
461 label& nInternalPoints,
464 const label nInternalFaces,
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;
502 //- Move points, returns volumes swept by faces in motion
503 tmp<scalarField> movePoints
506 const pointField& oldP
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
519 const bool report = false,
520 labelHashSet* setPtr = NULL
523 //- Check uniqueness of face vertices
524 bool checkFaceVertices
526 const bool report = false,
527 labelHashSet* setPtr = NULL
530 //- Check face-face connectivity
533 const bool report = false,
534 labelHashSet* setPtr = NULL
537 //- Check face ordering
538 bool checkUpperTriangular
540 const bool report = false,
541 labelHashSet* setPtr = NULL
547 //- Check boundary for closedness
548 bool checkClosedBoundary(const bool report = false) const;
550 //- Check cells for closedness
551 bool checkClosedCells
553 const bool report = false,
554 labelHashSet* setPtr = NULL,
555 labelHashSet* highAspectSetPtr = NULL,
556 const Vector<label>& solutionD = Vector<label>::one
559 //- Check for negative face areas
562 const bool report = false,
563 labelHashSet* setPtr = NULL
566 //- Check for negative cell volumes
567 bool checkCellVolumes
569 const bool report = false,
570 labelHashSet* setPtr = NULL
573 //- Check for non-orthogonality
574 bool checkFaceOrthogonality
576 const bool report = false,
577 labelHashSet* setPtr = NULL
580 //- Check face pyramid volume
581 bool checkFacePyramids
583 const bool report = false,
584 const scalar minPyrVol = -SMALL,
585 labelHashSet* setPtr = NULL
588 //- Check face skewness
589 bool checkFaceSkewness
591 const bool report = false,
592 labelHashSet* setPtr = NULL
595 //- Check face angles
598 const bool report = false,
599 const scalar maxSin = 10, // In degrees
600 labelHashSet* setPtr = NULL
603 //- Check face warpage: decompose face and check ratio between
604 // magnitude of sum of triangle areas and sum of magnitude of
606 bool checkFaceFlatness
609 const scalar warnFlatness, // When to include in set.
613 //- Check edge alignment for 1D/2D cases
614 bool checkEdgeAlignment
617 const Vector<label>& directions,
618 labelHashSet* setPtr = NULL
621 //- Check for unused points
624 const bool report = false,
625 labelHashSet* setPtr = NULL
628 //- Check for point-point-nearness,
629 // e.g. colocated points which may be part of baffles.
630 bool checkPointNearness
633 const scalar reportDistSqr,
634 labelHashSet* setPtr = NULL
637 //- Check edge length
641 const scalar minLenSqr,
642 labelHashSet* setPtr = NULL
645 //- Check cell determinant
646 bool checkCellDeterminant
648 const bool report = false,
649 labelHashSet* setPtr = NULL,
650 const Vector<label>& solutionD = Vector<label>::one
653 //- Check for concave cells by the planes of faces
654 bool checkConcaveCells
656 const bool report = false,
657 labelHashSet* setPtr = NULL
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
675 const pointField& newPoints,
676 const bool report = false
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
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
745 //- cellCells using cells.
746 const labelList& cellCells
752 const labelList& cellCells(const label cellI) const;
754 //- cellPoints using cells
755 const labelList& cellPoints
761 const labelList& cellPoints(const label cellI) const;
763 //- pointCells using pointFaces
764 const labelList& pointCells
770 const labelList& pointCells(const label pointI) const;
772 //- pointPoints using edges, pointEdges
773 const labelList& pointPoints
779 const labelList& pointPoints(const label pointI) const;
781 //- faceEdges using pointFaces, edges, pointEdges
782 const labelList& faceEdges
788 const labelList& faceEdges(const label faceI) const;
790 //- edgeFaces using pointFaces, edges, pointEdges
791 const labelList& edgeFaces
797 const labelList& edgeFaces(const label edgeI) const;
799 //- edgeCells using pointFaces, edges, pointEdges
800 const labelList& edgeCells
806 const labelList& edgeCells(const label edgeI) const;
808 //- cellEdges using cells, pointFaces, edges, pointEdges
809 const labelList& cellEdges
815 const labelList& cellEdges(const label cellI) const;
821 //- Clear topological data
822 void clearAddressing();
824 //- Clear cell tree data
825 void clearCellTree();
827 //- Clear all geometry and addressing unnecessary for CFD
832 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
834 } // End namespace Foam
836 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
838 #include "primitiveMeshI.H"
840 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
844 // ************************************************************************* //