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-2025 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  // Private Member 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  // Private Member Functions
182 
183  // Topological calculations
184 
185  //- Calculate cell shapes
186  void calcCellShapes() const;
187 
188  //- Calculate cell-cell addressing
189  void calcCellCells() const;
190 
191  //- Calculate point-cell addressing
192  void calcPointCells() const;
193 
194  //- Calculate cell-face addressing
195  void calcCells() const;
196 
197  //- Calculate edge list
198  void calcCellEdges() const;
199 
200  //- Calculate point-point addressing
201  void calcPointPoints() const;
202 
203  //- Calculate edges, pointEdges and faceEdges (if doFaceEdges=true)
204  // During edge calculation, a larger set of data is assembled.
205  // Create and destroy as a set, using clearOutEdges()
206  void calcEdges(const bool doFaceEdges) const;
207 
208  void clearOutEdges();
209 
210  //- Helper: return (after optional creation) edge between two points
211  static label getEdge
212  (
215  const label,
216  const label
217  );
218 
219  //- For on-the-fly addressing calculation
220  static label findFirstCommonElementFromSortedLists
221  (
222  const labelList&,
223  const labelList&
224  );
225 
226 
227  // Geometrical calculations
228 
229  //- Calculate face centres and areas
230  void calcFaceCentresAndAreas() const;
231 
232  //- Calculate face centres and areas
233  void makeFaceCentresAndAreas
234  (
235  const pointField& p,
236  vectorField& fCtrs,
237  vectorField& fAreas,
238  scalarField& magfAreas
239  ) const;
240 
241  //- Calculate cell centres and volumes
242  void calcCellCentresAndVols() const;
243 
244  //- Calculate cell centres and volumes
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 protected:
258 
259  // Protected Static Member Functions
260 
261  //- Test if the supplied methods are the same. Same type overload.
262  // Compares pointers.
263  template<class Class, class Type>
264  static inline bool isMethod
265  (
266  const Type& (Class::*method)() const,
267  const Type& (Class::*otherMethod)() const
268  );
269 
270  //- Test if the supplied methods are the same. Different type
271  // overload. Returns false.
272  template<class Class, class Type, class OtherType>
273  static inline bool isMethod
274  (
275  const Type& (Class::*method)() const,
276  const OtherType& (Class::*otherMethod)() const
277  );
278 
279 
280  // Protected Constructors
281 
282  //- Construct null
283  primitiveMesh();
284 
285 
286 public:
287 
288  //- Runtime type information
289  ClassName("primitiveMesh");
290 
291 
292  // Static data
293 
294  //- Estimated number of cells per edge
295  static const unsigned cellsPerEdge_ = 4;
296 
297  //- Estimated number of cells per point
298  static const unsigned cellsPerPoint_ = 8;
299 
300  //- Estimated number of faces per cell
301  static const unsigned facesPerCell_ = 6;
302 
303  //- Estimated number of faces per edge
304  static const unsigned facesPerEdge_ = 4;
305 
306  //- Estimated number of faces per point
307  static const unsigned facesPerPoint_ = 12;
308 
309  //- Estimated number of edges per cell
310  static const unsigned edgesPerCell_ = 12;
311 
312  //- Estimated number of edges per cell
313  static const unsigned edgesPerFace_ = 4;
314 
315  //- Estimated number of edges per point
316  static const unsigned edgesPerPoint_ = 6;
317 
318  //- Estimated number of points per cell
319  static const unsigned pointsPerCell_ = 8;
320 
321  //- Estimated number of points per face
322  static const unsigned pointsPerFace_ = 4;
323 
324 
325  // Constructors
326 
327  //- Construct from components
329  (
330  const label nPoints,
331  const label nInternalFaces,
332  const label nFaces,
333  const label nCells
334  );
335 
336  //- Move constructor
337  primitiveMesh(primitiveMesh&&) = default;
338 
339  //- Disallow default bitwise copy construction
340  primitiveMesh(const primitiveMesh&) = delete;
341 
342 
343  //- Destructor
344  virtual ~primitiveMesh();
345 
346 
347  // Member Functions
348 
349  //- Reset this primitiveMesh given the primitive array sizes
350  void reset
351  (
352  const label nPoints,
353  const label nInternalFaces,
354  const label nFaces,
355  const label nCells
356  );
357 
358  //- Reset this primitiveMesh given the primitive array sizes and cells
359  void reset
360  (
361  const label nPoints,
362  const label nInternalFaces,
363  const label nFaces,
364  const label nCells,
365  cellList& cells
366  );
367 
368  //- Reset this primitiveMesh given the primitive array sizes and cells
369  void reset
370  (
371  const label nPoints,
372  const label nInternalFaces,
373  const label nFaces,
374  const label nCells,
375  cellList&& cells
376  );
377 
378 
379  // Access
380 
381  // Mesh size parameters
382 
383  inline label nPoints() const;
384  inline label nEdges() const;
385  inline label nInternalFaces() const;
386  inline label nFaces() const;
387  inline label nCells() const;
388 
389  // If points are ordered (nInternalPoints != -1):
390 
391  //- Points not on boundary
392  inline label nInternalPoints() const;
393 
394  //- Internal edges (i.e. not on boundary face) using
395  // no boundary point
396  inline label nInternal0Edges() const;
397 
398  //- Internal edges using 0 or 1 boundary point
399  inline label nInternal1Edges() const;
400 
401  //- Internal edges using 0,1 or 2 boundary points
402  inline label nInternalEdges() const;
403 
404 
405  // Primitive mesh data
406 
407  //- Return mesh points
408  virtual const pointField& points() const = 0;
409 
410  //- Return faces
411  virtual const faceList& faces() const = 0;
412 
413  //- Face face-owner addressing
414  virtual const labelList& faceOwner() const = 0;
415 
416  //- Face face-neighbour addressing
417  virtual const labelList& faceNeighbour() const = 0;
418 
419  //- Return old points for mesh motion
420  virtual const pointField& oldPoints() const = 0;
421 
422 
423  // Derived mesh data
424 
425  //- Return cell shapes
426  const cellShapeList& cellShapes() const;
427 
428  //- Return mesh edges. Uses calcEdges.
429  const edgeList& edges() const;
430 
431  //- Helper function to calculate cell-face addressing from
432  // face-cell addressing. If nCells is not provided it will
433  // scan for the maximum.
434  static void calcCells
435  (
436  cellList&,
437  const labelUList& own,
438  const labelUList& nei,
439  const label nCells = -1
440  );
441 
442  //- Helper function to calculate point ordering. Returns true
443  // if points already ordered, false and fills pointMap (old to
444  // new). Map splits points into those not used by any boundary
445  // face and those that are.
446  static bool calcPointOrder
447  (
449  labelList& pointMap,
450  const faceList&,
451  const label nInternalFaces,
452  const label nPoints
453  );
454 
455  // Return mesh connectivity
456 
457  const labelListList& cellCells() const;
458  // faceCells given as owner and neighbour
459  const labelListList& edgeCells() const;
460  const labelListList& pointCells() const;
461 
462  const cellList& cells() const;
463  // faceFaces considered unnecessary
464  const labelListList& edgeFaces() const;
465  const labelListList& pointFaces() const;
466 
467  const labelListList& cellEdges() const;
468  const labelListList& faceEdges() const;
469  // edgeEdges considered unnecessary
470  const labelListList& pointEdges() const;
471  const labelListList& pointPoints() const;
472  const labelListList& cellPoints() const;
473 
474 
475  // Geometric data (raw!)
476 
477  const vectorField& cellCentres() const;
478  const vectorField& faceCentres() const;
479  const scalarField& cellVolumes() const;
480  const vectorField& faceAreas() const;
481  const scalarField& magFaceAreas() const;
482 
483 
484  // Mesh motion
485 
486  //- Move points, returns volumes swept by faces in motion
488  (
489  const pointField& p,
490  const pointField& oldP
491  );
492 
493 
494  //- Return true if given face label is internal to the mesh
495  inline bool isInternalFace(const label faceIndex) const;
496 
497 
498  // Useful derived info
499 
500  //- Return true if the point in the cell bounding box.
501  // The bounding box may be isotropically inflated by the fraction
502  // inflationFraction
503  bool pointInCellBB
504  (
505  const point& p,
506  label celli,
507  scalar inflationFraction = 0
508  ) const;
509 
510  //- Return true if the point is in the cell
511  bool pointInCell(const point& p, label celli) const;
512 
513  //- Find the cell with the nearest cell centre to location
514  label findNearestCell(const point& location) const;
515 
516  //- Find cell enclosing this location (-1 if not in mesh)
517  label findCell(const point& location) const;
518 
519 
520  // Storage management
521 
522  //- Print a list of all the currently allocated mesh data
523  void printAllocated() const;
524 
525  //- Return whether the result of the given method has been allocated
526  template<class Type>
527  inline bool has
528  (
529  const Type& (primitiveMesh::*method)() const
530  ) const;
531 
532  // On-the-fly addressing calculation. These functions return either
533  // a reference to the full addressing (if already calculated) or
534  // a reference to the supplied storage. The one-argument ones
535  // use member DynamicList labels_ so be careful when not storing
536  // result.
537 
538  //- cellCells using cells.
539  const labelList& cellCells
540  (
541  const label celli,
543  ) const;
544 
545  const labelList& cellCells(const label celli) const;
546 
547  //- cellPoints using cells
548  const labelList& cellPoints
549  (
550  const label celli,
552  ) const;
553 
554  const labelList& cellPoints(const label celli) const;
555 
556  //- pointCells using pointFaces
557  const labelList& pointCells
558  (
559  const label pointi,
561  ) const;
562 
563  const labelList& pointCells(const label pointi) const;
564 
565  //- pointPoints using edges, pointEdges
566  const labelList& pointPoints
567  (
568  const label pointi,
570  ) const;
571 
572  const labelList& pointPoints(const label pointi) const;
573 
574  //- faceEdges using pointFaces, edges, pointEdges
575  const labelList& faceEdges
576  (
577  const label facei,
579  ) const;
580 
581  const labelList& faceEdges(const label facei) const;
582 
583  //- edgeFaces using pointFaces, edges, pointEdges
584  const labelList& edgeFaces
585  (
586  const label edgeI,
588  ) const;
589 
590  const labelList& edgeFaces(const label edgeI) const;
591 
592  //- edgeCells using pointFaces, edges, pointEdges
593  const labelList& edgeCells
594  (
595  const label edgeI,
597  ) const;
598 
599  const labelList& edgeCells(const label edgeI) const;
600 
601  //- cellEdges using cells, pointFaces, edges, pointEdges
602  const labelList& cellEdges
603  (
604  const label celli,
606  ) const;
607 
608  const labelList& cellEdges(const label celli) const;
609 
610  //- Clear geometry
611  void clearGeom();
612 
613  //- Clear topological data
614  void clearAddressing();
615 
616  //- Clear all geometry and addressing unnecessary for CFD
617  void clearOut();
618 
619 
620  // Member Operators
621 
622  //- Disallow default bitwise assignment
623  void operator=(const primitiveMesh&) = delete;
624 };
625 
626 
627 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
628 
629 } // End namespace Foam
630 
631 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
632 
633 #include "primitiveMeshI.H"
634 
635 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
636 
637 #endif
638 
639 // ************************************************************************* //
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:75
label nInternal1Edges() const
Internal edges using 0 or 1 boundary point.
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.
primitiveMesh()
Construct null.
Definition: primitiveMesh.C:39
const labelListList & pointEdges() const
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
label nInternalEdges() const
Internal edges using 0,1 or 2 boundary points.
const labelListList & cellEdges() const
bool pointInCell(const point &p, label celli) const
Return true if the point is in the cell.
const vectorField & faceCentres() const
virtual const faceList & faces() const =0
Return faces.
label nInternalPoints() const
Points not on boundary.
const labelListList & pointCells() const
static const unsigned facesPerEdge_
Estimated number of faces per edge.
const scalarField & cellVolumes() const
void clearGeom()
Clear geometry.
bool pointInCellBB(const point &p, label celli, scalar inflationFraction=0) const
Return true if the point in the cell bounding box.
label nInternalFaces() const
static const unsigned edgesPerCell_
Estimated number of edges per cell.
const vectorField & cellCentres() const
virtual ~primitiveMesh()
Destructor.
const cellShapeList & cellShapes() const
Return cell shapes.
static const unsigned facesPerPoint_
Estimated number of faces per point.
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)
static const unsigned pointsPerFace_
Estimated number of points per face.
ClassName("primitiveMesh")
Runtime type information.
const labelListList & cellCells() const
const labelListList & cellPoints() const
label nCells() const
static bool isMethod(const Type &(Class::*method)() const, const Type &(Class::*otherMethod)() const)
Test if the supplied methods are the same. Same type overload.
void clearAddressing()
Clear topological data.
static const unsigned cellsPerPoint_
Estimated number of cells per point.
static const unsigned cellsPerEdge_
Estimated number of cells per edge.
void operator=(const primitiveMesh &)=delete
Disallow default bitwise assignment.
bool has(const Type &(primitiveMesh::*method)() const) const
Return whether the result of the given method has been allocated.
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
label nPoints() 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.
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 isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
static const unsigned edgesPerFace_
Estimated number of edges per cell.
const cellList & cells() const
label nEdges() const
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
label nInternal0Edges() const
Internal edges (i.e. not on boundary face) using.
label nFaces() 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