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

addPatchCellLayer.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::addPatchCellLayer
00027 
00028 Description
00029     Adds layers of cells to outside of polyPatch.
00030 
00031     Call setRefinement with offset vector for every patch point and number
00032     of layers per patch face and number of layers per patch point.
00033     - offset vector should be zero for any non-manifold point and synchronised
00034       on coupled points before calling this.
00035     - offset vector of zero will not add any points.
00036     - gets supplied the number of extruded layers both per face and per
00037       point. Usually the point nlayers is the max of surrounding face nlayers.
00038 
00039       point nlayers:
00040        -  0 : no extrusion. Any surrounding face being extruded becomes 'prism'
00041        - >0 : should be max of surrounding face nlayers.
00042 
00043     - differing face nlayers: 'termination' : (e.g. from 2 to 4 layers) match
00044       at original patch face side.
00045 
00046         E.g. 2 boundary faces on patches a,b. 2 layers for a, 3 for b.
00047 
00048     @verbatim
00049         Was:
00050 
00051            a      b         <- patch of boundary face
00052         +------+------+
00053         |      |      |     <- original cells
00054         +------+------+
00055 
00056         Becomes:
00057 
00058            a      b         <- patch of boundary face
00059         +------+------+
00060         +      +------+
00061         +------+------+
00062         +------+------+
00063         |      |      |     <- original cells
00064         +------+------+
00065     @endverbatim
00066 
00067 
00068     - added faces get same patchID as face they are extruded from
00069     - 'side' faces (i.e. on the edge of pp) get the patchID of the
00070     other patch they are connected to.
00071 
00072 
00073     E.g. 3 boundary faces on patches a,b. b gets extruded, a doesn't.
00074 
00075     @verbatim
00076            a      b      b          <- patch of boundary face
00077         +------+------+------+
00078         |      |      |      |      <- cells
00079         +------+------+------+
00080 
00081 
00082                ^      ^             <- wanted extrusion vector (none at far right)
00083            a   |  b   |  b          <- patch of boundary face
00084         +------+------+------+
00085         |      |      |      |      <- cells
00086         +------+------+------+
00087 
00088                   b
00089                +------+\ b          1. prism cell added onto second b face since
00090            a  a|      | ----\          only one side gets extruded.
00091         +------+------+------+      2. side-face gets patch a, not b.
00092         |      |      |      |
00093         +------+------+------+
00094     @endverbatim
00095 
00096 
00097 SourceFiles
00098     addPatchCellLayer.C
00099 
00100 \*---------------------------------------------------------------------------*/
00101 
00102 #ifndef addPatchCellLayer_H
00103 #define addPatchCellLayer_H
00104 
00105 #include "labelList.H"
00106 #include "typeInfo.H"
00107 #include "labelPair.H"
00108 #include "indirectPrimitivePatch.H"
00109 
00110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00111 
00112 namespace Foam
00113 {
00114 
00115 // Forward declaration of classes
00116 class polyMesh;
00117 class polyTopoChange;
00118 class mapPolyMesh;
00119 class primitiveMesh;
00120 class globalIndex;
00121 
00122 /*---------------------------------------------------------------------------*\
00123                            Class addPatchCellLayer Declaration
00124 \*---------------------------------------------------------------------------*/
00125 
00126 class addPatchCellLayer
00127 {
00128     // Private classes
00129 
00130         // To combineReduce a labelList. Filters out duplicates.
00131         class uniqueEqOp
00132         {
00133 
00134         public:
00135 
00136             void operator()(labelList& x, const labelList& y) const
00137             {
00138                 if (x.empty())
00139                 {
00140                     if (y.size())
00141                     {
00142                         x = y;
00143                     }
00144                 }
00145                 else
00146                 {
00147                     forAll(y, yi)
00148                     {
00149                         if (findIndex(x, y[yi]) == -1)
00150                         {
00151                             label sz = x.size();
00152                             x.setSize(sz+1);
00153                             x[sz] = y[yi];
00154                         }
00155                     }
00156                 }
00157             }
00158         };
00159 
00160 
00161 
00162     // Private data
00163 
00164         //- Reference to mesh
00165         const polyMesh& mesh_;
00166 
00167         //- For all patchpoints: list of added points (size 0 or nLayers)
00168         //  First point in list is one nearest to original point in patch,
00169         //  last one is the new point on the surface.
00170         labelListList addedPoints_;
00171 
00172         //- For all patchfaces: list of layer faces.
00173         //  - empty if no face extruded
00174         //  - first face is original boundary face
00175         //  - last one is new boundary face.
00176         labelListList layerFaces_;
00177 
00178 
00179     // Private Member Functions
00180 
00181         //- Per patch edge the pp faces (in global indices) using it. Uses
00182         //  uniqueEqOp() to remove duplicates.
00183         labelListList calcGlobalEdgeFaces
00184         (
00185             const polyMesh& mesh,
00186             const globalIndex& globalFaces,
00187             const indirectPrimitivePatch& pp,
00188             const labelList& meshEdges
00189         );
00190 
00191         //- Get the face on the other side of the edge.
00192         static label nbrFace
00193         (
00194             const labelListList& edgeFaces,
00195             const label edgeI,
00196             const label faceI
00197         );
00198 
00199         //- Add vertex to face if unique.
00200         static void addVertex(const label, face&, label& fp);
00201 
00202         bool sameEdgeNeighbour
00203         (
00204             const indirectPrimitivePatch& pp,
00205             const labelListList& globalEdgeFaces,
00206             const boolList& doneEdge,
00207             const label thisGlobalFaceI,
00208             const label nbrGlobalFaceI,
00209             const label edgeI
00210         ) const;
00211 
00212         labelPair getEdgeString
00213         (
00214             const indirectPrimitivePatch& pp,
00215             const labelListList& globalEdgeFaces,
00216             const boolList& doneEdge,
00217             const label patchFaceI,
00218             const label globalFaceI
00219         ) const;
00220 
00221 
00222         //- Add face between layer-1 and layer.
00223         label addSideFace
00224         (
00225             const indirectPrimitivePatch&,
00226             const labelList& patchID,
00227             const labelListList& addedCells,
00228             const face& newFace,
00229             const label ownFaceI,
00230             const label nbrFaceI,
00231             const label patchEdgeI,
00232             const label meshEdgeI,
00233             const label layerI,
00234             const label numEdgeFaces,
00235             const labelList& meshFaces,
00236             polyTopoChange&
00237         ) const;
00238 
00239 
00240         //- Disallow default bitwise copy construct
00241         addPatchCellLayer(const addPatchCellLayer&);
00242 
00243         //- Disallow default bitwise assignment
00244         void operator=(const addPatchCellLayer&);
00245 
00246 
00247 public:
00248 
00249     //- Runtime type information
00250     ClassName("addPatchCellLayer");
00251 
00252 
00253     // Constructors
00254 
00255         //- Construct from mesh.
00256         addPatchCellLayer(const polyMesh& mesh);
00257 
00258 
00259     // Member Functions
00260 
00261 
00262         // Access
00263 
00264             //- Added points per patch point.
00265             const labelListList& addedPoints() const
00266             {
00267                 return addedPoints_;
00268             }
00269 
00270             //- Layer faces per patch face. See above.
00271             const labelListList& layerFaces() const
00272             {
00273                 return layerFaces_;
00274             }
00275 
00276             //- Helper: get added cells per patch face.
00277             //  addedCells[patchFace] is list of cells added. Last element is
00278             //  the top cells (i.e. the boundary cell)
00279             static labelListList addedCells
00280             (
00281                 const polyMesh&,
00282                 const labelListList& layerFaces
00283             );
00284 
00285             //- added cells given current mesh & layerfaces.
00286             labelListList addedCells() const;
00287 
00288 
00289         // Edit
00290 
00291             //- Play commands into polyTopoChange to create layers on top
00292             //  of indirectPrimitivePatch (have to be outside faces).
00293             //  Gets displacement per patch point.
00294             //  - nPointLayers : number of layers per (patch)point
00295             //  - nFaceLayers : number of layers per (patch) face
00296             //  - firstDisplacement : displacement per point for first
00297             //    layer of points (i.e. nearest to original mesh). If zero
00298             //    do not add point.
00299             //  Layer thicknesses are calculated to constant geometric
00300             //  expansion. Use expansionRatio 1 for constant size.
00301             //  Sets addedPoints_ which is per pp point a list of points
00302             //  added.
00303             //  Note: firstDisplacement has to be parallel synchronised before
00304             //        calling this routine. Only if all procs sharing a point
00305             //        get a cell should firstDisplacement be <> 0
00306             //  Note: cells get added from owner cells of patch faces
00307             //        (instead of e.g. from patch faces)
00308            void setRefinement
00309            (
00310                const scalarField& expansionRatio,
00311                const indirectPrimitivePatch& pp,
00312                const labelList& nFaceLayers,
00313                const labelList& nPointLayers,
00314                const vectorField& firstLayerDisp,
00315                polyTopoChange& meshMod
00316             );
00317 
00318 
00319             //- Add with constant expansion ratio and same nLayers everywhere
00320             void setRefinement
00321             (
00322                 const label nLayers,
00323                 const indirectPrimitivePatch& pp,
00324                 const vectorField& overallDisplacement,
00325                 polyTopoChange& meshMod
00326             )
00327             {
00328                 setRefinement
00329                 (
00330                     scalarField(pp.nPoints(), 1.0), // expansion ration
00331                     pp,
00332                     labelList(pp.size(), nLayers),
00333                     labelList(pp.nPoints(), nLayers),
00334                     overallDisplacement / nLayers,
00335                     meshMod
00336                 );
00337             }
00338 
00339 
00340             //- Update any locally stored mesh information. Gets additional
00341             //  map from new to old patch (since patch needs to be
00342             //  recreated since has to be on outside).
00343             void updateMesh
00344             (
00345                 const mapPolyMesh&,
00346                 const labelList& faceMap,   // new to old patch faces
00347                 const labelList& pointMap   // new to old patch points
00348             );
00349 
00350         // Helper
00351 
00352             //- Per patch edge the corresponding mesh edge
00353             static labelList calcMeshEdges
00354             (
00355                 const primitiveMesh& mesh,
00356                 const indirectPrimitivePatch&
00357             );
00358 };
00359 
00360 
00361 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00362 
00363 } // End namespace Foam
00364 
00365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00366 
00367 #endif
00368 
00369 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd