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

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-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::fvMeshSubset
00026 
00027 Description
00028     Post-processing mesh subset tool.  Given the original mesh and the
00029     list of selected cells, it creates the mesh consisting only of the
00030     desired cells, with the mapping list for points, faces, and cells.
00031 
00032     Puts all exposed internal faces into either
00033     - a user supplied patch
00034     - a newly created patch "oldInternalFaces"
00035 
00036     - setCellSubset is for small subsets. Uses Maps to minimize memory.
00037     - setLargeCellSubset is for largish subsets (>10% of mesh).
00038       Uses labelLists instead.
00039 
00040     - setLargeCellSubset does coupled patch subsetting as well. If it detects
00041       a face on a coupled patch 'losing' its neighbour it will move the
00042       face into the oldInternalFaces patch.
00043 
00044     - if a user supplied patch is used the mapping becomes a problem.
00045     Do the new faces get the value of the internal face they came from?
00046     What if e.g. the user supplied patch is a fixedValue 0? So for now
00047     they get the face of existing patch face 0.
00048 
00049 SourceFiles
00050     fvMeshSubset.C
00051 
00052 \*---------------------------------------------------------------------------*/
00053 
00054 #ifndef fvMeshSubset_H
00055 #define fvMeshSubset_H
00056 
00057 #include <finiteVolume/fvMesh.H>
00058 #include <OpenFOAM/pointMesh.H>
00059 #include <finiteVolume/fvPatchFieldMapper.H>
00060 #include <OpenFOAM/pointPatchFieldMapper.H>
00061 #include <OpenFOAM/GeometricField.H>
00062 #include <OpenFOAM/HashSet.H>
00063 #include <finiteVolume/surfaceMesh.H>
00064 
00065 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00066 
00067 namespace Foam
00068 {
00069 
00070 /*---------------------------------------------------------------------------*\
00071                         Class fvMeshSubset Declaration
00072 \*---------------------------------------------------------------------------*/
00073 
00074 class fvMeshSubset
00075 {
00076 
00077 public:
00078 
00079     //- Patch-field subset interpolation class
00080     class patchFieldSubset
00081     :
00082         public fvPatchFieldMapper
00083     {
00084         const labelList& directAddressing_;
00085 
00086     public:
00087 
00088         // Constructors
00089 
00090             //- Construct given addressing
00091             patchFieldSubset(const labelList& directAddressing)
00092             :
00093                 directAddressing_(directAddressing)
00094             {}
00095 
00096         // Destructor
00097 
00098             virtual ~patchFieldSubset()
00099             {}
00100 
00101 
00102         // Member Functions
00103 
00104             label size() const
00105             {
00106                 return directAddressing_.size();
00107             }
00108 
00109             bool direct() const
00110             {
00111                 return true;
00112             }
00113 
00114             const unallocLabelList& directAddressing() const
00115             {
00116                 return directAddressing_;
00117             }
00118     };
00119 
00120 
00121     //- Patch-field subset interpolation class
00122     class pointPatchFieldSubset
00123     :
00124         public pointPatchFieldMapper
00125     {
00126         const labelList& directAddressing_;
00127 
00128     public:
00129 
00130         // Constructors
00131 
00132             //- Construct given addressing
00133             pointPatchFieldSubset(const labelList& directAddressing)
00134             :
00135                 directAddressing_(directAddressing)
00136             {}
00137 
00138         // Destructor
00139 
00140             virtual ~pointPatchFieldSubset()
00141             {}
00142 
00143 
00144         // Member Functions
00145 
00146             label size() const
00147             {
00148                 return directAddressing_.size();
00149             }
00150 
00151             bool direct() const
00152             {
00153                 return true;
00154             }
00155 
00156             const unallocLabelList& directAddressing() const
00157             {
00158                 return directAddressing_;
00159             }
00160     };
00161 
00162 
00163 private:
00164 
00165     // Private data
00166 
00167         //- Mesh to subset from
00168         const fvMesh& baseMesh_;
00169 
00170         //- Subset mesh pointer
00171         autoPtr<fvMesh> fvMeshSubsetPtr_;
00172 
00173         //- Point mapping array
00174         labelList pointMap_;
00175 
00176         //- Face mapping array
00177         labelList faceMap_;
00178 
00179         //- Cell mapping array
00180         labelList cellMap_;
00181 
00182         //- Patch mapping array
00183         labelList patchMap_;
00184 
00185 
00186     // Private Member Functions
00187 
00188         //- Check if subset has been performed
00189         bool checkCellSubset() const;
00190 
00191         //- Mark points in Map
00192         static void markPoints(const labelList&, Map<label>&); 
00193 
00194         //- Mark points (with 0) in labelList
00195         static void markPoints(const labelList&, labelList&); 
00196 
00197         //- Adapt nCellsUsingFace for coupled faces becoming 'uncoupled'.
00198         void doCoupledPatches
00199         (
00200             const bool syncPar,
00201             labelList& nCellsUsingFace
00202         ) const;
00203 
00204         //- Subset of subset
00205         static labelList subset
00206         (
00207             const label nElems,
00208             const labelList& selectedElements,
00209             const labelList& subsetMap
00210         );
00211 
00212         //- Create zones for submesh
00213         void subsetZones();
00214 
00215         //- Disallow default bitwise copy construct
00216         fvMeshSubset(const fvMeshSubset&);
00217 
00218         //- Disallow default bitwise assignment
00219         void operator=(const fvMeshSubset&);
00220 
00221 public:
00222 
00223     // Constructors
00224 
00225         //- Construct given a mesh to subset
00226         explicit fvMeshSubset(const fvMesh&);
00227 
00228 
00229     // Member Functions
00230 
00231         // Edit
00232 
00233             //- Set the subset. Create "oldInternalFaces" patch for exposed
00234             //  internal faces (patchID==-1) or use supplied patch.
00235             //  Does not handle coupled patches correctly if only one side
00236             //  gets deleted.
00237             void setCellSubset
00238             (
00239                 const labelHashSet& globalCellMap,
00240                 const label patchID = -1
00241             );
00242 
00243             //- Set the subset from all cells with region == currentRegion.
00244             //  Create "oldInternalFaces" patch for exposed
00245             //  internal faces (patchID==-1) or use supplied patch.
00246             //  Handles coupled patches by if nessecary making coupled patch
00247             //  face part of patchID (so uncoupled)
00248             void setLargeCellSubset
00249             (
00250                 const labelList& region,
00251                 const label currentRegion,
00252                 const label patchID = -1,
00253                 const bool syncCouples = true
00254             );
00255 
00256             //- setLargeCellSubset but with labelHashSet.
00257             void setLargeCellSubset
00258             (
00259                 const labelHashSet& globalCellMap,
00260                 const label patchID = -1,
00261                 const bool syncPar = true
00262             );
00263 
00264 
00265         // Access
00266 
00267             //- Original mesh
00268             const fvMesh& baseMesh() const
00269             {
00270                 return baseMesh_;
00271             }
00272 
00273             //- Return reference to subset mesh
00274             const fvMesh& subMesh() const;
00275 
00276             fvMesh& subMesh();
00277 
00278             //- Return point map
00279             const labelList& pointMap() const;
00280 
00281             //- Return face map
00282             const labelList& faceMap() const;
00283 
00284             //- Return cell map
00285             const labelList& cellMap() const;
00286 
00287             //- Return patch map
00288             const labelList& patchMap() const;
00289 
00290 
00291         // Field mapping
00292 
00293             //- Map volume field
00294             template<class Type>
00295             static tmp<GeometricField<Type, fvPatchField, volMesh> >
00296             interpolate
00297             (
00298                 const GeometricField<Type, fvPatchField, volMesh>&,
00299                 const fvMesh& sMesh,
00300                 const labelList& patchMap,
00301                 const labelList& cellMap,
00302                 const labelList& faceMap
00303             );
00304 
00305             template<class Type>
00306             tmp<GeometricField<Type, fvPatchField, volMesh> >
00307             interpolate
00308             (
00309                 const GeometricField<Type, fvPatchField, volMesh>&
00310             ) const;
00311 
00312             //- Map surface field
00313             template<class Type>
00314             static tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00315             interpolate
00316             (
00317                 const GeometricField<Type, fvsPatchField, surfaceMesh>&,
00318                 const fvMesh& sMesh,
00319                 const labelList& patchMap,
00320                 const labelList& faceMap
00321             );
00322 
00323             template<class Type>
00324             tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00325             interpolate
00326             (
00327                 const GeometricField<Type, fvsPatchField, surfaceMesh>&
00328             ) const;
00329 
00330             //- Map point field
00331             template<class Type>
00332             static tmp<GeometricField<Type, pointPatchField, pointMesh> >
00333             interpolate
00334             (
00335                 const GeometricField<Type, pointPatchField, pointMesh>&,
00336                 const pointMesh& sMesh,
00337                 const labelList& patchMap,
00338                 const labelList& pointMap
00339             );
00340 
00341             template<class Type>
00342             tmp<GeometricField<Type, pointPatchField, pointMesh> >
00343             interpolate
00344             (
00345                 const GeometricField<Type, pointPatchField, pointMesh>&
00346             ) const;
00347 };
00348 
00349 
00350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00351 
00352 } // End namespace Foam
00353 
00354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00355 
00356 #ifdef NoRepository
00357 #   include "fvMeshSubsetInterpolate.C"
00358 #endif
00359 
00360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00361 
00362 #endif
00363 
00364 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines