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;
124 
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  //- Find patch to neighbouring processor
206  static label findProcPatch(const polyMesh&, const label nbrProcID);
207 
208  //- Extract properties from mesh face
209  static void setFaceProps
210  (
211  const polyMesh&,
212  const label,
213  label&,
214  label&,
215  bool&
216  );
217 
218  //- Extract properties from mesh face in pp edge ordering
219  static void setFaceProps
220  (
221  const polyMesh& mesh,
222  const indirectPrimitivePatch& pp,
223  const label ppEdgeI,
224  const label faceI,
225 
226  label& patchI,
227  label& zoneI,
228  bool& zoneFlip,
229  label& inflateFaceI
230  );
231 
232  //- Find internal or boundary face to get extrude properties
233  // from. zoneFlip consistent with ppEdge ordering
234  static void findZoneFace
235  (
236  const bool useInternalFaces,
237  const bool useBoundaryFaces,
238 
239  const polyMesh& mesh,
240  const indirectPrimitivePatch& pp,
241  const label ppEdgeI,
242  const labelUIndList& excludeFaces,
243  const labelList& meshFaces,
244 
245  label& inflateFaceI,
246  label& patchI,
247  label& zoneI,
248  bool& zoneFlip
249  );
250 
251  //- Mark internal and boundary edges of patch. In mesh edges
252  //- since processor might not have pp but does have edge.
253  static void markPatchEdges
254  (
255  const polyMesh& mesh,
256  const indirectPrimitivePatch& pp,
257  const labelListList& edgeGlobalFaces,
258  const labelList& meshEdges,
259 
260  bitSet& isPatchEdge,
261  bitSet& isPatchBoundaryEdge
262  );
263 
264  //- For every edge on pp return
265  // - patchEdgeToFace : face (in global indexing) to inflate from
266  // - patchEdgeToPatch : patch (only for boundary edges of pp)
267  // - patchEdgeToZone,flip : zone info
268  static void globalEdgeInfo
269  (
270  const bool zoneFromAnyFace,
271 
272  const polyMesh& mesh,
273  const globalIndex& globalFaces,
274  const labelListList& edgeGlobalFaces,
275  const indirectPrimitivePatch& pp,
276  const labelList& meshEdges,
277 
278  labelList& patchEdgeToFace, // face (in globalFaces index)
279  labelList& patchEdgeToPatch, // patch on face (or -1 for int faces)
280  labelList& patchEdgeToZone, // zone on face
281  bitSet& patchEdgeToFlip // flip orientation on face
282  );
283 
284  //- No copy construct
285  addPatchCellLayer(const addPatchCellLayer&) = delete;
286 
287  //- No copy assignment
288  void operator=(const addPatchCellLayer&) = delete;
289 
290 
291 public:
292 
293  //- Runtime type information
294  ClassName("addPatchCellLayer");
295 
296 
297  // Constructors
298 
299  //- Construct from mesh.
300  explicit addPatchCellLayer(const polyMesh&, const bool addToMesh=true);
301 
302 
303  // Member Functions
304 
305  // Access
306 
307  //- Added points per patch point.
308  const labelListList& addedPoints() const
309  {
310  return addedPoints_;
311  }
312 
313  //- Layer faces per patch face. See above.
314  const labelListList& layerFaces() const
315  {
316  return layerFaces_;
317  }
318 
319  //- Helper: get added cells per patch face.
320  // addedCells[patchFace] is list of cells added. Last element is
321  // the top cells (i.e. the boundary cell)
323  (
324  const polyMesh&,
326  );
327 
328  //- Added cells given current mesh & layerfaces.
329  labelListList addedCells() const;
330 
331 
332  // Edit
333 
334  //- Per patch edge the pp faces (in global indices) using it.
335  // Uses ListOps::uniqueEqOp to remove duplicates.
337  (
338  const polyMesh&,
339  const globalIndex& globalFaces,
340  const indirectPrimitivePatch& pp
341  );
342 
343  //- Determine extrude information per patch edge:
344  // - zoneID, zoneFlip :
345  // picks one of the faces that connects to
346  // the edge. For boundary edge only looks
347  // at boundary faces. For internal edge it looks at internal
348  // faces only (zoneFromAnyFace = false) or at any face
349  // (zoneFromAnyFace = true). zoneFlip is consistent with
350  // ordering of pp edge.
351  // Face selected gets stored in inflateFaceID
352  // - patchID :
353  // get patch from any boundary face connected to the
354  // edge. The patch might be a to-be-created processor patch
355  // (patchI >= mesh.boundaryMesh().size()) in which case the
356  // nbrProcToPatch, patchToNbrProc give the correspondence.
357  // nPatches is the new number of patches.
358  static void calcExtrudeInfo
359  (
360  const bool zoneFromAnyFace,
361 
362  const polyMesh&,
363  const globalIndex& globalFaces,
365  const indirectPrimitivePatch& pp,
366 
367  labelList& edgePatchID, // if extruding a patch edge
368  label& nPatches,
369  Map<label>& nbrProcToPatch,
370  Map<label>& patchToNbrProc,
371  labelList& edgeZoneID,
372  boolList& edgeFlip,
373  labelList& inflateFaceID
374  );
375 
376  //- Play commands into polyTopoChange to create layers on top
377  // of indirectPrimitivePatch (have to be outside faces).
378  // Gets displacement per patch point.
379  // - exposedPatchID : only used if creating a new mesh
380  // (addToMesh=false) gives per pp face the patch the
381  // exposed face should get.
382  // - nPointLayers : number of layers per (patch)point.
383  // - nFaceLayers : number of layers per (patch) face.
384  // - firstDisplacement : displacement per point for first
385  // layer of points (i.e. nearest to original mesh). If zero
386  // do not add point.
387  // Layer thicknesses are calculated to constant geometric
388  // expansion. Use expansionRatio 1 for constant size.
389  // Sets addedPoints_ which is per pp point a list of points
390  // added.
391  // Note: firstDisplacement has to be parallel synchronised before
392  // calling this routine. Only if all procs sharing a point
393  // get a cell should firstDisplacement be <> 0
394  // Note: cells get added from owner cells of patch faces
395  // (instead of e.g. from patch faces)
396  void setRefinement
397  (
398  const globalIndex& globalFaces,
400  const scalarField& expansionRatio,
401  const indirectPrimitivePatch& pp,
402 
403  const labelList& sidePatchID,
404  const labelList& sideZoneID,
405  const boolList& sideFlip,
406  const labelList& inflateFaceID,
407 
408  const labelList& exposedPatchID,
409  const labelList& nFaceLayers,
410  const labelList& nPointLayers,
411  const vectorField& firstLayerDisp,
412  polyTopoChange& meshMod
413  );
414 
415 
416  //- Add with constant expansion ratio and same nLayers everywhere
418  (
419  const globalIndex& globalFaces,
421  const label nLayers,
422  const indirectPrimitivePatch& pp,
423  const labelList& sidePatchID,
424  const vectorField& overallDisplacement,
425  polyTopoChange& meshMod
426  )
427  {
429  (
430  globalFaces,
432  scalarField(pp.nPoints(), 1.0), // expansion ration
433  pp,
434 
435  sidePatchID,
436  labelList(pp.nEdges(), -1), // zoneID
437  boolList(pp.nEdges(), false), // zoneFlip
438  labelList(pp.nEdges(), -1), // inflateFaceID
439 
440  labelList(0),
441  labelList(pp.size(), nLayers), // nFaceLayers
442  labelList(pp.nPoints(), nLayers), // nPointLayers
443  overallDisplacement / nLayers, // firstLayerDisp
444  meshMod
445  );
446  }
447 
448 
449  //- Update any locally stored mesh information. Gets additional
450  // map from new to old patch (since patch needs to be
451  // recreated since has to be on outside).
452  void updateMesh
453  (
454  const mapPolyMesh&,
455  const labelList& faceMap, // new to old patch faces
456  const labelList& pointMap // new to old patch points
457  );
458 };
459 
460 
461 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
462 
463 } // End namespace Foam
464 
465 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
466 
467 #endif
468 
469 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
typeInfo.H
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.
Definition: addPatchCellLayer.C:647
Foam::PrimitivePatch::nEdges
label nEdges() const
Number of edges in patch.
Definition: PrimitivePatch.H:322
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:99
Foam::Map< label >
Foam::boolList
List< bool > boolList
A List of bools.
Definition: List.H:65
Foam::addPatchCellLayer::addedPoints
const labelListList & addedPoints() const
Added points per patch point.
Definition: addPatchCellLayer.H:307
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
nPatches
const label nPatches
Definition: printMeshSummary.H:30
labelList.H
Foam::Field< scalar >
indirectPrimitivePatch.H
Foam::PrimitivePatch::nPoints
label nPoints() const
Number of points supporting patch faces.
Definition: PrimitivePatch.H:316
Foam::addPatchCellLayer
Adds layers of cells to outside of polyPatch. Can optionally create stand-alone extruded mesh (addToM...
Definition: addPatchCellLayer.H:128
Foam::addPatchCellLayer::ClassName
ClassName("addPatchCellLayer")
Runtime type information.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Foam::addPatchCellLayer::updateMesh
void updateMesh(const mapPolyMesh &, const labelList &faceMap, const labelList &pointMap)
Update any locally stored mesh information. Gets additional.
Definition: addPatchCellLayer.C:2379
Foam::addPatchCellLayer::layerFaces
const labelListList & layerFaces() const
Layer faces per patch face. See above.
Definition: addPatchCellLayer.H:313
Foam::Pair< label >
Foam::List< labelList >
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:1090
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:60
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
labelPair.H
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:79
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:1418
Foam::addPatchCellLayer::addedCells
labelListList addedCells() const
Added cells given current mesh & layerfaces.
Definition: addPatchCellLayer.C:640