polyMesh.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::polyMesh
26 
27 Description
28  Mesh consisting of general polyhedral cells.
29 
30 SourceFiles
31  polyMesh.C
32  polyMeshInitMesh.C
33  polyMeshClear.C
34  polyMeshFromShapeMesh.C
35  polyMeshIO.C
36  polyMeshUpdate.C
37  polyMeshCheck.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef polyMesh_H
42 #define polyMesh_H
43 
44 #include "objectRegistry.H"
45 #include "primitiveMesh.H"
46 #include "pointField.H"
47 #include "faceList.H"
48 #include "cellList.H"
49 #include "cellShapeList.H"
50 #include "pointIOField.H"
51 #include "faceIOList.H"
52 #include "labelIOList.H"
53 #include "polyBoundaryMesh.H"
54 #include "boundBox.H"
55 #include "pointZoneList.H"
56 #include "faceZoneList.H"
57 #include "cellZoneList.H"
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61 namespace Foam
62 {
63 
64 // Forward declaration of classes
65 class globalMeshData;
66 class polyTopoChangeMap;
67 class polyMeshMap;
68 class polyDistributionMap;
69 class polyMeshTetDecomposition;
70 
71 /*---------------------------------------------------------------------------*\
72  Class polyMesh Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 class polyMesh
76 :
77  public objectRegistry,
78  public primitiveMesh
79 {
80 
81 public:
82 
83  // Public data types
84 
85  //- Enumeration defining the state of the mesh after a read update.
86  // Used for post-processing applications, where the mesh
87  // needs to update based on the files written in time directories.
88  enum readUpdateState
89  {
94  };
95 
96 
97 private:
98 
99  // Private Member Data
100 
101  // Primitive mesh data
102 
103  //- Points
104  pointIOField points_;
105 
106  //- Faces
107  faceCompactIOList faces_;
108 
109  //- Face owner
110  labelIOList owner_;
111 
112  //- Face neighbour
113  labelIOList neighbour_;
114 
115  //- Have the primitives been cleared
116  bool clearedPrimitives_;
117 
118  //- Boundary mesh
119  mutable polyBoundaryMesh boundary_;
120 
121  //- Mesh bounding-box.
122  // Created from points on construction, updated when the mesh moves
123  boundBox bounds_;
124 
125  //- Communicator used for parallel communication
126  label comm_;
127 
128  //- Vector of non-constrained directions in mesh
129  // defined according to the presence of empty and wedge patches
130  mutable Vector<label> geometricD_;
131 
132  //- Vector of valid directions in mesh
133  // defined according to the presence of empty patches
134  mutable Vector<label> solutionD_;
135 
136  //- Base point for face decomposition into tets
137  mutable autoPtr<labelIOList> tetBasePtIsPtr_;
138 
139 
140  // Zoning information
141 
142  //- Point zones
143  pointZoneList pointZones_;
144 
145  //- Face zones
146  faceZoneList faceZones_;
147 
148  //- Cell zones
149  cellZoneList cellZones_;
150 
151 
152  //- Parallel info
153  mutable autoPtr<globalMeshData> globalMeshDataPtr_;
154 
155 
156  // Mesh motion related dat
157 
158  //- Current time index for mesh motion
159  mutable label curMotionTimeIndex_;
160 
161  //- Old points (for the last mesh motion)
162  mutable autoPtr<pointField> oldPointsPtr_;
163 
164  //- Old cell centres (for the last mesh motion)
165  mutable autoPtr<pointField> oldCellCentresPtr_;
166 
167  //- Whether or not to store the old cell centres
168  mutable bool storeOldCellCentres_;
169 
170 
171  // Private Member Functions
172 
173  //- Return the region directory
174  static fileName regionDir(const IOobject& io);
175 
176  //- Initialise the polyMesh from the primitive data
177  void initMesh();
178 
179  //- Initialise the polyMesh from the given set of cells
180  void initMesh(cellList& c);
181 
182  //- Calculate the valid directions in the mesh from the boundaries
183  void calcDirections() const;
184 
185  //- Calculate the cell shapes from the primitive
186  // polyhedral information
187  void calcCellShapes() const;
188 
189  //- Read and return the tetBasePtIs
190  autoPtr<labelIOList> readTetBasePtIs() const;
191 
192  //- Set the write option of the points
193  void setPointsWrite(const IOobject::writeOption wo);
194 
195  //- Set the write option of the topology
196  void setTopologyWrite(const IOobject::writeOption wo);
197 
198 
199  // Helper functions for constructor from cell shapes
200 
201  labelListList cellShapePointCells(const cellShapeList&) const;
202 
203  labelList facePatchFaceCells
204  (
205  const faceList& patchFaces,
206  const labelListList& pointCells,
207  const faceListList& cellsFaceShapes,
208  const label patchID
209  ) const;
210 
211  void setTopology
212  (
213  const cellShapeList& cellsAsShapes,
214  const faceListList& boundaryFaces,
215  const wordList& boundaryPatchNames,
216  labelList& patchSizes,
217  labelList& patchStarts,
218  label& defaultPatchStart,
219  label& nFaces,
220  cellList& cells
221  );
222 
223 
224 protected:
225 
226  // Protected Member Data
227 
228  //- Member data pending transfer to fvMesh
229 
230  //- Is the mesh moving
231  bool moving_;
232 
233  //- Has the mesh topology changed
234  bool topoChanged_;
235 
236 
237 public:
238 
239  // Public Typedefs
240 
241  typedef polyMesh Mesh;
243 
244 
245  //- Runtime type information
246  TypeName("polyMesh");
247 
248 
249  // Static data
250 
251  //- Return the default region name
252  static word defaultRegion;
253 
254  //- Return the mesh sub-directory name (usually "polyMesh")
255  static word meshSubDir;
256 
257 
258  // Constructors
259 
260  //- Return whether the given IOobject relates to a mesh on disk
261  static bool found(const IOobject& io);
262 
263  //- Construct from IOobject.
264  explicit polyMesh(const IOobject& io);
265 
266  //- Move construct from IOobject or from components.
267  // Boundary is added using addPatches() member function
268  polyMesh
269  (
270  const IOobject& io,
271  pointField&& points,
272  faceList&& faces,
273  labelList&& owner,
274  labelList&& neighbour,
275  const bool syncPar = true
276  );
277 
278  //- Move construct without boundary with cells rather than
279  // owner/neighbour.
280  // Boundary is added using addPatches() member function
281  polyMesh
282  (
283  const IOobject& io,
284  pointField&& points,
285  faceList&& faces,
286  cellList&& cells,
287  const bool syncPar = true
288  );
289 
290  //- Move construct from cell shapes
291  polyMesh
292  (
293  const IOobject& io,
294  pointField&& points,
295  const cellShapeList& shapes,
296  const faceListList& boundaryFaces,
297  const wordList& boundaryPatchNames,
298  const wordList& boundaryPatchTypes,
299  const word& defaultBoundaryPatchName,
300  const word& defaultBoundaryPatchType,
301  const wordList& boundaryPatchPhysicalTypes,
302  const bool syncPar = true
303  );
304 
305  //- Move construct from cell shapes with patch information in dictionary
306  // format.
307  polyMesh
308  (
309  const IOobject& io,
310  pointField&& points,
311  const cellShapeList& shapes,
312  const faceListList& boundaryFaces,
313  const wordList& boundaryPatchNames,
314  const PtrList<dictionary>& boundaryDicts,
315  const word& defaultBoundaryPatchName,
316  const word& defaultBoundaryPatchType,
317  const bool syncPar = true
318  );
319 
320  //- Move constructor
321  polyMesh(polyMesh&&);
322 
323  //- Disallow default bitwise copy construction
324  polyMesh(const polyMesh&) = delete;
325 
326 
327  //- Destructor
328  virtual ~polyMesh();
329 
330 
331  // Member Functions
332 
333  // Database
334 
335  //- Return the local mesh directory (dbDir()/meshSubDir)
336  fileName meshDir() const;
337 
338  //- Return the current instance directory for points
339  // Used in the construction of geometric mesh data dependent
340  // on points
341  const fileName& pointsInstance() const;
342 
343  //- Return the current instance directory for faces
344  const fileName& facesInstance() const;
345 
346  //- Return the points write option
348 
349  //- Return the points write option
351 
352  //- Set the instance for the points files
353  void setPointsInstance(const fileName&);
354 
355  //- Set the instance for mesh files
356  void setInstance(const fileName&);
357 
358 
359  // Access
360 
361  // Primitive mesh data
362 
363  //- Return raw points
364  virtual const pointField& points() const;
365 
366  //- Return raw faces
367  virtual const faceList& faces() const;
368 
369  //- Return face owner
370  virtual const labelList& faceOwner() const;
371 
372  //- Return face neighbour
373  virtual const labelList& faceNeighbour() const;
374 
375  //- Return old points for mesh motion
376  virtual const pointField& oldPoints() const;
377 
378  //- Return old cell centres for mesh motion
379  virtual const pointField& oldCellCentres() const;
380 
381 
382  //- Return boundary mesh
383  const polyBoundaryMesh& boundaryMesh() const
384  {
385  return boundary_;
386  }
387 
388  //- Return mesh bounding box
389  const boundBox& bounds() const
390  {
391  return bounds_;
392  }
393 
394  //- Return the vector of geometric directions in mesh.
395  // Defined according to the presence of empty and wedge patches.
396  // 1 indicates unconstrained direction and -1 a constrained
397  // direction.
398  const Vector<label>& geometricD() const;
399 
400  //- Return the number of valid geometric dimensions in the mesh
401  label nGeometricD() const;
402 
403  //- Return the vector of solved-for directions in mesh.
404  // Differs from geometricD in that it includes for wedge cases
405  // the circumferential direction in case of swirl.
406  // 1 indicates valid direction and -1 an invalid direction.
407  const Vector<label>& solutionD() const;
408 
409  //- Return the number of valid solved-for dimensions in the mesh
410  label nSolutionD() const;
411 
412  //- Return the tetBasePtIs
413  const labelIOList& tetBasePtIs() const;
414 
415  //- Return point zones
416  const pointZoneList& pointZones() const
417  {
418  return pointZones_;
419  }
420 
421  //- Return face zones
422  const faceZoneList& faceZones() const
423  {
424  return faceZones_;
425  }
426 
427  //- Return cell zones
428  const cellZoneList& cellZones() const
429  {
430  return cellZones_;
431  }
432 
433  //- Return parallel info
434  const globalMeshData& globalData() const;
435 
436  //- Return communicator used for parallel communication
437  label comm() const;
438 
439  //- Return communicator used for parallel communication
440  label& comm();
441 
442  //- Return the object registry
443  const objectRegistry& thisDb() const
444  {
445  return *this;
446  }
447 
448 
449  // Mesh motion
450 
451  //- Is mesh moving
452  bool moving() const
453  {
454  return moving_;
455  }
456 
457  //- Has the mesh topology changed this time-step
458  bool topoChanged() const
459  {
460  return topoChanged_;
461  }
462 
463  //- Is mesh changing
464  // Moving or mesh topology changed this time-step)
465  bool changing() const
466  {
467  return moving() || topoChanged();
468  }
469 
470  //- Reset the points
471  // without storing old points or returning swept volumes
472  virtual void setPoints(const pointField&);
473 
474  //- Move points, returns volumes swept by faces in motion
475  virtual tmp<scalarField> movePoints(const pointField&);
476 
477  //- Reset motion
478  void resetMotion() const;
479 
480 
481  // Topological change
482 
483  //- Return non-const access to the pointZones
485  {
486  return pointZones_;
487  }
488 
489  //- Return non-const access to the faceZones
491  {
492  return faceZones_;
493  }
494 
495  //- Return non-const access to the cellZones
497  {
498  return cellZones_;
499  }
500 
501  //- Add boundary patches
502  void addPatches
503  (
504  const List<polyPatch*>&,
505  const bool validBoundary = true
506  );
507 
508  //- Add mesh zones
509  void addZones
510  (
511  const List<pointZone*>& pz,
512  const List<faceZone*>& fz,
513  const List<cellZone*>& cz
514  );
515 
516  //- Add/insert single patch
517  virtual void addPatch
518  (
519  const label insertPatchi,
520  const polyPatch& patch
521  );
522 
523  //- Complete addition of single patches
524  void addedPatches();
525 
526  //- Reorder and trim existing patches. If validBoundary the new
527  // situation is consistent across processors
528  virtual void reorderPatches
529  (
530  const labelUList& newToOld,
531  const bool validBoundary
532  );
533 
534  //- Update the mesh based on the mesh files saved in
535  // time directories
537 
538  //- Update zones using the given map
539  void topoChangeZones(const polyTopoChangeMap&);
540 
541  //- Update topology using the given map
542  virtual void topoChange(const polyTopoChangeMap&);
543 
544  //- Update from another mesh using the given map
545  virtual void mapMesh(const polyMeshMap&);
546 
547  //- Redistribute or update using the given distribution map
548  virtual void distribute(const polyDistributionMap& map);
549 
550  //- Remove boundary patches
551  void removeBoundary();
552 
553  //- Reset mesh primitive data. Assumes all patch info correct
554  // (so does e.g. parallel communication). If not use
555  // validBoundary=false
556  void resetPrimitives
557  (
558  pointField&& points,
559  faceList&& faces,
560  labelList&& owner,
561  labelList&& neighbour,
562  const labelList& patchSizes,
563  const labelList& patchStarts,
564  const bool validBoundary = true
565  );
566 
567  //- Swap mesh
568  // For run-time mesh replacement and mesh to mesh mapping
569  void swap(polyMesh&);
570 
571 
572  // Storage management
573 
574  //- Print a list of all the currently allocated mesh data
575  void printAllocated() const;
576 
577  //- Clear geometry
578  void clearGeom();
579 
580  //- Clear addressing
581  void clearAddressing(const bool isMeshUpdate = false);
582 
583  //- Clear all geometry and addressing unnecessary for CFD
584  void clearOut();
585 
586  //- Clear primitive data (points, faces and cells)
587  void clearPrimitives();
588 
589  //- Clear tet base points
590  void clearTetBasePtIs();
591 
592  //- Remove all files from mesh instance
593  void removeFiles(const fileName& instanceDir) const;
594 
595  //- Remove all files from mesh instance()
596  void removeFiles() const;
597 
598 
599  // Write
600 
601  //- Write the underlying polyMesh
602  virtual bool writeObject
603  (
607  const bool write = true
608  ) const;
609 
610 
611  // Member Operators
612 
613  //- Disallow default bitwise assignment
614  void operator=(const polyMesh&) = delete;
615 };
616 
617 
618 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
619 
620 } // End namespace Foam
621 
622 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
623 
624 #endif
625 
626 // ************************************************************************* //
Foam::cellZoneList.
A primitive field of type <Type> with automated input and output.
Definition: IOField.H:53
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
writeOption
Enumeration defining the write options.
Definition: IOobject.H:126
Version number type.
Definition: IOstream.H:97
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:59
A class for handling file names.
Definition: fileName.H:82
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
Registry of regIOobjects.
Foam::polyBoundaryMesh.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
const pointZoneList & pointZones() const
Return point zones.
Definition: polyMesh.H:415
virtual ~polyMesh()
Destructor.
Definition: polyMesh.C:948
bool topoChanged_
Has the mesh topology changed.
Definition: polyMesh.H:233
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:992
label nGeometricD() const
Return the number of valid geometric dimensions in the mesh.
Definition: polyMesh.C:1021
const cellZoneList & cellZones() const
Return cell zones.
Definition: polyMesh.H:427
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:251
polyMesh Mesh
Definition: polyMesh.H:240
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: polyMesh.C:980
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: polyMesh.C:1418
bool moving_
Member data pending transfer to fvMesh.
Definition: polyMesh.H:230
IOobject::writeOption facesWriteOpt() const
Return the points write option.
Definition: polyMesh.C:1004
static bool found(const IOobject &io)
Return whether the given IOobject relates to a mesh on disk.
Definition: polyMesh.C:957
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1315
void addedPatches()
Complete addition of single patches.
Definition: polyMesh.C:1290
void clearGeom()
Clear geometry.
Definition: polyMeshClear.C:64
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
@ TOPO_PATCH_CHANGE
Definition: polyMesh.H:92
void resetPrimitives(pointField &&points, faceList &&faces, labelList &&owner, labelList &&neighbour, const labelList &patchSizes, const labelList &patchStarts, const bool validBoundary=true)
Reset mesh primitive data. Assumes all patch info correct.
Definition: polyMesh.C:714
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1328
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:1044
void operator=(const polyMesh &)=delete
Disallow default bitwise assignment.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
TypeName("polyMesh")
Runtime type information.
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1486
const objectRegistry & thisDb() const
Return the object registry.
Definition: polyMesh.H:442
bool changing() const
Is mesh changing.
Definition: polyMesh.H:464
void clearPrimitives()
Clear primitive data (points, faces and cells)
label nSolutionD() const
Return the number of valid solved-for dimensions in the mesh.
Definition: polyMesh.C:1038
polyBoundaryMesh BoundaryMesh
Definition: polyMesh.H:241
virtual const pointField & oldPoints() const
Return old points for mesh motion.
Definition: polyMesh.C:1340
void swap(polyMesh &)
Swap mesh.
Definition: polyMesh.C:815
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: polyMesh.C:986
label comm() const
Return communicator used for parallel communication.
Definition: polyMesh.C:1504
polyMesh(const IOobject &io)
Construct from IOobject.
Definition: polyMesh.C:178
void resetMotion() const
Reset motion.
Definition: polyMesh.C:1478
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write=true) const
Write the underlying polyMesh.
Definition: polyMeshIO.C:526
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
const faceZoneList & faceZones() const
Return face zones.
Definition: polyMesh.H:421
readUpdateState readUpdate()
Update the mesh based on the mesh files saved in.
Definition: polyMeshIO.C:124
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:382
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1334
void topoChangeZones(const polyTopoChangeMap &)
Update zones using the given map.
void addPatches(const List< polyPatch * > &, const bool validBoundary=true)
Add boundary patches.
Definition: polyMesh.C:1078
bool topoChanged() const
Has the mesh topology changed this time-step.
Definition: polyMesh.H:457
void clearTetBasePtIs()
Clear tet base points.
virtual void distribute(const polyDistributionMap &map)
Redistribute or update using the given distribution map.
void setPointsInstance(const fileName &)
Set the instance for the points files.
Definition: polyMeshIO.C:71
void addZones(const List< pointZone * > &pz, const List< faceZone * > &fz, const List< cellZone * > &cz)
Add mesh zones.
Definition: polyMesh.C:1116
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1302
void printAllocated() const
Print a list of all the currently allocated mesh data.
Definition: polyMeshClear.C:51
IOobject::writeOption pointsWriteOpt() const
Return the points write option.
Definition: polyMesh.C:998
void removeFiles() const
Remove all files from mesh instance()
Definition: polyMesh.C:1540
void removeBoundary()
Remove boundary patches.
Definition: polyMeshClear.C:34
virtual const pointField & oldCellCentres() const
Return old cell centres for mesh motion.
Definition: polyMesh.C:1358
virtual void reorderPatches(const labelUList &newToOld, const bool validBoundary)
Reorder and trim existing patches. If validBoundary the new.
Definition: polyMesh.C:1174
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:254
void setInstance(const fileName &)
Set the instance for mesh files.
Definition: polyMeshIO.C:91
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:388
virtual void addPatch(const label insertPatchi, const polyPatch &patch)
Add/insert single patch.
Definition: polyMesh.C:1217
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
virtual void setPoints(const pointField &)
Reset the points.
Definition: polyMesh.C:1378
const Vector< label > & solutionD() const
Return the vector of solved-for directions in mesh.
Definition: polyMesh.C:1027
bool moving() const
Is mesh moving.
Definition: polyMesh.H:451
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
Definition: polyMesh.C:1010
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:75
const labelListList & pointCells() const
void clearAddressing()
Clear topological data.
const cellList & cells() const
label nFaces() const
virtual bool write(const bool write=true) const
Write using setting from DB.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Foam::faceZoneList.
const dimensionedScalar c
Speed of light in a vacuum.
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
Foam::pointZoneList.