1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Mesh consisting of general polyhedral cells.
34 polyMeshFromShapeMesh.C
38 \*---------------------------------------------------------------------------*/
43 #include "objectRegistry.H"
44 #include "primitiveMesh.H"
45 #include "pointField.H"
48 #include "cellShapeList.H"
49 #include "pointIOField.H"
50 #include "faceIOList.H"
51 #include "labelIOList.H"
52 #include "polyBoundaryMesh.H"
54 #include "pointZoneMesh.H"
55 #include "faceZoneMesh.H"
56 #include "cellZoneMesh.H"
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 // Forward declaration of classes
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 allPoints_;
104 pointField::subField points_;
107 faceIOList allFaces_;
110 faceList::subList faces_;
116 labelIOList neighbour_;
118 //- Have the primitives been cleared
119 bool clearedPrimitives_;
123 mutable polyBoundaryMesh boundary_;
125 //- Mesh bounding-box.
126 // Created from points on construction, updated with mesh motion
129 //- Vector of non-constrained directions in mesh
130 // Defined according to the presence of empty and wedge patches
131 mutable Vector<label> geometricD_;
133 //- Vector of valid directions in mesh
134 // Defined according to the presence of empty patches
135 mutable Vector<label> solutionD_;
138 // Zoning information
141 pointZoneMesh pointZones_;
144 faceZoneMesh faceZones_;
147 cellZoneMesh cellZones_;
151 mutable globalMeshData* globalMeshDataPtr_;
154 // Mesh motion related data
156 //- Is the mesh moving
159 //- Is the mesh changing (moving and/or topology changing)
162 //- Current time index for mesh motion
163 mutable label curMotionTimeIndex_;
165 //- Old points (for the last mesh motion)
166 mutable pointField* oldAllPointsPtr_;
169 mutable pointField::subField* oldPointsPtr_;
172 // Private member functions
174 //- Disallow construct as copy
175 polyMesh(const polyMesh&);
177 //- Disallow default bitwise assignment
178 void operator=(const polyMesh&);
180 //- Initialise the polyMesh from the primitive data
183 //- Initialise the polyMesh from the given set of cells
184 void initMesh(cellList& c);
186 //- Calculate the valid directions in the mesh from the boundaries
187 void calcDirections() const;
189 //- Calculate the cell shapes from the primitive
190 // polyhedral information
191 void calcCellShapes() const;
194 // Helper functions for constructor from cell shapes
196 labelListList cellShapePointCells(const cellShapeList&) const;
198 labelList facePatchFaceCells
200 const faceList& patchFaces,
201 const labelListList& pointCells,
202 const faceListList& cellsFaceShapes,
208 const cellShapeList& cellsAsShapes,
209 const faceListList& boundaryFaces,
210 const wordList& boundaryPatchNames,
211 labelList& patchSizes,
212 labelList& patchStarts,
213 label& defaultPatchStart,
223 typedef polyMesh Mesh;
224 typedef polyBoundaryMesh BoundaryMesh;
227 //- Runtime type information
228 TypeName("polyMesh");
230 //- Return the default region name
231 static word defaultRegion;
233 //- Return the mesh sub-directory name (usually "polyMesh")
234 static word meshSubDir;
239 //- Construct from IOobject
240 explicit polyMesh(const IOobject& io);
242 //- Construct from components without boundary.
243 // Boundary is added using addPatches() member function
247 const Xfer<pointField>& points,
248 const Xfer<faceList>& faces,
249 const Xfer<labelList>& owner,
250 const Xfer<labelList>& neighbour,
251 const bool syncPar = true
254 //- Construct without boundary with cells rather than owner/neighbour.
255 // Boundary is added using addPatches() member function
259 const Xfer<pointField>& points,
260 const Xfer<faceList>& faces,
261 const Xfer<cellList>& cells,
262 const bool syncPar = true
265 //- Construct from cell shapes
269 const Xfer<pointField>& points,
270 const cellShapeList& shapes,
271 const faceListList& boundaryFaces,
272 const wordList& boundaryPatchNames,
273 const wordList& boundaryPatchTypes,
274 const word& defaultBoundaryPatchName,
275 const word& defaultBoundaryPatchType,
276 const wordList& boundaryPatchPhysicalTypes,
277 const bool syncPar = true
280 //- Construct from cell shapes with patch information in dictionary
285 const Xfer<pointField>& points,
286 const cellShapeList& shapes,
287 const faceListList& boundaryFaces,
288 const wordList& boundaryPatchNames,
289 const PtrList<dictionary>& boundaryDicts,
290 const word& defaultBoundaryPatchName,
291 const word& defaultBoundaryPatchType,
292 const bool syncPar = true
305 //- Override the objectRegistry dbDir for a single-region case
306 virtual const fileName& dbDir() const;
308 //- Return the local mesh directory (dbDir()/meshSubDir)
309 fileName meshDir() const;
311 //- Return the current instance directory for points
312 // Used in the consruction of gemometric mesh data dependent
314 const fileName& pointsInstance() const;
316 //- Return the current instance directory for faces
317 const fileName& facesInstance() const;
319 //- Set the instance for mesh files
320 void setInstance(const fileName&);
323 //- Set motion write option
324 void setMotionWriteOpt(IOobject::writeOption);
326 //- Set topological write option
327 void setTopoWriteOpt(IOobject::writeOption);
332 //- Return all points, including inactive ones
333 const pointField& allPoints() const;
335 //- Return all faces, including inactive ones
336 const faceList& allFaces() const;
338 //- Return old mesh motion points, including inactive ones
339 const pointField& oldAllPoints() const;
344 //- Return raw points
345 virtual const pointField& points() const;
348 virtual const faceList& faces() const;
350 //- Return face owner
351 virtual const labelList& faceOwner() const;
353 //- Return face neighbour
354 virtual const labelList& faceNeighbour() const;
356 //- Return old points for mesh motion
357 virtual const pointField& oldPoints() const;
359 //- Return boundary mesh
360 const polyBoundaryMesh& boundaryMesh() const
365 //- Return mesh bounding box
366 const boundBox& bounds() const
371 //- Return the vector of geometric directions in mesh.
372 // Defined according to the presence of empty and wedge patches.
373 // 1 indicates unconstrained direction and -1 a constrained
375 const Vector<label>& geometricD() const;
377 //- Return the number of valid geometric dimensions in the mesh
378 label nGeometricD() const;
380 //- Return the vector of solved-for directions in mesh.
381 // Differs from geometricD in that it includes for wedge cases
382 // the circumferential direction in case of swirl.
383 // 1 indicates valid direction and -1 an invalid direction.
384 const Vector<label>& solutionD() const;
386 //- Return the number of valid solved-for dimensions in the mesh
387 label nSolutionD() const;
389 //- Return point zone mesh
390 const pointZoneMesh& pointZones() const
395 //- Return face zone mesh
396 const faceZoneMesh& faceZones() const
401 //- Return cell zone mesh
402 const cellZoneMesh& cellZones() const
407 //- Return parallel info
408 const globalMeshData& globalData() const;
410 //- Return the object registry
411 const objectRegistry& thisDb() const
425 //- Return current motion time index
426 label curMotionTimeIndex() const
431 //- Set the mesh to be moving
432 bool moving(const bool m)
436 changing_ = changing_ || moving_;
440 //- Is mesh changing (topology changing and/or moving)
441 bool changing() const
446 //- Set the mesh to be changing
447 bool changing(const bool c)
454 //- Move points, returns volumes swept by faces in motion
455 virtual tmp<scalarField> movePoints(const pointField&);
458 void resetMotion() const;
460 //- Set old points without executing motion
461 void setOldPoints(const pointField& setPoints);
464 // Topological change
466 //- Return non-const access to the pointZones
467 pointZoneMesh& pointZones()
472 //- Return non-const access to the faceZones
473 faceZoneMesh& faceZones()
478 //- Return non-const access to the cellZones
479 cellZoneMesh& cellZones()
484 //- Add boundary patches
487 const List<polyPatch*>&,
488 const bool validBoundary = true
494 const List<pointZone*>& pz,
495 const List<faceZone*>& fz,
496 const List<cellZone*>& cz
499 //- Update the mesh based on the mesh files saved in
501 virtual readUpdateState readUpdate();
503 //- Update the mesh corresponding to given map
504 virtual void updateMesh(const mapPolyMesh& mpm);
506 //- Sync mesh update for topo change on other processors
507 // Locally, there is no topological change
508 virtual void syncUpdateMesh();
510 //- Remove boundary patches
511 void removeBoundary();
513 //- Remove point, face and cell zones
516 //- Reset mesh primitive data. Assumes all patch info correct
517 // (so does e.g. parallel communication). If not use
518 // validBoundary=false
519 // (still assumes patchStarts[0] = nInternalFaces and last
520 // patch ends at nActiveFaces) and change patches with addPatches.
523 const Xfer<pointField>& points,
524 const Xfer<faceList>& faces,
525 const Xfer<labelList>& owner,
526 const Xfer<labelList>& neighbour,
527 const labelList& patchSizes,
528 const labelList& patchStarts,
529 const bool validBoundary = true
533 // Storage management
539 void clearAddressing();
541 //- Clear all geometry and addressing unnecessary for CFD
544 //- Clear primitive data (points, faces and cells)
545 void clearPrimitives();
547 //- Remove all files from mesh instance
548 void removeFiles(const fileName& instanceDir) const;
550 //- Remove all files from mesh instance()
551 void removeFiles() const;
556 //- Find cell enclosing this location (-1 if not in mesh)
557 label findCell(const point&) const;
561 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
563 } // End namespace Foam
565 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
569 // ************************************************************************* //