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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::addPatchCellLayer
29 
30 Description
31  Adds layers of cells to outside of polyPatch. Can optionally create
32  stand-alone extruded mesh (addToMesh=false).
33 
34  Call setRefinement with offset vector for every patch point and number
35  of layers per patch face and number of layers per patch point.
36  - offset vector should be zero for any non-manifold point and synchronised
37  on coupled points before calling this.
38  - offset vector of zero will not add any points.
39  - gets supplied the number of extruded layers both per face and per
40  point. Usually the point nlayers is the max of surrounding face nlayers.
41 
42  point nlayers:
43  - 0 : no extrusion. Any surrounding face being extruded becomes 'prism'
44  - >0 : should be max of surrounding face nlayers.
45 
46  - differing face nlayers: 'termination' : (e.g. from 2 to 4 layers) match
47  at original patch face side.
48 
49  E.g. 2 boundary faces on patches a,b. 2 layers for a, 3 for b.
50 
51  \verbatim
52  Was:
53 
54  a b <- patch of boundary face
55  +------+------+
56  | | | <- original cells
57  +------+------+
58 
59  Becomes:
60 
61  a b <- patch of boundary face
62  +------+------+
63  + +------+
64  +------+------+
65  +------+------+
66  | | | <- original cells
67  +------+------+
68  \endverbatim
69 
70 
71  - added faces get same patchID as face they are extruded from
72  - 'side' faces (i.e. on the edge of pp) get the patchID/zoneID of the
73  other patch/zone they are connected to (hopefully only 1)
74 
75 
76  E.g. 3 boundary faces on patches a,b. b gets extruded, a doesn't.
77 
78  \verbatim
79  a b b <- patch of boundary face
80  +------+------+------+
81  | | | | <- cells
82  +------+------+------+
83 
84 
85  ^ ^ <- wanted extrusion vector (none at far right)
86  a | b | b <- patch of boundary face
87  +------+------+------+
88  | | | | <- cells
89  +------+------+------+
90 
91  b
92  +------+\ b 1. prism cell added onto second b face since
93  a a| | ----\ only one side gets extruded.
94  +------+------+------+ 2. side-face gets patch a, not b.
95  | | | |
96  +------+------+------+
97  \endverbatim
98 
99 
100 SourceFiles
101  addPatchCellLayer.C
102 
103 \*---------------------------------------------------------------------------*/
104 
105 #ifndef addPatchCellLayer_H
106 #define addPatchCellLayer_H
107 
108 #include "labelList.H"
109 #include "typeInfo.H"
110 #include "labelPair.H"
111 #include "indirectPrimitivePatch.H"
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 namespace Foam
116 {
117 
118 // Forward Declarations
119 class polyMesh;
120 class polyTopoChange;
121 class mapPolyMesh;
122 class primitiveMesh;
123 class globalIndex;
125 /*---------------------------------------------------------------------------*\
126  Class addPatchCellLayer Declaration
127 \*---------------------------------------------------------------------------*/
128 
129 class addPatchCellLayer
130 {
131  // Private Data
132 
133  //- Reference to mesh
134  const polyMesh& mesh_;
135 
136  //- Add layers to existing mesh or create new mesh
137  const bool addToMesh_;
138 
139  //- For all patchpoints: list of added points (size 0 or nLayers)
140  // First point in list is one nearest to original point in patch,
141  // last one is the new point on the surface.
142  labelListList addedPoints_;
143 
144  //- For all patchfaces: list of layer faces.
145  // - empty if no face extruded
146  // - first face is original boundary face
147  // - last one is new boundary face.
148  labelListList layerFaces_;
149 
150 
151  // Private Member Functions
152 
153  //- Get the face on the other side of the edge.
154  static label nbrFace
155  (
156  const labelListList& edgeFaces,
157  const label edgeI,
158  const label faceI
159  );
160 
161  //- Add vertex to face if unique.
162  static void addVertex(const label, face&, label& fp);
163 
164  bool sameEdgeNeighbour
165  (
166  const indirectPrimitivePatch& pp,
168  const boolList& doneEdge,
169  const label thisGlobalFaceI,
170  const label nbrGlobalFaceI,
171  const label edgeI
172  ) const;
173 
174  labelPair getEdgeString
175  (
176  const indirectPrimitivePatch& pp,
178  const boolList& doneEdge,
179  const label patchFaceI,
180  const label globalFaceI
181  ) const;
182 
183 
184  //- Add face between layer-1 and layer.
185  label addSideFace
186  (
187  const indirectPrimitivePatch&,
188  const labelListList& addedCells,
189 
190  const face& newFace,
191  const label newPatchID,
192  const label newZoneI,
193  const bool newFlip,
194  const label inflateFaceI,
195 
196  const label ownFaceI,
197  const label nbrFaceI,
198  const label meshEdgeI,
199  const label layerI,
200  const label numEdgeFaces,
201  const labelList& meshFaces,
203  ) const;
204 
205  //- Extract properties from mesh face
206  static void setFaceProps
207  (
208  const polyMesh&,
209  const label,
210  label&,
211  label&,
212  bool&
213  );
214 
215  //- Extract properties from mesh face in pp edge ordering
216  static void setFaceProps
217  (
218  const polyMesh& mesh,
219  const indirectPrimitivePatch& pp,
220  const label ppEdgeI,
221  const label faceI,
222 
223  label& patchI,
224  label& zoneI,
225  bool& zoneFlip,
226  label& inflateFaceI
227  );
228 
229  //- Find internal or boundary face to get extrude properties
230  // from. zoneFlip consistent with ppEdge ordering
231  static void findZoneFace
232  (
233  const bool useInternalFaces,
234  const bool useBoundaryFaces,
235 
236  const polyMesh& mesh,
237  const indirectPrimitivePatch& pp,
238  const label ppEdgeI,
239  const labelUIndList& excludeFaces,
240  const labelList& meshFaces,
241 
242  label& inflateFaceI,
243  label& patchI,
244  label& zoneI,
245  bool& zoneFlip
246  );
247 
248  //- Mark internal and boundary edges of patch. In mesh edges
249  //- since processor might not have pp but does have edge.
250  static void markPatchEdges
251  (
252  const polyMesh& mesh,
253  const indirectPrimitivePatch& pp,
254  const labelListList& edgeGlobalFaces,
255  const labelList& meshEdges,
256 
257  bitSet& isPatchEdge,
258  bitSet& isPatchBoundaryEdge
259  );
260 
261  //- For every edge on pp return
262  // - patchEdgeToFace : face (in global indexing) to inflate from
263  // - patchEdgeToPatch : patch (only for boundary edges of pp)
264  // - patchEdgeToZone,flip : zone info
265  static void globalEdgeInfo
266  (
267  const bool zoneFromAnyFace,
268 
269  const polyMesh& mesh,
270  const globalIndex& globalFaces,
271  const labelListList& edgeGlobalFaces,
272  const indirectPrimitivePatch& pp,
273  const labelList& meshEdges,
274 
275  labelList& patchEdgeToFace, // face (in globalFaces index)
276  labelList& patchEdgeToPatch, // patch on face (or -1 for int faces)
277  labelList& patchEdgeToZone, // zone on face
278  bitSet& patchEdgeToFlip // flip orientation on face
279  );
280 
281  //- No copy construct
282  addPatchCellLayer(const addPatchCellLayer&) = delete;
283 
284  //- No copy assignment
285  void operator=(const addPatchCellLayer&) = delete;
286 
287 
288 public:
289 
290  //- Runtime type information
291  ClassName("addPatchCellLayer");
292 
293 
294  // Constructors
295 
296  //- Construct from mesh.
297  explicit addPatchCellLayer(const polyMesh&, const bool addToMesh=true);
298 
299 
300  // Member Functions
301 
302  // Access
303 
304  //- Added points per patch point.
305  const labelListList& addedPoints() const
306  {
307  return addedPoints_;
308  }
309 
310  //- Layer faces per patch face. See above.
311  const labelListList& layerFaces() const
312  {
313  return layerFaces_;
314  }
315 
316  //- Helper: get added cells per patch face.
317  // addedCells[patchFace] is list of cells added. Last element is
318  // the top cells (i.e. the boundary cell)
320  (
321  const polyMesh&,
323  );
324 
325  //- Added cells given current mesh & layerfaces.
326  labelListList addedCells() const;
327 
328 
329  // Edit
330 
331  //- Per patch edge the pp faces (in global indices) using it.
332  // Uses ListOps::uniqueEqOp to remove duplicates.
334  (
335  const polyMesh&,
336  const globalIndex& globalFaces,
338  );
339 
340  //- Determine extrude information per patch edge:
341  // - zoneID, zoneFlip :
342  // picks one of the faces that connects to
343  // the edge. For boundary edge only looks
344  // at boundary faces. For internal edge it looks at internal
345  // faces only (zoneFromAnyFace = false) or at any face
346  // (zoneFromAnyFace = true). zoneFlip is consistent with
347  // ordering of pp edge.
348  // Face selected gets stored in inflateFaceID
349  // - patchID :
350  // get patch from any boundary face connected to the
351  // edge. The patch might be a to-be-created processor patch
352  // (patchI >= mesh.boundaryMesh().size()) in which case the
353  // nbrProcToPatch, patchToNbrProc give the correspondence.
354  // nPatches is the new number of patches.
355  static void calcExtrudeInfo
356  (
357  const bool zoneFromAnyFace,
358 
359  const polyMesh&,
360  const globalIndex& globalFaces,
362  const indirectPrimitivePatch& pp,
363 
364  labelList& edgePatchID, // if extruding a patch edge
365  label& nPatches,
366  Map<label>& nbrProcToPatch,
367  Map<label>& patchToNbrProc,
368  labelList& edgeZoneID,
369  boolList& edgeFlip,
370  labelList& inflateFaceID
371  );
372 
373  //- Play commands into polyTopoChange to create layers on top
374  // of indirectPrimitivePatch (have to be outside faces).
375  // Gets displacement per patch point.
376  // - exposedPatchID : only used if creating a new mesh
377  // (addToMesh=false) gives per pp face the patch the
378  // exposed face should get.
379  // - nPointLayers : number of layers per (patch)point.
380  // - nFaceLayers : number of layers per (patch) face.
381  // - firstDisplacement : displacement per point for first
382  // layer of points (i.e. nearest to original mesh). If zero
383  // do not add point.
384  // Layer thicknesses are calculated to constant geometric
385  // expansion. Use expansionRatio 1 for constant size.
386  // Sets addedPoints_ which is per pp point a list of points
387  // added.
388  // Note: firstDisplacement has to be parallel synchronised before
389  // calling this routine. Only if all procs sharing a point
390  // get a cell should firstDisplacement be <> 0
391  // Note: cells get added from owner cells of patch faces
392  // (instead of e.g. from patch faces)
393  void setRefinement
394  (
395  const globalIndex& globalFaces,
397  const scalarField& expansionRatio,
398  const indirectPrimitivePatch& pp,
399  const bitSet& flip,
400 
401  const labelList& sidePatchID,
402  const labelList& sideZoneID,
403  const boolList& sideFlip,
404  const labelList& inflateFaceID,
405 
406  const labelList& exposedPatchID,
407  const labelList& nFaceLayers,
408  const labelList& nPointLayers,
409  const vectorField& firstLayerDisp,
410  polyTopoChange& meshMod
411  );
412 
413 
414  //- Add with constant expansion ratio and same nLayers everywhere
415  void setRefinement
416  (
417  const globalIndex& globalFaces,
419  const label nLayers,
420  const indirectPrimitivePatch& pp,
421  const labelList& sidePatchID,
422  const vectorField& overallDisplacement,
423  polyTopoChange& meshMod
424  )
425  {
427  (
428  globalFaces,
430  scalarField(pp.nPoints(), 1.0), // expansion ration
431  pp,
432  bitSet(pp.size()), // flip
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
468 // ************************************************************************* //
label nPatches
Definition: readKivaGrid.H:396
const labelListList & addedPoints() const
Added points per patch point.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
ClassName("addPatchCellLayer")
Runtime type information.
const labelListList & layerFaces() const
Layer faces per patch face. See above.
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:
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
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:61
dynamicFvMesh & mesh
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.
void setRefinement(const globalIndex &globalFaces, const labelListList &globalEdgeFaces, const scalarField &expansionRatio, const indirectPrimitivePatch &pp, const bitSet &flip, 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.
void updateMesh(const mapPolyMesh &, const labelList &faceMap, const labelList &pointMap)
Update any locally stored mesh information. Gets additional.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
A List with indirect addressing. Like IndirectList but does not store addressing. ...
Definition: faMatrix.H:56
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.
labelListList addedCells() const
Added cells given current mesh & layerfaces.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< label > labelList
A List of labels.
Definition: List.H:62
List< bool > boolList
A List of bools.
Definition: List.H:60
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.