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) 2011-2016 OpenFOAM Foundation
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. Can optionally create
29  stand-alone extruded mesh (addToMesh=false).
30 
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.
38 
39  point nlayers:
40  - 0 : no extrusion. Any surrounding face being extruded becomes 'prism'
41  - >0 : should be max of surrounding face nlayers.
42 
43  - differing face nlayers: 'termination' : (e.g. from 2 to 4 layers) match
44  at original patch face side.
45 
46  E.g. 2 boundary faces on patches a,b. 2 layers for a, 3 for b.
47 
48  \verbatim
49  Was:
50 
51  a b <- patch of boundary face
52  +------+------+
53  | | | <- original cells
54  +------+------+
55 
56  Becomes:
57 
58  a b <- patch of boundary face
59  +------+------+
60  + +------+
61  +------+------+
62  +------+------+
63  | | | <- original cells
64  +------+------+
65  \endverbatim
66 
67 
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/zoneID of the
70  other patch/zone they are connected to (hopefully only 1)
71 
72 
73  E.g. 3 boundary faces on patches a,b. b gets extruded, a doesn't.
74 
75  \verbatim
76  a b b <- patch of boundary face
77  +------+------+------+
78  | | | | <- cells
79  +------+------+------+
80 
81 
82  ^ ^ <- wanted extrusion vector (none at far right)
83  a | b | b <- patch of boundary face
84  +------+------+------+
85  | | | | <- cells
86  +------+------+------+
87 
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
95 
96 
97 SourceFiles
98  addPatchCellLayer.C
99 
100 \*---------------------------------------------------------------------------*/
101 
102 #ifndef addPatchCellLayer_H
103 #define addPatchCellLayer_H
104 
105 #include "labelList.H"
106 #include "typeInfo.H"
107 #include "labelPair.H"
108 #include "indirectPrimitivePatch.H"
109 
110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
111 
112 namespace Foam
113 {
114 
115 // Forward declaration of classes
116 class polyMesh;
117 class polyTopoChange;
118 class mapPolyMesh;
119 class primitiveMesh;
120 class globalIndex;
121 
122 /*---------------------------------------------------------------------------*\
123  Class addPatchCellLayer Declaration
124 \*---------------------------------------------------------------------------*/
126 class addPatchCellLayer
127 {
128  // Private classes
129 
130  // To combineReduce a labelList. Filters out duplicates.
131  class uniqueEqOp
132  {
133 
134  public:
135 
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  };
159 
160 
161 
162  // Private data
163 
164  //- Reference to mesh
165  const polyMesh& mesh_;
166 
167  //- Add layers to existing mesh or create new mesh
168  const bool addToMesh_;
169 
170  //- For all patchpoints: list of added points (size 0 or nLayers)
171  // First point in list is one nearest to original point in patch,
172  // last one is the new point on the surface.
173  labelListList addedPoints_;
174 
175  //- For all patchfaces: list of layer faces.
176  // - empty if no face extruded
177  // - first face is original boundary face
178  // - last one is new boundary face.
179  labelListList layerFaces_;
180 
181 
182  // Private Member Functions
183 
184  //- Get the face on the other side of the edge.
185  static label nbrFace
186  (
187  const labelListList& edgeFaces,
188  const label edgeI,
189  const label facei
190  );
191 
192  //- Add vertex to face if unique.
193  static void addVertex(const label, face&, label& fp);
194 
195  bool sameEdgeNeighbour
196  (
197  const indirectPrimitivePatch& pp,
199  const boolList& doneEdge,
200  const label thisGlobalFacei,
201  const label nbrGlobalFacei,
202  const label edgeI
203  ) const;
204 
205  labelPair getEdgeString
206  (
207  const indirectPrimitivePatch& pp,
208  const labelListList& globalEdgeFaces,
209  const boolList& doneEdge,
210  const label patchFacei,
211  const label globalFacei
212  ) const;
213 
214 
215  //- Add face between layer-1 and layer.
216  label addSideFace
217  (
218  const indirectPrimitivePatch&,
219  const labelListList& addedCells,
220 
221  const face& newFace,
222  const label newPatchID,
223 
224  const label ownFacei,
225  const label nbrFacei,
226  const label meshEdgeI,
227  const label layerI,
228  const label numEdgeFaces,
229  const labelList& meshFaces,
231  ) const;
232 
233  //- Find patch to neighbouring processor
234  static label findProcPatch(const polyMesh&, const label nbrProcID);
235 
236  //- Extract properties from mesh face
237  static void setFaceProps
238  (
239  const polyMesh&,
240  const label,
241  label&,
242  label&,
243  bool&
244  );
245 
246  //- Disallow default bitwise copy construct
248 
249  //- Disallow default bitwise assignment
250  void operator=(const addPatchCellLayer&);
251 
252 
253 public:
254 
255  //- Runtime type information
256  ClassName("addPatchCellLayer");
257 
258 
259  // Constructors
260 
261  //- Construct from mesh.
262  addPatchCellLayer(const polyMesh&, const bool addToMesh = true);
263 
264 
265  // Member Functions
266 
267 
268  // Access
269 
270  //- Added points per patch point.
271  const labelListList& addedPoints() const
272  {
273  return addedPoints_;
274  }
275 
276  //- Layer faces per patch face. See above.
277  const labelListList& layerFaces() const
278  {
279  return layerFaces_;
280  }
281 
282  //- Helper: get added cells per patch face.
283  // addedCells[patchFace] is list of cells added. Last element is
284  // the top cells (i.e. the boundary cell)
286  (
287  const polyMesh&,
289  );
290 
291  //- Added cells given current mesh & layerfaces.
292  labelListList addedCells() const;
293 
294 
295  // Edit
296 
297  //- Per patch edge the pp faces (in global indices) using it. Uses
298  // uniqueEqOp() to remove duplicates.
300  (
301  const polyMesh&,
302  const globalIndex& globalFaces,
303  const indirectPrimitivePatch& pp
304  );
305 
306  //- Boundary edges get extruded into boundary faces. Determine patch
307  // for these faces. This might be a to-be-created processor patch
308  // (patchi >= mesh.boundaryMesh().size()) in which case the
309  // nbrProcToPatch, patchToNbrProc give the correspondence. nPatches
310  // is the new number of patches.
311  static void calcSidePatch
312  (
313  const polyMesh&,
314  const globalIndex& globalFaces,
315  const labelListList& globalEdgeFaces,
316  const indirectPrimitivePatch& pp,
317 
318  labelList& sidePatchID,
319  label& nPatches,
320  Map<label>& nbrProcToPatch,
321  Map<label>& patchToNbrProc
322  );
323 
324  //- Play commands into polyTopoChange to create layers on top
325  // of indirectPrimitivePatch (have to be outside faces).
326  // Gets displacement per patch point.
327  // - exposedPatchID : only used if creating a new mesh
328  // (addToMesh=false) gives per pp face the patch the
329  // exposed face should get.
330  // - nPointLayers : number of layers per (patch)point.
331  // - nFaceLayers : number of layers per (patch) face.
332  // - firstDisplacement : displacement per point for first
333  // layer of points (i.e. nearest to original mesh). If zero
334  // do not add point.
335  // Layer thicknesses are calculated to constant geometric
336  // expansion. Use expansionRatio 1 for constant size.
337  // Sets addedPoints_ which is per pp point a list of points
338  // added.
339  // Note: firstDisplacement has to be parallel synchronised before
340  // calling this routine. Only if all procs sharing a point
341  // get a cell should firstDisplacement be <> 0
342  // Note: cells get added from owner cells of patch faces
343  // (instead of e.g. from patch faces)
344  void setRefinement
345  (
346  const globalIndex& globalFaces,
347  const labelListList& globalEdgeFaces,
348  const scalarField& expansionRatio,
349  const indirectPrimitivePatch& pp,
350  const labelList& sidePatchID,
351  const labelList& exposedPatchID,
352  const labelList& nFaceLayers,
353  const labelList& nPointLayers,
354  const vectorField& firstLayerDisp,
355  polyTopoChange& meshMod
356  );
357 
358 
359  //- Add with constant expansion ratio and same nLayers everywhere
361  (
362  const globalIndex& globalFaces,
363  const labelListList& globalEdgeFaces,
364  const label nLayers,
365  const indirectPrimitivePatch& pp,
366  const labelList& sidePatchID,
367  const vectorField& overallDisplacement,
368  polyTopoChange& meshMod
369  )
370  {
372  (
373  globalFaces,
374  globalEdgeFaces,
375  scalarField(pp.nPoints(), 1.0), // expansion ration
376  pp,
377  sidePatchID,
378  labelList(0),
379  labelList(pp.size(), nLayers), // nFaceLayers
380  labelList(pp.nPoints(), nLayers), // nPointLayers
381  overallDisplacement / nLayers, // firstLayerDisp
382  meshMod
383  );
384  }
385 
386 
387  //- Update any locally stored mesh information. Gets additional
388  // map from new to old patch (since patch needs to be
389  // recreated since has to be on outside).
390  void updateMesh
391  (
392  const mapPolyMesh&,
393  const labelList& faceMap, // new to old patch faces
394  const labelList& pointMap // new to old patch points
395  );
396 };
397 
398 
399 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
400 
401 } // End namespace Foam
402 
403 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
404 
405 #endif
406 
407 // ************************************************************************* //
label nPatches
Definition: readKivaGrid.H:402
label nPoints() const
Return number of points supporting patch faces.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:313
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
ClassName("addPatchCellLayer")
Runtime type information.
const labelListList & addedPoints() const
Added points per patch point.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
scalar y
A list of faces which address into the list of points.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
Adds layers of cells to outside of polyPatch. Can optionally create stand-alone extruded mesh (addToM...
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
List< label > labelList
A List of labels.
Definition: labelList.H:56
labelListList addedCells() const
Added cells given current mesh & layerfaces.
const labelListList & layerFaces() const
Layer faces per patch face. See above.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
void updateMesh(const mapPolyMesh &, const labelList &faceMap, const labelList &pointMap)
Update any locally stored mesh information. Gets additional.
void setSize(const label)
Reset size of List.
Definition: List.C:295
Direct mesh changes based on v1.3 polyTopoChange syntax.
static labelListList globalEdgeFaces(const polyMesh &, const globalIndex &globalFaces, const indirectPrimitivePatch &pp)
Per patch edge the pp faces (in global indices) using it. Uses.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
void setRefinement(const globalIndex &globalFaces, const labelListList &globalEdgeFaces, const scalarField &expansionRatio, const indirectPrimitivePatch &pp, const labelList &sidePatchID, const labelList &exposedPatchID, const labelList &nFaceLayers, const labelList &nPointLayers, const vectorField &firstLayerDisp, polyTopoChange &meshMod)
Play commands into polyTopoChange to create layers on top.
static void calcSidePatch(const polyMesh &, const globalIndex &globalFaces, const labelListList &globalEdgeFaces, const indirectPrimitivePatch &pp, labelList &sidePatchID, label &nPatches, Map< label > &nbrProcToPatch, Map< label > &patchToNbrProc)
Boundary edges get extruded into boundary faces. Determine patch.
Namespace for OpenFOAM.