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

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