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-2015 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 \*---------------------------------------------------------------------------*/
125 
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.
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.
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 
206  (
207  const indirectPrimitivePatch& pp,
209  const boolList& doneEdge,
210  const label patchFaceI,
211  const label globalFaceI
212  ) const;
213 
214 
215  //- Add face between layer-1 and layer.
217  (
218  const indirectPrimitivePatch&,
219  const labelListList& addedCells,
220 
221  const face& newFace,
222  const label newPatchID,
223  const label newZoneI,
224  const bool newFlip,
225  const label inflateFaceI,
226 
227  const label ownFaceI,
228  const label nbrFaceI,
229  const label meshEdgeI,
230  const label layerI,
231  const label numEdgeFaces,
232  const labelList& meshFaces,
234  ) const;
235 
236  //- Find patch to neighbouring processor
237  static label findProcPatch(const polyMesh&, const label nbrProcID);
238 
239  //- Extract properties from mesh face
240  static void setFaceProps
241  (
242  const polyMesh&,
243  const label,
244  label&,
245  label&,
246  bool&
247  );
248 
249  //- Extract properties from mesh face in pp edge ordering
250  static void setFaceProps
251  (
252  const polyMesh& mesh,
253  const indirectPrimitivePatch& pp,
254  const label ppEdgeI,
255  const label faceI,
256 
257  label& patchI,
258  label& zoneI,
259  bool& zoneFlip,
260  label& inflateFaceI
261  );
262 
263  //- Find internal or boundary face to get extrude properties
264  // from. zoneFlip consistent with ppEdge ordering
265  static void findZoneFace
266  (
267  const bool useInternalFaces,
268  const bool useBoundaryFaces,
269 
270  const polyMesh& mesh,
271  const indirectPrimitivePatch& pp,
272  const label ppEdgeI,
273  const UIndirectList<label>& excludeFaces,
274  const labelList& meshFaces,
275 
276  label& inflateFaceI,
277  label& patchI,
278  label& zoneI,
279  bool& zoneFlip
280  );
281 
282  //- Disallow default bitwise copy construct
284 
285  //- Disallow default bitwise assignment
286  void operator=(const addPatchCellLayer&);
287 
288 
289 public:
290 
291  //- Runtime type information
292  ClassName("addPatchCellLayer");
293 
294 
295  // Constructors
296 
297  //- Construct from mesh.
298  addPatchCellLayer(const polyMesh&, const bool addToMesh = true);
299 
300 
301  // Member Functions
302 
303 
304  // Access
305 
306  //- Added points per patch point.
307  const labelListList& addedPoints() const
308  {
309  return addedPoints_;
310  }
311 
312  //- Layer faces per patch face. See above.
313  const labelListList& layerFaces() const
314  {
315  return layerFaces_;
316  }
317 
318  //- Helper: get added cells per patch face.
319  // addedCells[patchFace] is list of cells added. Last element is
320  // the top cells (i.e. the boundary cell)
322  (
323  const polyMesh&,
325  );
326 
327  //- Added cells given current mesh & layerfaces.
328  labelListList addedCells() const;
329 
330 
331  // Edit
332 
333  //- Per patch edge the pp faces (in global indices) using it. Uses
334  // uniqueEqOp() to remove duplicates.
336  (
337  const polyMesh&,
338  const globalIndex& globalFaces,
339  const indirectPrimitivePatch& pp
340  );
341 
342  //- Determine extrude information per patch edge:
343  // - zoneID, zoneFlip :
344  // picks one of the faces that connects to
345  // the edge. For boundary edge only looks
346  // at boundary faces. For internal edge it looks at internal
347  // faces only (zoneFromAnyFace = false) or at any face
348  // (zoneFromAnyFace = true). zoneFlip is consistent with
349  // ordering of pp edge.
350  // Face selected gets stored in inflateFaceID
351  // - patchID :
352  // get patch from any boundary face connected to the
353  // edge. The patch might be a to-be-created processor patch
354  // (patchI >= mesh.boundaryMesh().size()) in which case the
355  // nbrProcToPatch, patchToNbrProc give the correspondence.
356  // nPatches is the new number of patches.
357  static void calcExtrudeInfo
358  (
359  const bool zoneFromAnyFace,
360 
361  const polyMesh&,
362  const globalIndex& globalFaces,
364  const indirectPrimitivePatch& pp,
365 
366  labelList& edgePatchID, // if extruding a patch edge
367  label& nPatches,
368  Map<label>& nbrProcToPatch,
369  Map<label>& patchToNbrProc,
370  labelList& edgeZoneID,
371  boolList& edgeFlip,
372  labelList& inflateFaceID
373  );
374 
375  //- Play commands into polyTopoChange to create layers on top
376  // of indirectPrimitivePatch (have to be outside faces).
377  // Gets displacement per patch point.
378  // - exposedPatchID : only used if creating a new mesh
379  // (addToMesh=false) gives per pp face the patch the
380  // exposed face should get.
381  // - nPointLayers : number of layers per (patch)point.
382  // - nFaceLayers : number of layers per (patch) face.
383  // - firstDisplacement : displacement per point for first
384  // layer of points (i.e. nearest to original mesh). If zero
385  // do not add point.
386  // Layer thicknesses are calculated to constant geometric
387  // expansion. Use expansionRatio 1 for constant size.
388  // Sets addedPoints_ which is per pp point a list of points
389  // added.
390  // Note: firstDisplacement has to be parallel synchronised before
391  // calling this routine. Only if all procs sharing a point
392  // get a cell should firstDisplacement be <> 0
393  // Note: cells get added from owner cells of patch faces
394  // (instead of e.g. from patch faces)
395  void setRefinement
396  (
397  const globalIndex& globalFaces,
399  const scalarField& expansionRatio,
400  const indirectPrimitivePatch& pp,
401 
402  const labelList& sidePatchID,
403  const labelList& sideZoneID,
404  const boolList& sideFlip,
405  const labelList& inflateFaceID,
406 
407  const labelList& exposedPatchID,
408  const labelList& nFaceLayers,
409  const labelList& nPointLayers,
410  const vectorField& firstLayerDisp,
411  polyTopoChange& meshMod
412  );
413 
414 
415  //- Add with constant expansion ratio and same nLayers everywhere
417  (
418  const globalIndex& globalFaces,
420  const label nLayers,
421  const indirectPrimitivePatch& pp,
422  const labelList& sidePatchID,
423  const vectorField& overallDisplacement,
424  polyTopoChange& meshMod
425  )
426  {
428  (
429  globalFaces,
431  scalarField(pp.nPoints(), 1.0), // expansion ration
432  pp,
433 
434  sidePatchID,
435  labelList(pp.nEdges(), -1), // zoneID
436  boolList(pp.nEdges(), false), // zoneFlip
437  labelList(pp.nEdges(), -1), // inflateFaceID
438 
439  labelList(0),
440  labelList(pp.size(), nLayers), // nFaceLayers
441  labelList(pp.nPoints(), nLayers), // nPointLayers
442  overallDisplacement / nLayers, // firstLayerDisp
443  meshMod
444  );
445  }
446 
447 
448  //- Update any locally stored mesh information. Gets additional
449  // map from new to old patch (since patch needs to be
450  // recreated since has to be on outside).
451  void updateMesh
452  (
453  const mapPolyMesh&,
454  const labelList& faceMap, // new to old patch faces
455  const labelList& pointMap // new to old patch points
456  );
457 };
458 
459 
460 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
461 
462 } // End namespace Foam
463 
464 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
465 
466 #endif
467 
468 // ************************************************************************* //
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:48
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:90
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
typeInfo.H
nPatches
label nPatches
Definition: readKivaGrid.H:402
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::findIndex
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
Foam::addPatchCellLayer::globalEdgeFaces
static labelListList globalEdgeFaces(const polyMesh &, const globalIndex &globalFaces, const indirectPrimitivePatch &pp)
Per patch edge the pp faces (in global indices) using it. Uses.
Definition: addPatchCellLayer.C:618
Foam::addPatchCellLayer::findProcPatch
static label findProcPatch(const polyMesh &, const label nbrProcID)
Find patch to neighbouring processor.
Definition: addPatchCellLayer.C:393
Foam::PrimitivePatch::nEdges
label nEdges() const
Return number of edges in patch.
Definition: PrimitivePatchTemplate.H:299
Foam::addPatchCellLayer::findZoneFace
static void findZoneFace(const bool useInternalFaces, const bool useBoundaryFaces, const polyMesh &mesh, const indirectPrimitivePatch &pp, const label ppEdgeI, const UIndirectList< label > &excludeFaces, const labelList &meshFaces, label &inflateFaceI, label &patchI, label &zoneI, bool &zoneFlip)
Find internal or boundary face to get extrude properties.
Definition: addPatchCellLayer.C:509
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:97
Foam::addPatchCellLayer::addSideFace
label addSideFace(const indirectPrimitivePatch &, const labelListList &addedCells, const face &newFace, const label newPatchID, const label newZoneI, const bool newFlip, const label inflateFaceI, const label ownFaceI, const label nbrFaceI, const label meshEdgeI, const label layerI, const label numEdgeFaces, const labelList &meshFaces, polyTopoChange &) const
Add face between layer-1 and layer.
Definition: addPatchCellLayer.C:227
Foam::Map< label >
Foam::addPatchCellLayer::layerFaces_
labelListList layerFaces_
For all patchfaces: list of layer faces.
Definition: addPatchCellLayer.H:178
Foam::addPatchCellLayer::addedPoints
const labelListList & addedPoints() const
Added points per patch point.
Definition: addPatchCellLayer.H:306
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::addPatchCellLayer::setFaceProps
static void setFaceProps(const polyMesh &, const label, label &, label &, bool &)
Extract properties from mesh face.
Definition: addPatchCellLayer.C:418
Foam::addPatchCellLayer::addToMesh_
const bool addToMesh_
Add layers to existing mesh or create new mesh.
Definition: addPatchCellLayer.H:167
Foam::addPatchCellLayer::addPatchCellLayer
addPatchCellLayer(const addPatchCellLayer &)
Disallow default bitwise copy construct.
Foam::addPatchCellLayer::uniqueEqOp
Definition: addPatchCellLayer.H:130
Foam::label
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
labelList.H
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::addPatchCellLayer::getEdgeString
labelPair getEdgeString(const indirectPrimitivePatch &pp, const labelListList &globalEdgeFaces, const boolList &doneEdge, const label patchFaceI, const label globalFaceI) const
Definition: addPatchCellLayer.C:122
Foam::addPatchCellLayer::addVertex
static void addVertex(const label, face &, label &fp)
Add vertex to face if unique.
Definition: addPatchCellLayer.C:71
Foam::PrimitivePatch::nPoints
label nPoints() const
Return number of points supporting patch faces.
Definition: PrimitivePatchTemplate.H:293
Foam::addPatchCellLayer
Adds layers of cells to outside of polyPatch. Can optionally create stand-alone extruded mesh (addToM...
Definition: addPatchCellLayer.H:125
Foam::addPatchCellLayer::ClassName
ClassName("addPatchCellLayer")
Runtime type information.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::addPatchCellLayer::uniqueEqOp::operator()
void operator()(labelList &x, const labelList &y) const
Definition: addPatchCellLayer.H:135
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
Foam::addPatchCellLayer::nbrFace
static label nbrFace(const labelListList &edgeFaces, const label edgeI, const label faceI)
Get the face on the other side of the edge.
Definition: addPatchCellLayer.C:51
Foam::addPatchCellLayer::updateMesh
void updateMesh(const mapPolyMesh &, const labelList &faceMap, const labelList &pointMap)
Update any locally stored mesh information. Gets additional.
Definition: addPatchCellLayer.C:1972
Foam::addPatchCellLayer::layerFaces
const labelListList & layerFaces() const
Layer faces per patch face. See above.
Definition: addPatchCellLayer.H:312
Foam::addPatchCellLayer::addedPoints_
labelListList addedPoints_
For all patchpoints: list of added points (size 0 or nLayers)
Definition: addPatchCellLayer.H:172
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::addPatchCellLayer::calcExtrudeInfo
static void calcExtrudeInfo(const bool zoneFromAnyFace, const polyMesh &, const globalIndex &globalFaces, const labelListList &globalEdgeFaces, const indirectPrimitivePatch &pp, labelList &edgePatchID, label &nPatches, Map< label > &nbrProcToPatch, Map< label > &patchToNbrProc, labelList &edgeZoneID, boolList &edgeFlip, labelList &inflateFaceID)
Determine extrude information per patch edge:
Definition: addPatchCellLayer.C:663
Foam::addPatchCellLayer::sameEdgeNeighbour
bool sameEdgeNeighbour(const indirectPrimitivePatch &pp, const labelListList &globalEdgeFaces, const boolList &doneEdge, const label thisGlobalFaceI, const label nbrGlobalFaceI, const label edgeI) const
Definition: addPatchCellLayer.C:94
Foam::addPatchCellLayer::operator=
void operator=(const addPatchCellLayer &)
Disallow default bitwise assignment.
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:106
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::addPatchCellLayer::mesh_
const polyMesh & mesh_
Reference to mesh.
Definition: addPatchCellLayer.H:164
y
scalar y
Definition: LISASMDCalcMethod1.H:14
labelPair.H
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88
Foam::addPatchCellLayer::setRefinement
void setRefinement(const globalIndex &globalFaces, const labelListList &globalEdgeFaces, const scalarField &expansionRatio, const indirectPrimitivePatch &pp, const labelList &sidePatchID, const labelList &sideZoneID, const boolList &sideFlip, const labelList &inflateFaceID, const labelList &exposedPatchID, const labelList &nFaceLayers, const labelList &nPointLayers, const vectorField &firstLayerDisp, polyTopoChange &meshMod)
Play commands into polyTopoChange to create layers on top.
Definition: addPatchCellLayer.C:1008
Foam::addPatchCellLayer::addedCells
labelListList addedCells() const
Added cells given current mesh & layerfaces.
Definition: addPatchCellLayer.C:610