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  //- No copy construct
252  addPatchCellLayer(const addPatchCellLayer&) = delete;
253 
254  //- No copy assignment
255  void operator=(const addPatchCellLayer&) = delete;
256 
257 
258 public:
259 
260  //- Runtime type information
261  ClassName("addPatchCellLayer");
262 
263 
264  // Constructors
265 
266  //- Construct from mesh.
267  explicit addPatchCellLayer(const polyMesh&, const bool addToMesh=true);
268 
269 
270  // Member Functions
271 
272  // Access
273 
274  //- Added points per patch point.
275  const labelListList& addedPoints() const
276  {
277  return addedPoints_;
278  }
279 
280  //- Layer faces per patch face. See above.
281  const labelListList& layerFaces() const
282  {
283  return layerFaces_;
284  }
285 
286  //- Helper: get added cells per patch face.
287  // addedCells[patchFace] is list of cells added. Last element is
288  // the top cells (i.e. the boundary cell)
290  (
291  const polyMesh&,
293  );
294 
295  //- Added cells given current mesh & layerfaces.
296  labelListList addedCells() const;
297 
298 
299  // Edit
300 
301  //- Per patch edge the pp faces (in global indices) using it.
302  // Uses ListOps::uniqueEqOp to remove duplicates.
304  (
305  const polyMesh&,
306  const globalIndex& globalFaces,
307  const indirectPrimitivePatch& pp
308  );
309 
310  //- Determine extrude information per patch edge:
311  // - zoneID, zoneFlip :
312  // picks one of the faces that connects to
313  // the edge. For boundary edge only looks
314  // at boundary faces. For internal edge it looks at internal
315  // faces only (zoneFromAnyFace = false) or at any face
316  // (zoneFromAnyFace = true). zoneFlip is consistent with
317  // ordering of pp edge.
318  // Face selected gets stored in inflateFaceID
319  // - patchID :
320  // get patch from any boundary face connected to the
321  // edge. The patch might be a to-be-created processor patch
322  // (patchI >= mesh.boundaryMesh().size()) in which case the
323  // nbrProcToPatch, patchToNbrProc give the correspondence.
324  // nPatches is the new number of patches.
325  static void calcExtrudeInfo
326  (
327  const bool zoneFromAnyFace,
328 
329  const polyMesh&,
330  const globalIndex& globalFaces,
332  const indirectPrimitivePatch& pp,
333 
334  labelList& edgePatchID, // if extruding a patch edge
335  label& nPatches,
336  Map<label>& nbrProcToPatch,
337  Map<label>& patchToNbrProc,
338  labelList& edgeZoneID,
339  boolList& edgeFlip,
340  labelList& inflateFaceID
341  );
342 
343  //- Play commands into polyTopoChange to create layers on top
344  // of indirectPrimitivePatch (have to be outside faces).
345  // Gets displacement per patch point.
346  // - exposedPatchID : only used if creating a new mesh
347  // (addToMesh=false) gives per pp face the patch the
348  // exposed face should get.
349  // - nPointLayers : number of layers per (patch)point.
350  // - nFaceLayers : number of layers per (patch) face.
351  // - firstDisplacement : displacement per point for first
352  // layer of points (i.e. nearest to original mesh). If zero
353  // do not add point.
354  // Layer thicknesses are calculated to constant geometric
355  // expansion. Use expansionRatio 1 for constant size.
356  // Sets addedPoints_ which is per pp point a list of points
357  // added.
358  // Note: firstDisplacement has to be parallel synchronised before
359  // calling this routine. Only if all procs sharing a point
360  // get a cell should firstDisplacement be <> 0
361  // Note: cells get added from owner cells of patch faces
362  // (instead of e.g. from patch faces)
363  void setRefinement
364  (
365  const globalIndex& globalFaces,
367  const scalarField& expansionRatio,
368  const indirectPrimitivePatch& pp,
369 
370  const labelList& sidePatchID,
371  const labelList& sideZoneID,
372  const boolList& sideFlip,
373  const labelList& inflateFaceID,
374 
375  const labelList& exposedPatchID,
376  const labelList& nFaceLayers,
377  const labelList& nPointLayers,
378  const vectorField& firstLayerDisp,
379  polyTopoChange& meshMod
380  );
381 
382 
383  //- Add with constant expansion ratio and same nLayers everywhere
385  (
386  const globalIndex& globalFaces,
388  const label nLayers,
389  const indirectPrimitivePatch& pp,
390  const labelList& sidePatchID,
391  const vectorField& overallDisplacement,
392  polyTopoChange& meshMod
393  )
394  {
396  (
397  globalFaces,
399  scalarField(pp.nPoints(), 1.0), // expansion ration
400  pp,
401 
402  sidePatchID,
403  labelList(pp.nEdges(), -1), // zoneID
404  boolList(pp.nEdges(), false), // zoneFlip
405  labelList(pp.nEdges(), -1), // inflateFaceID
406 
407  labelList(0),
408  labelList(pp.size(), nLayers), // nFaceLayers
409  labelList(pp.nPoints(), nLayers), // nPointLayers
410  overallDisplacement / nLayers, // firstLayerDisp
411  meshMod
412  );
413  }
414 
415 
416  //- Update any locally stored mesh information. Gets additional
417  // map from new to old patch (since patch needs to be
418  // recreated since has to be on outside).
419  void updateMesh
420  (
421  const mapPolyMesh&,
422  const labelList& faceMap, // new to old patch faces
423  const labelList& pointMap // new to old patch points
424  );
425 };
426 
427 
428 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
429 
430 } // End namespace Foam
431 
432 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
433 
434 #endif
435 
436 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
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
typeInfo.H
nPatches
label nPatches
Definition: readKivaGrid.H:396
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:648
Foam::PrimitivePatch::nEdges
label nEdges() const
Return 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:69
Foam::addPatchCellLayer::addedPoints
const labelListList & addedPoints() const
Added points per patch point.
Definition: addPatchCellLayer.H:274
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
labelList.H
Foam::Field< scalar >
indirectPrimitivePatch.H
Foam::PrimitivePatch::nPoints
label nPoints() const
Return 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:2002
Foam::addPatchCellLayer::layerFaces
const labelListList & layerFaces() const
Layer faces per patch face. See above.
Definition: addPatchCellLayer.H:280
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:693
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:109
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:85
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:1038
Foam::addPatchCellLayer::addedCells
labelListList addedCells() const
Added cells given current mesh & layerfaces.
Definition: addPatchCellLayer.C:640