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,2024 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 (or inside) of polyMesh. Can optionally
32  create 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  Extrusion:
60 
61 
62  added added
63  face cell
64  ---- ----
65  a b <- patch of boundary face
66  +------+------+ 3
67  | | | 2
68  + +------+ 2
69  | | | 1
70  +------+------+ 1
71  | | | 0
72  +------+------+ 0 <- original boundary faces
73  | | | <- original cells
74  +------+------+
75 
76 
77 
78  Intrusion:
79 
80  face cell
81  ---- ----
82  a b <- patch of boundary face
83  +------+------+ 0
84  | | | 0
85  +------+------+ 1
86  | | | 1
87  + +------+ 2
88  | | | 2
89  +------+------+ 3
90  | | | <- original cells
91  +------+------+
92  \endverbatim
93 
94 
95  - 'side' faces (i.e. on the edge of pp) get the patchID/zoneID of the
96  other patch/zone they are connected to (hopefully only 1)
97 
98 
99  E.g. 3 boundary faces on patches a,b. b gets extruded, a doesn't.
100 
101  \verbatim
102  a b b <- patch of boundary face
103  +------+------+------+
104  | | | |
105  | | | | <- cells
106  | | | |
107  +------+------+------+
108 
109 
110  (shown for extrusion mode only):
111 
112 
113  ^ ^ <- wanted extrusion vector (none at far right)
114  a | b | b <- patch of boundary face
115  +------+------+------+
116  | | | | <- cells
117  +------+------+------+
118 
119  b
120  +------+\ b 1. prism cell added onto second b face since
121  a a| | ----\ only one side gets extruded.
122  +------+------+------+ 2. side-face gets patch a, not b.
123  | | | |
124  +------+------+------+
125  \endverbatim
126 
127 
128 SourceFiles
129  addPatchCellLayer.C
130 
131 \*---------------------------------------------------------------------------*/
132 
133 #ifndef addPatchCellLayer_H
134 #define addPatchCellLayer_H
135 
136 #include "labelList.H"
137 #include "typeInfo.H"
138 #include "labelPair.H"
139 #include "indirectPrimitivePatch.H"
140 
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 
143 namespace Foam
144 {
145 
146 // Forward Declarations
147 class polyMesh;
148 class polyTopoChange;
149 class mapPolyMesh;
150 class primitiveMesh;
151 class globalIndex;
153 /*---------------------------------------------------------------------------*\
154  Class addPatchCellLayer Declaration
155 \*---------------------------------------------------------------------------*/
156 
157 class addPatchCellLayer
158 {
159  // Private Data
160 
161  //- Reference to mesh
162  const polyMesh& mesh_;
163 
164  //- Add layers to existing mesh or create new mesh
165  const bool addToMesh_;
166 
167  //- Add layers to outside of mesh or to inside
168  const bool extrude_;
169 
170 
171  //- For all patchpoints: list of added points (size 0 or nLayers)
172  // First point in list is one nearest to original point in patch,
173  // last one is
174  // - extrude : the new point on the surface
175  // - intrude : the point connecting to the original cell.
176  labelListList addedPoints_;
177 
178  //- For all patchfaces: list of layer faces.
179  // - empty if no face extruded
180  // - first element is original patch face
181  // - last element is
182  // - extrude : the new boundary face
183  // - intrude : the new internal face to the original cell.
184  labelListList layerFaces_;
185 
186 
187  // Private Member Functions
188 
189  //- Get the face on the other side of the edge.
190  static label nbrFace
191  (
192  const labelListList& edgeFaces,
193  const label edgeI,
194  const label faceI
195  );
196 
197  //- Add vertex to face if unique.
198  static void addVertex(const label, face&, label& fp);
199 
200  bool sameEdgeNeighbour
201  (
202  const indirectPrimitivePatch& pp,
204  const boolList& doneEdge,
205  const label thisGlobalFaceI,
206  const label nbrGlobalFaceI,
207  const label edgeI
208  ) const;
209 
210  labelPair getEdgeString
211  (
212  const indirectPrimitivePatch& pp,
214  const boolList& doneEdge,
215  const label patchFaceI,
216  const label globalFaceI
217  ) const;
218 
219 
220  //- Add face between layer-1 and layer.
221  label addSideFace
222  (
223  const indirectPrimitivePatch&,
224  const labelListList& addedCells,
225 
226  const face& newFace,
227  const label newPatchID,
228  const label newZoneI,
229  const bool newFlip,
230  const label inflateFaceI,
231 
232  const label ownFaceI,
233  const label nbrFaceI,
234  const label meshEdgeI,
235  const label layerI,
236  const label numEdgeFaces,
237  const labelList& meshFaces,
239  ) const;
240 
241  //- Extract properties from mesh face
242  static void setFaceProps
243  (
244  const polyMesh&,
245  const label,
246  label&,
247  label&,
248  bool&
249  );
250 
251  //- Extract properties from mesh face in pp edge ordering
252  static void setFaceProps
253  (
254  const polyMesh& mesh,
255  const indirectPrimitivePatch& pp,
256  const label ppEdgeI,
257  const label faceI,
258 
259  label& patchI,
260  label& zoneI,
261  bool& zoneFlip,
262  label& inflateFaceI
263  );
264 
265  //- Mark internal and boundary edges of patch. In mesh edges
266  //- since processor might not have pp but does have edge.
267  static void markPatchEdges
268  (
269  const polyMesh& mesh,
270  const indirectPrimitivePatch& pp,
271  const labelListList& edgeGlobalFaces,
272  const labelList& meshEdges,
273 
274  bitSet& isPatchEdge,
275  bitSet& isPatchBoundaryEdge
276  );
277 
278  //- For every edge on pp return
279  // - patchEdgeToFace : face (in global indexing) to inflate from
280  // - patchEdgeToPatch : patch (only for boundary edges of pp)
281  // - patchEdgeToZone,flip : zone info
282  static void globalEdgeInfo
283  (
284  const bool zoneFromAnyFace,
285 
286  const polyMesh& mesh,
287  const globalIndex& globalFaces,
288  const labelListList& edgeGlobalFaces,
289  const indirectPrimitivePatch& pp,
290  const labelList& meshEdges,
291 
292  labelList& patchEdgeToFace, // face (in globalFaces index)
293  labelList& patchEdgeToPatch, // patch on face (or -1 for int faces)
294  labelList& patchEdgeToZone, // zone on face
295  bitSet& patchEdgeToFlip // flip orientation on face
296  );
297 
298  //- No copy construct
299  addPatchCellLayer(const addPatchCellLayer&) = delete;
300 
301  //- No copy assignment
302  void operator=(const addPatchCellLayer&) = delete;
303 
304 
305 public:
306 
307  //- Runtime type information
308  ClassName("addPatchCellLayer");
309 
310 
311  // Constructors
312 
313  //- Construct from mesh.
314  explicit addPatchCellLayer
315  (
316  const polyMesh&,
317  const bool addToMesh=true,
318  const bool extrude=true
319  );
320 
321 
322  // Member Functions
323 
324  // Access
325 
326  //- Added points per patch point.
327  const labelListList& addedPoints() const
328  {
329  return addedPoints_;
330  }
331 
332  //- Layer faces per patch face. See above.
333  const labelListList& layerFaces() const
334  {
335  return layerFaces_;
336  }
337 
338  //- Helper: get added cells per patch face.
339  // addedCells[patchFace] is list of cells added.
340  // extrude :
341  // first element : next to original cell
342  // last element : is the top cell (i.e. the boundary cell)
343  // intrude :
344  // first element : top cell
345  // last element : next to original cell
347  (
348  const polyMesh&,
350  );
351 
352  //- Added cells given current mesh & layerfaces.
353  labelListList addedCells() const;
354 
355 
356  // Edit
357 
358  //- Per patch edge the pp faces (in global indices) using it.
359  // Uses ListOps::uniqueEqOp to remove duplicates. On coupled
360  // faces only selects the one with the correct orientation/flip
361  // (assumes the orientation is opposite on a coupled face pair)
363  (
364  const polyMesh&,
365  const globalIndex& globalFaces,
366  const indirectPrimitivePatch& pp,
367  const bitSet& orientation
368  );
369 
370  //- Per patch edge the pp faces (in global indices) using it.
371  // Uses ListOps::uniqueEqOp to remove duplicates.
373  (
374  const polyMesh&,
375  const globalIndex& globalFaces,
377  );
378 
379  //- Determine extrude information per patch edge:
380  // - zoneID, zoneFlip :
381  // picks one of the faces that connects to
382  // the edge. For boundary edge only looks
383  // at boundary faces. For internal edge it looks at internal
384  // faces only (zoneFromAnyFace = false) or at any face
385  // (zoneFromAnyFace = true). zoneFlip is consistent with
386  // ordering of pp edge.
387  // Face selected gets stored in inflateFaceID
388  // - patchID :
389  // get patch from any boundary face connected to the
390  // edge. The patch might be a to-be-created processor patch
391  // (patchI >= mesh.boundaryMesh().size()) in which case the
392  // nbrProcToPatch, patchToNbrProc give the correspondence.
393  // nPatches is the new number of patches.
394  static void calcExtrudeInfo
395  (
396  const bool zoneFromAnyFace,
397 
398  const polyMesh&,
399  const globalIndex& globalFaces,
401  const indirectPrimitivePatch& pp,
402 
403  labelList& edgePatchID, // if extruding a patch edge
404  label& nPatches,
405  Map<label>& nbrProcToPatch,
406  Map<label>& patchToNbrProc,
407  labelList& edgeZoneID,
408  boolList& edgeFlip,
409  labelList& inflateFaceID
410  );
411 
412  //- Play commands into polyTopoChange to create layers on top
413  // of indirectPrimitivePatch (have to be outside faces).
414  // Gets displacement per patch point.
415  // - exposedPatchID : only used if creating a new mesh
416  // (addToMesh=false) gives per pp face the patch the
417  // exposed face should get.
418  // - nPointLayers : number of layers per (patch)point.
419  // - nFaceLayers : number of layers per (patch) face.
420  // - firstDisplacement : displacement per point for first
421  // layer of points (i.e. nearest to original mesh). If zero
422  // do not add point.
423  // Layer thicknesses are calculated to constant geometric
424  // expansion. Use expansionRatio 1 for constant size.
425  // Sets addedPoints_ which is per pp point a list of points
426  // added.
427  // Note: firstDisplacement has to be parallel synchronised before
428  // calling this routine. Only if all procs sharing a point
429  // get a cell should firstDisplacement be <> 0
430  // Note: cells get added from owner cells of patch faces
431  // (instead of e.g. from patch faces)
432  void setRefinement
433  (
434  const globalIndex& globalFaces,
436  const scalarField& expansionRatio,
437  const indirectPrimitivePatch& pp,
438  const bitSet& flip,
439 
440  const labelList& sidePatchID,
441  const labelList& sideZoneID,
442  const boolList& sideFlip,
443  const labelList& inflateFaceID,
444 
445  const labelList& exposedPatchID,
446  const labelList& nFaceLayers,
447  const labelList& nPointLayers,
448  const vectorField& firstLayerDisp,
449  polyTopoChange& meshMod
450  );
451 
452 
453  //- Add with constant expansion ratio and same nLayers everywhere
454  void setRefinement
455  (
456  const globalIndex& globalFaces,
458  const label nLayers,
459  const indirectPrimitivePatch& pp,
460  const labelList& sidePatchID,
461  const vectorField& overallDisplacement,
462  polyTopoChange& meshMod
463  )
464  {
466  (
467  globalFaces,
469  scalarField(pp.nPoints(), 1.0), // expansion ration
470  pp,
471  bitSet(pp.size()), // flip
472 
473  sidePatchID,
474  labelList(pp.nEdges(), -1), // zoneID
475  boolList(pp.nEdges(), false), // zoneFlip
476  labelList(pp.nEdges(), -1), // inflateFaceID
477 
478  labelList(0),
479  labelList(pp.size(), nLayers), // nFaceLayers
480  labelList(pp.nPoints(), nLayers), // nPointLayers
481  overallDisplacement / nLayers, // firstLayerDisp
482  meshMod
483  );
484  }
485 
486 
487  //- Update any locally stored mesh information. Gets additional
488  // map from new to old patch (since patch needs to be
489  // recreated since has to be on outside).
490  void updateMesh
491  (
492  const mapPolyMesh&,
493  const labelList& faceMap, // new to old patch faces
494  const labelList& pointMap // new to old patch points
495  );
496 
497 
498 
499  //- Helper: given patch and points on patch that are extruded
500  // (to slave side or master side) find the affected
501  // points. Calculates by walking across faces which vertices on
502  // which face are affected. isDupMeshPoint:
503  // -1 : unaffected
504  // >=0 : should use local duplicate of point
505  // (though it does not tell us whether it should use
506  // slave side or master side)
507  static void findDuplicatedPoints
508  (
509  const polyMesh& mesh,
510  const indirectPrimitivePatch& pp,
511  const bitSet& ppFlip, // optional orientation on top of pp
512  const bitSet& isBlockedFace,// any mesh faces not to be
513  // traversed.Usually pp.addressing()
514  const bitSet& isDupPatchPoint,
515  const bool extrude, // which side to extrude
516  faceList& isDupMeshPoint
517  );
518 };
519 
520 
521 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
522 
523 } // End namespace Foam
524 
525 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
526 
527 #endif
528 
529 // ************************************************************************* //
label nPatches
Definition: readKivaGrid.H:394
const labelListList & addedPoints() const
Added points per patch point.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
const bitSet isBlockedFace(intersectedFaces())
static void findDuplicatedPoints(const polyMesh &mesh, const indirectPrimitivePatch &pp, const bitSet &ppFlip, const bitSet &isBlockedFace, const bitSet &isDupPatchPoint, const bool extrude, faceList &isDupMeshPoint)
Helper: given patch and points on patch that are extruded.
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:158
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
static labelListList globalEdgeFaces(const polyMesh &, const globalIndex &globalFaces, const indirectPrimitivePatch &pp, const bitSet &orientation)
Per patch edge the pp faces (in global indices) using it.
dynamicFvMesh & mesh
Adds layers of cells to outside (or inside) of polyMesh. Can optionally create stand-alone extruded m...
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.
Basic run-time type information using word as the type&#39;s name. Used to enhance the standard RTTI to c...
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
Direct mesh changes based on v1.3 polyTopoChange syntax.
labelListList addedCells() const
Added cells given current mesh & layerfaces.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
List< label > labelList
A List of labels.
Definition: List.H:61
List< bool > boolList
A List of bools.
Definition: List.H:59
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.