FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

polyTopoChange.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::polyTopoChange
00026 
00027 Description
00028     Direct mesh changes based on v1.3 polyTopoChange syntax.
00029 
00030     Instead of recording changes and executing them all in one go (as did
00031     v1.3 polyTopoChange) this class actually holds the current
00032     points/faces/cells and does the change immediately.
00033     It can be asked to compress out all unused points/faces/cells and
00034     renumber everything to be consistent.
00035 
00036     Note:
00037     - polyTopoChange can be copied.
00038     - adding a face using non-existing cells causes all intermediate cells
00039     to be added. So always first add cells/points and then faces.
00040     (or set strict checking)
00041     - strict checking:
00042         - any added/modified face can only use already existing vertices
00043         - any added face can only use already existing cells
00044         - no item can be removed more than once.
00045     - removed cell: cell set to 0 faces.
00046     - removed face: face set to 0 vertices.
00047     - removed point: coordinate set to greatPoint (GREAT,GREAT,GREAT).
00048     Note that this might give problems if this value is used already.
00049     To see if point is equal to above value we don't use == (which might give
00050     problems with roundoff error) but instead compare the individual component
00051     with >.
00052     - coupled patches: the reorderCoupledFaces routine (borrowed from
00053     the couplePatches utility) reorders coupled patch faces and
00054     uses the cyclicPolyPatch,processorPolyPatch functionality.
00055 
00056 SourceFiles
00057     polyTopoChange.C
00058     polyTopoChangeI.H
00059     polyTopoChangeTemplates.C
00060 
00061 \*---------------------------------------------------------------------------*/
00062 
00063 #ifndef polyTopoChange_H
00064 #define polyTopoChange_H
00065 
00066 #include <OpenFOAM/autoPtr.H>
00067 #include <OpenFOAM/DynamicList.H>
00068 #include <OpenFOAM/labelList.H>
00069 #include <OpenFOAM/IOobject.H>
00070 #include <OpenFOAM/typeInfo.H>
00071 #include <OpenFOAM/pointField.H>
00072 #include <OpenFOAM/PtrList.H>
00073 #include <OpenFOAM/cellList.H>
00074 #include <OpenFOAM/Map.H>
00075 #include <OpenFOAM/HashSet.H>
00076 #include <OpenFOAM/mapPolyMesh.H>
00077 #include <OpenFOAM/CompactListList.H>
00078 #include <OpenFOAM/PackedBoolList.H>
00079 
00080 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00081 
00082 namespace Foam
00083 {
00084 
00085 // Forward declaration of classes
00086 class face;
00087 class primitiveMesh;
00088 class polyMesh;
00089 class fvMesh;
00090 class Time;
00091 class fileName;
00092 class polyBoundaryMesh;
00093 class polyPatch;
00094 class dictionary;
00095 class topoAction;
00096 class objectMap;
00097 
00098 /*---------------------------------------------------------------------------*\
00099                            Class polyTopoChange Declaration
00100 \*---------------------------------------------------------------------------*/
00101 
00102 class polyTopoChange
00103 {
00104     // Static data members
00105 
00106         //- Value of deleted point
00107         static const point greatPoint;
00108 
00109 
00110     // Private data
00111 
00112         //- Whether to allow referencing illegal points/cells/faces
00113         //  when adding/removing data.
00114         bool strict_;
00115 
00116 
00117         // Patches
00118 
00119             //- Number of patches
00120             label nPatches_;
00121 
00122 
00123         // Points
00124 
00125             //- Current point set
00126             DynamicList<point> points_;
00127 
00128             //- Original point label (or masterpoint for added points)
00129             DynamicList<label> pointMap_;
00130 
00131             //- For all original and added points contains new point label.
00132             //  (used to map return value of addPoint to new mesh point)
00133             DynamicList<label> reversePointMap_;
00134 
00135             //- Zone of point
00136             DynamicList<label> pointZone_;
00137 
00138             //- Retired points
00139             labelHashSet retiredPoints_;
00140 
00141 
00142         // Faces
00143 
00144             //- Current faceList
00145             DynamicList<face> faces_;
00146 
00147             //- Patch for every external face (-1 for internal faces)
00148             DynamicList<label> region_;
00149 
00150             //- Owner for all faces
00151             DynamicList<label> faceOwner_;
00152 
00153             //- Neighbour for internal faces (-1 for external faces)
00154             DynamicList<label> faceNeighbour_;
00155 
00156             //- Original face label. Or master face for added-from-faces;
00157             //  -1 for faces added-from-edge or added-from-point)
00158             DynamicList<label> faceMap_;
00159 
00160             //- For all original and added faces contains new face label
00161             //  (used to map return value of addFace to new mesh face)
00162             DynamicList<label> reverseFaceMap_;
00163 
00164             //- Faces added from point (corresponding faceMap_ will
00165             //  be -1)
00166             Map<label> faceFromPoint_;
00167 
00168             //- Faces added from edge (corresponding faceMap_ will
00169             //  be -1)
00170             Map<label> faceFromEdge_;
00171 
00172             //- In mapping whether to reverse the flux.
00173             PackedBoolList flipFaceFlux_;
00174 
00175             //- Zone of face
00176             DynamicList<label> faceZone_;
00177 
00178             //- Orientation of face in zone
00179             PackedBoolList faceZoneFlip_;
00180 
00181             //- Active faces
00182             label nActiveFaces_;
00183 
00184 
00185         // Cells
00186 
00187             //- Original cell label or master cell for added-from-cell;
00188             //  -1 for cells added from face or edge.
00189             DynamicList<label> cellMap_;
00190 
00191             //- For all original and added cells contains new cell label
00192             //  (used to map return value of addCell to new mesh cell)
00193             DynamicList<label> reverseCellMap_;
00194 
00195             //- Cells added from point
00196             Map<label> cellFromPoint_;
00197 
00198             //- Cells added from edge
00199             Map<label> cellFromEdge_;
00200 
00201             //- Cells added from face
00202             Map<label> cellFromFace_;
00203 
00204             //- Zone of cell
00205             DynamicList<label> cellZone_;
00206 
00207 
00208     // Private Member Functions
00209 
00210         //- Reorder contents of container according to map
00211         template<class T>
00212         static void reorder(const labelList& map, DynamicList<T>&);
00213         template<class T>
00214         static void reorder(const labelList& map, List<DynamicList<T> >&);
00215         template<class T>
00216         static void renumberKey(const labelList& map, Map<T>&);
00217 
00218         //- Renumber elements of container according to map
00219         static void renumber(const labelList&, labelHashSet&);
00220         //- Special handling of reverse maps which have <-1 in them
00221         static void renumberReverseMap(const labelList&, DynamicList<label>&);
00222 
00223         //- Renumber & compact elements of list according to map
00224         static void renumberCompact(const labelList&, labelList&);
00225 
00226         //- Get all set elements as a labelHashSet
00227         static labelHashSet getSetIndices(const PackedBoolList&);
00228 
00229         //- Count number of added and removed quantities from maps.
00230         static void countMap
00231         (
00232             const labelList& map,
00233             const labelList& reverseMap,
00234             label& nAdd,
00235             label& nInflate,
00236             label& nMerge,
00237             label& nRemove
00238         );
00239 
00240         //- Print some stats about mesh
00241         static void writeMeshStats(const polyMesh& mesh, Ostream&);
00242 
00243         //- Calculate object maps. Requires reverseMap to have destination
00244         //  to be marked with <-1.
00245         static void getMergeSets
00246         (
00247             const labelList& reverseCellMap,
00248             const labelList& cellMap,
00249             List<objectMap>& cellsFromCells
00250         );
00251 
00252         //- Check inputs to modFace or addFace
00253         void checkFace
00254         (
00255             const face&,
00256             const label faceI,
00257             const label own,
00258             const label nei,
00259             const label patchI,
00260             const label zoneI
00261         ) const;
00262 
00263         //- Construct cells (in packed storage)
00264         void makeCells
00265         (
00266             const label nActiveFaces,
00267             labelList& cellFaces,
00268             labelList& cellFaceOffsets
00269         ) const;
00270 
00271         //- Construct cellCells (in packed storage)
00272         void makeCellCells
00273         (
00274             const label nActiveFaces,
00275             CompactListList<label>& cellCells
00276         ) const;
00277 
00278         //- Cell ordering (bandCompression). Returns number of remaining cells.
00279         label getCellOrder(const CompactListList<label>&, labelList&) const;
00280 
00281         //- Do upper-triangular ordering and patch ordering.
00282         void getFaceOrder
00283         (
00284             const label nActiveFaces,
00285             const labelList& cellFaces,
00286             const labelList& cellFaceOffsets,
00287 
00288             labelList& oldToNew,
00289             labelList& patchSizes,
00290             labelList& patchStarts
00291         ) const;
00292 
00293         //- Compact and reorder faces according to map
00294         void reorderCompactFaces
00295         (
00296             const label newSize,
00297             const labelList& oldToNew
00298         );
00299 
00300         //- Remove all unused/removed points/faces/cells and update
00301         //  face ordering (always), cell ordering (bandcompression,
00302         //  orderCells=true),
00303         //  point ordering (sorted into internal and boundary points,
00304         //  orderPoints=true)
00305         void compact
00306         (
00307             const bool orderCells,
00308             const bool orderPoints,
00309             label& nInternalPoints,
00310             labelList& patchSizes,
00311             labelList& patchStarts
00312         );
00313 
00314         //- Select either internal or external faces out of faceLabels
00315         static labelList selectFaces
00316         (
00317             const primitiveMesh&,
00318             const labelList& faceLabels,
00319             const bool internalFacesOnly
00320         );
00321 
00322         //- Calculate mapping for patchpoints only
00323         void calcPatchPointMap
00324         (
00325             const List<Map<label> >&,
00326             const polyBoundaryMesh&,
00327             labelListList&
00328         ) const;
00329 
00330         void calcFaceInflationMaps
00331         (
00332             const polyMesh&,
00333             List<objectMap>&,
00334             List<objectMap>&,
00335             List<objectMap>&
00336         ) const;
00337 
00338         void calcCellInflationMaps
00339         (
00340             const polyMesh&,
00341             List<objectMap>&,
00342             List<objectMap>&,
00343             List<objectMap>&,
00344             List<objectMap>&
00345         ) const;
00346 
00347         void resetZones
00348         (
00349             const polyMesh&,        // mesh to get existing info from
00350             polyMesh&,              // mesh to change zones on
00351             labelListList&,
00352             labelListList&,
00353             labelListList&
00354         ) const;
00355 
00356         void calcFaceZonePointMap
00357         (
00358             const polyMesh&,
00359             const List<Map<label> >&,
00360             labelListList&
00361         ) const;
00362 
00363 
00364         // Coupling
00365 
00366             //- Rotate face by number of positions
00367             static face rotateFace(const face& f, const label nPos);
00368 
00369             //- Do all coupled patch face reordering
00370             void reorderCoupledFaces
00371             (
00372                 const bool syncParallel,
00373                 const polyBoundaryMesh&,
00374                 const labelList& patchStarts,
00375                 const labelList& patchSizes,
00376                 const pointField& points
00377             );
00378 
00379         void compactAndReorder
00380         (
00381             const polyMesh&,
00382             const bool syncParallel,
00383             const bool orderCells,
00384             const bool orderPoints,
00385             label& nInternalPoints,
00386             pointField& newPoints,
00387             labelList& patchSizes,
00388             labelList& patchStarts,
00389             List<objectMap>& pointsFromPoints,
00390             List<objectMap>& facesFromPoints,
00391             List<objectMap>& facesFromEdges,
00392             List<objectMap>& facesFromFaces,
00393             List<objectMap>& cellsFromPoints,
00394             List<objectMap>& cellsFromEdges,
00395             List<objectMap>& cellsFromFaces,
00396             List<objectMap>& cellsFromCells,
00397             List<Map<label> >& oldPatchMeshPointMaps,
00398             labelList& oldPatchNMeshPoints,
00399             labelList& oldPatchStarts,
00400             List<Map<label> >& oldFaceZoneMeshPointMaps
00401         );
00402 
00403 public:
00404 
00405     //- Runtime type information
00406     ClassName("polyTopoChange");
00407 
00408 
00409 
00410     // Constructors
00411 
00412         //- Construct without mesh. Either specify nPatches or use
00413         //  setNumPatches before trying to make a mesh (makeMesh, changeMesh)
00414         polyTopoChange(const label nPatches, const bool strict = true);
00415 
00416         //- Construct from mesh. Adds all points/face/cells from mesh.
00417         polyTopoChange(const polyMesh& mesh, const bool strict = true);
00418 
00419 
00420     // Member Functions
00421 
00422         // Access
00423 
00424             //- Points. Shrunk after constructing mesh (or calling of compact())
00425             const DynamicList<point>& points() const
00426             {
00427                 return points_;
00428             }
00429 
00430             const DynamicList<face>& faces() const
00431             {
00432                 return faces_;
00433             }
00434 
00435             const DynamicList<label>& region() const
00436             {
00437                 return region_;
00438             }
00439 
00440             const DynamicList<label>& faceOwner() const
00441             {
00442                 return faceOwner_;
00443             }
00444 
00445             const DynamicList<label>& faceNeighbour() const
00446             {
00447                 return faceNeighbour_;
00448             }
00449 
00450             //- Is point removed?
00451             inline bool pointRemoved(const label pointI) const;
00452             //- Is face removed?
00453             inline bool faceRemoved(const label faceI) const;
00454             //- Is cell removed?
00455             inline bool cellRemoved(const label cellI) const;
00456 
00457 
00458         // Edit
00459 
00460             //- Clear all storage
00461             void clear();
00462 
00463             //- Add all points/faces/cells of mesh. Additional offset for patch
00464             //  or zone ids.
00465             void addMesh
00466             (
00467                 const polyMesh&,
00468                 const labelList& patchMap,
00469                 const labelList& pointZoneMap,
00470                 const labelList& faceZoneMap,
00471                 const labelList& cellZoneMap
00472             );
00473 
00474             //- Explicitly pre-size the dynamic storage for expected mesh
00475             //  size for if construct-without-mesh
00476             void setCapacity
00477             (
00478                 const label nPoints,
00479                 const label nFaces,
00480                 const label nCells
00481             );
00482 
00483             //- Move all points. Incompatible with other topology changes.
00484             void movePoints(const pointField& newPoints);
00485 
00486             //- For compatibility with polyTopoChange: set topological action.
00487             label setAction(const topoAction& action);
00488 
00489             //- Add point. Return new point label.
00490             //  Notes:
00491             //  - masterPointID can be < 0 (appended points)
00492             //  - inCell = false: add retired point (to end of point list)
00493             label addPoint
00494             (
00495                 const point&,
00496                 const label masterPointID,
00497                 const label zoneID,
00498                 const bool inCell
00499             );
00500 
00501             //- Modify coordinate.
00502             //  Notes:
00503             //  - inCell = false: add retired point (to end of point list)
00504             void modifyPoint
00505             (
00506                 const label,
00507                 const point&,
00508                 const label newZoneID,
00509                 const bool inCell
00510             );
00511 
00512             //- Remove/merge point.
00513             void removePoint(const label, const label);
00514 
00515             //- Add face to cells. Return new face label.
00516             //  own,nei<0, zoneID>=0 : add inactive face (to end of face list)
00517             label addFace
00518             (
00519                 const face& f,
00520                 const label own,
00521                 const label nei,
00522                 const label masterPointID,
00523                 const label masterEdgeID,
00524                 const label masterFaceID,
00525                 const bool flipFaceFlux,
00526                 const label patchID,
00527                 const label zoneID,
00528                 const bool zoneFlip
00529             );
00530 
00531             //- Modify vertices or cell of face.
00532             void modifyFace
00533             (
00534                 const face& f,
00535                 const label faceI,
00536                 const label own,
00537                 const label nei,
00538                 const bool flipFaceFlux,
00539                 const label patchID,
00540                 const label zoneID,
00541                 const bool zoneFlip
00542             );
00543 
00544             //- Remove/merge face.
00545             void removeFace(const label, const label);
00546 
00547             //- Add cell. Return new cell label.
00548             label addCell
00549             (
00550                 const label masterPointID,
00551                 const label masterEdgeID,
00552                 const label masterFaceID,
00553                 const label masterCellID,
00554                 const label zoneID
00555             );
00556 
00557             //- Modify zone of cell
00558             void modifyCell(const label, const label zoneID);
00559 
00560             //- Remove/merge cell.
00561             void removeCell(const label, const label);
00562 
00563             //- Explicitly set the number of patches if construct-without-mesh
00564             //  used.
00565             inline void setNumPatches(const label nPatches);
00566 
00567 
00568         // Other
00569 
00570             //- Inplace changes mesh without change of patches.
00571             //  Adapts patch start/end and by default does parallel matching.
00572             //  Clears all data. Returns map.
00573             //  inflate = true : keep old mesh points. Put new points into the
00574             //  returned map (preMotionPoints) so we can use inflation. Any
00575             //  points out of nothing (appended points) are vector::zero.
00576             //  inflate = false: set mesh points directly. Empty preMotionPoints
00577             //  in the map.
00578             //  orderCells :  whether to order the cells (see bandCompression.H)
00579             //  orderPoints : whether to order the points into internal first
00580             //  followed by boundary points. This is not fully consistent
00581             //  with upper-triangular ordering of points and edges so
00582             //  is only done when explicitly asked for.
00583             autoPtr<mapPolyMesh> changeMesh
00584             (
00585                 polyMesh& mesh,
00586                 const bool inflate,
00587                 const bool syncParallel = true,
00588                 const bool orderCells = false,
00589                 const bool orderPoints = false
00590             );
00591 
00592             //- Create new mesh with old mesh patches
00593             autoPtr<mapPolyMesh> makeMesh
00594             (
00595                 autoPtr<fvMesh>& newMesh,
00596                 const IOobject& io,
00597                 const fvMesh& mesh,
00598                 const bool syncParallel = true,
00599                 const bool orderCells = false,
00600                 const bool orderPoints = false
00601             );
00602 
00603 };
00604 
00605 
00606 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00607 
00608 } // End namespace Foam
00609 
00610 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00611 
00612 #include "polyTopoChangeI.H"
00613 
00614 #ifdef NoRepository
00615 #   include "polyTopoChangeTemplates.C"
00616 #endif
00617 
00618 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00619 
00620 #endif
00621 
00622 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines