snappyLayerDriver.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-2021 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::snappyLayerDriver
26 
27 Description
28  All to do with adding layers
29 
30 SourceFiles
31  snappyLayerDriver.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef snappyLayerDriver_H
36 #define snappyLayerDriver_H
37 
38 #include "meshRefinement.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 // Forward declaration of classes
46 class removePoints;
47 class pointSet;
48 class motionSmoother;
49 class addPatchCellLayer;
50 class pointData;
51 class faceSet;
52 class layerParameters;
53 
54 /*---------------------------------------------------------------------------*\
55  Class snappyLayerDriver Declaration
56 \*---------------------------------------------------------------------------*/
57 
59 {
60 public:
61 
62  // Public data types
63 
64  //- Extrusion controls
65  enum extrudeMode
66  {
70  };
72 
73 private:
74 
75  // Private classes
76 
77  //- Combine operator class to combine normal with other normal.
78  class normalsCombine
79  {
80  public:
81 
82  void operator()(vector& x, const vector& y) const
83  {
84  if (y != point::max)
85  {
86  if (x == point::max)
87  {
88  x = y;
89  }
90  else
91  {
92  x *= (x&y);
93  }
94  }
95  }
96  };
97 
98 
99  // Private Data
100 
101  //- Mesh+surface
102  meshRefinement& meshRefiner_;
103 
104  //- From surface region to patch
105  const labelList globalToMasterPatch_;
106 
107  //- From surface region to patch
108  const labelList globalToSlavePatch_;
109 
110 
111 
112  // Private Member Functions
113 
114  // Layers
115 
116  //- For debugging: Dump displacement to .obj files
117  static void dumpDisplacement
118  (
119  const fileName&,
120  const indirectPrimitivePatch&,
121  const vectorField&,
122  const List<extrudeMode>&
123  );
124 
125  //- Average point wise data to face wise
126  static tmp<scalarField> avgPointData
127  (
128  const indirectPrimitivePatch&,
129  const scalarField& pointFld
130  );
131 
132  //- Check that primitivePatch is not multiply connected.
133  // Collect non-manifold points in pointSet.
134  static void checkManifold
135  (
136  const indirectPrimitivePatch&,
137  pointSet& nonManifoldPoints
138  );
139 
140  //- Check that mesh outside is not multiply connected.
141  void checkMeshManifold() const;
142 
143 
144  // Static extrusion setup
145 
146  //- Unset extrusion on point. Returns true if anything unset.
147  static bool unmarkExtrusion
148  (
149  const label patchPointi,
150  pointField& patchDisp,
151  labelList& patchNLayers,
152  List<extrudeMode>& extrudeStatus
153  );
154 
155  //- Unset extrusion on face. Returns true if anything unset.
156  static bool unmarkExtrusion
157  (
158  const face& localFace,
159  pointField& patchDisp,
160  labelList& patchNLayers,
161  List<extrudeMode>& extrudeStatus
162  );
163 
164  //- No extrusion at non-manifold points.
165  void handleNonManifolds
166  (
167  const indirectPrimitivePatch& pp,
168  const labelList& meshEdges,
169  const labelListList& edgeGlobalFaces,
170  pointField& patchDisp,
171  labelList& patchNLayers,
172  List<extrudeMode>& extrudeStatus
173  ) const;
174 
175  //- No extrusion on feature edges. Assumes non-manifold
176  // edges already handled.
177  void handleFeatureAngle
178  (
179  const indirectPrimitivePatch& pp,
180  const labelList& meshEdges,
181  const scalar minCos,
182  pointField& patchDisp,
183  labelList& patchNLayers,
184  List<extrudeMode>& extrudeStatus
185  ) const;
186 
187  //- No extrusion on warped faces
188  void handleWarpedFaces
189  (
190  const indirectPrimitivePatch& pp,
191  const scalar faceRatio,
192  const scalar edge0Len,
193  const labelList& cellLevel,
194  pointField& patchDisp,
195  labelList& patchNLayers,
196  List<extrudeMode>& extrudeStatus
197  ) const;
198 
199  //- Determine the number of layers per point from the number of
200  // layers per surface.
201  void setNumLayers
202  (
203  const labelList& patchToNLayers,
204  const labelList& patchIDs,
205  const indirectPrimitivePatch& pp,
206  pointField& patchDisp,
207  labelList& patchNLayers,
208  List<extrudeMode>& extrudeStatus,
209  label& nIdealAddedCells
210  ) const;
211 
212  //- Helper function to make a pointVectorField with correct
213  // bcs for layer addition:
214  // - numLayers > 0 : fixedValue
215  // - numLayers == 0 : fixedValue (always zero)
216  // - processor : calculated (so free to move)
217  // - cyclic/wedge/symmetry : slip
218  // - other : slip
219  static tmp<pointVectorField> makeLayerDisplacementField
220  (
221  const pointMesh& pMesh,
222  const labelList& numLayers
223  );
224 
225  //- Grow no-extrusion layer.
226  void growNoExtrusion
227  (
228  const indirectPrimitivePatch& pp,
229  pointField& patchDisp,
230  labelList& patchNLayers,
231  List<extrudeMode>& extrudeStatus
232  ) const;
233 
234  //- See what patches boundaryedges should be extruded into
235  void determineSidePatches
236  (
237  const globalIndex& globalFaces,
238  const labelListList& edgeGlobalFaces,
239  const indirectPrimitivePatch& pp,
240 
241  labelList& sidePatchID
242  );
243 
244  //- Calculate pointwise wanted and minimum thickness.
245  // thickness: wanted thickness
246  // minthickness: when to give up and not extrude
247  // Gets per patch parameters and determine pp pointwise
248  // parameters.
249  void calculateLayerThickness
250  (
251  const indirectPrimitivePatch& pp,
252  const labelList& patchIDs,
253  const layerParameters& layerParams,
254  const labelList& cellLevel,
255  const labelList& patchNLayers,
256  const scalar edge0Len,
257 
258  scalarField& thickness,
259  scalarField& minThickness,
260  scalarField& expansionRatio
261  ) const;
262 
263 
264  // Extrusion execution
265 
266  //- Synchronise displacement among coupled patches.
267  void syncPatchDisplacement
268  (
269  const indirectPrimitivePatch& pp,
270  const scalarField& minThickness,
271  pointField& patchDisp,
272  labelList& patchNLayers,
273  List<extrudeMode>& extrudeStatus
274  ) const;
275 
276  //- Get nearest point on surface to snap to
277  void getPatchDisplacement
278  (
279  const indirectPrimitivePatch& pp,
280  const scalarField& thickness,
281  const scalarField& minThickness,
282  pointField& patchDisp,
283  labelList& patchNLayers,
284  List<extrudeMode>& extrudeStatus
285  ) const;
286 
287  //- For truncateDisplacement: find strings of edges
288  bool sameEdgeNeighbour
289  (
290  const labelListList& globalEdgeFaces,
291  const label myGlobalFacei,
292  const label nbrGlobFacei,
293  const label edgeI
294  ) const;
295 
296  //- For truncateDisplacement: find strings of edges
297  void getVertexString
298  (
299  const indirectPrimitivePatch& pp,
300  const labelListList& globalEdgeFaces,
301  const label facei,
302  const label edgeI,
303  const label myGlobFacei,
304  const label nbrGlobFacei,
306  ) const;
307 
308  //- Truncates displacement
309  // - for all patchFaces in the faceset displacement gets set
310  // to zero
311  // - all displacement < minThickness gets set to zero
312  // - all non-consecutive extrusions get set to 0
313  label truncateDisplacement
314  (
315  const globalIndex& globalFaces,
316  const labelListList& edgeGlobalFaces,
317  const indirectPrimitivePatch& pp,
318  const scalarField& minThickness,
319  const faceSet& illegalPatchFaces,
320  pointField& patchDisp,
321  labelList& patchNLayers,
322  List<extrudeMode>& extrudeStatus
323  ) const;
324 
325  //- Setup layer information (at points and faces) to
326  // modify mesh topology in
327  // regions where layer mesh terminates. Guarantees an
328  // optional slow decreasing of the number of layers.
329  // Returns the number of layers per face and per point
330  // to go into the actual layer addition engine.
331  void setupLayerInfoTruncation
332  (
333  const indirectPrimitivePatch& pp,
334  const labelList& patchNLayers,
335  const List<extrudeMode>& extrudeStatus,
336  const label nBufferCellsNoExtrude,
337  labelList& nPatchPointLayers,
338  labelList& nPatchFaceLayers
339  ) const;
340 
341  //- Does any of the cells use a face from faces?
342  static bool cellsUseFace
343  (
344  const polyMesh& mesh,
345  const labelList& cellLabels,
346  const labelHashSet& faces
347  );
348 
349  //- Checks the newly added cells and locally unmarks points
350  // so they will not get extruded next time round. Returns
351  // global number of unmarked points (0 if all was fine)
352  static label checkAndUnmark
353  (
354  const addPatchCellLayer& addLayer,
355  const dictionary& motionDict,
356  const bool additionalReporting,
357  const List<labelPair>& baffles,
358  const indirectPrimitivePatch& pp,
359  const fvMesh&,
360 
361  pointField& patchDisp,
362  labelList& patchNLayers,
363  List<extrudeMode>& extrudeStatus
364  );
365 
366  //- Count global number of extruded faces
367  static label countExtrusion
368  (
369  const indirectPrimitivePatch& pp,
370  const List<extrudeMode>& extrudeStatus
371  );
372 
373  //- Collect layer faces and layer cells into bools
374  // for ease of handling
375  static void getLayerCellsFaces
376  (
377  const polyMesh&,
378  const addPatchCellLayer&,
379  const scalarField& oldRealThickness,
380 
381  labelList& cellStatus,
382  scalarField& faceRealThickness
383  );
384 
385  //- Print layer coverage table
386  void printLayerData
387  (
388  const fvMesh& mesh,
389  const labelList& patchIDs,
390  const labelList& cellNLayers,
391  const scalarField& faceWantedThickness,
392  const scalarField& faceRealThickness
393  ) const;
394 
395  //- Write cellSet,faceSet for layers
396  bool writeLayerData
397  (
398  const fvMesh& mesh,
399  const labelList& patchIDs,
400  const labelList& cellNLayers,
401  const scalarField& faceWantedThickness,
402  const scalarField& faceRealThickness
403  ) const;
404 
405 
406  // Mesh shrinking (to create space for layers)
407 
408  //- Average field (over all subset of mesh points) by
409  // summing contribution from edges. Global parallel since only
410  // does master edges for coupled edges.
411  template<class Type>
412  static void averageNeighbours
413  (
414  const polyMesh& mesh,
415  const PackedBoolList& isMasterEdge,
416  const labelList& meshEdges,
417  const labelList& meshPoints,
418  const edgeList& edges,
419  const scalarField& invSumWeight,
420  const Field<Type>& data,
422  );
423 
424  //- Calculate inverse sum of edge weights (currently always 1.0)
425  void sumWeights
426  (
427  const PackedBoolList& isMasterEdge,
428  const labelList& meshEdges,
429  const labelList& meshPoints,
430  const edgeList& edges,
431  scalarField& invSumWeight
432  ) const;
433 
434  //- Smooth scalar field on patch
435  void smoothField
436  (
437  const motionSmoother& meshMover,
438  const PackedBoolList& isMasterPoint,
439  const PackedBoolList& isMasterEdge,
440  const labelList& meshEdges,
441  const scalarField& fieldMin,
442  const label nSmoothDisp,
444  ) const;
445 
446  //- Smooth normals on patch.
447  void smoothPatchNormals
448  (
449  const motionSmoother& meshMover,
450  const PackedBoolList& isMasterPoint,
451  const PackedBoolList& isMasterEdge,
452  const labelList& meshEdges,
453  const label nSmoothDisp,
454  pointField& normals
455  ) const;
456 
457  //- Smooth normals in interior.
458  void smoothNormals
459  (
460  const label nSmoothDisp,
461  const PackedBoolList& isMasterPoint,
462  const PackedBoolList& isMasterEdge,
463  const labelList& fixedPoints,
464  pointVectorField& normals
465  ) const;
466 
467  bool isMaxEdge
468  (
469  const List<pointData>&,
470  const label edgeI,
471  const scalar minCos
472  ) const;
473 
474  //- Stop layer growth where mesh wraps around edge with a
475  // large feature angle
476  void handleFeatureAngleLayerTerminations
477  (
478  const scalar minCos,
479  const PackedBoolList& isMasterPoint,
480  const indirectPrimitivePatch& pp,
481  const labelList& meshEdges,
482 
483  List<extrudeMode>& extrudeStatus,
484  pointField& patchDisp,
485  labelList& patchNLayers,
486  label& nPointCounter
487  ) const;
488 
489  //- Find isolated islands (points, edges and faces and
490  // layer terminations)
491  // in the layer mesh and stop any layer growth at these points.
492  void findIsolatedRegions
493  (
494  const scalar minCosLayerTermination,
495  const PackedBoolList& isMasterPoint,
496  const PackedBoolList& isMasterEdge,
497  const indirectPrimitivePatch& pp,
498  const labelList& meshEdges,
499  const scalarField& minThickness,
500 
501  List<extrudeMode>& extrudeStatus,
502  pointField& patchDisp,
503  labelList& patchNLayers
504  ) const;
505 
506  // Calculate medial axis fields
507  void medialAxisSmoothingInfo
508  (
509  const motionSmoother& meshMover,
510  const label nSmoothNormals,
511  const label nSmoothSurfaceNormals,
512  const scalar minMedialAxisAngleCos,
513  const scalar featureAngle,
514 
515  pointVectorField& dispVec,
516  pointScalarField& medialRatio,
517  pointScalarField& medialDist,
518  pointVectorField& medialVec
519  ) const;
520 
521  //- Main routine to shrink mesh
522  void shrinkMeshMedialDistance
523  (
524  motionSmoother& meshMover,
525  const dictionary& meshQualityDict,
526  const List<labelPair>& baffles,
527  const label nSmoothPatchThickness,
528  const label nSmoothDisplacement,
529  const scalar maxThicknessToMedialRatio,
530  const label nAllowableErrors,
531  const label nSnap,
532  const scalar minCosLayerTermination,
533 
534  const scalarField& layerThickness,
535  const scalarField& minThickness,
536 
537  const pointVectorField& dispVec,
538  const pointScalarField& medialRatio,
539  const pointScalarField& medialDist,
540  const pointVectorField& medialVec,
541 
542  List<extrudeMode>& extrudeStatus,
543  pointField& patchDisp,
544  labelList& patchNLayers
545  ) const;
546 
547 
548 public:
549 
550  //- Runtime type information
551  ClassName("snappyLayerDriver");
552 
553  // Constructors
554 
555  //- Construct from components
557  (
558  meshRefinement& meshRefiner,
559  const labelList& globalToMasterPatch,
560  const labelList& globalToSlavePatch
561  );
562 
563  //- Disallow default bitwise copy construction
564  snappyLayerDriver(const snappyLayerDriver&) = delete;
565 
566 
567  // Member Functions
568 
569  //- Merge patch faces on same cell.
571  (
572  const layerParameters& layerParams,
573  const dictionary& motionDict
574  );
575 
576  //- Add cell layers
577  void addLayers
578  (
579  const layerParameters& layerParams,
580  const dictionary& motionDict,
581  const labelList& patchIDs,
582  const label nAllowableErrors,
583  decompositionMethod& decomposer,
584  fvMeshDistribute& distributor
585  );
586 
587  //- Add layers according to the dictionary settings
588  void doLayers
589  (
590  const dictionary& shrinkDict,
591  const dictionary& motionDict,
592  const layerParameters& layerParams,
593  const bool preBalance, // balance before adding?
594  decompositionMethod& decomposer,
595  fvMeshDistribute& distributor
596  );
597 
598 
599  // Member Operators
600 
601  //- Disallow default bitwise assignment
602  void operator=(const snappyLayerDriver&) = delete;
603 };
604 
605 
606 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
607 
608 } // End namespace Foam
609 
610 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
611 
612 #ifdef NoRepository
614 #endif
615 
616 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
617 
618 #endif
619 
620 // ************************************************************************* //
Given a displacement moves the mesh by scaling the displacement back until there are no more mesh err...
Simple container to keep together layer specific information.
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
A class for handling file names.
Definition: fileName.H:79
A list of face labels.
Definition: faceSet.H:48
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
A set of point labels.
Definition: pointSet.H:48
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
void operator=(const snappyLayerDriver &)=delete
Disallow default bitwise assignment.
void addLayers(const layerParameters &layerParams, const dictionary &motionDict, const labelList &patchIDs, const label nAllowableErrors, decompositionMethod &decomposer, fvMeshDistribute &distributor)
Add cell layers.
ClassName("snappyLayerDriver")
Runtime type information.
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:48
pointField vertices(const blockVertexList &bvl)
scalar y
A list of faces which address into the list of points.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
snappyLayerDriver(meshRefinement &meshRefiner, const labelList &globalToMasterPatch, const labelList &globalToSlavePatch)
Construct from components.
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
dynamicFvMesh & mesh
Adds layers of cells to outside of polyPatch. Can optionally create stand-alone extruded mesh (addToM...
void doLayers(const dictionary &shrinkDict, const dictionary &motionDict, const layerParameters &layerParams, const bool preBalance, decompositionMethod &decomposer, fvMeshDistribute &distributor)
Add layers according to the dictionary settings.
Do not extrude. No layers added.
Abstract base class for decomposition.
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Database for solution and other reduced data.
Definition: data.H:51
All to do with adding layers.
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
A bit-packed bool list.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
extrudeMode
Extrusion controls.
void mergePatchFacesUndo(const layerParameters &layerParams, const dictionary &motionDict)
Merge patch faces on same cell.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
rDeltaTY field()
A class for managing temporary objects.
Definition: PtrList.H:53
Namespace for OpenFOAM.