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

hexRef8.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     hexRef8
00027 
00028 Description
00029     Refinement of (split) hexes using polyTopoChange.
00030 
00031 SourceFiles
00032     hexRef8.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef hexRef8_H
00037 #define hexRef8_H
00038 
00039 #include "labelIOList.H"
00040 #include "face.H"
00041 #include "labelHashSet.H"
00042 #include "DynamicList.H"
00043 #include "primitivePatch.H"
00044 #include "removeFaces.H"
00045 #include "refinementHistory.H"
00046 #include "PackedList.H"
00047 
00048 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00049 
00050 namespace Foam
00051 {
00052 
00053 // Class forward declarations
00054 class polyMesh;
00055 class polyPatch;
00056 class polyTopoChange;
00057 class mapPolyMesh;
00058 class mapDistributePolyMesh;
00059 
00060 /*---------------------------------------------------------------------------*\
00061                            Class hexRef8 Declaration
00062 \*---------------------------------------------------------------------------*/
00063 
00064 class hexRef8
00065 {
00066     // Private data
00067 
00068         //- Reference to underlying mesh.
00069         const polyMesh& mesh_;
00070 
00071         //- Per cell the refinement level
00072         labelIOList cellLevel_;
00073 
00074         //- Per point the refinement level
00075         labelIOList pointLevel_;
00076 
00077         //- Refinement history
00078         refinementHistory history_;
00079 
00080         //- Face remover engine
00081         removeFaces faceRemover_;
00082 
00083 
00084     // Private Member Functions
00085 
00086         //- Reorder according to map.
00087         static void reorder
00088         (
00089             const labelList& map,
00090             const label len,
00091             const label null,
00092             labelList& elems
00093         );
00094 
00095         //- Get patch and zone info
00096         void getFaceInfo
00097         (
00098             const label faceI,
00099             label& patchID,
00100             label& zoneID,
00101             label& zoneFlip
00102         ) const;
00103 
00104         //- Adds a face on top of existing faceI. Reverses if nessecary.
00105         label addFace
00106         (
00107             polyTopoChange& meshMod,
00108             const label faceI,
00109             const face& newFace,
00110             const label own,
00111             const label nei
00112         ) const;
00113 
00114         //- Adds internal face from point. No checks on reversal.
00115         label addInternalFace
00116         (
00117             polyTopoChange& meshMod,
00118             const label meshFaceI,
00119             const label meshPointI,
00120             const face& newFace,
00121             const label own,
00122             const label nei
00123         ) const;
00124 
00125         //- Modifies existing faceI for either new owner/neighbour or new face
00126         //  points. Reverses if nessecary.
00127         void modFace
00128         (
00129             polyTopoChange& meshMod,
00130             const label faceI,
00131             const face& newFace,
00132             const label own,
00133             const label nei
00134         ) const;
00135 
00136         //- Get cell added to point of cellI (if any)
00137         label getAnchorCell
00138         (
00139             const labelListList& cellAnchorPoints,
00140             const labelListList& cellAddedCells,
00141             const label cellI,
00142             const label faceI,
00143             const label pointI
00144         ) const;
00145 
00146         //- Get new owner and neighbour (in unspecified order) of pointI
00147         //  on faceI.
00148         void getFaceNeighbours
00149         (
00150             const labelListList& cellAnchorPoints,
00151             const labelListList& cellAddedCells,
00152             const label faceI,
00153             const label pointI,
00154 
00155             label& own,
00156             label& nei
00157         ) const;
00158 
00159 
00160         //- Get index of minimum pointlevel.
00161         label findMinLevel(const labelList& f) const;
00162         //- Get maximum pointlevel.
00163         label findMaxLevel(const labelList& f) const;
00164         //- Count number of vertices <= anchorLevel
00165         label countAnchors(const labelList&, const label) const;
00166         //- Find index of point with wantedLevel, starting from fp.
00167         label findLevel
00168         (
00169             const face& f,
00170             const label startFp,
00171             const bool searchForward,
00172             const label wantedLevel
00173         ) const;
00174         //- Gets level such that the face has four points <= level.
00175         label getAnchorLevel(const label faceI) const;
00176 
00178         //void printLevels(Ostream&, const labelList&) const;
00179 
00180         //- debug:check orientation of added internal face
00181         static void checkInternalOrientation
00182         (
00183             polyTopoChange& meshMod,
00184             const label cellI,
00185             const label faceI,
00186             const point& ownPt,
00187             const point& neiPt,
00188             const face& newFace
00189         );
00190 
00191         //- debug:check orientation of new boundary face
00192         static void checkBoundaryOrientation
00193         (
00194             polyTopoChange& meshMod,
00195             const label cellI,
00196             const label faceI,
00197             const point& ownPt,
00198             const point& boundaryPt,
00199             const face& newFace
00200         );
00201 
00202         //- If p0 and p1 are existing vertices check if edge is split and insert
00203         // splitPoint.
00204         void insertEdgeSplit
00205         (
00206             const labelList& edgeMidPoint,
00207             const label p0,
00208             const label p1,
00209             DynamicList<label>& verts
00210         ) const;
00211 
00212         //- Store in maps correspondence from midpoint to anchors and faces.
00213         label storeMidPointInfo
00214         (
00215             const labelListList& cellAnchorPoints,
00216             const labelListList& cellAddedCells,
00217             const labelList& cellMidPoint,
00218             const labelList& edgeMidPoint,
00219             const label cellI,
00220             const label faceI,
00221             const bool faceOrder,
00222             const label midPointI,
00223             const label anchorPointI,
00224             const label faceMidPointI,
00225 
00226             Map<edge>& midPointToAnchors,
00227             Map<edge>& midPointToFaceMids,
00228             polyTopoChange& meshMod
00229         ) const;
00230 
00231         //- Create all internal faces from an unsplit face.
00232         void createInternalFromSplitFace
00233         (
00234             const labelListList& cellAnchorPoints,
00235             const labelListList& cellAddedCells,
00236             const labelList& cellMidPoint,
00237             const labelList& faceMidPoint,
00238             const labelList& edgeMidPoint,
00239             const label cellI,
00240             const label faceI,
00241 
00242             Map<edge>& midPointToAnchors,
00243             Map<edge>& midPointToFaceMids,
00244             polyTopoChange& meshMod,
00245             label& nFacesAdded
00246         ) const;
00247 
00248         //- Create all internal faces to split cellI into 8.
00249         void createInternalFaces
00250         (
00251             const labelListList& cellAnchorPoints,
00252             const labelListList& cellAddedCells,
00253             const labelList& cellMidPoint,
00254             const labelList& faceMidPoint,
00255             const labelList& faceAnchorLevel,
00256             const labelList& edgeMidPoint,
00257             const label cellI,
00258             polyTopoChange& meshMod
00259         ) const;
00260 
00261         //- Store vertices from startFp upto face split point.
00262         //  Used when splitting face into 4.
00263         void walkFaceToMid
00264         (
00265             const labelList& edgeMidPoint,
00266             const label cLevel,
00267             const label faceI,
00268             const label startFp,
00269             DynamicList<label>& faceVerts
00270         ) const;
00271 
00272         //- Same as walkFaceToMid but now walk back.
00273         void walkFaceFromMid
00274         (
00275             const labelList& edgeMidPoint,
00276             const label cLevel,
00277             const label faceI,
00278             const label startFp,
00279             DynamicList<label>& faceVerts
00280         ) const;
00281 
00282         //- Updates refineCell so consistent 2:1 refinement. Returns local
00283         //  number of cells changed.
00284         label faceConsistentRefinement
00285         (
00286             const bool maxSet,
00287             PackedList<1>& refineCell
00288         ) const;
00289 
00290         //- Check wanted refinement for 2:1 consistency
00291         void checkWantedRefinementLevels(const labelList&) const;
00292 
00293 
00294 
00295         //- Disallow default bitwise copy construct
00296         hexRef8(const hexRef8&);
00297 
00298         //- Disallow default bitwise assignment
00299         void operator=(const hexRef8&);
00300 
00301 
00302 public:
00303 
00304     //- Runtime type information
00305     ClassName("hexRef8");
00306 
00307 
00308     // Constructors
00309 
00310         //- Construct from mesh, read_if_present refinement data
00311         //  (from write below)
00312         hexRef8(const polyMesh& mesh);
00313 
00314         //- Construct from mesh and un/refinement data.
00315         hexRef8
00316         (
00317             const polyMesh& mesh,
00318             const labelList& cellLevel,
00319             const labelList& pointLevel,
00320             const refinementHistory& history
00321         );
00322 
00323         //- Construct from mesh and refinement data.
00324         hexRef8
00325         (
00326             const polyMesh& mesh,
00327             const labelList& cellLevel,
00328             const labelList& pointLevel
00329         );
00330 
00331 
00332     // Member Functions
00333 
00334         // Access
00335 
00336             const labelIOList& cellLevel() const
00337             {
00338                 return cellLevel_;
00339             }
00340 
00341             const labelIOList& pointLevel() const
00342             {
00343                 return pointLevel_;
00344             }
00345 
00346             const refinementHistory& history() const
00347             {
00348                 return history_;
00349             }
00350 
00351 
00352         // Refinement
00353 
00354             //- Helper:get points of a cell without using cellPoints addressing
00355             labelList cellPoints(const label cellI) const;
00356 
00357             //- Given valid mesh and current cell level and proposed
00358             //  cells to refine calculate any clashes (due to 2:1) and return
00359             //  ok list of cells to refine.
00360             //  Either adds cells to refine to set (maxSet = true) or
00361             //  removes cells to refine (maxSet = false)
00362             labelList consistentRefinement
00363             (
00364                 const labelList& cellsToRefine,
00365                 const bool maxSet
00366             ) const;
00367 
00368             //- Like consistentRefinement but slower:
00369             //  - specify number of cells between consecutive refinement levels
00370             //    (consistentRefinement equivalent to 1)
00371             //  - specify max level difference between point-connected cells.
00372             //    (-1 to disable) Note that with normal 2:1 limitation
00373             //    (maxFaceDiff=1) there can be 8:1 size difference across point
00374             //    connected cells so maxPointDiff allows you to make that less.
00375             //  cellsToRefine : cells we're thinking about refining. It will
00376             //                  extend this set. All refinement levels will be
00377             //                  at least maxFaceDiff layers thick.
00378             //  facesToCheck  : additional faces where to implement the
00379             //                  maxFaceDiff thickness (usually only boundary
00380             //                  faces)
00381             labelList consistentSlowRefinement
00382             (
00383                 const label maxFaceDiff,
00384                 const labelList& cellsToRefine,
00385                 const labelList& facesToCheck,
00386                 const label maxPointDiff,
00387                 const labelList& pointsToCheck
00388             ) const;
00389 
00390             //- Insert refinement. All selected cells will be split into 8.
00391             //  Returns per element in cells the 8 cells they were split into.
00392             //  Guarantees that the 0th element is the original cell label.
00393             //  Mapping:
00394             //  -split cells: 7 new ones get added from original
00395             //  -split faces: original gets modified; 3 new ones get added
00396             //               from original
00397             //  -added internal faces: added from original cell face(if
00398             //   that was internal) or created out-of-nothing (so will not
00399             //   get mapped!). Note: could make this inflate from point but
00400             //   that will allocate interpolation.
00401             //  -points added to split edge: added from edge start()
00402             //  -midpoints added: added from cellPoints[0].
00403             labelListList setRefinement
00404             (
00405                 const labelList& cells, 
00406                 polyTopoChange&
00407             );
00408 
00409             //- Update local numbering for changed mesh.
00410             void updateMesh(const mapPolyMesh&);
00411 
00412             //- Update local numbering for subsetted mesh.
00413             //  Gets new-to-old maps. Not compatible with unrefinement.
00414             void subset
00415             (
00416                 const labelList& pointMap,
00417                 const labelList& faceMap,
00418                 const labelList& cellMap
00419             );
00420 
00421             //- Update local numbering for mesh redistribution
00422             void distribute(const mapDistributePolyMesh&);
00423 
00424             //- Debug: Check coupled mesh for correctness
00425             void checkMesh() const;
00426 
00427             //- Debug: Check 2:1 consistency across faces.
00428             //  maxPointDiff==-1 : only check 2:1 across faces
00429             //  maxPointDiff!=-1 : check point-connected cells.
00430             void checkRefinementLevels
00431             (
00432                 const label maxPointDiff,
00433                 const labelList& pointsToCheck
00434             ) const;
00435 
00436         // Unrefinement (undoing refinement, not arbitrary coarsening)
00437 
00438             //- Return the points at the centre of top-level split cells
00439             //  that can be unsplit.
00440             labelList getSplitPoints() const;
00441 
00442             //- Given proposed
00443             //  splitPoints to unrefine according to calculate any clashes
00444             //  (due to 2:1) and return ok list of points to unrefine.
00445             //  Either adds points to refine to set (maxSet = true) or
00446             //  removes points to refine (maxSet = false)
00447             labelList consistentUnrefinement
00448             (
00449                 const labelList& pointsToUnrefine,
00450                 const bool maxSet
00451             ) const;
00452 
00453             //- Remove some refinement. Needs to be supplied output of
00454             //  consistentUnrefinement. Only call if undoable set.
00455             //  All 8 pointCells of a split point will be combined into
00456             //  the lowest numbered cell of those 8.
00457             void setUnrefinement
00458             (
00459                 const labelList& splitPointLabels,
00460                 polyTopoChange&
00461             );
00462 
00463         // Write
00464 
00465             // Set instance for mesh files
00466             void setInstance(const fileName& inst);
00467 
00468             //- Force writing refinement+history to polyMesh directory.
00469             bool write() const;
00470 
00471 };
00472 
00473 
00474 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00475 
00476 } // End namespace Foam
00477 
00478 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00479 
00480 #endif
00481 
00482 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd