All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
primitiveMesh.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
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  primitiveMeshFindCell.C
47 
48 \*---------------------------------------------------------------------------*/
49 
50 #ifndef primitiveMesh_H
51 #define primitiveMesh_H
52 
53 #include "DynamicList.H"
54 #include "edgeList.H"
55 #include "pointField.H"
56 #include "faceList.H"
57 #include "cellList.H"
58 #include "cellShapeList.H"
59 #include "labelList.H"
60 #include "boolList.H"
61 #include "HashSet.H"
62 #include "Map.H"
63 
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 
66 namespace Foam
67 {
68 
69 class PackedBoolList;
70 
71 /*---------------------------------------------------------------------------*\
72  Class primitiveMesh Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 class primitiveMesh
76 {
77  // Permanent data
78 
79  // Primitive size data
80 
81  //- Number of internal points (or -1 if points not sorted)
82  label nInternalPoints_;
83 
84  //- Number of points
85  label nPoints_;
86 
87  //- Number of internal edges using 0 boundary points
88  mutable label nInternal0Edges_;
89 
90  //- Number of internal edges using 0 or 1 boundary points
91  mutable label nInternal1Edges_;
92 
93  //- Number of internal edges using 0,1 or 2boundary points
94  mutable label nInternalEdges_;
95 
96  //- Number of edges
97  mutable label nEdges_;
98 
99  //- Number of internal faces
100  label nInternalFaces_;
101 
102  //- Number of faces
103  label nFaces_;
104 
105  //- Number of cells
106  label nCells_;
107 
108 
109  // Shapes
110 
111  //- Cell shapes
112  mutable cellShapeList* cellShapesPtr_;
113 
114  //- Edges
115  mutable edgeList* edgesPtr_;
116 
117 
118  // Connectivity
119 
120  //- Cell-cells
121  mutable labelListList* ccPtr_;
122 
123  //- Edge-cells
124  mutable labelListList* ecPtr_;
125 
126  //- Point-cells
127  mutable labelListList* pcPtr_;
128 
129  //- Cell-faces
130  mutable cellList* cfPtr_;
131 
132  //- Edge-faces
133  mutable labelListList* efPtr_;
134 
135  //- Point-faces
136  mutable labelListList* pfPtr_;
137 
138  //- Cell-edges
139  mutable labelListList* cePtr_;
140 
141  //- Face-edges
142  mutable labelListList* fePtr_;
143 
144  //- Point-edges
145  mutable labelListList* pePtr_;
146 
147  //- Point-points
148  mutable labelListList* ppPtr_;
149 
150  //- Cell-points
151  mutable labelListList* cpPtr_;
152 
153 
154  // On-the-fly edge addressing storage
155 
156  //- Temporary storage for addressing.
157  mutable DynamicList<label> labels_;
158 
159  //- Temporary storage for addressing
160  mutable labelHashSet labelSet_;
161 
162 
163  // Geometric data
164 
165  //- Cell centres
166  mutable vectorField* cellCentresPtr_;
167 
168  //- Face centres
169  mutable vectorField* faceCentresPtr_;
170 
171  //- Cell volumes
172  mutable scalarField* cellVolumesPtr_;
173 
174  //- Face areas
175  mutable vectorField* faceAreasPtr_;
176 
177  //- Face area magnitudes
178  mutable scalarField* magFaceAreasPtr_;
179 
180 
181  // Topological calculations
182 
183  //- Calculate cell shapes
184  void calcCellShapes() const;
185 
186  //- Calculate cell-cell addressing
187  void calcCellCells() const;
188 
189  //- Calculate point-cell addressing
190  void calcPointCells() const;
191 
192  //- Calculate cell-face addressing
193  void calcCells() const;
194 
195  //- Calculate edge list
196  void calcCellEdges() const;
197 
198  //- Calculate point-point addressing
199  void calcPointPoints() const;
200 
201  //- Calculate edges, pointEdges and faceEdges (if doFaceEdges=true)
202  // During edge calculation, a larger set of data is assembled.
203  // Create and destroy as a set, using clearOutEdges()
204  void calcEdges(const bool doFaceEdges) const;
205  void clearOutEdges();
206  //- Helper: return (after optional creation) edge between two points
207  static label getEdge
208  (
211  const label,
212  const label
213  );
214  //- For on-the-fly addressing calculation
215  static label findFirstCommonElementFromSortedLists
216  (
217  const labelList&,
218  const labelList&
219  );
220 
221 protected:
222 
223  // Static Data Members
224 
225  // Geometrical calculations
226 
227  //- Calculate face centres and areas
228  void calcFaceCentresAndAreas() const;
229 
231  (
232  const pointField& p,
233  vectorField& fCtrs,
234  vectorField& fAreas,
235  scalarField& magfAreas
236  ) const;
237 
238  //- Calculate cell centres and volumes
239  void calcCellCentresAndVols() const;
240 
242  (
243  const vectorField& fCtrs,
244  const vectorField& fAreas,
245  vectorField& cellCtrs,
247  ) const;
248 
249  //- Calculate edge vectors
250  void calcEdgeVectors() const;
251 
252 
253  //- Construct null
254  primitiveMesh();
255 
256 
257 public:
258 
259  // Static data
260 
261  ClassName("primitiveMesh");
262 
263  //- Estimated number of cells per edge
264  static const unsigned cellsPerEdge_ = 4;
265 
266  //- Estimated number of cells per point
267  static const unsigned cellsPerPoint_ = 8;
268 
269  //- Estimated number of faces per cell
270  static const unsigned facesPerCell_ = 6;
271 
272  //- Estimated number of faces per edge
273  static const unsigned facesPerEdge_ = 4;
274 
275  //- Estimated number of faces per point
276  static const unsigned facesPerPoint_ = 12;
277 
278  //- Estimated number of edges per cell
279  static const unsigned edgesPerCell_ = 12;
280 
281  //- Estimated number of edges per cell
282  static const unsigned edgesPerFace_ = 4;
283 
284  //- Estimated number of edges per point
285  static const unsigned edgesPerPoint_ = 6;
286 
287  //- Estimated number of points per cell
288  static const unsigned pointsPerCell_ = 8;
289 
290  //- Estimated number of points per face
291  static const unsigned pointsPerFace_ = 4;
292 
293 
294  // Constructors
295 
296  //- Construct from components
298  (
299  const label nPoints,
300  const label nInternalFaces,
301  const label nFaces,
302  const label nCells
303  );
304 
305  //- Move constructor
306  primitiveMesh(primitiveMesh&&) = default;
307 
308  //- Disallow default bitwise copy construction
309  primitiveMesh(const primitiveMesh&) = delete;
310 
311 
312  //- Destructor
313  virtual ~primitiveMesh();
314 
315 
316  // Member Functions
317 
318  //- Reset this primitiveMesh given the primitive array sizes
319  void reset
320  (
321  const label nPoints,
322  const label nInternalFaces,
323  const label nFaces,
324  const label nCells
325  );
326 
327  //- Reset this primitiveMesh given the primitive array sizes and cells
328  void reset
329  (
330  const label nPoints,
331  const label nInternalFaces,
332  const label nFaces,
333  const label nCells,
334  cellList& cells
335  );
336 
337  //- Reset this primitiveMesh given the primitive array sizes and cells
338  void reset
339  (
340  const label nPoints,
341  const label nInternalFaces,
342  const label nFaces,
343  const label nCells,
344  cellList&& cells
345  );
346 
347 
348  // Access
349 
350  // Mesh size parameters
351 
352  inline label nPoints() const;
353  inline label nEdges() const;
354  inline label nInternalFaces() const;
355  inline label nFaces() const;
356  inline label nCells() const;
357 
358  // If points are ordered (nInternalPoints != -1):
359 
360  //- Points not on boundary
361  inline label nInternalPoints() const;
362 
363  //- Internal edges (i.e. not on boundary face) using
364  // no boundary point
365  inline label nInternal0Edges() const;
366 
367  //- Internal edges using 0 or 1 boundary point
368  inline label nInternal1Edges() const;
369 
370  //- Internal edges using 0,1 or 2 boundary points
371  inline label nInternalEdges() const;
372 
373 
374  // Primitive mesh data
375 
376  //- Return mesh points
377  virtual const pointField& points() const = 0;
378 
379  //- Return faces
380  virtual const faceList& faces() const = 0;
381 
382  //- Face face-owner addressing
383  virtual const labelList& faceOwner() const = 0;
384 
385  //- Face face-neighbour addressing
386  virtual const labelList& faceNeighbour() const = 0;
387 
388  //- Return old points for mesh motion
389  virtual const pointField& oldPoints() const = 0;
390 
391 
392  // Derived mesh data
393 
394  //- Return cell shapes
395  const cellShapeList& cellShapes() const;
396 
397  //- Return mesh edges. Uses calcEdges.
398  const edgeList& edges() const;
399 
400  //- Helper function to calculate cell-face addressing from
401  // face-cell addressing. If nCells is not provided it will
402  // scan for the maximum.
403  static void calcCells
404  (
405  cellList&,
406  const labelUList& own,
407  const labelUList& nei,
408  const label nCells = -1
409  );
410 
411  //- Helper function to calculate point ordering. Returns true
412  // if points already ordered, false and fills pointMap (old to
413  // new). Map splits points into those not used by any boundary
414  // face and those that are.
415  static bool calcPointOrder
416  (
418  labelList& pointMap,
419  const faceList&,
420  const label nInternalFaces,
421  const label nPoints
422  );
423 
424  // Return mesh connectivity
425 
426  const labelListList& cellCells() const;
427  // faceCells given as owner and neighbour
428  const labelListList& edgeCells() const;
429  const labelListList& pointCells() const;
430 
431  const cellList& cells() const;
432  // faceFaces considered unnecessary
433  const labelListList& edgeFaces() const;
434  const labelListList& pointFaces() const;
435 
436  const labelListList& cellEdges() const;
437  const labelListList& faceEdges() const;
438  // edgeEdges considered unnecessary
439  const labelListList& pointEdges() const;
440  const labelListList& pointPoints() const;
441  const labelListList& cellPoints() const;
442 
443 
444  // Geometric data (raw!)
445 
446  const vectorField& cellCentres() const;
447  const vectorField& faceCentres() const;
448  const scalarField& cellVolumes() const;
449  const vectorField& faceAreas() const;
450  const scalarField& magFaceAreas() const;
451 
452 
453  // Mesh motion
454 
455  //- Move points, returns volumes swept by faces in motion
457  (
458  const pointField& p,
459  const pointField& oldP
460  );
461 
462 
463  //- Return true if given face label is internal to the mesh
464  inline bool isInternalFace(const label faceIndex) const;
465 
466 
467  // Useful derived info
468 
469  //- Return true if the point in the cell bounding box.
470  // The bounding box may be isotropically inflated by the fraction
471  // inflationFraction
472  bool pointInCellBB
473  (
474  const point& p,
475  label celli,
476  scalar inflationFraction = 0
477  ) const;
478 
479  //- Return true if the point is in the cell
480  bool pointInCell(const point& p, label celli) const;
481 
482  //- Find the cell with the nearest cell centre to location
483  label findNearestCell(const point& location) const;
484 
485  //- Find cell enclosing this location (-1 if not in mesh)
486  label findCell(const point& location) const;
487 
488 
489  // Storage management
490 
491  //- Print a list of all the currently allocated mesh data
492  void printAllocated() const;
493 
494  // Per storage whether allocated
495  inline bool hasCellShapes() const;
496  inline bool hasEdges() const;
497  inline bool hasCellCells() const;
498  inline bool hasEdgeCells() const;
499  inline bool hasPointCells() const;
500  inline bool hasCells() const;
501  inline bool hasEdgeFaces() const;
502  inline bool hasPointFaces() const;
503  inline bool hasCellEdges() const;
504  inline bool hasFaceEdges() const;
505  inline bool hasPointEdges() const;
506  inline bool hasPointPoints() const;
507  inline bool hasCellPoints() const;
508  inline bool hasCellCentres() const;
509  inline bool hasFaceCentres() const;
510  inline bool hasCellVolumes() const;
511  inline bool hasFaceAreas() const;
512 
513  // On-the-fly addressing calculation. These functions return either
514  // a reference to the full addressing (if already calculated) or
515  // a reference to the supplied storage. The one-argument ones
516  // use member DynamicList labels_ so be careful when not storing
517  // result.
518 
519  //- cellCells using cells.
520  const labelList& cellCells
521  (
522  const label celli,
524  ) const;
525 
526  const labelList& cellCells(const label celli) const;
527 
528  //- cellPoints using cells
529  const labelList& cellPoints
530  (
531  const label celli,
533  ) const;
534 
535  const labelList& cellPoints(const label celli) const;
536 
537  //- pointCells using pointFaces
538  const labelList& pointCells
539  (
540  const label pointi,
542  ) const;
543 
544  const labelList& pointCells(const label pointi) const;
545 
546  //- pointPoints using edges, pointEdges
547  const labelList& pointPoints
548  (
549  const label pointi,
551  ) const;
552 
553  const labelList& pointPoints(const label pointi) const;
554 
555  //- faceEdges using pointFaces, edges, pointEdges
556  const labelList& faceEdges
557  (
558  const label facei,
560  ) const;
561 
562  const labelList& faceEdges(const label facei) const;
563 
564  //- edgeFaces using pointFaces, edges, pointEdges
565  const labelList& edgeFaces
566  (
567  const label edgeI,
569  ) const;
570 
571  const labelList& edgeFaces(const label edgeI) const;
572 
573  //- edgeCells using pointFaces, edges, pointEdges
574  const labelList& edgeCells
575  (
576  const label edgeI,
578  ) const;
579 
580  const labelList& edgeCells(const label edgeI) const;
581 
582  //- cellEdges using cells, pointFaces, edges, pointEdges
583  const labelList& cellEdges
584  (
585  const label celli,
587  ) const;
588 
589  const labelList& cellEdges(const label celli) const;
590 
591 
592  //- Clear geometry
593  void clearGeom();
594 
595  //- Clear topological data
596  void clearAddressing();
597 
598  //- Clear all geometry and addressing unnecessary for CFD
599  void clearOut();
600 
601 
602  // Member Operators
603 
604  //- Disallow default bitwise assignment
605  void operator=(const primitiveMesh&) = delete;
606 };
607 
608 
609 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
610 
611 } // End namespace Foam
612 
613 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
614 
615 #include "primitiveMeshI.H"
616 
617 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
618 
619 #endif
620 
621 // ************************************************************************* //
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:75
label nEdges() const
label nCells() const
static bool calcPointOrder(label &nInternalPoints, labelList &pointMap, const faceList &, const label nInternalFaces, const label nPoints)
Helper function to calculate point ordering. Returns true.
label findNearestCell(const point &location) const
Find the cell with the nearest cell centre to location.
bool hasCellCells() const
bool hasCellShapes() const
primitiveMesh()
Construct null.
Definition: primitiveMesh.C:39
bool hasPointFaces() const
label nPoints() const
bool hasCellEdges() const
bool hasCellVolumes() const
const labelListList & pointEdges() const
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
const labelListList & cellEdges() const
bool pointInCell(const point &p, label celli) const
Return true if the point is in the cell.
bool hasPointPoints() const
const vectorField & faceCentres() const
virtual const faceList & faces() const =0
Return faces.
const labelListList & pointCells() const
static const unsigned facesPerEdge_
Estimated number of faces per edge.
const scalarField & cellVolumes() const
void clearGeom()
Clear geometry.
bool hasFaceAreas() const
bool pointInCellBB(const point &p, label celli, scalar inflationFraction=0) const
Return true if the point in the cell bounding box.
bool hasEdges() const
label nInternal1Edges() const
Internal edges using 0 or 1 boundary point.
bool hasFaceCentres() const
void makeCellCentresAndVols(const vectorField &fCtrs, const vectorField &fAreas, vectorField &cellCtrs, scalarField &cellVols) const
static const unsigned edgesPerCell_
Estimated number of edges per cell.
const vectorField & cellCentres() const
bool hasPointCells() const
virtual ~primitiveMesh()
Destructor.
const cellShapeList & cellShapes() const
Return cell shapes.
static const unsigned facesPerPoint_
Estimated number of faces per point.
void calcCellCentresAndVols() const
Calculate cell centres and volumes.
virtual const labelList & faceOwner() const =0
Face face-owner addressing.
label findCell(const point &location) const
Find cell enclosing this location (-1 if not in mesh)
void calcEdgeVectors() const
Calculate edge vectors.
static const unsigned pointsPerFace_
Estimated number of points per face.
ClassName("primitiveMesh")
const labelListList & cellCells() const
const labelListList & cellPoints() const
label nInternalFaces() const
void clearAddressing()
Clear topological data.
static const unsigned cellsPerPoint_
Estimated number of cells per point.
bool hasCellCentres() const
bool hasCellPoints() const
static const unsigned cellsPerEdge_
Estimated number of cells per edge.
label nInternal0Edges() const
Internal edges (i.e. not on boundary face) using.
label nFaces() const
void operator=(const primitiveMesh &)=delete
Disallow default bitwise assignment.
label nInternalEdges() const
Internal edges using 0,1 or 2 boundary points.
const scalarField & magFaceAreas() const
void printAllocated() const
Print a list of all the currently allocated mesh data.
void reset(const label nPoints, const label nInternalFaces, const label nFaces, const label nCells)
Reset this primitiveMesh given the primitive array sizes.
static const unsigned edgesPerPoint_
Estimated number of edges per point.
const labelListList & pointFaces() const
bool hasCells() const
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
tmp< scalarField > movePoints(const pointField &p, const pointField &oldP)
Move points, returns volumes swept by faces in motion.
static const unsigned pointsPerCell_
Estimated number of points per cell.
static const unsigned facesPerCell_
Estimated number of faces per cell.
bool hasFaceEdges() const
virtual const pointField & points() const =0
Return mesh points.
const labelListList & edgeFaces() const
const labelListList & pointPoints() const
const labelListList & faceEdges() const
const labelListList & edgeCells() const
const vectorField & faceAreas() const
bool hasEdgeCells() const
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
void calcFaceCentresAndAreas() const
Calculate face centres and areas.
label nInternalPoints() const
Points not on boundary.
static const unsigned edgesPerFace_
Estimated number of edges per cell.
bool hasEdgeFaces() const
const cellList & cells() const
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
void makeFaceCentresAndAreas(const pointField &p, vectorField &fCtrs, vectorField &fAreas, scalarField &magfAreas) const
bool hasPointEdges() const
virtual const pointField & oldPoints() const =0
Return old points for mesh motion.
A class for managing temporary objects.
Definition: tmp.H:55
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
volScalarField & p
const scalarField & cellVols