OpenFOAM logo
Open Source CFD Toolkit

directPolyTopoChange.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-2005 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     directPolyTopoChange
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     directPolyTopoChange.C
00058     directPolyTopoChangeI.H
00059     directPolyTopoChangeTemplates.C
00060 
00061 \*---------------------------------------------------------------------------*/
00062 
00063 #ifndef directPolyTopoChange_H
00064 #define directPolyTopoChange_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 directPolyTopoChange Declaration
00098 \*---------------------------------------------------------------------------*/
00099 
00100 class directPolyTopoChange
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 
00289         //- Renumber & compact elements of list according to map
00290         static void renumberCompact(const labelList&, labelList&);
00291 
00292         //- Remove selected element from labelList
00293         //static void remove(const label elemToRemove, labelList&);
00294 
00295         //- Is point removed?
00296         inline bool pointRemoved(const label pointI) const;
00297         inline bool faceRemoved(const label faceI) const;
00298         inline bool cellRemoved(const label cellI) const;
00299 
00300         //- Check inputs to modFace or addFace
00301         void checkFace
00302         (
00303             const face&,
00304             const label faceI,
00305             const label own,
00306             const label nei,
00307             const label patchI,
00308             const label zoneI
00309         ) const;
00310 
00311         //- Construct cells (in packed storage)
00312         void makeCells
00313         (
00314             const label nActiveFaces,
00315             labelList& cellFaces,
00316             labelList& cellFaceOffsets
00317         ) const;
00318 
00319         //- Do upper-triangular ordering and patch ordering.
00320         labelList getFaceOrder
00321         (
00322             const label nActiveFaces,
00323             const labelList& cellFaces,
00324             const labelList& cellFaceOffsets
00325         ) const;
00326 
00327         //- Compact and reorder faces according to map
00328         void reorderCompactFaces
00329         (
00330             const label newSize,
00331             const labelList& oldToNew
00332         );
00333 
00334         //- Remove all unused/removed points/faces/cells and update
00335         //  face ordering.
00336         void compact();
00337 
00338         //- Given a sorted faceList calculates sizes and starts of patches.
00339         void calcPatchSizes
00340         (
00341             labelList& patchSizes,
00342             labelList& patchStarts
00343         ) const;
00344 
00345         //- Select either internal or external faces out of faceLabels
00346         static labelList selectFaces
00347         (
00348             const primitiveMesh&,
00349             const labelList& faceLabels,
00350             const bool internalFacesOnly
00351         );
00352 
00353         //- Calculate mapping for patchpoints only
00354         void calcPatchPointMap
00355         (
00356             const List<Map<label> >&,
00357             const labelList&,
00358             const polyBoundaryMesh&,
00359             labelListList&
00360         ) const;
00361 
00362         void calcFaceInflationMaps
00363         (
00364             const polyMesh&,
00365             List<objectMap>&,
00366             List<objectMap>&
00367         ) const;
00368 
00369         void calcCellInflationMaps
00370         (
00371             const polyMesh&,
00372             List<objectMap>&,
00373             List<objectMap>&,
00374             List<objectMap>& 
00375         ) const;
00376 
00377         void resetZones
00378         (
00379             polyMesh&,
00380             labelListList&,
00381             labelListList&,
00382             labelListList&
00383         ) const;
00384 
00385         void calcFaceZonePointMap
00386         (
00387             polyMesh&,
00388             const List<Map<label> >&,
00389             labelListList&
00390         ) const;
00391 
00392 
00393         // Coupling
00394 
00395             //- Rotate face by number of positions
00396             static face rotateFace(const face& f, const label nPos);
00397 
00398             //- Do all coupled patch face reordering
00399             void reorderCoupledFaces
00400             (
00401                 const polyBoundaryMesh&,
00402                 const labelList& patchStarts,
00403                 const labelList& patchSizes,
00404                 const pointField& points
00405             );
00406 
00407 public:
00408 
00409     //- Runtime type information
00410     ClassName("directPolyTopoChange");
00411 
00412 
00413 
00414     // Constructors
00415 
00416         //- Construct from mesh. Adds all points/face/cells from mesh.
00417         directPolyTopoChange(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 
00451         // Edit
00452 
00453             //- Clear all storage
00454             void clear();
00455 
00456             //- Add all points/faces/cells of mesh. Additional offset for patch
00457             //  or zone ids.
00458             void addMesh
00459             (
00460                 const polyMesh&,
00461                 const labelList& patchMap,
00462                 const labelList& pointZoneMap,
00463                 const labelList& faceZoneMap,
00464                 const labelList& cellZoneMap
00465             );
00466 
00467 
00468             //- For compatibility with polyTopoChange: set topological action.
00469             label setAction(const topoAction& action);
00470 
00471             //- Add point. Return new point label.
00472             //  Notes:
00473             //  - masterPointID can be < 0 (appended points)
00474             //  - inCell = false: add retired point (to end of point list)
00475             label addPoint
00476             (
00477                 const point&,
00478                 const label masterPointID,
00479                 const label zoneID,
00480                 const bool inCell
00481             );
00482 
00483             //- Modify coordinate.
00484             //  Notes:
00485             //  - inCell = false: add retired point (to end of point list)
00486             void modifyPoint
00487             (
00488                 const label,
00489                 const point&,
00490                 const label newZoneID,
00491                 const bool inCell
00492             );
00493 
00494             //- Remove point.
00495             void removePoint(const label);
00496 
00497             //- Add face to cells. Return new face label.
00498             //  own,nei<0, zoneID>=0 : add inactive face (to end of face list)
00499             label addFace
00500             (
00501                 const face& f,
00502                 const label own,
00503                 const label nei,
00504                 const label masterPointID,
00505                 const label masterEdgeID,
00506                 const label masterFaceID,
00507                 const bool flipFaceFlux,
00508                 const label patchID,
00509                 const label zoneID,
00510                 const bool zoneFlip
00511             );
00512 
00513             //- Modify vertices or cell of face.
00514             void modifyFace
00515             (
00516                 const face& f,
00517                 const label faceI,
00518                 const label own,
00519                 const label nei,
00520                 const bool flipFaceFlux,
00521                 const label patchID,
00522                 const label zoneID,
00523                 const bool zoneFlip
00524             );
00525 
00526             //- Remove face.
00527             void removeFace(const label);
00528 
00529             //- Add cell. Return new cell label.
00530             label addCell
00531             (
00532                 const label masterPointID,
00533                 const label masterEdgeID,
00534                 const label masterFaceID,
00535                 const label masterCellID,
00536                 const label zoneID
00537             );
00538 
00539             //- Modify zone of cell
00540             void modifyCell(const label, const label zoneID);
00541 
00542             //- Remove cell.
00543             void removeCell(const label);
00544 
00545 
00546         // Other
00547 
00548             //- Inplace changes mesh without change of patches.
00549             //  Adapts patch start/end and does reorderCoupledFaces.
00550             //  Clears all data. Returns map.
00551             autoPtr<mapPolyMesh> changeMesh(polyMesh& mesh);
00552 };
00553 
00554 
00555 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00556 
00557 } // End namespace Foam
00558 
00559 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00560 
00561 #include "directPolyTopoChangeI.H"
00562 
00563 #ifdef NoRepository
00564 #   include "directPolyTopoChangeTemplates.C"
00565 #endif
00566 
00567 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00568 
00569 #endif
00570 
00571 // ************************************************************************* //
For further information go to www.openfoam.org