OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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