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

dynamicRefineFvMesh.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::dynamicRefineFvMesh
00027 
00028 Description
00029     A fvMesh with built-in refinement.
00030 
00031     Determines which cells to refine/unrefine and does all in update().
00032 
00033 SourceFiles
00034     dynamicRefineFvMesh.C
00035 
00036 \*---------------------------------------------------------------------------*/
00037 
00038 #ifndef dynamicRefineFvMesh_H
00039 #define dynamicRefineFvMesh_H
00040 
00041 #include "dynamicFvMesh.H"
00042 #include "hexRef8.H"
00043 #include "PackedBoolList.H"
00044 #include "Switch.H"
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 namespace Foam
00049 {
00050 
00051 /*---------------------------------------------------------------------------*\
00052                            Class dynamicRefineFvMesh Declaration
00053 \*---------------------------------------------------------------------------*/
00054 
00055 class dynamicRefineFvMesh
00056 :
00057     public dynamicFvMesh
00058 {
00059 protected:
00060 
00061         //- Mesh cutting engine
00062         hexRef8 meshCutter_;
00063 
00064         //- Dump cellLevel for postprocessing
00065         Switch dumpLevel_;
00066 
00067         //- Fluxes to map
00068         List<Pair<word> > correctFluxes_;
00069 
00070         //- Number of refinement/unrefinement steps done so far.
00071         label nRefinementIterations_;
00072 
00073         //- Protected cells (usually since not hexes)
00074         PackedBoolList protectedCell_;
00075 
00076 
00077     // Private Member Functions
00078 
00079         //- Count set/unset elements in packedlist.
00080         static label count(const PackedBoolList&, const unsigned int);
00081 
00082         //- Calculate cells that cannot be refined since would trigger
00083         //  refinement of protectedCell_ (since 2:1 refinement cascade)
00084         void calculateProtectedCells(PackedBoolList& unrefineableCell) const;
00085 
00086         //- Read the projection parameters from dictionary
00087         void readDict();
00088 
00089 
00090         //- Refine cells. Update mesh and fields.
00091         autoPtr<mapPolyMesh> refine(const labelList&);
00092 
00093         //- Unrefine cells. Gets passed in centre points of cells to combine.
00094         autoPtr<mapPolyMesh> unrefine(const labelList&);
00095 
00096 
00097         // Selection of cells to un/refine
00098 
00099             //- Calculates approximate value for refinement level so
00100             //  we don't go above maxCell
00101             scalar getRefineLevel
00102             (
00103                 const label maxCells,
00104                 const label maxRefinement,
00105                 const scalar refineLevel,
00106                 const scalarField&
00107             ) const;
00108 
00109             //- Get per cell max of connected point
00110             scalarField maxPointField(const scalarField&) const;
00111 
00112             //- Get point min of connected cell
00113             scalarField minCellField(const volScalarField&) const;
00114 
00115             scalarField cellToPoint(const scalarField& vFld) const;
00116 
00117             scalarField error
00118             (
00119                 const scalarField& fld,
00120                 const scalar minLevel,
00121                 const scalar maxLevel
00122             ) const;
00123 
00124             //- Select candidate cells for refinement
00125             virtual void selectRefineCandidates
00126             (
00127                 const scalar lowerRefineLevel,
00128                 const scalar upperRefineLevel,
00129                 const scalarField& vFld,
00130                 PackedBoolList& candidateCell
00131             ) const;
00132 
00133             //- Subset candidate cells for refinement
00134             virtual labelList selectRefineCells
00135             (
00136                 const label maxCells,
00137                 const label maxRefinement,
00138                 const PackedBoolList& candidateCell
00139             ) const;
00140 
00141             //- Select points that can be unrefined.
00142             virtual labelList selectUnrefinePoints
00143             (
00144                 const scalar unrefineLevel,
00145                 const PackedBoolList& markedCell,
00146                 const scalarField& pFld
00147             ) const;
00148 
00149             //- Extend markedCell with cell-face-cell.
00150             void extendMarkedCells(PackedBoolList& markedCell) const;
00151 
00152 
00153 private:
00154 
00155         //- Disallow default bitwise copy construct
00156         dynamicRefineFvMesh(const dynamicRefineFvMesh&);
00157 
00158         //- Disallow default bitwise assignment
00159         void operator=(const dynamicRefineFvMesh&);
00160 
00161 public:
00162 
00163     //- Runtime type information
00164     TypeName("dynamicRefineFvMesh");
00165 
00166 
00167     // Constructors
00168 
00169         //- Construct from IOobject
00170         explicit dynamicRefineFvMesh(const IOobject& io);
00171 
00172 
00173     // Destructor
00174 
00175         virtual ~dynamicRefineFvMesh();
00176 
00177 
00178     // Member Functions
00179 
00180         //- Direct access to the refinement engine
00181         const hexRef8& meshCutter() const
00182         {
00183             return meshCutter_;
00184         }
00185 
00186         //- Cells which should not be refined/unrefined
00187         const PackedBoolList& protectedCell() const
00188         {
00189             return protectedCell_;
00190         }
00191 
00192         //- Cells which should not be refined/unrefined
00193         PackedBoolList& protectedCell()
00194         {
00195             return protectedCell_;
00196         }
00197 
00198         //- Update the mesh for both mesh motion and topology change
00199         virtual bool update();
00200 
00201 
00202     // Writing
00203 
00204         //- Write using given format, version and compression
00205         virtual bool writeObject
00206         (
00207             IOstream::streamFormat fmt,
00208             IOstream::versionNumber ver,
00209             IOstream::compressionType cmp
00210         ) const;
00211 
00212 };
00213 
00214 
00215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00216 
00217 } // End namespace Foam
00218 
00219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00220 
00221 #endif
00222 
00223 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd