FreeFOAM The Cross-Platform CFD Toolkit
addPatchCellLayer.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::addPatchCellLayer
26 
27 Description
28  Adds layers of cells to outside of polyPatch.
29 
30  Call setRefinement with offset vector for every patch point and number
31  of layers per patch face and number of layers per patch point.
32  - offset vector should be zero for any non-manifold point and synchronised
33  on coupled points before calling this.
34  - offset vector of zero will not add any points.
35  - gets supplied the number of extruded layers both per face and per
36  point. Usually the point nlayers is the max of surrounding face nlayers.
37 
38  point nlayers:
39  - 0 : no extrusion. Any surrounding face being extruded becomes 'prism'
40  - >0 : should be max of surrounding face nlayers.
41 
42  - differing face nlayers: 'termination' : (e.g. from 2 to 4 layers) match
43  at original patch face side.
44 
45  E.g. 2 boundary faces on patches a,b. 2 layers for a, 3 for b.
46 
47  @verbatim
48  Was:
49 
50  a b <- patch of boundary face
51  +------+------+
52  | | | <- original cells
53  +------+------+
54 
55  Becomes:
56 
57  a b <- patch of boundary face
58  +------+------+
59  + +------+
60  +------+------+
61  +------+------+
62  | | | <- original cells
63  +------+------+
64  @endverbatim
65 
66 
67  - added faces get same patchID as face they are extruded from
68  - 'side' faces (i.e. on the edge of pp) get the patchID of the
69  other patch they are connected to.
70 
71 
72  E.g. 3 boundary faces on patches a,b. b gets extruded, a doesn't.
73 
74  @verbatim
75  a b b <- patch of boundary face
76  +------+------+------+
77  | | | | <- cells
78  +------+------+------+
79 
80 
81  ^ ^ <- wanted extrusion vector (none at far right)
82  a | b | b <- patch of boundary face
83  +------+------+------+
84  | | | | <- cells
85  +------+------+------+
86 
87  b
88  +------+\ b 1. prism cell added onto second b face since
89  a a| | ----\ only one side gets extruded.
90  +------+------+------+ 2. side-face gets patch a, not b.
91  | | | |
92  +------+------+------+
93  @endverbatim
94 
95 
96 SourceFiles
97  addPatchCellLayer.C
98 
99 \*---------------------------------------------------------------------------*/
100 
101 #ifndef addPatchCellLayer_H
102 #define addPatchCellLayer_H
103 
104 #include <OpenFOAM/labelList.H>
105 #include <OpenFOAM/typeInfo.H>
106 #include <OpenFOAM/labelPair.H>
108 
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110 
111 namespace Foam
112 {
113 
114 // Forward declaration of classes
115 class polyMesh;
116 class polyTopoChange;
117 class mapPolyMesh;
118 class primitiveMesh;
119 class globalIndex;
120 
121 /*---------------------------------------------------------------------------*\
122  Class addPatchCellLayer Declaration
123 \*---------------------------------------------------------------------------*/
124 
126 {
127  // Private classes
128 
129  // To combineReduce a labelList. Filters out duplicates.
130  class uniqueEqOp
131  {
132 
133  public:
134 
135  void operator()(labelList& x, const labelList& y) const
136  {
137  if (x.empty())
138  {
139  if (y.size())
140  {
141  x = y;
142  }
143  }
144  else
145  {
146  forAll(y, yi)
147  {
148  if (findIndex(x, y[yi]) == -1)
149  {
150  label sz = x.size();
151  x.setSize(sz+1);
152  x[sz] = y[yi];
153  }
154  }
155  }
156  }
157  };
158 
159 
160 
161  // Private data
162 
163  //- Reference to mesh
164  const polyMesh& mesh_;
165 
166  //- For all patchpoints: list of added points (size 0 or nLayers)
167  // First point in list is one nearest to original point in patch,
168  // last one is the new point on the surface.
169  labelListList addedPoints_;
170 
171  //- For all patchfaces: list of layer faces.
172  // - empty if no face extruded
173  // - first face is original boundary face
174  // - last one is new boundary face.
175  labelListList layerFaces_;
176 
177 
178  // Private Member Functions
179 
180  //- Per patch edge the pp faces (in global indices) using it. Uses
181  // uniqueEqOp() to remove duplicates.
182  labelListList calcGlobalEdgeFaces
183  (
184  const polyMesh& mesh,
185  const globalIndex& globalFaces,
186  const indirectPrimitivePatch& pp,
187  const labelList& meshEdges
188  );
189 
190  //- Get the face on the other side of the edge.
191  static label nbrFace
192  (
193  const labelListList& edgeFaces,
194  const label edgeI,
195  const label faceI
196  );
197 
198  //- Add vertex to face if unique.
199  static void addVertex(const label, face&, label& fp);
200 
201  bool sameEdgeNeighbour
202  (
203  const indirectPrimitivePatch& pp,
204  const labelListList& globalEdgeFaces,
205  const boolList& doneEdge,
206  const label thisGlobalFaceI,
207  const label nbrGlobalFaceI,
208  const label edgeI
209  ) const;
210 
211  labelPair getEdgeString
212  (
213  const indirectPrimitivePatch& pp,
214  const labelListList& globalEdgeFaces,
215  const boolList& doneEdge,
216  const label patchFaceI,
217  const label globalFaceI
218  ) const;
219 
220 
221  //- Add face between layer-1 and layer.
222  label addSideFace
223  (
224  const indirectPrimitivePatch&,
225  const labelList& patchID,
226  const labelListList& addedCells,
227  const face& newFace,
228  const label ownFaceI,
229  const label nbrFaceI,
230  const label patchEdgeI,
231  const label meshEdgeI,
232  const label layerI,
233  const label numEdgeFaces,
234  const labelList& meshFaces,
236  ) const;
237 
238 
239  //- Disallow default bitwise copy construct
241 
242  //- Disallow default bitwise assignment
243  void operator=(const addPatchCellLayer&);
244 
245 
246 public:
247 
248  //- Runtime type information
249  ClassName("addPatchCellLayer");
250 
251 
252  // Constructors
253 
254  //- Construct from mesh.
255  addPatchCellLayer(const polyMesh& mesh);
256 
257 
258  // Member Functions
259 
260 
261  // Access
262 
263  //- Added points per patch point.
264  const labelListList& addedPoints() const
265  {
266  return addedPoints_;
267  }
268 
269  //- Layer faces per patch face. See above.
270  const labelListList& layerFaces() const
271  {
272  return layerFaces_;
273  }
274 
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)
279  (
280  const polyMesh&,
282  );
283 
284  //- added cells given current mesh & layerfaces.
285  labelListList addedCells() const;
286 
287 
288  // Edit
289 
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 (i.e. nearest to original mesh). If zero
297  // do not add point.
298  // Layer thicknesses are calculated to constant geometric
299  // expansion. Use expansionRatio 1 for constant size.
300  // Sets addedPoints_ which is per pp point a list of points
301  // added.
302  // Note: firstDisplacement has to be parallel synchronised before
303  // calling this routine. Only if all procs sharing a point
304  // get a cell should firstDisplacement be <> 0
305  // Note: cells get added from owner cells of patch faces
306  // (instead of e.g. from patch faces)
307  void setRefinement
308  (
309  const scalarField& expansionRatio,
310  const indirectPrimitivePatch& pp,
311  const labelList& nFaceLayers,
312  const labelList& nPointLayers,
313  const vectorField& firstLayerDisp,
314  polyTopoChange& meshMod
315  );
316 
317 
318  //- Add with constant expansion ratio and same nLayers everywhere
319  void setRefinement
320  (
321  const label nLayers,
322  const indirectPrimitivePatch& pp,
323  const vectorField& overallDisplacement,
324  polyTopoChange& meshMod
325  )
326  {
328  (
329  scalarField(pp.nPoints(), 1.0), // expansion ration
330  pp,
331  labelList(pp.size(), nLayers),
332  labelList(pp.nPoints(), nLayers),
333  overallDisplacement / nLayers,
334  meshMod
335  );
336  }
337 
338 
339  //- Update any locally stored mesh information. Gets additional
340  // map from new to old patch (since patch needs to be
341  // recreated since has to be on outside).
342  void updateMesh
343  (
344  const mapPolyMesh&,
345  const labelList& faceMap, // new to old patch faces
346  const labelList& pointMap // new to old patch points
347  );
348 
349  // Helper
350 
351  //- Per patch edge the corresponding mesh edge
352  static labelList calcMeshEdges
353  (
354  const primitiveMesh& mesh,
356  );
357 };
358 
359 
360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361 
362 } // End namespace Foam
363 
364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365 
366 #endif
367 
368 // ************************ vim: set sw=4 sts=4 et: ************************ //