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-2024 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  //- Zones of the added points
176  List<labelHashSet> pointZonesAddedPoints_;
177 
178  //- Zones of the added cells
179  List<labelHashSet> cellZonesAddedCells_;
180 
181  //- For all patchfaces: list of layer faces.
182  // - empty if no face extruded
183  // - first face is original boundary face
184  // - last one is new boundary face.
185  labelListList layerFaces_;
186 
187 
188  // Private Member Functions
189 
190  //- Get the face on the other side of the edge.
191  static label nbrFace
192  (
193  const labelListList& edgeFaces,
194  const label edgeI,
195  const label facei
196  );
197 
198  //- Add vertex to face if unique.
199  static void addVertex(const label, face&, label& fp);
200 
201  //- Is edge to the same neighbour? (and needs extrusion and has not been
202  // dealt with already)
203  bool sameEdgeNeighbour
204  (
205  const indirectPrimitivePatch& pp,
207  const boolList& doneEdge,
208  const label thisGlobalFacei,
209  const label nbrGlobalFacei,
210  const label edgeI
211  ) const;
212 
213  //- Collect consecutive string of edges that connects the same two
214  // (possibly coupled) faces. Returns -1 if no unvisited edge can be
215  // found. Otherwise returns start and end index in face.
216  labelPair getEdgeString
217  (
218  const indirectPrimitivePatch& pp,
220  const boolList& doneEdge,
221  const label patchFacei,
222  const label globalFacei
223  ) const;
224 
225 
226  //- Add face between layer-1 and layer.
227  // i.e. extrudes a patch edge.
228  label addSideFace
229  (
230  const indirectPrimitivePatch&,
231  const labelListList& addedCells,
232 
233  const face& newFace,
234  const label newPatchID,
235 
236  const label ownFacei,
237  const label nbrFacei,
238  const label layerI,
239  const label numEdgeFaces,
240  const labelList& meshFaces,
242  ) const;
243 
244  //- Find patch to neighbouring processor
245  static label findProcPatch(const polyMesh&, const label nbrProcID);
246 
247 
248 public:
249 
250  //- Runtime type information
251  ClassName("addPatchCellLayer");
252 
253 
254  // Constructors
255 
256  //- Construct from mesh.
257  addPatchCellLayer(const polyMesh&, const bool addToMesh = true);
258 
259  //- Disallow default bitwise copy construction
260  addPatchCellLayer(const addPatchCellLayer&) = delete;
261 
262 
263  // Member Functions
264 
265 
266  // Access
267 
268  //- Added points per patch point.
269  const labelListList& addedPoints() const
270  {
271  return addedPoints_;
272  }
273 
274  //- Layer faces per patch face. See above.
275  const labelListList& layerFaces() const
276  {
277  return layerFaces_;
278  }
279 
280  //- Helper: get added cells per patch face.
281  // addedCells[patchFace] is list of cells added. Last element is
282  // the top cells (i.e. the boundary cell)
284  (
285  const polyMesh&,
287  );
288 
289  //- Added cells given current mesh & layerfaces.
290  labelListList addedCells() const;
291 
292 
293  // Edit
294 
295  //- Per patch edge the pp faces (in global indices) using it. Uses
296  // uniqueEqOp() to remove duplicates.
298  (
299  const polyMesh&,
300  const globalIndex& globalFaces,
301  const indirectPrimitivePatch& pp
302  );
303 
304  //- Boundary edges get extruded into boundary faces. Determine patch
305  // for these faces. This might be a to-be-created processor patch
306  // (patchi >= mesh.boundaryMesh().size()) in which case the
307  // nbrProcToPatch, patchToNbrProc give the correspondence. nPatches
308  // is the new number of patches.
309  static void calcSidePatch
310  (
311  const polyMesh&,
312  const globalIndex& globalFaces,
314  const indirectPrimitivePatch& pp,
315 
316  labelList& sidePatchID,
317  label& nPatches,
318  Map<label>& nbrProcToPatch,
319  Map<label>& patchToNbrProc
320  );
321 
322  //- Play commands into polyTopoChange to create layers on top
323  // of indirectPrimitivePatch (have to be outside faces).
324  // Gets displacement per patch point.
325  // - exposedPatchID : only used if creating a new mesh
326  // (addToMesh=false) gives per pp face the patch the
327  // exposed face should get.
328  // - nPointLayers : number of layers per (patch)point.
329  // - nFaceLayers : number of layers per (patch) face.
330  // - firstDisplacement : displacement per point for first
331  // layer of points (i.e. nearest to original mesh). If zero
332  // do not add point.
333  // Layer thicknesses are calculated to constant geometric
334  // expansion. Use expansionRatio 1 for constant size.
335  // Sets addedPoints_ which is per pp point a list of points
336  // added.
337  // Note: firstDisplacement has to be parallel synchronised before
338  // calling this routine. Only if all procs sharing a point
339  // get a cell should firstDisplacement be <> 0
340  // Note: cells get added from owner cells of patch faces
341  // (instead of e.g. from patch faces)
342  void setRefinement
343  (
344  const globalIndex& globalFaces,
346  const scalarField& expansionRatio,
347  const indirectPrimitivePatch& pp,
348  const labelList& sidePatchID,
349  const labelList& exposedPatchID,
350  const labelList& nFaceLayers,
351  const labelList& nPointLayers,
352  const vectorField& firstLayerDisp,
353  const labelList& faceCellZones,
354  polyTopoChange& meshMod
355  );
356 
357 
358  //- Add with constant expansion ratio and same nLayers everywhere
359  void setRefinement
360  (
361  const globalIndex& globalFaces,
363  const label nLayers,
364  const indirectPrimitivePatch& pp,
365  const labelList& sidePatchID,
366  const vectorField& overallDisplacement,
367  const labelList& faceCellZones,
368  polyTopoChange& meshMod
369  )
370  {
372  (
373  globalFaces,
375  scalarField(pp.nPoints(), 1.0), // expansion ration
376  pp,
377  sidePatchID,
378  labelList(0),
379  labelList(pp.size(), nLayers), // nFaceLayers
380  labelList(pp.nPoints(), nLayers), // nPointLayers
381  overallDisplacement / nLayers, // firstLayerDisp
382  faceCellZones,
383  meshMod
384  );
385  }
386 
387 
388  //- Update any locally stored mesh information. Gets additional
389  // map from new to old patch (since patch needs to be
390  // recreated since has to be on outside).
391  void topoChange
392  (
393  const polyTopoChangeMap&,
394  const labelList& faceMap, // new to old patch faces
395  const labelList& pointMap // new to old patch points
396  );
397 
398  //- Update the mesh zones
399  // adding the point and cell zones for the added layer
400  void updateZones(polyMesh& mesh);
401 
402 
403  // Member Operators
404 
405  //- Disallow default bitwise assignment
406  void operator=(const addPatchCellLayer&) = delete;
407 };
408 
409 
410 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
411 
412 } // End namespace Foam
413 
414 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
415 
416 #endif
417 
418 // ************************************************************************* //
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.
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, const labelList &faceCellZones, polyTopoChange &meshMod)
Play commands into polyTopoChange to create layers on top.
void updateZones(polyMesh &mesh)
Update the mesh zones.
ClassName("addPatchCellLayer")
Runtime type information.
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
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...