initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / dynamicMesh / polyTopoChange / polyTopoChange / addPatchCellLayer.H
blob0b5caaba86f8d2b84c6f1605809ecb5925937d0b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::addPatchCellLayer
28 Description
29     Adds layers of cells to outside of polyPatch.
31     Call setRefinement with offset vector for every patch point and number
32     of layers per patch face and number of layers per patch point.
33     - offset vector should be zero for any non-manifold point and synchronised
34       on coupled points before calling this.
35     - offset vector of zero will not add any points.
36     - gets supplied the number of extruded layers both per face and per
37       point. Usually the point nlayers is the max of surrounding face nlayers.
39       point nlayers:
40        -  0 : no extrusion. Any surrounding face being extruded becomes 'prism'
41        - >0 : should be max of surrounding face nlayers.
43     - differing face nlayers: 'termination' : (e.g. from 2 to 4 layers) match
44       at original patch face side.
46         E.g. 2 boundary faces on patches a,b. 2 layers for a, 3 for b.
48     @verbatim
49         Was:
51            a      b         <- patch of boundary face
52         +------+------+
53         |      |      |     <- original cells
54         +------+------+
56         Becomes:
58            a      b         <- patch of boundary face
59         +------+------+
60         +      +------+
61         +------+------+
62         +------+------+
63         |      |      |     <- original cells
64         +------+------+
65     @endverbatim
68     - added faces get same patchID as face they are extruded from
69     - 'side' faces (i.e. on the edge of pp) get the patchID of the
70     other patch they are connected to.
73     E.g. 3 boundary faces on patches a,b. b gets extruded, a doesn't.
75     @verbatim
76            a      b      b          <- patch of boundary face
77         +------+------+------+
78         |      |      |      |      <- cells
79         +------+------+------+
82                ^      ^             <- wanted extrusion vector (none at far right)
83            a   |  b   |  b          <- patch of boundary face
84         +------+------+------+
85         |      |      |      |      <- cells
86         +------+------+------+
88                   b
89                +------+\ b          1. prism cell added onto second b face since
90            a  a|      | ----\          only one side gets extruded.
91         +------+------+------+      2. side-face gets patch a, not b.
92         |      |      |      |
93         +------+------+------+
94     @endverbatim
97 SourceFiles
98     addPatchCellLayer.C
100 \*---------------------------------------------------------------------------*/
102 #ifndef addPatchCellLayer_H
103 #define addPatchCellLayer_H
105 #include "labelList.H"
106 #include "typeInfo.H"
107 #include "labelPair.H"
108 #include "indirectPrimitivePatch.H"
110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112 namespace Foam
115 // Forward declaration of classes
116 class polyMesh;
117 class polyTopoChange;
118 class mapPolyMesh;
119 class primitiveMesh;
120 class globalIndex;
122 /*---------------------------------------------------------------------------*\
123                            Class addPatchCellLayer Declaration
124 \*---------------------------------------------------------------------------*/
126 class addPatchCellLayer
128     // Private classes
130         // To combineReduce a labelList. Filters out duplicates.
131         class uniqueEqOp
132         {
134         public:
136             void operator()(labelList& x, const labelList& y) const
137             {
138                 if (x.size() == 0)
139                 {
140                     if (y.size() > 0)
141                     {
142                         x = y;
143                     }
144                 }
145                 else
146                 {
147                     forAll(y, yi)
148                     {
149                         if (findIndex(x, y[yi]) == -1)
150                         {
151                             label sz = x.size();
152                             x.setSize(sz+1);
153                             x[sz] = y[yi];
154                         }
155                     }
156                 }
157             }
158         };
162     // Private data
164         //- Reference to mesh
165         const polyMesh& mesh_;
167         //- For all patchpoints: list of added points (size 0 or nLayers)
168         //  First point in list is one nearest to original point in patch,
169         //  last one is the new point on the surface.
170         labelListList addedPoints_;
172         //- For all patchfaces: list of layer faces.
173         //  - empty if no face extruded
174         //  - first face is original boundary face
175         //  - last one is new boundary face.
176         labelListList layerFaces_;
179     // Private Member Functions
181         //- Per patch edge the pp faces (in global indices) using it. Uses
182         //  uniqueEqOp() to remove duplicates.
183         labelListList calcGlobalEdgeFaces
184         (
185             const polyMesh& mesh,
186             const globalIndex& globalFaces,
187             const indirectPrimitivePatch& pp,
188             const labelList& meshEdges
189         );
191         //- Get the face on the other side of the edge.
192         static label nbrFace
193         (
194             const labelListList& edgeFaces,
195             const label edgeI,
196             const label faceI
197         );
199         //- Add vertex to face if unique.
200         static void addVertex(const label, face&, label& fp);
202         bool sameEdgeNeighbour
203         (
204             const indirectPrimitivePatch& pp,
205             const labelListList& globalEdgeFaces,
206             const boolList& doneEdge,
207             const label thisGlobalFaceI,
208             const label nbrGlobalFaceI,
209             const label edgeI
210         ) const;
212         labelPair getEdgeString
213         (
214             const indirectPrimitivePatch& pp,
215             const labelListList& globalEdgeFaces,
216             const boolList& doneEdge,
217             const label patchFaceI,
218             const label globalFaceI
219         ) const;
222         //- Add face between layer-1 and layer.
223         label addSideFace
224         (
225             const indirectPrimitivePatch&,
226             const labelList& patchID,
227             const labelListList& addedCells,
228             const face& newFace,
229             const label ownFaceI,
230             const label nbrFaceI,
231             const label patchEdgeI,
232             const label meshEdgeI,
233             const label layerI,
234             const label numEdgeFaces,
235             polyTopoChange&
236         ) const;
239         //- Disallow default bitwise copy construct
240         addPatchCellLayer(const addPatchCellLayer&);
242         //- Disallow default bitwise assignment
243         void operator=(const addPatchCellLayer&);
246 public:
248     //- Runtime type information
249     ClassName("addPatchCellLayer");
252     // Constructors
254         //- Construct from mesh.
255         addPatchCellLayer(const polyMesh& mesh);
258     // Member Functions
261         // Access
263             //- Added points per patch point.
264             const labelListList& addedPoints() const
265             {
266                 return addedPoints_;
267             }
269             //- Layer faces per patch face. See above.
270             const labelListList& layerFaces() const
271             {
272                 return layerFaces_;
273             }
275             //- Helper: get added cells per patch face.
276             //  addedCells[patchFace] is list of cells added. Last element is
277             //  the top cells (i.e. the boundary cell)
278             static labelListList addedCells
279             (
280                 const polyMesh&,
281                 const labelListList& layerFaces
282             );
284             //- added cells given current mesh & layerfaces.
285             labelListList addedCells() const;
288         // Edit
290             //- Play commands into polyTopoChange to create layers on top
291             //  of indirectPrimitivePatch (have to be outside faces).
292             //  Gets displacement per patch point.
293             //  - nPointLayers : number of layers per (patch)point
294             //  - nFaceLayers : number of layers per (patch) face
295             //  - firstDisplacement : displacement per point for first
296             //    layer of points. If zero do not add point.
297             //  Layer thicknesses are calculated to constant geometric
298             //  expansion. Use expansionRatio for constant size.
299             //  Sets addedPoints_ which is per pp point a list of points
300             //  added.
301             //  Note: firstDisplacement has to be parallel synchronised before
302             //        calling this routine. Only if all procs sharing a point
303             //        get a cell should firstDisplacement be <> 0
304             //  Note: cells get added from owner cells of patch faces
305             //        (instead of e.g. from patch faces)
306            void setRefinement
307            (
308                const scalarField& expansionRatio,
309                const indirectPrimitivePatch& pp,
310                const labelList& nFaceLayers,
311                const labelList& nPointLayers,
312                const vectorField& firstLayerDisp,
313                polyTopoChange& meshMod
314             );
317             //- Add with constant expansion ratio and same nLayers everywhere
318             void setRefinement
319             (
320                 const label nLayers,
321                 const indirectPrimitivePatch& pp,
322                 const vectorField& overallDisplacement,
323                 polyTopoChange& meshMod
324             )
325             {
326                 setRefinement
327                 (
328                     scalarField(pp.nPoints(), 1.0), // expansion ration
329                     pp,
330                     labelList(pp.size(), nLayers),
331                     labelList(pp.nPoints(), nLayers),
332                     overallDisplacement / nLayers,
333                     meshMod
334                 );
335             }
338             //- Update any locally stored mesh information. Gets additional
339             //  map from new to old patch (since patch needs to be
340             //  recreated since has to be on outside).
341             void updateMesh
342             (
343                 const mapPolyMesh&,
344                 const labelList& faceMap,   // new to old patch faces
345                 const labelList& pointMap   // new to old patch points
346             );
348         // Helper
350             //- Per patch edge the corresponding mesh edge
351             static labelList calcMeshEdges
352             (
353                 const primitiveMesh& mesh,
354                 const indirectPrimitivePatch&
355             );
359 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361 } // End namespace Foam
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365 #endif
367 // ************************************************************************* //