addPatchCellLayer.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 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 polyTopoChangeMap;
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.
173  labelListList addedPoints_;
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.
179  labelListList layerFaces_;
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 
205  labelPair getEdgeString
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.
216  label addSideFace
217  (
218  const indirectPrimitivePatch&,
219  const labelListList& addedCells,
220 
221  const face& newFace,
222  const label newPatchID,
223 
224  const label ownFacei,
225  const label nbrFacei,
226  const label meshEdgeI,
227  const label layerI,
228  const label numEdgeFaces,
229  const labelList& meshFaces,
231  ) const;
232 
233  //- Find patch to neighbouring processor
234  static label findProcPatch(const polyMesh&, const label nbrProcID);
235 
236  //- Extract properties from mesh face
237  static void setFaceProps
238  (
239  const polyMesh&,
240  const label,
241  label&,
242  label&,
243  bool&
244  );
245 
246 
247 public:
248 
249  //- Runtime type information
250  ClassName("addPatchCellLayer");
251 
252 
253  // Constructors
254 
255  //- Construct from mesh.
256  addPatchCellLayer(const polyMesh&, const bool addToMesh = true);
257 
258  //- Disallow default bitwise copy construction
259  addPatchCellLayer(const addPatchCellLayer&) = delete;
260 
261 
262  // Member Functions
263 
264 
265  // Access
266 
267  //- Added points per patch point.
268  const labelListList& addedPoints() const
269  {
270  return addedPoints_;
271  }
272 
273  //- Layer faces per patch face. See above.
274  const labelListList& layerFaces() const
275  {
276  return layerFaces_;
277  }
278 
279  //- Helper: get added cells per patch face.
280  // addedCells[patchFace] is list of cells added. Last element is
281  // the top cells (i.e. the boundary cell)
283  (
284  const polyMesh&,
286  );
287 
288  //- Added cells given current mesh & layerfaces.
289  labelListList addedCells() const;
290 
291 
292  // Edit
293 
294  //- Per patch edge the pp faces (in global indices) using it. Uses
295  // uniqueEqOp() to remove duplicates.
297  (
298  const polyMesh&,
299  const globalIndex& globalFaces,
300  const indirectPrimitivePatch& pp
301  );
302 
303  //- Boundary edges get extruded into boundary faces. Determine patch
304  // for these faces. This might be a to-be-created processor patch
305  // (patchi >= mesh.boundaryMesh().size()) in which case the
306  // nbrProcToPatch, patchToNbrProc give the correspondence. nPatches
307  // is the new number of patches.
308  static void calcSidePatch
309  (
310  const polyMesh&,
311  const globalIndex& globalFaces,
313  const indirectPrimitivePatch& pp,
314 
315  labelList& sidePatchID,
316  label& nPatches,
317  Map<label>& nbrProcToPatch,
318  Map<label>& patchToNbrProc
319  );
320 
321  //- Play commands into polyTopoChange to create layers on top
322  // of indirectPrimitivePatch (have to be outside faces).
323  // Gets displacement per patch point.
324  // - exposedPatchID : only used if creating a new mesh
325  // (addToMesh=false) gives per pp face the patch the
326  // exposed face should get.
327  // - nPointLayers : number of layers per (patch)point.
328  // - nFaceLayers : number of layers per (patch) face.
329  // - firstDisplacement : displacement per point for first
330  // layer of points (i.e. nearest to original mesh). If zero
331  // do not add point.
332  // Layer thicknesses are calculated to constant geometric
333  // expansion. Use expansionRatio 1 for constant size.
334  // Sets addedPoints_ which is per pp point a list of points
335  // added.
336  // Note: firstDisplacement has to be parallel synchronised before
337  // calling this routine. Only if all procs sharing a point
338  // get a cell should firstDisplacement be <> 0
339  // Note: cells get added from owner cells of patch faces
340  // (instead of e.g. from patch faces)
341  void setRefinement
342  (
343  const globalIndex& globalFaces,
345  const scalarField& expansionRatio,
346  const indirectPrimitivePatch& pp,
347  const labelList& sidePatchID,
348  const labelList& exposedPatchID,
349  const labelList& nFaceLayers,
350  const labelList& nPointLayers,
351  const vectorField& firstLayerDisp,
352  polyTopoChange& meshMod
353  );
354 
355 
356  //- Add with constant expansion ratio and same nLayers everywhere
357  void setRefinement
358  (
359  const globalIndex& globalFaces,
361  const label nLayers,
362  const indirectPrimitivePatch& pp,
363  const labelList& sidePatchID,
364  const vectorField& overallDisplacement,
365  polyTopoChange& meshMod
366  )
367  {
369  (
370  globalFaces,
372  scalarField(pp.nPoints(), 1.0), // expansion ration
373  pp,
374  sidePatchID,
375  labelList(0),
376  labelList(pp.size(), nLayers), // nFaceLayers
377  labelList(pp.nPoints(), nLayers), // nPointLayers
378  overallDisplacement / nLayers, // firstLayerDisp
379  meshMod
380  );
381  }
382 
383 
384  //- Update any locally stored mesh information. Gets additional
385  // map from new to old patch (since patch needs to be
386  // recreated since has to be on outside).
387  void topoChange
388  (
389  const polyTopoChangeMap&,
390  const labelList& faceMap, // new to old patch faces
391  const labelList& pointMap // new to old patch points
392  );
393 
394 
395  // Member Operators
396 
397  //- Disallow default bitwise assignment
398  void operator=(const addPatchCellLayer&) = delete;
399 };
400 
401 
402 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
403 
404 } // End namespace Foam
405 
406 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
407 
408 #endif
409 
410 // ************************************************************************* //
scalar y
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
label nPoints() const
Return number of points supporting patch faces.
label size() const
Return the number of elements in the list.
Adds layers of cells to outside of polyPatch. Can optionally create stand-alone extruded mesh (addToM...
static void calcSidePatch(const polyMesh &, const globalIndex &globalFaces, const labelListList &globalEdgeFaces, const indirectPrimitivePatch &pp, labelList &sidePatchID, label &nPatches, Map< label > &nbrProcToPatch, Map< label > &patchToNbrProc)
Boundary edges get extruded into boundary faces. Determine patch.
void operator=(const addPatchCellLayer &)=delete
Disallow default bitwise assignment.
const labelListList & layerFaces() const
Layer faces per patch face. See above.
ClassName("addPatchCellLayer")
Runtime type information.
void setRefinement(const globalIndex &globalFaces, const labelListList &globalEdgeFaces, const scalarField &expansionRatio, const indirectPrimitivePatch &pp, const labelList &sidePatchID, const labelList &exposedPatchID, const labelList &nFaceLayers, const labelList &nPointLayers, const vectorField &firstLayerDisp, polyTopoChange &meshMod)
Play commands into polyTopoChange to create layers on top.
void topoChange(const polyTopoChangeMap &, const labelList &faceMap, const labelList &pointMap)
Update any locally stored mesh information. Gets additional.
addPatchCellLayer(const polyMesh &, const bool addToMesh=true)
Construct from mesh.
labelListList addedCells() const
Added cells given current mesh & layerfaces.
const labelListList & addedPoints() const
Added points per patch point.
static labelListList globalEdgeFaces(const polyMesh &, const globalIndex &globalFaces, const indirectPrimitivePatch &pp)
Per patch edge the pp faces (in global indices) using it. Uses.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:64
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Direct mesh changes based on v1.3 polyTopoChange syntax.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
label nPatches
Definition: readKivaGrid.H:396