OpenFOAM logo
Open Source CFD Toolkit

fvMeshSubset.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-2005 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     fvMeshSubset
00027 
00028 Description
00029     Post-processing mesh subset tool.  Given the original mesh and the
00030     list of selected cells, it creates the mesh consisting only of the
00031     desired cells, with the mapping list for points, faces, and cells.
00032 
00033     Puts all exposed internal faces into either
00034     - a user supplied patch
00035     - a newly created patch "oldInternalFaces"
00036 
00037     - setCellSubset is for small subsets. Uses Maps to minimize memory.
00038     - setLargeCellSubset is for largish subsets (>10% of mesh).
00039       Uses labelLists instead.
00040 
00041     - setLargeCellSubset does coupled patch subsetting as well. If it detects
00042       a face on a coupled patch 'losing' its neighbour it will move the
00043       face into the oldInternalFaces patch.
00044 
00045     - if a user supplied patch is used the mapping becomes a problem.
00046     Do the new faces get the value of the internal face they came from?
00047     What if e.g. the user supplied patch is a fixedValue 0? So for now
00048     they get the face of existing patch face 0.
00049 
00050 SourceFiles
00051     fvMeshSubset.C
00052 
00053 \*---------------------------------------------------------------------------*/
00054 
00055 #ifndef fvMeshSubset_H
00056 #define fvMeshSubset_H
00057 
00058 #include "fvMesh.H"
00059 #include "fvPatchFieldMapper.H"
00060 #include "GeometricField.H"
00061 #include "emptyFvPatchFields.H"
00062 #include "labelHashSet.H"
00063 #include "SubField.H"
00064 #include "surfaceMesh.H"
00065 
00066 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00067 
00068 namespace Foam
00069 {
00070 
00071 /*---------------------------------------------------------------------------*\
00072                         Class fvMeshSubset Declaration
00073 \*---------------------------------------------------------------------------*/
00074 
00075 class fvMeshSubset
00076 :
00077     public fvMesh
00078 {
00079 
00080 public:
00081 
00082     //- Patch-field subset interpolation class
00083     class patchFieldSubset
00084     :
00085         public fvPatchFieldMapper
00086     {
00087         labelField directAddressing_;
00088 
00089     public:
00090 
00091         // Constructors
00092 
00093             //- Construct given addressing
00094             patchFieldSubset(const fvMeshSubset& ms, const label patchNo)
00095             :
00096                 directAddressing_
00097                 (
00098                     static_cast<const labelField&>
00099                     (
00100                         labelField::subField
00101                         (
00102                             ms.faceMap(),
00103                             ms.subMesh().boundary()[patchNo].size(),
00104                             ms.subMesh().boundary()[patchNo].patch().start()
00105                         )
00106                     )
00107                   - ms.boundary()[ms.patchMap()[patchNo]].patch().start()
00108                 )
00109             {
00110                 // If patchID supplied so exposed internal faces or uncoupled
00111                 // patch faces get into existing patch what to do with
00112                 // mapping? Truncate to 0 for now.
00113                 const label sz = ms.subMesh().boundary()[patchNo].size();
00114 
00115                 forAll(directAddressing_, i)
00116                 {
00117                     label& address = directAddressing_[i];
00118 
00119                     if (address < 0 || address >= sz)
00120                     {
00121                         address = 0;
00122                     }
00123                 }
00124             }
00125 
00126 
00127         // Destructor
00128 
00129             virtual ~patchFieldSubset()
00130             {}
00131 
00132 
00133         // Member Functions
00134 
00135             label size() const
00136             {
00137                 return directAddressing_.size();
00138             }
00139 
00140             bool direct() const
00141             {
00142                 return true;
00143             }
00144 
00145             const unallocLabelList& directAddressing() const
00146             {
00147                 return directAddressing_;
00148             }
00149     };
00150 
00151 
00152 private:
00153 
00154     // Private data
00155 
00156         //- Subset mesh pointer
00157         fvMesh* fvMeshSubsetPtr_;
00158 
00159         //- Point mapping array
00160         labelList pointMap_;
00161 
00162         //- Face mapping array
00163         labelList faceMap_;
00164 
00165         //- Cell mapping array
00166         labelList cellMap_;
00167 
00168         //- Patch mapping array
00169         labelList patchMap_;
00170 
00171 
00172     // Private Member Functions
00173 
00174         //- Disallow default bitwise copy construct
00175         fvMeshSubset(const fvMeshSubset&);
00176 
00177         //- Disallow default bitwise assignment
00178         void operator=(const fvMeshSubset&);
00179 
00180         //- Check if subset has been performed
00181         bool checkCellSubset() const;
00182 
00183         //- Mark points in Map
00184         static void markPoints(const labelList&, Map<label>&); 
00185 
00186         //- Mark points (with 0) in labelList
00187         static void markPoints(const labelList&, labelList&); 
00188 
00189         //- Adapt nCellsUsingFace for coupled faces becoming 'uncoupled'.
00190         void doCoupledPatches(labelList& nCellsUsingFace) const;
00191 
00192 public:
00193 
00194     // Constructors
00195 
00196         //- Construct given a mesh and the map of cells to subset
00197         explicit fvMeshSubset(const IOobject& io);
00198 
00199 
00200     // Destructor
00201 
00202         ~fvMeshSubset();
00203 
00204 
00205     // Member Functions
00206 
00207         // Edit
00208 
00209             //- Set the subset. Create "oldInternalFaces" patch for exposed
00210             //  internal faces (patchID==-1) or use supplied patch.
00211             //  Does not handle coupled patches correctly if only one side
00212             //  gets deleted.
00213             void setCellSubset
00214             (
00215                 const labelHashSet& globalCellMap,
00216                 const label patchID = -1
00217             );
00218 
00219             //- Set the subset from all cells with region == currentRegion.
00220             //  Create "oldInternalFaces" patch for exposed
00221             //  internal faces (patchID==-1) or use supplied patch.
00222             //  Handles coupled patches by if nessecary making coupled patch
00223             //  face part of patchID (so uncoupled)
00224             void setLargeCellSubset
00225             (
00226                 const labelList& region,
00227                 const label currentRegion,
00228                 const label patchID = -1
00229             );
00230 
00231             //- setLargeCellSubset but with labelHashSet.
00232             void setLargeCellSubset
00233             (
00234                 const labelHashSet& globalCellMap,
00235                 const label patchID = -1
00236             );
00237 
00238 
00239         // Access
00240 
00241             //- Return reference to subset mesh
00242             const fvMesh& subMesh() const;
00243 
00244             //- Return point map
00245             const labelList& pointMap() const;
00246 
00247             //- Return face map
00248             const labelList& faceMap() const;
00249 
00250             //- Return cell map
00251             const labelList& cellMap() const;
00252 
00253             //- Return patch map
00254             const labelList& patchMap() const;
00255 
00256 
00257         // Field mapping
00258 
00259             //- Map volume field
00260             template<class Type>
00261             tmp<GeometricField<Type, fvPatchField, volMesh> > interpolate
00262             (
00263                 const GeometricField<Type, fvPatchField, volMesh>&
00264             ) const;
00265 
00266             //- Map surface field
00267             template<class Type>
00268             tmp<GeometricField<Type, fvPatchField, surfaceMesh> > interpolate
00269             (
00270                 const GeometricField<Type, fvPatchField, surfaceMesh>&
00271             ) const;
00272 };
00273 
00274 
00275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00276 
00277 } // End namespace Foam
00278 
00279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00280 
00281 #ifdef NoRepository
00282 #   include "fvMeshSubsetInterpolate.C"
00283 #endif
00284 
00285 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00286 
00287 #endif
00288 
00289 // ************************************************************************* //
For further information go to www.openfoam.org