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-2025 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  public:
134 
135  void operator()(labelList& x, const labelList& y) const
136  {
137  if (x.empty())
138  {
139  if (y.size())
140  {
141  x = y;
142  }
143  }
144  else
145  {
146  forAll(y, yi)
147  {
148  if (findIndex(x, y[yi]) == -1)
149  {
150  label sz = x.size();
151  x.setSize(sz+1);
152  x[sz] = y[yi];
153  }
154  }
155  }
156  }
157  };
158 
159 
160  // Private Data
161 
162  //- Add layers to existing mesh or create new mesh
163  bool addToMesh_;
164 
165  //- For all patchpoints: list of added points (size 0 or nLayers)
166  // First point in list is one nearest to original point in patch,
167  // last one is the new point on the surface.
168  labelListList addedPoints_;
169 
170  //- Zones of the added points
171  List<labelHashSet> pointZonesAddedPoints_;
172 
173  //- Zones of the added faces
174  List<Map<bool>> faceZonesAddedFaces_;
175 
176  //- Zones of the added cells
177  List<labelHashSet> cellZonesAddedCells_;
178 
179  //- For all patchfaces: list of layer faces.
180  // - empty if no face extruded
181  // - first face is original boundary face
182  // - last one is new boundary face.
183  labelListList layerFaces_;
184 
185 
186  // Private Member Functions
187 
188  //- Get the face on the other side of the edge.
189  static label nbrFace
190  (
191  const labelListList& edgeFaces,
192  const label edgeI,
193  const label facei
194  );
195 
196  //- Add vertex to face if unique.
197  static void addVertex(const label, face&, label& fp);
198 
199  //- Is edge to the same neighbour? (and needs extrusion and has not been
200  // dealt with already)
201  bool sameEdgeNeighbour
202  (
203  const indirectPrimitivePatch& pp,
205  const boolList& doneEdge,
206  const label thisGlobalFacei,
207  const label nbrGlobalFacei,
208  const label edgeI
209  ) const;
210 
211  //- Collect consecutive string of edges that connects the same two
212  // (possibly coupled) faces. Returns -1 if no unvisited edge can be
213  // found. Otherwise returns start and end index in face.
214  labelPair getEdgeString
215  (
216  const indirectPrimitivePatch& pp,
218  const boolList& doneEdge,
219  const label patchFacei,
220  const label globalFacei
221  ) const;
222 
223  //- Add face between layer-1 and layer.
224  // i.e. extrudes a patch edge.
225  label addSideFace
226  (
227  const polyMesh& mesh,
228  const indirectPrimitivePatch&,
229  const labelListList& addedCells,
230 
231  const face& newFace,
232  const label newPatchID,
233 
234  const label ownFacei,
235  const label nbrFacei,
236  const label layerI,
237  const label numEdgeFaces,
238  const labelList& meshFaces,
240  ) const;
241 
242  //- Find patch to neighbouring processor
243  static label findProcPatch(const polyMesh&, const label nbrProcID);
244 
245 
246 public:
247 
248  //- Runtime type information
249  ClassName("addPatchCellLayer");
250 
251 
252  // Constructors
253 
254  //- Construct from mesh.
255  addPatchCellLayer(const polyMesh&, const bool addToMesh = true);
256 
257 
258  // Member Functions
259 
260  // Access
261 
262  //- Added points per patch point.
263  const labelListList& addedPoints() const
264  {
265  return addedPoints_;
266  }
267 
268  //- Layer faces per patch face. See above.
269  const labelListList& layerFaces() const
270  {
271  return layerFaces_;
272  }
273 
274  //- Helper: get added cells per patch face.
275  // addedCells[patchFace] is list of cells added. Last element is
276  // the top cells (i.e. the boundary cell)
278  (
279  const polyMesh&,
281  );
282 
283  //- Added cells given current mesh & layerfaces.
284  labelListList addedCells(const polyMesh&) const;
285 
286 
287  // Edit
288 
289  //- Per patch edge the pp faces (in global indices) using it. Uses
290  // uniqueEqOp() to remove duplicates.
292  (
293  const polyMesh&,
294  const globalIndex& globalFaces,
295  const indirectPrimitivePatch& pp
296  );
297 
298  //- Boundary edges get extruded into boundary faces. Determine patch
299  // for these faces. This might be a to-be-created processor patch
300  // (patchi >= mesh.boundaryMesh().size()) in which case the
301  // nbrProcToPatch, patchToNbrProc give the correspondence. nPatches
302  // is the new number of patches.
303  static void calcSidePatch
304  (
305  const polyMesh&,
306  const globalIndex& globalFaces,
308  const indirectPrimitivePatch& pp,
309 
310  labelList& sidePatchID,
311  label& nPatches,
312  Map<label>& nbrProcToPatch,
313  Map<label>& patchToNbrProc
314  );
315 
316  //- Play commands into polyTopoChange to create layers on top
317  // of indirectPrimitivePatch (have to be outside faces).
318  // Gets displacement per patch point.
319  // - exposedPatchID : only used if creating a new mesh
320  // (addToMesh=false) gives per pp face the patch the
321  // exposed face should get.
322  // - nPointLayers : number of layers per (patch)point.
323  // - nFaceLayers : number of layers per (patch) face.
324  // - firstDisplacement : displacement per point for first
325  // layer of points (i.e. nearest to original mesh). If zero
326  // do not add point.
327  // Layer thicknesses are calculated to constant geometric
328  // expansion. Use expansionRatio 1 for constant size.
329  // Sets addedPoints_ which is per pp point a list of points
330  // added.
331  // Note: firstDisplacement has to be parallel synchronised before
332  // calling this routine. Only if all procs sharing a point
333  // get a cell should firstDisplacement be <> 0
334  // Note: cells get added from owner cells of patch faces
335  // (instead of e.g. from patch faces)
336  void setRefinement
337  (
338  const polyMesh& mesh,
339  const globalIndex& globalFaces,
341  const scalarField& expansionRatio,
342  const indirectPrimitivePatch& pp,
343  const labelList& sidePatchID,
344  const labelList& exposedPatchID,
345  const labelList& nFaceLayers,
346  const labelList& nPointLayers,
347  const vectorField& firstLayerDisp,
348  const labelList& faceCellZones,
349  polyTopoChange& meshMod
350  );
351 
352  //- Add with constant expansion ratio and same nLayers everywhere
353  void setRefinement
354  (
355  const polyMesh& mesh,
356  const globalIndex& globalFaces,
358  const label nLayers,
359  const indirectPrimitivePatch& pp,
360  const labelList& sidePatchID,
361  const vectorField& overallDisplacement,
362  const labelList& faceCellZones,
363  polyTopoChange& meshMod
364  )
365  {
367  (
368  mesh,
369  globalFaces,
371  scalarField(pp.nPoints(), 1.0), // expansion ration
372  pp,
373  sidePatchID,
374  labelList(0),
375  labelList(pp.size(), nLayers), // nFaceLayers
376  labelList(pp.nPoints(), nLayers), // nPointLayers
377  overallDisplacement / nLayers, // firstLayerDisp
378  faceCellZones,
379  meshMod
380  );
381  }
382 
383  //- Update any locally stored mesh information. Gets additional
384  // map from new to old patch (since patch needs to be
385  // recreated since has to be on outside).
386  void topoChange
387  (
388  const polyTopoChangeMap&,
389  const labelList& faceMap, // new to old patch faces
390  const labelList& pointMap // new to old patch points
391  );
392 
393  //- Update the mesh zones
394  // adding the point and cell zones for the added layer
395  void updateZones(polyMesh& mesh);
396 };
397 
398 
399 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
400 
401 } // End namespace Foam
402 
403 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
404 
405 #endif
406 
407 // ************************************************************************* //
scalar y
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
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.
static labelListList addedCells(const polyMesh &, const labelListList &layerFaces)
Helper: get added cells per patch face.
const labelListList & layerFaces() const
Layer faces per patch face. See above.
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.
void setRefinement(const polyMesh &mesh, 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.
addPatchCellLayer(const polyMesh &, const bool addToMesh=true)
Construct from mesh.
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.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
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...