FreeFOAM The Cross-Platform CFD Toolkit
polyMesh.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::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 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef polyMesh_H
41 #define polyMesh_H
42 
44 #include <OpenFOAM/primitiveMesh.H>
45 #include <OpenFOAM/pointField.H>
46 #include <OpenFOAM/faceList.H>
47 #include <OpenFOAM/cellList.H>
48 #include <OpenFOAM/cellShapeList.H>
49 #include <OpenFOAM/pointIOField.H>
50 #include <OpenFOAM/faceIOList.H>
51 #include <OpenFOAM/labelIOList.H>
53 #include <OpenFOAM/boundBox.H>
54 #include <OpenFOAM/pointZoneMesh.H>
55 #include <OpenFOAM/faceZoneMesh.H>
56 #include <OpenFOAM/cellZoneMesh.H>
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 
63 class globalMeshData;
64 class mapPolyMesh;
65 
66 /*---------------------------------------------------------------------------*\
67  Class polyMesh Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 class polyMesh
71 :
72  public objectRegistry,
73  public primitiveMesh
74 {
75 
76 public:
77 
78  // Public data types
79 
80  //- Enumeration defining the state of the mesh after a read update.
81  // Used for post-processing applications, where the mesh
82  // needs to update based on the files written in time
83  // directores
85  {
90  };
91 
92 
93 private:
94 
95  // Permanent data
96 
97  // Primitive mesh data
98 
99  //- Points
100  pointIOField points_;
101 
102  //- Faces
103  faceIOList faces_;
104 
105  //- Face owner
106  labelIOList owner_;
107 
108  //- Face neighbour
109  labelIOList neighbour_;
110 
111  //- Have the primitives been cleared
112  bool clearedPrimitives_;
113 
114 
115  //- Boundary mesh
116  mutable polyBoundaryMesh boundary_;
117 
118  //- Mesh bounding-box.
119  // Created from points on construction, updated when the mesh moves
120  boundBox bounds_;
121 
122  //- vector of non-constrained directions in mesh
123  // defined according to the presence of empty and wedge patches
124  mutable Vector<label> geometricD_;
125 
126  //- vector of valid directions in mesh
127  // defined according to the presence of empty patches
128  mutable Vector<label> solutionD_;
129 
130 
131  // Zoning information
132 
133  //- Point zones
134  pointZoneMesh pointZones_;
135 
136  //- Face zones
137  faceZoneMesh faceZones_;
138 
139  //- Cell zones
140  cellZoneMesh cellZones_;
141 
142 
143  //- Parallel info
144  mutable globalMeshData* globalMeshDataPtr_;
145 
146 
147  // Mesh motion related data
148 
149  //- Is the mesh moving
150  bool moving_;
151 
152  //- Is the mesh changing (moving and/or topology changing)
153  bool changing_;
154 
155  //- Current time index for mesh motion
156  mutable label curMotionTimeIndex_;
157 
158  //- Old points (for the last mesh motion)
159  mutable pointField* oldPointsPtr_;
160 
161 
162  // Private member functions
163 
164  //- Disallow construct as copy
165  polyMesh(const polyMesh&);
166 
167  //- Disallow default bitwise assignment
168  void operator=(const polyMesh&);
169 
170  //- Initialise the polyMesh from the primitive data
171  void initMesh();
172 
173  //- Initialise the polyMesh from the given set of cells
174  void initMesh(cellList& c);
175 
176  //- Calculate the valid directions in the mesh from the boundaries
177  void calcDirections() const;
178 
179  //- Calculate the cell shapes from the primitive
180  // polyhedral information
181  void calcCellShapes() const;
182 
183 
184  // Helper functions for constructor from cell shapes
185 
186  labelListList cellShapePointCells(const cellShapeList&) const;
187 
188  labelList facePatchFaceCells
189  (
190  const faceList& patchFaces,
191  const labelListList& pointCells,
192  const faceListList& cellsFaceShapes,
193  const label patchID
194  ) const;
195 
196 
197 public:
198 
199  // Public typedefs
200 
201  typedef polyMesh Mesh;
203 
204 
205  //- Runtime type information
206  TypeName("polyMesh");
207 
208  //- Return the default region name
210 
211  //- Return the mesh sub-directory name (usually "polyMesh")
212  static word meshSubDir;
213 
214 
215  // Constructors
216 
217  //- Construct from IOobject
218  explicit polyMesh(const IOobject& io);
219 
220  //- Construct without boundary from components.
221  // Boundary is added using addPatches() member function
222  polyMesh
223  (
224  const IOobject& io,
225  const Xfer<pointField>& points,
226  const Xfer<faceList>& faces,
227  const Xfer<labelList>& owner,
228  const Xfer<labelList>& neighbour,
229  const bool syncPar = true
230  );
231 
232  //- Construct without boundary with cells rather than owner/neighbour.
233  // Boundary is added using addPatches() member function
234  polyMesh
235  (
236  const IOobject& io,
237  const Xfer<pointField>& points,
238  const Xfer<faceList>& faces,
239  const Xfer<cellList>& cells,
240  const bool syncPar = true
241  );
242 
243  //- Construct from cell shapes
244  polyMesh
245  (
246  const IOobject& io,
247  const Xfer<pointField>& points,
248  const cellShapeList& shapes,
249  const faceListList& boundaryFaces,
250  const wordList& boundaryPatchNames,
251  const wordList& boundaryPatchTypes,
252  const word& defaultBoundaryPatchName,
253  const word& defaultBoundaryPatchType,
254  const wordList& boundaryPatchPhysicalTypes,
255  const bool syncPar = true
256  );
257 
258 
259  // Destructor
260 
261  virtual ~polyMesh();
262 
263 
264  // Member Functions
265 
266  // Database
267 
268  //- Override the objectRegistry dbDir for a single-region case
269  virtual const fileName& dbDir() const;
270 
271  //- Return the local mesh directory (dbDir()/meshSubDir)
272  fileName meshDir() const;
273 
274  //- Return the current instance directory for points
275  // Used in the consruction of gemometric mesh data dependent
276  // on points
277  const fileName& pointsInstance() const;
278 
279  //- Return the current instance directory for faces
280  const fileName& facesInstance() const;
281 
282  //- Set the instance for mesh files
283  void setInstance(const fileName&);
284 
285 
286  // Access
287 
288  //- Return raw points
289  virtual const pointField& points() const;
290 
291  //- Return raw faces
292  virtual const faceList& faces() const;
293 
294  //- Return face owner
295  virtual const labelList& faceOwner() const;
296 
297  //- Return face neighbour
298  virtual const labelList& faceNeighbour() const;
299 
300  //- Return old points for mesh motion
301  virtual const pointField& oldPoints() const;
302 
303  //- Return boundary mesh
305  {
306  return boundary_;
307  }
308 
309  //- Return mesh bounding box
310  const boundBox& bounds() const
311  {
312  return bounds_;
313  }
314 
315  //- Return the vector of geometric directions in mesh.
316  // Defined according to the presence of empty and wedge patches.
317  // 1 indicates unconstrained direction and -1 a constrained
318  // direction.
319  const Vector<label>& geometricD() const;
320 
321  //- Return the number of valid geometric dimensions in the mesh
322  label nGeometricD() const;
323 
324  //- Return the vector of solved-for directions in mesh.
325  // Differs from geometricD in that it includes for wedge cases
326  // the circumferential direction in case of swirl.
327  // 1 indicates valid direction and -1 an invalid direction.
328  const Vector<label>& solutionD() const;
329 
330  //- Return the number of valid solved-for dimensions in the mesh
331  label nSolutionD() const;
332 
333  //- Return point zone mesh
334  const pointZoneMesh& pointZones() const
335  {
336  return pointZones_;
337  }
338 
339  //- Return face zone mesh
340  const faceZoneMesh& faceZones() const
341  {
342  return faceZones_;
343  }
344 
345  //- Return cell zone mesh
346  const cellZoneMesh& cellZones() const
347  {
348  return cellZones_;
349  }
350 
351  //- Return parallel info
352  const globalMeshData& globalData() const;
353 
354  //- Return the object registry
355  const objectRegistry& thisDb() const
356  {
357  return *this;
358  }
359 
360  // Mesh motion
361 
362  //- Is mesh moving
363  bool moving() const
364  {
365  return moving_;
366  }
367 
368  //- Set the mesh to be moving
369  bool moving(const bool m)
370  {
371  bool m0 = moving_;
372  moving_ = m;
373  changing_ = changing_ || moving_;
374  return m0;
375  }
376 
377  //- Is mesh changing (topology changing and/or moving)
378  bool changing() const
379  {
380  return changing_;
381  }
382 
383  //- Set the mesh to be changing
384  bool changing(const bool c)
385  {
386  bool c0 = changing_;
387  changing_ = c;
388  return c0;
389  }
390 
391  //- Move points, returns volumes swept by faces in motion
392  virtual tmp<scalarField> movePoints(const pointField&);
393 
394  //- Reset motion
395  void resetMotion() const;
396 
397 
398  // Topological change
399 
400  //- Return non-const access to the pointZones
402  {
403  return pointZones_;
404  }
405 
406  //- Return non-const access to the faceZones
408  {
409  return faceZones_;
410  }
411 
412  //- Return non-const access to the cellZones
414  {
415  return cellZones_;
416  }
417 
418  //- Add boundary patches
419  void addPatches
420  (
421  const List<polyPatch*>&,
422  const bool validBoundary = true
423  );
424 
425  //- Add mesh zones
426  void addZones
427  (
428  const List<pointZone*>& pz,
429  const List<faceZone*>& fz,
430  const List<cellZone*>& cz
431  );
432 
433  //- Update the mesh based on the mesh files saved in
434  // time directories
435  virtual readUpdateState readUpdate();
436 
437  //- Update the mesh corresponding to given map
438  virtual void updateMesh(const mapPolyMesh& mpm);
439 
440  //- Remove boundary patches
441  void removeBoundary();
442 
443  //- Reset mesh primitive data. Assumes all patch info correct
444  // (so does e.g. parallel communication). If not use
445  // validBoundary=false
446  // (still assumes patchStarts[0] = nInternalFaces and last
447  // patch ends at nActiveFaces) and change patches with addPatches.
448  void resetPrimitives
449  (
450  const Xfer<pointField>& points,
451  const Xfer<faceList>& faces,
452  const Xfer<labelList>& owner,
453  const Xfer<labelList>& neighbour,
454  const labelList& patchSizes,
455  const labelList& patchStarts,
456  const bool validBoundary = true
457  );
458 
459 
460  // Storage management
461 
462  //- Clear geometry
463  void clearGeom();
464 
465  //- Clear addressing
466  void clearAddressing();
467 
468  //- Clear all geometry and addressing unnecessary for CFD
469  void clearOut();
470 
471  //- Clear primitive data (points, faces and cells)
472  void clearPrimitives();
473 
474  //- Remove all files from mesh instance
475  void removeFiles(const fileName& instanceDir) const;
476 
477  //- Remove all files from mesh instance()
478  void removeFiles() const;
479 };
480 
481 
482 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
483 
484 } // End namespace Foam
485 
486 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
487 
488 #endif
489 
490 // ************************ vim: set sw=4 sts=4 et: ************************ //