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