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

refinementHistory.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::refinementHistory
00026 
00027 Description
00028     All refinement history. Used in unrefinement.
00029 
00030     - visibleCells: valid for the current mesh and contains per cell -1
00031     (cell unrefined) or an index into splitCells_.
00032     - splitCells: for every split contains the parent (also index into
00033       splitCells) and optionally a subsplit as 8 indices into splitCells.
00034       Note that the numbers in splitCells are not cell labels, they are purely
00035       indices into splitCells.
00036 
00037     E.g. 2 cells, cell 1 gets refined so end up with 9 cells:
00038     @verbatim
00039         // splitCells
00040         9
00041         (
00042         -1 (1 2 3 4 5 6 7 8)
00043         0 0()
00044         0 0()
00045         0 0()
00046         0 0()
00047         0 0()
00048         0 0()
00049         0 0()
00050         0 0()
00051         )
00052 
00053         // visibleCells
00054         9(-1 1 2 3 4 5 6 7 8)
00055     @endverbatim
00056 
00057 
00058     So cell0 (visibleCells=-1) is unrefined.
00059     Cells 1-8 have all valid splitCells entries which are:
00060       - parent:0
00061       - subsplits:0()
00062 
00063     The parent 0 refers back to the splitcell entries.
00064 
00065 
00066 SourceFiles
00067     refinementHistory.C
00068 
00069 \*---------------------------------------------------------------------------*/
00070 
00071 #ifndef refinementHistory_H
00072 #define refinementHistory_H
00073 
00074 #include <OpenFOAM/DynamicList.H>
00075 #include <OpenFOAM/labelList.H>
00076 #include <OpenFOAM/FixedList.H>
00077 #include <OpenFOAM/SLList.H>
00078 #include <OpenFOAM/autoPtr.H>
00079 #include <OpenFOAM/regIOobject.H>
00080 
00081 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00082 
00083 namespace Foam
00084 {
00085 
00086 // Forward declaration of classes
00087 class mapPolyMesh;
00088 class mapDistributePolyMesh;
00089 
00090 /*---------------------------------------------------------------------------*\
00091                            Class refinementHistory Declaration
00092 \*---------------------------------------------------------------------------*/
00093 
00094 class refinementHistory
00095 :
00096     public regIOobject
00097 {
00098 public:
00099 
00100     class splitCell8
00101     {
00102     public:
00103 
00104         // Index to original splitCell this cell was refined off from
00105         // -1: top level cell
00106         // -2: free splitCell (so should also be in freeSplitCells_)
00107         label parent_;
00108 
00109         //- cells this cell was refined into
00110         autoPtr<FixedList<label, 8> > addedCellsPtr_;
00111 
00112         //- Construct null (parent = -1)
00113         splitCell8();
00114 
00115         //- Construct from parent
00116         splitCell8(const label parent);
00117 
00118         //- Construct from Istream
00119         splitCell8(Istream& is);
00120 
00121         //- Construct as deep copy
00122         splitCell8(const splitCell8&);
00123 
00124         //- Copy operator since autoPtr otherwise 'steals' storage.
00125         void operator=(const splitCell8& s)
00126         {
00127             // Check for assignment to self
00128             if (this == &s)
00129             {
00130                 FatalErrorIn("splitCell8::operator=(const Foam::splitCell8&)")
00131                     << "Attempted assignment to self"
00132                     << abort(FatalError);
00133             }
00134 
00135             parent_ = s.parent_;
00136 
00137             addedCellsPtr_.reset
00138             (
00139                 s.addedCellsPtr_.valid()
00140               ? new FixedList<label, 8>(s.addedCellsPtr_())
00141               : NULL
00142             );
00143         }
00144 
00145         bool operator==(const splitCell8& s) const
00146         {
00147             if (addedCellsPtr_.valid() != s.addedCellsPtr_.valid())
00148             {
00149                 return false;
00150             }
00151             else if (parent_ != s.parent_)
00152             {
00153                 return false;
00154             }
00155             else if (addedCellsPtr_.valid())
00156             {
00157                 return addedCellsPtr_() == s.addedCellsPtr_();
00158             }
00159             else
00160             {
00161                 return true;
00162             }
00163         }
00164 
00165         bool operator!=(const splitCell8& s) const
00166         {
00167             return !operator==(s);
00168         }
00169 
00170         friend Istream& operator>>(Istream&, splitCell8&);
00171         friend Ostream& operator<<(Ostream&, const splitCell8&);
00172     };
00173 
00174 
00175 private:
00176 
00177     TypeName("refinementHistory");
00178 
00179     // Private data
00180 
00181         //- Storage for splitCells
00182         DynamicList<splitCell8> splitCells_;
00183 
00184         //- Unused indices in splitCells
00185         DynamicList<label> freeSplitCells_;
00186 
00187         //- Currently visible cells. Indices into splitCells.
00188         labelList visibleCells_;
00189 
00190 
00191     // Private member functions
00192 
00193         //- Debug write
00194         static void writeEntry
00195         (
00196             const List<splitCell8>&,
00197             const splitCell8&
00198         );
00199         //- Debug write
00200         static void writeDebug
00201         (
00202             const labelList&,
00203             const List<splitCell8>&
00204         );
00205 
00206         //- Check consistency of structure, i.e. indices into splitCells_.
00207         void checkIndices() const;
00208 
00209         //- Allocate a splitCell. Return index in splitCells_.
00210         label allocateSplitCell(const label parent, const label i);
00211 
00212         //- Free a splitCell.
00213         void freeSplitCell(const label index);
00214 
00215         //- Mark entry in splitCells. Recursively mark its parent and subs.
00216         void markSplit
00217         (
00218             const label,
00219             labelList& oldToNew,
00220             DynamicList<splitCell8>&
00221         ) const;
00222 
00223         void countProc
00224         (
00225             const label index,
00226             const label newProcNo,
00227             labelList& splitCellProc,
00228             labelList& splitCellNum
00229         ) const;
00230 
00231 public:
00232 
00233     // Constructors
00234 
00235         //- Construct (read) given an IOobject
00236         refinementHistory(const IOobject&);
00237 
00238         //- Construct (read) or construct null
00239         refinementHistory
00240         (
00241             const IOobject&,
00242             const List<splitCell8>& splitCells,
00243             const labelList& visibleCells
00244         );
00245 
00246         //- Construct (read) or construct from initial number of cells
00247         //  (all visible)
00248         refinementHistory(const IOobject&, const label nCells);
00249 
00250         //- Construct as copy
00251         refinementHistory(const IOobject&, const refinementHistory&);
00252 
00253         //- Construct from Istream
00254         refinementHistory(const IOobject&, Istream&);
00255 
00256 
00257     // Member Functions
00258 
00259 
00260         //- Per cell in the current mesh (i.e. visible) either -1 (unrefined)
00261         //  or an index into splitCells.
00262         const labelList& visibleCells() const
00263         {
00264             return visibleCells_;
00265         }
00266 
00267         //- Storage for splitCell8s.
00268         const DynamicList<splitCell8>& splitCells() const
00269         {
00270             return splitCells_;
00271         }
00272 
00273         //- Cache of unused indices in splitCells
00274         const DynamicList<label>& freeSplitCells() const
00275         {
00276             return freeSplitCells_;
00277         }
00278 
00279         //- Is there unrefinement history. Note that this will fall over if
00280         //  there are 0 cells in the mesh. But this gives problems with
00281         //  lots of other programs anyway.
00282         bool active() const
00283         {
00284             return visibleCells_.size() > 0;
00285         }
00286 
00287         //- Get parent of cell
00288         label parentIndex(const label cellI) const
00289         {
00290             label index = visibleCells_[cellI];
00291 
00292             if (index < 0)
00293             {
00294                 FatalErrorIn("refinementHistory::parentIndex(const label)")
00295                     << "Cell " << cellI << " is not visible"
00296                     << abort(FatalError);
00297             }
00298             return splitCells_[index].parent_;
00299         }
00300 
00301         //- Store splitting of cell into 8
00302         void storeSplit
00303         (
00304             const label cellI,
00305             const labelList& addedCells
00306         );
00307 
00308         //- Store combining 8 cells into master
00309         void combineCells
00310         (
00311             const label masterCellI,
00312             const labelList& combinedCells
00313         );
00314 
00315 
00316         //- Update numbering for mesh changes
00317         void updateMesh(const mapPolyMesh&);
00318 
00319         //- Update numbering for subsetting
00320         void subset
00321         (
00322             const labelList& pointMap,
00323             const labelList& faceMap,
00324             const labelList& cellMap
00325         );
00326 
00327         //- Update local numbering for mesh redistribution.
00328         //  Can only distribute clusters sent across in one go; cannot
00329         //  handle parts recombined in multiple passes.
00330         void distribute(const mapDistributePolyMesh&);
00331 
00332 
00333         //- Compact splitCells_. Removes all freeSplitCells_ elements.
00334         void compact();
00335 
00336         //- Extend/shrink storage. additional visibleCells_ elements get
00337         //  set to -1.
00338         void resize(const label nCells);
00339 
00340         //- Debug write
00341         void writeDebug() const;
00342 
00343 
00344         //- ReadData function required for regIOobject read operation
00345         virtual bool readData(Istream&);
00346 
00347         //- WriteData function required for regIOobject write operation
00348         virtual bool writeData(Ostream&) const;
00349 
00350 
00351     // Friend Functions
00352 
00353     // Friend Operators
00354 
00355     // IOstream Operators
00356 
00357         friend Istream& operator>>(Istream&, refinementHistory&);
00358         friend Ostream& operator<<(Ostream&, const refinementHistory&);
00359 };
00360 
00361 
00362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00363 
00364 } // End namespace Foam
00365 
00366 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00367 
00368 #endif
00369 
00370 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines