1 /*---------------------------------------------------------------------------*\
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 -------------------------------------------------------------------------------
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/>.
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"
63 #include "cellShapeList.H"
64 #include "labelList.H"
69 #include "tolerancesSwitch.H"
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 /*---------------------------------------------------------------------------*\
77 Class primitiveMesh Declaration
78 \*---------------------------------------------------------------------------*/
84 // Primitive size data
90 mutable label nEdges_;
92 //- Number of internal faces
93 label nInternalFaces_;
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
111 mutable edgeList* edgesPtr_;
117 mutable labelListList* ccPtr_;
120 mutable labelListList* ecPtr_;
123 mutable labelListList* pcPtr_;
126 mutable cellList* cfPtr_;
129 mutable labelListList* efPtr_;
132 mutable labelListList* pfPtr_;
135 mutable labelListList* cePtr_;
138 mutable labelListList* fePtr_;
141 mutable labelListList* pePtr_;
144 mutable labelListList* ppPtr_;
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_;
162 mutable vectorField* cellCentresPtr_;
165 mutable vectorField* faceCentresPtr_;
168 mutable scalarField* cellVolumesPtr_;
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();
214 // return (after optional creation) edge between two points
217 List<dynamicLabelList >&,
222 //- For on-the-fly addressing calculation
223 static label findFirstCommonElementFromSortedLists
230 // Geometrical calculations
232 //- Calculate face centres and areas
233 void calcFaceCentresAndAreas() const;
235 void makeFaceCentresAndAreas
242 //- Calculate cell centres and volumes
243 void calcCellCentresAndVols() const;
244 void makeCellCentresAndVols
246 const vectorField& fCtrs,
247 const vectorField& fAreas,
248 vectorField& cellCtrs,
249 scalarField& cellVols
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
267 //- Check that shared points are in consecutive order.
268 bool checkCommonOrder
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_;
345 //- Construct from components
349 const label nInternalFaces,
357 virtual ~primitiveMesh();
362 //- Reset this primitiveMesh given the primitive array sizes
366 const label nInternalFaces,
371 //- Reset this primitiveMesh given the primitive array sizes and cells
375 const label nInternalFaces,
382 //- Reset this primitiveMesh given the primitive array sizes and cells
386 const label nInternalFaces,
389 const Xfer<cellList>& cells
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;
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;
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
436 const unallocLabelList& own,
437 const unallocLabelList& nei,
438 const label nCells = -1
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;
474 //- Move points, returns volumes swept by faces in motion
475 tmp<scalarField> movePoints
478 const pointField& oldP
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
491 const bool report = false,
492 labelHashSet* setPtr = NULL
495 //- Check uniqueness of face vertices
496 bool checkFaceVertices
498 const bool report = false,
499 labelHashSet* setPtr = NULL
502 //- Check face-face connectivity
505 const bool report = false,
506 labelHashSet* setPtr = NULL
509 //- Check face ordering
510 bool checkUpperTriangular
512 const bool report = false,
513 labelHashSet* setPtr = NULL
519 //- Check boundary for closedness
520 bool checkClosedBoundary(const bool report = false) const;
522 //- Check cells for closedness
523 bool checkClosedCells
525 const bool report = false,
526 labelHashSet* setPtr = NULL,
527 labelHashSet* highAspectSetPtr = NULL
530 //- Check for negative face areas
533 const bool report = false,
534 labelHashSet* setPtr = NULL
537 //- Check for negative cell volumes
538 bool checkCellVolumes
540 const bool report = false,
541 labelHashSet* setPtr = NULL
544 //- Check for non-orthogonality
545 bool checkFaceOrthogonality
547 const bool report = false,
548 labelHashSet* setPtr = NULL
551 //- Check face pyramid volume
552 bool checkFacePyramids
554 const bool report = false,
555 const scalar minPyrVol = -SMALL,
556 labelHashSet* setPtr = NULL
559 //- Check face skewness
560 bool checkFaceSkewness
562 const bool report = false,
563 labelHashSet* setPtr = NULL
566 //- Check face angles
569 const bool report = false,
570 labelHashSet* setPtr = NULL
573 //- Check face warpage: decompose face and check ratio between
574 // magnitude of sum of triangle areas and sum of magnitude of
576 bool checkFaceFlatness
582 //- Check edge alignment for 1D/2D cases
583 bool checkEdgeAlignment
586 const Vector<label>& directions,
587 labelHashSet* setPtr = NULL
590 //- Check for unused points
593 const bool report = false,
594 labelHashSet* setPtr = NULL
597 //- Check for point-point-nearness,
598 // e.g. colocated points which may be part of baffles.
599 bool checkPointNearness
602 const scalar reportDistSqr,
603 labelHashSet* setPtr = NULL
606 //- Check edge length
610 const scalar minLenSqr,
611 labelHashSet* setPtr = NULL
614 //- Check cell determinant
615 bool checkCellDeterminant
617 const bool report = false,
618 labelHashSet* setPtr = NULL
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
636 const pointField& newPoints,
637 const bool report = false
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
686 //- cellCells using cells.
687 const labelList& cellCells
693 const labelList& cellCells(const label cellI) const;
695 //- cellPoints using cells
696 const labelList& cellPoints
702 const labelList& cellPoints(const label cellI) const;
704 //- pointCells using pointFaces
705 const labelList& pointCells
711 const labelList& pointCells(const label pointI) const;
713 //- pointPoints using edges, pointEdges
714 const labelList& pointPoints
720 const labelList& pointPoints(const label pointI) const;
722 //- faceEdges using pointFaces, edges, pointEdges
723 const labelList& faceEdges
729 const labelList& faceEdges(const label faceI) const;
731 //- edgeFaces using pointFaces, edges, pointEdges
732 const labelList& edgeFaces
738 const labelList& edgeFaces(const label edgeI) const;
740 //- edgeCells using pointFaces, edges, pointEdges
741 const labelList& edgeCells
747 const labelList& edgeCells(const label edgeI) const;
749 //- cellEdges using cells, pointFaces, edges, pointEdges
750 const labelList& cellEdges
756 const labelList& cellEdges(const label cellI) const;
762 //- Clear topological data
763 void clearAddressing();
765 //- Clear all geometry and addressing unnecessary for CFD
770 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
772 } // End namespace Foam
774 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
776 #include "primitiveMeshI.H"
778 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
782 // ************************************************************************* //