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