OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

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-2007 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     polyTopoChange
00027 
00028 Description
00029     Direct mesh changes based on polyTopoChange syntax.
00030 
00031     Instead of recording changes and executing them all in one go (as does
00032     polyTopoChange) this class actually holds the current points/faces/cells
00033     and does the change immediately.
00034     It can be asked to compress out all unused points/faces/cells and
00035     renumber everything to be consistent.
00036 
00037     Note:
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                 ,,                     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 "autoPtr.H"
00067 #include "DynamicList.H"
00068 #include "labelList.H"
00069 #include "IOobject.H"
00070 #include "typeInfo.H"
00071 #include "pointField.H"
00072 #include "PtrList.H"
00073 #include "cellList.H"
00074 #include "Map.H"
00075 #include "labelHashSet.H"
00076 #include "mapPolyMesh.H"
00077 
00078 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00079 
00080 namespace Foam
00081 {
00082 
00083 // Class forward declarations
00084 class face;
00085 class primitiveMesh;
00086 class polyMesh;
00087 class fvMesh;
00088 class Time;
00089 class fileName;
00090 class polyBoundaryMesh;
00091 class polyPatch;
00092 class dictionary;
00093 class topoAction;
00094 class objectMap;
00095 
00096 /*---------------------------------------------------------------------------*\
00097                            Class polyTopoChange Declaration
00098 \*---------------------------------------------------------------------------*/
00099 
00100 class polyTopoChange
00101 {
00106         //class faceLess
00107         //{
00108         //    const unallocLabelList& own_;
00109         //    const unallocLabelList& nei_;
00110         //    const unallocLabelList& region_;
00111         //
00112         //public:
00113         //
00114         //    faceLess
00115         //    (
00116         //        const unallocLabelList& own,
00117         //        const unallocLabelList& nei,
00118         //        const unallocLabelList& region
00119         //    )
00120         //    :
00121         //        own_(own),
00122         //        nei_(nei),
00123         //        region_(region)
00124         //    {}
00125         //
00126         //    bool operator()(const label a, const label b)
00127         //    {
00128         //        if (nei_[a] == -1)
00129         //        {
00130         //            if (nei_[b] == -1)
00131         //            {
00132         //                // Two boundary faces
00133         //                return region_[a] < region_[b];
00134         //            }
00135         //            else
00136         //            {
00137         //                // b is internal face.
00138         //                return false;
00139         //            }
00140         //        }
00141         //        else
00142         //        {
00143         //            if (nei_[b] == -1)
00144         //            {
00145         //                return true;
00146         //            }
00147         //            else
00148         //            {
00149         //                // two internal faces.
00150         //                if (own_[a] < own_[b])
00151         //                {
00152         //                    return true;
00153         //                }
00154         //                else if (own_[a] > own_[b])
00155         //                {
00156         //                    return false;
00157         //                }
00158         //                else
00159         //                {
00160         //                    return nei_[a] < nei_[b];
00161         //                }
00162         //            }
00163         //        }
00164         //    }
00165         //};
00166 
00167 
00168 
00169 private:
00170 
00171     // Static data members
00172 
00173         //- Value of deleted point
00174         static const point greatPoint;
00175 
00176 
00177     // Private data
00178 
00179         //- Whether to allow referencing illegal points/cells/faces
00180         //  when adding/removing data.
00181         const bool strict_;
00182 
00183 
00184         // Patches
00185 
00186             //- Number of patches
00187             label nPatches_;
00188 
00189 
00190         // Points
00191 
00192             //- Current point set
00193             DynamicList<point> points_;
00194 
00195             //- Original point label (or masterpoint for added points)
00196             DynamicList<label> pointMap_;
00197 
00198             //- For all original and added points contains new point label.
00199             //  (used to map return value of addPoint to new mesh point)
00200             DynamicList<label> reversePointMap_;
00201 
00202             //- Zone of point
00203             Map<label> pointZone_;
00204 
00205             //- Retired points
00206             labelHashSet retiredPoints_;
00207 
00208 
00209         // Faces
00210 
00211             //- Current faceList
00212             DynamicList<face> faces_;
00213 
00214             //- Patch for every external face (-1 for internal faces)
00215             DynamicList<label> region_;
00216 
00217             //- Owner for all faces
00218             DynamicList<label> faceOwner_;
00219 
00220             //- Neighbour for internal faces (-1 for external faces)
00221             DynamicList<label> faceNeighbour_;
00222 
00223             //- Original face label. Or master face for added-from-faces; 
00224             //  -1 for faces added-from-edge or added-from-point)
00225             DynamicList<label> faceMap_;
00226 
00227             //- For all original and added faces contains new face label
00228             //  (used to map return value of addFace to new mesh face)
00229             DynamicList<label> reverseFaceMap_;
00230 
00231             //- Faces added from point (corresponding faceMap_ will
00232             //  be -1)
00233             Map<label> faceFromPoint_;
00234 
00235             //- Faces added from edge (corresponding faceMap_ will
00236             //  be -1)
00237             Map<label> faceFromEdge_;
00238 
00239             //- In mapping whether to reverse the flux.
00240             labelHashSet flipFaceFlux_;
00241 
00242             //- Zone of face
00243             Map<label> faceZone_;
00244 
00245             //- Orientation of face in zone
00246             Map<bool> faceZoneFlip_;
00247 
00248             //- Active faces
00249             label nActiveFaces_;
00250 
00251 
00252         // Cells
00253 
00254             //- Original cell label or master cell for added-from-cell;
00255             //  -1 for cells added from face or edge.
00256             DynamicList<label> cellMap_;
00257 
00258             //- For all original and added cells contains new cell label
00259             //  (used to map return value of addCell to new mesh cell)
00260             DynamicList<label> reverseCellMap_;
00261 
00262             //- Cells added from point
00263             Map<label> cellFromPoint_;
00264 
00265             //- Cells added from edge
00266             Map<label> cellFromEdge_;
00267 
00268             //- Cells added from face
00269             Map<label> cellFromFace_;
00270 
00271             //- Zone of cell
00272             DynamicList<label> cellZone_;
00273 
00274 
00275     // Private Member Functions
00276 
00277         //- Reorder contents of container according to map
00278         template<class T>
00279         static void reorder(const labelList& map, DynamicList<T>&);
00280         template<class T>
00281         static void reorder(const labelList& map, List<DynamicList<T> >&);
00282         template<class T>
00283         static void renumberKey(const labelList& map, Map<T>&);
00284 
00285         //- Renumber elements of list according to map
00286         static void renumber(const labelList&, DynamicList<label>&);
00287         static void renumber(const labelList&, labelHashSet&);
00288         //- Special handling of reverse maps which have <-1 in them
00289         static void renumberReverseMap(const labelList&, DynamicList<label>&);
00290 
00291         //- Renumber & compact elements of list according to map
00292         static void renumberCompact(const labelList&, labelList&);
00293 
00294         //- Count number of added and removed quantities from maps.
00295         static void countMap
00296         (
00297             const labelList& map,
00298             const labelList& reverseMap,
00299             label& nAdd,
00300             label& nInflate,
00301             label& nMerge,
00302             label& nRemove
00303         );
00304 
00305         //- Print some stats about mesh
00306         static void writeMeshStats(const polyMesh& mesh, Ostream&);
00307 
00308         //- Calculate object maps. Requires reverseMap to have destination
00309         //  to be marked with <-1.
00310         static void getMergeSets
00311         (
00312             const labelList& reverseCellMap,
00313             const labelList& cellMap,
00314             List<objectMap>& cellsFromCells
00315         );
00316 
00317         //- Check inputs to modFace or addFace
00318         void checkFace
00319         (
00320             const face&,
00321             const label faceI,
00322             const label own,
00323             const label nei,
00324             const label patchI,
00325             const label zoneI
00326         ) const;
00327 
00328         //- Construct cells (in packed storage)
00329         void makeCells
00330         (
00331             const label nActiveFaces,
00332             labelList& cellFaces,
00333             labelList& cellFaceOffsets
00334         ) const;
00335 
00336         //- Do upper-triangular ordering and patch ordering.
00337         void getFaceOrder
00338         (
00339             const label nActiveFaces,
00340             const labelList& cellFaces,
00341             const labelList& cellFaceOffsets,
00342 
00343             labelList& oldToNew,
00344             labelList& patchSizes,
00345             labelList& patchStarts
00346         ) const;
00347 
00348         //- Compact and reorder faces according to map
00349         void reorderCompactFaces
00350         (
00351             const label newSize,
00352             const labelList& oldToNew
00353         );
00354 
00355         //- Remove all unused/removed points/faces/cells and update
00356         //  face ordering.
00357         void compact
00358         (
00359             labelList& patchSizes,
00360             labelList& patchStarts
00361         );
00362 
00363         //- Select either internal or external faces out of faceLabels
00364         static labelList selectFaces
00365         (
00366             const primitiveMesh&,
00367             const labelList& faceLabels,
00368             const bool internalFacesOnly
00369         );
00370 
00371         //- Calculate mapping for patchpoints only
00372         void calcPatchPointMap
00373         (
00374             const List<Map<label> >&,
00375             const labelList&,
00376             const polyBoundaryMesh&,
00377             labelListList&
00378         ) const;
00379 
00380         void calcFaceInflationMaps
00381         (
00382             const polyMesh&,
00383             List<objectMap>&,
00384             List<objectMap>&,
00385             List<objectMap>&
00386         ) const;
00387 
00388         void calcCellInflationMaps
00389         (
00390             const polyMesh&,
00391             List<objectMap>&,
00392             List<objectMap>&,
00393             List<objectMap>&,
00394             List<objectMap>& 
00395         ) const;
00396 
00397         void resetZones
00398         (
00399             const polyMesh&,        // mesh to get existing info from
00400             polyMesh&,              // mesh to change zones on
00401             labelListList&,
00402             labelListList&,
00403             labelListList&
00404         ) const;
00405 
00406         void calcFaceZonePointMap
00407         (
00408             const polyMesh&,
00409             const List<Map<label> >&,
00410             labelListList&
00411         ) const;
00412 
00413 
00414         // Coupling
00415 
00416             //- Rotate face by number of positions
00417             static face rotateFace(const face& f, const label nPos);
00418 
00419             //- Do all coupled patch face reordering
00420             void reorderCoupledFaces
00421             (
00422                 const bool syncParallel,
00423                 const polyBoundaryMesh&,
00424                 const labelList& patchStarts,
00425                 const labelList& patchSizes,
00426                 const pointField& points
00427             );
00428 
00429         void compactAndReorder
00430         (
00431             const polyMesh&,
00432             const bool syncParallel,
00433             pointField& newPoints,
00434             labelList& patchSizes,
00435             labelList& patchStarts,
00436             List<objectMap>& pointsFromPoints,
00437             List<objectMap>& facesFromPoints,
00438             List<objectMap>& facesFromEdges,
00439             List<objectMap>& facesFromFaces,
00440             List<objectMap>& cellsFromPoints,
00441             List<objectMap>& cellsFromEdges,
00442             List<objectMap>& cellsFromFaces,
00443             List<objectMap>& cellsFromCells,
00444             List<Map<label> >& oldPatchMeshPointMaps,
00445             labelList& oldPatchNMeshPoints,
00446             labelList& oldPatchStarts,
00447             List<Map<label> >& oldFaceZoneMeshPointMaps
00448         );
00449 
00450 public:
00451 
00452     //- Runtime type information
00453     ClassName("polyTopoChange");
00454 
00455 
00456 
00457     // Constructors
00458 
00459         //- Construct from mesh. Adds all points/face/cells from mesh.
00460         polyTopoChange(const polyMesh& mesh, const bool strict = true);
00461 
00462 
00463     // Member Functions
00464 
00465         // Access
00466 
00467             //- Points. Shrunk after constructing mesh (or calling of compact())
00468             const DynamicList<point>& points() const
00469             {
00470                 return points_;
00471             }
00472 
00473             const DynamicList<face>& faces() const
00474             {
00475                 return faces_;
00476             }
00477 
00478             const DynamicList<label>& region()const
00479             {
00480                 return region_;
00481             }
00482 
00483             const DynamicList<label>& faceOwner()const
00484             {
00485                 return faceOwner_;
00486             }
00487 
00488             const DynamicList<label>& faceNeighbour()const
00489             {
00490                 return faceNeighbour_;
00491             }
00492 
00493             //- Is point removed?
00494             inline bool pointRemoved(const label pointI) const;
00495             //- Is face removed?
00496             inline bool faceRemoved(const label faceI) const;
00497             //- Is cell removed?
00498             inline bool cellRemoved(const label cellI) const;
00499 
00500 
00501         // Edit
00502 
00503             //- Clear all storage
00504             void clear();
00505 
00506             //- Add all points/faces/cells of mesh. Additional offset for patch
00507             //  or zone ids.
00508             void addMesh
00509             (
00510                 const polyMesh&,
00511                 const labelList& patchMap,
00512                 const labelList& pointZoneMap,
00513                 const labelList& faceZoneMap,
00514                 const labelList& cellZoneMap
00515             );
00516 
00517             //- Move all points. Incompatible with other topology changes.
00518             void movePoints(const pointField& newPoints);
00519 
00520             //- For compatibility with polyTopoChange: set topological action.
00521             label setAction(const topoAction& action);
00522 
00523             //- Add point. Return new point label.
00524             //  Notes:
00525             //  - masterPointID can be < 0 (appended points)
00526             //  - inCell = false: add retired point (to end of point list)
00527             label addPoint
00528             (
00529                 const point&,
00530                 const label masterPointID,
00531                 const label zoneID,
00532                 const bool inCell
00533             );
00534 
00535             //- Modify coordinate.
00536             //  Notes:
00537             //  - inCell = false: add retired point (to end of point list)
00538             void modifyPoint
00539             (
00540                 const label,
00541                 const point&,
00542                 const label newZoneID,
00543                 const bool inCell
00544             );
00545 
00546             //- Remove/merge point.
00547             void removePoint(const label, const label);
00548 
00549             //- Add face to cells. Return new face label.
00550             //  own,nei<0, zoneID>=0 : add inactive face (to end of face list)
00551             label addFace
00552             (
00553                 const face& f,
00554                 const label own,
00555                 const label nei,
00556                 const label masterPointID,
00557                 const label masterEdgeID,
00558                 const label masterFaceID,
00559                 const bool flipFaceFlux,
00560                 const label patchID,
00561                 const label zoneID,
00562                 const bool zoneFlip
00563             );
00564 
00565             //- Modify vertices or cell of face.
00566             void modifyFace
00567             (
00568                 const face& f,
00569                 const label faceI,
00570                 const label own,
00571                 const label nei,
00572                 const bool flipFaceFlux,
00573                 const label patchID,
00574                 const label zoneID,
00575                 const bool zoneFlip
00576             );
00577 
00578             //- Remove/merge face.
00579             void removeFace(const label, const label);
00580 
00581             //- Add cell. Return new cell label.
00582             label addCell
00583             (
00584                 const label masterPointID,
00585                 const label masterEdgeID,
00586                 const label masterFaceID,
00587                 const label masterCellID,
00588                 const label zoneID
00589             );
00590 
00591             //- Modify zone of cell
00592             void modifyCell(const label, const label zoneID);
00593 
00594             //- Remove/merge cell.
00595             void removeCell(const label, const label);
00596 
00597 
00598         // Other
00599 
00600             //- Inplace changes mesh without change of patches.
00601             //  Adapts patch start/end and by default does parallel matching.
00602             //  Clears all data. Returns map.
00603             //  inflate = true : keep old mesh points. Put new points into the
00604             //  returned map (preMotionPoints) so we can use inflation. Any
00605             //  points out of nothing (appended points) are vector::zero.
00606             //  inflate = false: set mesh points directly. Empty preMotionPoints
00607             //  in the map.
00608             autoPtr<mapPolyMesh> changeMesh
00609             (
00610                 polyMesh& mesh,
00611                 const bool inflate,
00612                 const bool syncParallel = true
00613             );
00614 
00615             //- Create new mesh with old mesh patches
00616             autoPtr<mapPolyMesh> makeMesh
00617             (
00618                 autoPtr<fvMesh>& newMesh,
00619                 const IOobject& io,
00620                 const fvMesh& mesh,
00621                 const bool syncParallel = true
00622             );
00623 };
00624 
00625 
00626 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00627 
00628 } // End namespace Foam
00629 
00630 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00631 
00632 #include "polyTopoChangeI.H"
00633 
00634 #ifdef NoRepository
00635 #   include "polyTopoChangeTemplates.C"
00636 #endif
00637 
00638 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00639 
00640 #endif
00641 
00642 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd