1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Mesh consisting of general polyhedral cells.
35 polyMeshFromShapeMesh.C
39 \*---------------------------------------------------------------------------*/
44 #include "objectRegistry.H"
45 #include "primitiveMesh.H"
46 #include "pointField.H"
49 #include "cellShapeList.H"
50 #include "pointIOField.H"
51 #include "faceIOList.H"
52 #include "labelIOList.H"
53 #include "polyBoundaryMesh.H"
55 #include "pointZoneMesh.H"
56 #include "faceZoneMesh.H"
57 #include "cellZoneMesh.H"
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 /*---------------------------------------------------------------------------*\
68 Class polyMesh Declaration
69 \*---------------------------------------------------------------------------*/
73 public objectRegistry,
81 //- Enumeration defining the state of the mesh after a read update.
82 // Used for post-processing applications, where the mesh
83 // needs to update based on the files written in time
98 // Primitive mesh data
101 pointIOField points_;
110 labelIOList neighbour_;
112 //- Have the primitives been cleared
113 bool clearedPrimitives_;
117 mutable polyBoundaryMesh boundary_;
119 //- Mesh bounding-box. created from points on construction
120 // and updated when the mesh moves
123 //- vector of valid directions in mesh
124 // defined according to the presence of empty patches
125 mutable Vector<label> directions_;
128 // Zoning information
131 pointZoneMesh pointZones_;
134 faceZoneMesh faceZones_;
137 cellZoneMesh cellZones_;
141 mutable globalMeshData* globalMeshDataPtr_;
144 // Mesh motion related data
146 //- Is the mesh moving
149 //- Is the mesh changing (moving and/or topology changing)
152 //- Current time index for mesh motion
153 mutable label curMotionTimeIndex_;
155 //- Old points (for the last mesh motion)
156 mutable pointField* oldPointsPtr_;
159 // Private member functions
161 //- Disallow construct as copy
162 polyMesh(const polyMesh&);
164 //- Disallow default bitwise assignment
165 void operator=(const polyMesh&);
167 //- Initialise the polyMesh from the primitive data
170 //- Initialise the polyMesh from the given set of cells
171 void initMesh(cellList& c);
173 //- Calculate the valid directions in the mesh from the boundaries
174 void calcDirections() const;
176 //- Calculate the cell shapes from the primitive
177 // polyhedral information
178 void calcCellShapes() const;
181 // Helper functions for constructor from cell shapes
183 labelListList cellShapePointCells(const cellShapeList&) const;
185 labelList facePatchFaceCells
187 const faceList& patchFaces,
188 const labelListList& pointCells,
189 const faceListList& cellsFaceShapes,
198 typedef polyMesh Mesh;
199 typedef polyBoundaryMesh BoundaryMesh;
202 //- Runtime type information
203 TypeName("polyMesh");
205 //- Return the default region name
206 static word defaultRegion;
208 //- Return the mesh sub-directory name (usually "polyMesh")
209 static word meshSubDir;
214 //- Construct from IOobject
215 explicit polyMesh(const IOobject& io);
217 //- Construct from components without boundary.
218 // Boundary is added using addPatches() member function
222 const pointField& points,
223 const faceList& faces,
224 const labelList& owner,
225 const labelList& neighbour,
226 const bool syncPar = true
229 //- Construct from components with cells rather than owner
230 // and neighbourwithout boundary.
231 // Boundary is added using addPatches() member function
235 const pointField& points,
236 const faceList& faces,
237 const cellList& cells,
238 const bool syncPar = true
241 //- Construct from cell shapes
245 const pointField& points,
246 const cellShapeList& shapes,
247 const faceListList& boundaryFaces,
248 const wordList& boundaryPatchNames,
249 const wordList& boundaryPatchTypes,
250 const word& defaultBoundaryPatchName,
251 const word& defaultBoundaryPatchType,
252 const wordList& boundaryPatchPhysicalTypes,
253 const bool syncPar = true
266 //- Over-ride the objectRegistry dbDir
267 // if this is single-region case
268 virtual const fileName& dbDir() const;
270 //- Return the local mesh directory (dbDir()/meshSubDir)
271 fileName meshDir() const;
273 //- Return the current instance directory for points
274 // Used in the consruction of gemometric mesh data dependent
276 const fileName& pointsInstance() const;
278 //- Return the current instance directory for faces
279 const fileName& facesInstance() const;
281 //- Set the instance for mesh files
282 void setInstance(const fileName&);
287 //- Return raw points
288 virtual const pointField& points() const;
291 virtual const faceList& faces() const;
293 //- Return face owner
294 virtual const labelList& faceOwner() const;
296 //- Return face neighbour
297 virtual const labelList& faceNeighbour() const;
299 //- Return old points for mesh motion
300 virtual const pointField& oldPoints() const;
302 //- Return boundary mesh
303 const polyBoundaryMesh& boundaryMesh() const
308 //- Return mesh bounding box
309 const boundBox& bounds() const
314 //- Return the vector of valid directions in mesh
315 // defined according to the presence of empty patches.
316 // 1 indicates valid direction and -1 an invalid direction.
317 const Vector<label>& directions() const;
319 //- Return the number of valid geoemtric dimensions in the mesh
320 label nGeometricD() const;
322 //- Return the number of valid solution dimensions in the mesh
323 // For wedge cases this includes the circumferential direction
325 label nSolutionD() const;
327 //- Return point zone mesh
328 const pointZoneMesh& pointZones() const
333 //- Return face zone mesh
334 const faceZoneMesh& faceZones() const
339 //- Return cell zone mesh
340 const cellZoneMesh& cellZones() const
345 //- Return parallel info
346 const globalMeshData& globalData() const;
357 //- Set the mesh to be moving
358 bool moving(const bool m)
362 changing_ = changing_ || moving_;
366 //- Is mesh changing (topology changing and/or moving)
367 bool changing() const
372 //- Set the mesh to be changing
373 bool changing(const bool c)
380 //- Move points, returns volumes swept by faces in motion
381 virtual tmp<scalarField> movePoints(const pointField&);
384 void resetMotion() const;
387 // Topological change
389 //- Return non-const access to the pointZones
390 pointZoneMesh& pointZones()
395 //- Return non-const access to the faceZones
396 faceZoneMesh& faceZones()
401 //- Return non-const access to the cellZones
402 cellZoneMesh& cellZones()
407 //- Add boundary patches
410 const List<polyPatch*>&,
411 const bool validBoundary = true
417 const List<pointZone*>& pz,
418 const List<faceZone*>& fz,
419 const List<cellZone*>& cz
422 //- Update the mesh based on the mesh files saved in
424 virtual readUpdateState readUpdate();
426 //- Update the mesh corresponding to given map
427 virtual void updateMesh(const mapPolyMesh& mpm);
429 //- Remove boundary patches
430 void removeBoundary();
432 //- Reset mesh primitive data. Assumes all patch info correct
433 // (so does e.g. parallel communication). If not use
434 // validBoundary=false
435 // (still assumes patchStarts[0] = nInternalFaces and last
436 // patch ends at nActiveFaces) and change patches with addPatches.
439 const label nUsedFaces,
440 const pointField& points,
441 const faceList& faces,
442 const labelList& owner,
443 const labelList& neighbour,
444 const labelList& patchSizes,
445 const labelList& patchStarts,
446 const bool validBoundary = true
450 // Storage management
456 void clearAddressing();
458 //- Clear all geometry and addressing unnecessary for CFD
461 //- Clear primitive data (points, faces and cells)
462 void clearPrimitives();
464 //- Remove all files from mesh instance
465 void removeFiles(const fileName& instanceDir) const;
467 //- Remove all files from mesh instance()
468 void removeFiles() const;
472 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
474 } // End namespace Foam
476 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
480 // ************************************************************************* //