BUG: PointEdgeWave : n cyclics bool instead of label
[OpenFOAM-1.6.x.git] / src / dynamicMesh / polyTopoChange / polyTopoChange / addPatchCellLayer.H
blobf03d23e2144fb22c5a9f093f221ed5fd86dc4a42
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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.empty())
139                 {
140                     if (y.size())
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             const labelList& meshFaces,
236             polyTopoChange&
237         ) const;
240         //- Disallow default bitwise copy construct
241         addPatchCellLayer(const addPatchCellLayer&);
243         //- Disallow default bitwise assignment
244         void operator=(const addPatchCellLayer&);
247 public:
249     //- Runtime type information
250     ClassName("addPatchCellLayer");
253     // Constructors
255         //- Construct from mesh.
256         addPatchCellLayer(const polyMesh& mesh);
259     // Member Functions
262         // Access
264             //- Added points per patch point.
265             const labelListList& addedPoints() const
266             {
267                 return addedPoints_;
268             }
270             //- Layer faces per patch face. See above.
271             const labelListList& layerFaces() const
272             {
273                 return layerFaces_;
274             }
276             //- Helper: get added cells per patch face.
277             //  addedCells[patchFace] is list of cells added. Last element is
278             //  the top cells (i.e. the boundary cell)
279             static labelListList addedCells
280             (
281                 const polyMesh&,
282                 const labelListList& layerFaces
283             );
285             //- added cells given current mesh & layerfaces.
286             labelListList addedCells() const;
289         // Edit
291             //- Play commands into polyTopoChange to create layers on top
292             //  of indirectPrimitivePatch (have to be outside faces).
293             //  Gets displacement per patch point.
294             //  - nPointLayers : number of layers per (patch)point
295             //  - nFaceLayers : number of layers per (patch) face
296             //  - firstDisplacement : displacement per point for first
297             //    layer of points (i.e. nearest to original mesh). If zero
298             //    do not add point.
299             //  Layer thicknesses are calculated to constant geometric
300             //  expansion. Use expansionRatio 1 for constant size.
301             //  Sets addedPoints_ which is per pp point a list of points
302             //  added.
303             //  Note: firstDisplacement has to be parallel synchronised before
304             //        calling this routine. Only if all procs sharing a point
305             //        get a cell should firstDisplacement be <> 0
306             //  Note: cells get added from owner cells of patch faces
307             //        (instead of e.g. from patch faces)
308            void setRefinement
309            (
310                const scalarField& expansionRatio,
311                const indirectPrimitivePatch& pp,
312                const labelList& nFaceLayers,
313                const labelList& nPointLayers,
314                const vectorField& firstLayerDisp,
315                polyTopoChange& meshMod
316             );
319             //- Add with constant expansion ratio and same nLayers everywhere
320             void setRefinement
321             (
322                 const label nLayers,
323                 const indirectPrimitivePatch& pp,
324                 const vectorField& overallDisplacement,
325                 polyTopoChange& meshMod
326             )
327             {
328                 setRefinement
329                 (
330                     scalarField(pp.nPoints(), 1.0), // expansion ration
331                     pp,
332                     labelList(pp.size(), nLayers),
333                     labelList(pp.nPoints(), nLayers),
334                     overallDisplacement / nLayers,
335                     meshMod
336                 );
337             }
340             //- Update any locally stored mesh information. Gets additional
341             //  map from new to old patch (since patch needs to be
342             //  recreated since has to be on outside).
343             void updateMesh
344             (
345                 const mapPolyMesh&,
346                 const labelList& faceMap,   // new to old patch faces
347                 const labelList& pointMap   // new to old patch points
348             );
350         // Helper
352             //- Per patch edge the corresponding mesh edge
353             static labelList calcMeshEdges
354             (
355                 const primitiveMesh& mesh,
356                 const indirectPrimitivePatch&
357             );
361 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
363 } // End namespace Foam
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
367 #endif
369 // ************************************************************************* //