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