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

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-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::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 "pointMesh.H"
00060 #include "fvPatchFieldMapper.H"
00061 #include "pointPatchFieldMapper.H"
00062 #include "GeometricField.H"
00063 #include "HashSet.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 
00078 public:
00079 
00080     //- Patch-field subset interpolation class
00081     class patchFieldSubset
00082     :
00083         public fvPatchFieldMapper
00084     {
00085         const labelList& directAddressing_;
00086 
00087     public:
00088 
00089         // Constructors
00090 
00091             //- Construct given addressing
00092             patchFieldSubset(const labelList& directAddressing)
00093             :
00094                 directAddressing_(directAddressing)
00095             {}
00096 
00097         // Destructor
00098 
00099             virtual ~patchFieldSubset()
00100             {}
00101 
00102 
00103         // Member Functions
00104 
00105             label size() const
00106             {
00107                 return directAddressing_.size();
00108             }
00109 
00110             bool direct() const
00111             {
00112                 return true;
00113             }
00114 
00115             const unallocLabelList& directAddressing() const
00116             {
00117                 return directAddressing_;
00118             }
00119     };
00120 
00121 
00122     //- Patch-field subset interpolation class
00123     class pointPatchFieldSubset
00124     :
00125         public pointPatchFieldMapper
00126     {
00127         const labelList& directAddressing_;
00128 
00129     public:
00130 
00131         // Constructors
00132 
00133             //- Construct given addressing
00134             pointPatchFieldSubset(const labelList& directAddressing)
00135             :
00136                 directAddressing_(directAddressing)
00137             {}
00138 
00139         // Destructor
00140 
00141             virtual ~pointPatchFieldSubset()
00142             {}
00143 
00144 
00145         // Member Functions
00146 
00147             label size() const
00148             {
00149                 return directAddressing_.size();
00150             }
00151 
00152             bool direct() const
00153             {
00154                 return true;
00155             }
00156 
00157             const unallocLabelList& directAddressing() const
00158             {
00159                 return directAddressing_;
00160             }
00161     };
00162 
00163 
00164 private:
00165 
00166     // Private data
00167 
00168         //- Mesh to subset from
00169         const fvMesh& baseMesh_;
00170 
00171         //- Subset mesh pointer
00172         autoPtr<fvMesh> fvMeshSubsetPtr_;
00173 
00174         //- Point mapping array
00175         labelList pointMap_;
00176 
00177         //- Face mapping array
00178         labelList faceMap_;
00179 
00180         //- Cell mapping array
00181         labelList cellMap_;
00182 
00183         //- Patch mapping array
00184         labelList patchMap_;
00185 
00186 
00187     // Private Member Functions
00188 
00189         //- Check if subset has been performed
00190         bool checkCellSubset() const;
00191 
00192         //- Mark points in Map
00193         static void markPoints(const labelList&, Map<label>&); 
00194 
00195         //- Mark points (with 0) in labelList
00196         static void markPoints(const labelList&, labelList&); 
00197 
00198         //- Adapt nCellsUsingFace for coupled faces becoming 'uncoupled'.
00199         void doCoupledPatches
00200         (
00201             const bool syncPar,
00202             labelList& nCellsUsingFace
00203         ) const;
00204 
00205         //- Subset of subset
00206         static labelList subset
00207         (
00208             const label nElems,
00209             const labelList& selectedElements,
00210             const labelList& subsetMap
00211         );
00212 
00213         //- Create zones for submesh
00214         void subsetZones();
00215 
00216         //- Disallow default bitwise copy construct
00217         fvMeshSubset(const fvMeshSubset&);
00218 
00219         //- Disallow default bitwise assignment
00220         void operator=(const fvMeshSubset&);
00221 
00222 public:
00223 
00224     // Constructors
00225 
00226         //- Construct given a mesh to subset
00227         explicit fvMeshSubset(const fvMesh&);
00228 
00229 
00230     // Member Functions
00231 
00232         // Edit
00233 
00234             //- Set the subset. Create "oldInternalFaces" patch for exposed
00235             //  internal faces (patchID==-1) or use supplied patch.
00236             //  Does not handle coupled patches correctly if only one side
00237             //  gets deleted.
00238             void setCellSubset
00239             (
00240                 const labelHashSet& globalCellMap,
00241                 const label patchID = -1
00242             );
00243 
00244             //- Set the subset from all cells with region == currentRegion.
00245             //  Create "oldInternalFaces" patch for exposed
00246             //  internal faces (patchID==-1) or use supplied patch.
00247             //  Handles coupled patches by if nessecary making coupled patch
00248             //  face part of patchID (so uncoupled)
00249             void setLargeCellSubset
00250             (
00251                 const labelList& region,
00252                 const label currentRegion,
00253                 const label patchID = -1,
00254                 const bool syncCouples = true
00255             );
00256 
00257             //- setLargeCellSubset but with labelHashSet.
00258             void setLargeCellSubset
00259             (
00260                 const labelHashSet& globalCellMap,
00261                 const label patchID = -1,
00262                 const bool syncPar = true
00263             );
00264 
00265 
00266         // Access
00267 
00268             //- Original mesh
00269             const fvMesh& baseMesh() const
00270             {
00271                 return baseMesh_;
00272             }
00273 
00274             //- Return reference to subset mesh
00275             const fvMesh& subMesh() const;
00276 
00277             fvMesh& subMesh();
00278 
00279             //- Return point map
00280             const labelList& pointMap() const;
00281 
00282             //- Return face map
00283             const labelList& faceMap() const;
00284 
00285             //- Return cell map
00286             const labelList& cellMap() const;
00287 
00288             //- Return patch map
00289             const labelList& patchMap() const;
00290 
00291 
00292         // Field mapping
00293 
00294             //- Map volume field
00295             template<class Type>
00296             static tmp<GeometricField<Type, fvPatchField, volMesh> >
00297             interpolate
00298             (
00299                 const GeometricField<Type, fvPatchField, volMesh>&,
00300                 const fvMesh& sMesh,
00301                 const labelList& patchMap,
00302                 const labelList& cellMap,
00303                 const labelList& faceMap
00304             );
00305 
00306             template<class Type>
00307             tmp<GeometricField<Type, fvPatchField, volMesh> >
00308             interpolate
00309             (
00310                 const GeometricField<Type, fvPatchField, volMesh>&
00311             ) const;
00312 
00313             //- Map surface field
00314             template<class Type>
00315             static tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00316             interpolate
00317             (
00318                 const GeometricField<Type, fvsPatchField, surfaceMesh>&,
00319                 const fvMesh& sMesh,
00320                 const labelList& patchMap,
00321                 const labelList& faceMap
00322             );
00323 
00324             template<class Type>
00325             tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00326             interpolate
00327             (
00328                 const GeometricField<Type, fvsPatchField, surfaceMesh>&
00329             ) const;
00330 
00331             //- Map point field
00332             template<class Type>
00333             static tmp<GeometricField<Type, pointPatchField, pointMesh> >
00334             interpolate
00335             (
00336                 const GeometricField<Type, pointPatchField, pointMesh>&,
00337                 const pointMesh& sMesh,
00338                 const labelList& patchMap,
00339                 const labelList& pointMap
00340             );
00341 
00342             template<class Type>
00343             tmp<GeometricField<Type, pointPatchField, pointMesh> >
00344             interpolate
00345             (
00346                 const GeometricField<Type, pointPatchField, pointMesh>&
00347             ) const;
00348 };
00349 
00350 
00351 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00352 
00353 } // End namespace Foam
00354 
00355 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00356 
00357 #ifdef NoRepository
00358 #   include "fvMeshSubsetInterpolate.C"
00359 #endif
00360 
00361 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00362 
00363 #endif
00364 
00365 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd