FreeFOAM The Cross-Platform CFD Toolkit
primitiveMesh.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Class
25  Foam::primitiveMesh
26 
27 Description
28  Cell-face mesh analysis engine
29 
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
50 
51 \*---------------------------------------------------------------------------*/
52 
53 #ifndef primitiveMesh_H
54 #define primitiveMesh_H
55 
56 #include <OpenFOAM/DynamicList.H>
57 #include <OpenFOAM/edgeList.H>
58 #include <OpenFOAM/pointField.H>
59 #include <OpenFOAM/SubField.H>
60 #include <OpenFOAM/SubList.H>
61 #include <OpenFOAM/faceList.H>
62 #include <OpenFOAM/cellList.H>
63 #include <OpenFOAM/cellShapeList.H>
64 #include <OpenFOAM/labelList.H>
65 #include <OpenFOAM/boolList.H>
66 #include <OpenFOAM/HashSet.H>
67 #include <OpenFOAM/Map.H>
68 #include <OpenFOAM/EdgeMap.H>
69 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 
72 namespace Foam
73 {
74 
75 /*---------------------------------------------------------------------------*\
76  Class primitiveMesh Declaration
77 \*---------------------------------------------------------------------------*/
78 
80 {
81  // Permanent data
82 
83  // Primitive size data
84 
85  //- Number of internal points (or -1 if points not sorted)
86  label nInternalPoints_;
87 
88  //- Number of points
89  label nPoints_;
90 
91  //- Number of internal edges using 0 boundary points
92  mutable label nInternal0Edges_;
93 
94  //- Number of internal edges using 0 or 1 boundary points
95  mutable label nInternal1Edges_;
96 
97  //- Number of internal edges using 0,1 or 2boundary points
98  mutable label nInternalEdges_;
99 
100  //- Number of edges
101  mutable label nEdges_;
102 
103  //- Number of internal faces
104  label nInternalFaces_;
105 
106  //- Number of faces
107  label nFaces_;
108 
109  //- Number of cells
110  label nCells_;
111 
112 
113  // Shapes
114 
115  //- Cell shapes
116  mutable cellShapeList* cellShapesPtr_;
117 
118  //- Edges
119  mutable edgeList* edgesPtr_;
120 
121 
122  // Connectivity
123 
124  //- Cell-cells
125  mutable labelListList* ccPtr_;
126 
127  //- Edge-cells
128  mutable labelListList* ecPtr_;
129 
130  //- Point-cells
131  mutable labelListList* pcPtr_;
132 
133  //- Cell-faces
134  mutable cellList* cfPtr_;
135 
136  //- Edge-faces
137  mutable labelListList* efPtr_;
138 
139  //- Point-faces
140  mutable labelListList* pfPtr_;
141 
142  //- Cell-edges
143  mutable labelListList* cePtr_;
144 
145  //- Face-edges
146  mutable labelListList* fePtr_;
147 
148  //- Point-edges
149  mutable labelListList* pePtr_;
150 
151  //- Point-points
152  mutable labelListList* ppPtr_;
153 
154  //- Cell-points
155  mutable labelListList* cpPtr_;
156 
157 
158  // On-the-fly edge addresing storage
159 
160  //- Temporary storage for addressing.
161  mutable DynamicList<label> labels_;
162 
163  //- Temporary storage for addressing
164  mutable labelHashSet labelSet_;
165 
166 
167  // Geometric data
168 
169  //- Cell centres
170  mutable vectorField* cellCentresPtr_;
171 
172  //- Face centres
173  mutable vectorField* faceCentresPtr_;
174 
175  //- Cell volumes
176  mutable scalarField* cellVolumesPtr_;
177 
178  //- Face areas
179  mutable vectorField* faceAreasPtr_;
180 
181 
182  // Private member functions
183 
184  //- Disallow construct as copy
186 
187  //- Disallow default bitwise assignment
188  void operator=(const primitiveMesh&);
189 
190 
191  // Topological calculations
192 
193  //- Calculate cell shapes
194  void calcCellShapes() const;
195 
196  //- Calculate cell-cell addressing
197  void calcCellCells() const;
198 
199  //- Calculate point-cell addressing
200  void calcPointCells() const;
201 
202  //- Calculate cell-face addressing
203  void calcCells() const;
204 
205  //- Calculate edge list
206  void calcCellEdges() const;
207 
208  //- Calculate point-point addressing
209  void calcPointPoints() const;
210 
211  //- Calculate edges, pointEdges and faceEdges (if doFaceEdges=true)
212  // During edge calculation, a larger set of data is assembled.
213  // Create and destroy as a set, using clearOutEdges()
214  void calcEdges(const bool doFaceEdges) const;
215  void clearOutEdges();
216  //- Helper: return (after optional creation) edge between two points
217  static label getEdge
218  (
221  const label,
222  const label
223  );
224  //- For on-the-fly addressing calculation
225  static label findFirstCommonElementFromSortedLists
226  (
227  const labelList&,
228  const labelList&
229  );
230 
231 
232  // Geometrical calculations
233 
234  //- Calculate face centres and areas
235  void calcFaceCentresAndAreas() const;
236  void makeFaceCentresAndAreas
237  (
238  const pointField& p,
239  vectorField& fCtrs,
240  vectorField& fAreas
241  ) const;
242 
243  //- Calculate cell centres and volumes
244  void calcCellCentresAndVols() const;
245  void makeCellCentresAndVols
246  (
247  const vectorField& fCtrs,
248  const vectorField& fAreas,
249  vectorField& cellCtrs,
251  ) const;
252 
253  //- Calculate edge vectors
254  void calcEdgeVectors() const;
255 
256 
257  // Helper functions for mesh checking
258 
259  //- Check if all points on face are shared with another face.
260  bool checkDuplicateFaces
261  (
262  const label,
263  const Map<label>&,
264  label& nBaffleFaces,
265  labelHashSet*
266  ) const;
267 
268  //- Check that shared points are in consecutive order.
269  bool checkCommonOrder
270  (
271  const label,
272  const Map<label>&,
273  labelHashSet*
274  ) const;
275 
276 
277  // Static data members
278 
279  //- Static data to control mesh checking
280 
281  //- Cell closedness warning threshold
282  // set as the fraction of un-closed area to closed area
283  static scalar closedThreshold_;
284 
285  //- Aspect ratio warning threshold
286  static scalar aspectThreshold_;
287 
288  //- Non-orthogonality warning threshold in deg
289  static scalar nonOrthThreshold_;
290 
291  //- Skewness warning threshold
292  static scalar skewThreshold_;
293 
294 
295 protected:
296 
297  //- Construct null
298  primitiveMesh();
299 
300 
301 public:
302 
303  // Static data
304 
305  ClassName("primitiveMesh");
306 
307  //- Estimated number of cells per edge
308  static const unsigned cellsPerEdge_ = 4;
309 
310  //- Estimated number of cells per point
311  static const unsigned cellsPerPoint_ = 8;
312 
313  //- Estimated number of faces per cell
314  static const unsigned facesPerCell_ = 6;
315 
316  //- Estimated number of faces per edge
317  static const unsigned facesPerEdge_ = 4;
318 
319  //- Estimated number of faces per point
320  static const unsigned facesPerPoint_ = 12;
321 
322  //- Estimated number of edges per cell
323  static const unsigned edgesPerCell_ = 12;
324 
325  //- Estimated number of edges per cell
326  static const unsigned edgesPerFace_ = 4;
327 
328  //- Estimated number of edges per point
329  static const unsigned edgesPerPoint_ = 6;
330 
331  //- Estimated number of points per cell
332  static const unsigned pointsPerCell_ = 8;
333 
334  //- Estimated number of points per face
335  static const unsigned pointsPerFace_ = 4;
336 
337 
338  // Constructors
339 
340  //- Construct from components
342  (
343  const label nPoints,
344  const label nInternalFaces,
345  const label nFaces,
346  const label nCells
347  );
348 
349 
350  // Destructor
351 
352  virtual ~primitiveMesh();
353 
354 
355  // Member Functions
356 
357  //- Reset this primitiveMesh given the primitive array sizes
358  void reset
359  (
360  const label nPoints,
361  const label nInternalFaces,
362  const label nFaces,
363  const label nCells
364  );
365 
366  //- Reset this primitiveMesh given the primitive array sizes and cells
367  void reset
368  (
369  const label nPoints,
370  const label nInternalFaces,
371  const label nFaces,
372  const label nCells,
373  cellList& cells
374  );
375 
376 
377  //- Reset this primitiveMesh given the primitive array sizes and cells
378  void reset
379  (
380  const label nPoints,
381  const label nInternalFaces,
382  const label nFaces,
383  const label nCells,
384  const Xfer<cellList>& cells
385  );
386 
387 
388  // Access
389 
390  // Mesh size parameters
391 
392  inline label nPoints() const;
393  inline label nEdges() const;
394  inline label nInternalFaces() const;
395  inline label nFaces() const;
396  inline label nCells() const;
397 
398  // If points are ordered (nInternalPoints != -1):
399 
400  //- Points not on boundary
401  inline label nInternalPoints() const;
402 
403  //- Internal edges (i.e. not on boundary face) using
404  // no boundary point
405  inline label nInternal0Edges() const;
406  //- Internal edges using 0 or 1 boundary point
407  inline label nInternal1Edges() const;
408  //- Internal edges using 0,1 or 2 boundary points
409  inline label nInternalEdges() const;
410 
411 
412  // Primitive mesh data
413 
414  //- Return mesh points
415  virtual const pointField& points() const = 0;
416 
417  //- Return faces
418  virtual const faceList& faces() const = 0;
419 
420  //- Face face-owner addresing
421  virtual const labelList& faceOwner() const = 0;
422 
423  //- Face face-neighbour addressing
424  virtual const labelList& faceNeighbour() const = 0;
425 
426  //- Return old points for mesh motion
427  virtual const pointField& oldPoints() const = 0;
428 
429 
430  // Derived mesh data
431 
432  //- Return cell shapes
433  const cellShapeList& cellShapes() const;
434 
435  //- Return mesh edges. Uses calcEdges.
436  const edgeList& edges() const;
437 
438  //- Helper function to calculate cell-face addressing from
439  // face-cell addressing. If nCells is not provided it will
440  // scan for the maximum.
441  static void calcCells
442  (
443  cellList&,
444  const unallocLabelList& own,
445  const unallocLabelList& nei,
446  const label nCells = -1
447  );
448 
449  //- Helper function to calculate point ordering. Returns true
450  // if points already ordered, false and fills pointMap (old to
451  // new). Map splits points into those not used by any boundary
452  // face and those that are.
453  static bool calcPointOrder
454  (
455  label& nInternalPoints,
456  labelList& pointMap,
457  const faceList&,
458  const label nInternalFaces,
459  const label nPoints
460  );
461 
462  // Return mesh connectivity
463 
464  const labelListList& cellCells() const;
465  // faceCells given as owner and neighbour
466  const labelListList& edgeCells() const;
467  const labelListList& pointCells() const;
468 
469  const cellList& cells() const;
470  // faceFaces considered unnecessary
471  const labelListList& edgeFaces() const;
472  const labelListList& pointFaces() const;
473 
474  const labelListList& cellEdges() const;
475  const labelListList& faceEdges() const;
476  // edgeEdges considered unnecessary
477  const labelListList& pointEdges() const;
478  const labelListList& pointPoints() const;
479  const labelListList& cellPoints() const;
480 
481 
482  // Geometric data (raw!)
483 
484  const vectorField& cellCentres() const;
485  const vectorField& faceCentres() const;
486  const scalarField& cellVolumes() const;
487  const vectorField& faceAreas() const;
488 
489 
490  // Mesh motion
491 
492  //- Move points, returns volumes swept by faces in motion
494  (
495  const pointField& p,
496  const pointField& oldP
497  );
498 
499 
500  //- Return true if given face label is internal to the mesh
501  inline bool isInternalFace(const label faceIndex) const;
502 
503 
504  // Topological checks
505 
506  //- Check cell zip-up
507  bool checkCellsZipUp
508  (
509  const bool report = false,
510  labelHashSet* setPtr = NULL
511  ) const;
512 
513  //- Check uniqueness of face vertices
514  bool checkFaceVertices
515  (
516  const bool report = false,
517  labelHashSet* setPtr = NULL
518  ) const;
519 
520  //- Check face-face connectivity
521  bool checkFaceFaces
522  (
523  const bool report = false,
524  labelHashSet* setPtr = NULL
525  ) const;
526 
527  //- Check face ordering
529  (
530  const bool report = false,
531  labelHashSet* setPtr = NULL
532  ) const;
533 
534 
535  // Geometric checks
536 
537  //- Check boundary for closedness
538  bool checkClosedBoundary(const bool report = false) const;
539 
540  //- Check cells for closedness
541  bool checkClosedCells
542  (
543  const bool report = false,
544  labelHashSet* setPtr = NULL,
545  labelHashSet* highAspectSetPtr = NULL,
546  const Vector<label>& solutionD = Vector<label>::one
547  ) const;
548 
549  //- Check for negative face areas
550  bool checkFaceAreas
551  (
552  const bool report = false,
553  labelHashSet* setPtr = NULL
554  ) const;
555 
556  //- Check for negative cell volumes
557  bool checkCellVolumes
558  (
559 
560  const bool report = false,
561  labelHashSet* setPtr = NULL
562  ) const;
563 
564  //- Check for non-orthogonality
566  (
567  const bool report = false,
568  labelHashSet* setPtr = NULL
569  ) const;
570 
571  //- Check face pyramid volume
572  bool checkFacePyramids
573  (
574  const bool report = false,
575  const scalar minPyrVol = -SMALL,
576  labelHashSet* setPtr = NULL
577  ) const;
578 
579  //- Check face skewness
580  bool checkFaceSkewness
581  (
582  const bool report = false,
583  labelHashSet* setPtr = NULL
584  ) const;
585 
586  //- Check face angles
587  bool checkFaceAngles
588  (
589  const bool report = false,
590  const scalar maxSin = 10, // In degrees
591  labelHashSet* setPtr = NULL
592  ) const;
593 
594  //- Check face warpage: decompose face and check ratio between
595  // magnitude of sum of triangle areas and sum of magnitude of
596  // triangle areas.
597  bool checkFaceFlatness
598  (
599  const bool report,
600  const scalar warnFlatness, // When to include in set.
601  labelHashSet* setPtr
602  ) const;
603 
604  //- Check edge alignment for 1D/2D cases
605  bool checkEdgeAlignment
606  (
607  const bool report,
608  const Vector<label>& directions,
609  labelHashSet* setPtr = NULL
610  ) const;
611 
612  //- Check for unused points
613  bool checkPoints
614  (
615  const bool report = false,
616  labelHashSet* setPtr = NULL
617  ) const;
618 
619  //- Check for point-point-nearness,
620  // e.g. colocated points which may be part of baffles.
621  bool checkPointNearness
622  (
623  const bool report,
624  const scalar reportDistSqr,
625  labelHashSet* setPtr = NULL
626  ) const;
627 
628  //- Check edge length
629  bool checkEdgeLength
630  (
631  const bool report,
632  const scalar minLenSqr,
633  labelHashSet* setPtr = NULL
634  ) const;
635 
636  //- Check cell determinant
638  (
639  const bool report = false,
640  labelHashSet* setPtr = NULL,
641  const Vector<label>& solutionD = Vector<label>::one
642  ) const;
643 
644 
645  //- Check mesh topology for correctness.
646  // Returns false for no error.
647  bool checkTopology(const bool report = false) const;
648 
649  //- Check mesh geometry (& implicitly topology) for correctness.
650  // Returns false for no error.
651  bool checkGeometry(const bool report = false) const;
652 
653  //- Check mesh for correctness. Returns false for no error.
654  bool checkMesh(const bool report = false) const;
655 
656  //- Check mesh motion for correctness given motion points
657  bool checkMeshMotion
658  (
659  const pointField& newPoints,
660  const bool report = false
661  ) const;
662 
663 
664  //- Set the closedness ratio warning threshold
665  static scalar setClosedThreshold(const scalar);
666 
667  //- Set the aspect ratio warning threshold
668  static scalar setAspectThreshold(const scalar);
669 
670  //- Set the non-orthogonality warning threshold in degrees
671  static scalar setNonOrthThreshold(const scalar);
672 
673  //- Set the skewness warning threshold as percentage
674  // of the face area vector
675  static scalar setSkewThreshold(const scalar);
676 
677 
678  // Useful derived info
679 
680  //- Is the point in the cell bounding box
681  bool pointInCellBB(const point& p, label celli) const;
682 
683  //- Is the point in the cell
684  bool pointInCell(const point& p, label celli) const;
685 
686  //- Find the cell with the nearest cell centre to location
687  label findNearestCell(const point& location) const;
688 
689  //- Find cell enclosing this location (-1 if not in mesh)
690  label findCell(const point& location) const;
691 
692 
693  // Storage management
694 
695  //- Print a list of all the currently allocated mesh data
696  void printAllocated() const;
697 
698  // Per storage whether allocated
699  inline bool hasCellShapes() const;
700  inline bool hasEdges() const;
701  inline bool hasCellCells() const;
702  inline bool hasEdgeCells() const;
703  inline bool hasPointCells() const;
704  inline bool hasCells() const;
705  inline bool hasEdgeFaces() const;
706  inline bool hasPointFaces() const;
707  inline bool hasCellEdges() const;
708  inline bool hasFaceEdges() const;
709  inline bool hasPointEdges() const;
710  inline bool hasPointPoints() const;
711  inline bool hasCellPoints() const;
712  inline bool hasCellCentres() const;
713  inline bool hasFaceCentres() const;
714  inline bool hasCellVolumes() const;
715  inline bool hasFaceAreas() const;
716 
717  // On-the-fly addressing calculation. These functions return either
718  // a reference to the full addressing (if already calculated) or
719  // a reference to the supplied storage. The one-argument ones
720  // use member DynamicList labels_ so be careful when not storing
721  // result.
722 
723  //- cellCells using cells.
724  const labelList& cellCells
725  (
726  const label cellI,
728  ) const;
729 
730  const labelList& cellCells(const label cellI) const;
731 
732  //- cellPoints using cells
733  const labelList& cellPoints
734  (
735  const label cellI,
737  ) const;
738 
739  const labelList& cellPoints(const label cellI) const;
740 
741  //- pointCells using pointFaces
742  const labelList& pointCells
743  (
744  const label pointI,
746  ) const;
747 
748  const labelList& pointCells(const label pointI) const;
749 
750  //- pointPoints using edges, pointEdges
751  const labelList& pointPoints
752  (
753  const label pointI,
755  ) const;
756 
757  const labelList& pointPoints(const label pointI) const;
758 
759  //- faceEdges using pointFaces, edges, pointEdges
760  const labelList& faceEdges
761  (
762  const label faceI,
764  ) const;
765 
766  const labelList& faceEdges(const label faceI) const;
767 
768  //- edgeFaces using pointFaces, edges, pointEdges
769  const labelList& edgeFaces
770  (
771  const label edgeI,
773  ) const;
774 
775  const labelList& edgeFaces(const label edgeI) const;
776 
777  //- edgeCells using pointFaces, edges, pointEdges
778  const labelList& edgeCells
779  (
780  const label edgeI,
782  ) const;
783 
784  const labelList& edgeCells(const label edgeI) const;
785 
786  //- cellEdges using cells, pointFaces, edges, pointEdges
787  const labelList& cellEdges
788  (
789  const label cellI,
791  ) const;
792 
793  const labelList& cellEdges(const label cellI) const;
794 
795 
796  //- Clear geometry
797  void clearGeom();
798 
799  //- Clear topological data
800  void clearAddressing();
801 
802  //- Clear all geometry and addressing unnecessary for CFD
803  void clearOut();
804 };
805 
806 
807 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
808 
809 } // End namespace Foam
810 
811 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
812 
813 #include "primitiveMeshI.H"
814 
815 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
816 
817 #endif
818 
819 // ************************ vim: set sw=4 sts=4 et: ************************ //