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 scalar edge0Len,
239  const labelList& cellLevel,
240  pointField& patchDisp,
241  labelList& patchNLayers,
242  List<extrudeMode>& extrudeStatus
243  ) const;
244 
245  //- Determine the number of layers per point from the number of
246  // layers per surface.
247  void setNumLayers
248  (
249  const labelList& patchToNLayers,
250  const labelList& patchIDs,
251  const indirectPrimitivePatch& pp,
252  pointField& patchDisp,
253  labelList& patchNLayers,
254  List<extrudeMode>& extrudeStatus,
255  label& nIdealAddedCells
256  ) const;
257 
258  //- Helper function to make a pointVectorField with correct
259  // bcs for layer addition:
260  // - numLayers > 0 : fixedValue
261  // - numLayers == 0 : fixedValue (always zero)
262  // - processor : calculated (so free to move)
263  // - cyclic/wedge/symmetry : slip
264  // - other : slip
265  static tmp<pointVectorField> makeLayerDisplacementField
266  (
267  const pointMesh& pMesh,
268  const labelList& numLayers
269  );
270 
271  //- Grow no-extrusion layer.
272  void growNoExtrusion
273  (
274  const indirectPrimitivePatch& pp,
275  pointField& patchDisp,
276  labelList& patchNLayers,
277  List<extrudeMode>& extrudeStatus
278  ) const;
279 
280  //- See what zones and patches edges should be extruded into
281  void determineSidePatches
282  (
283  const globalIndex& globalFaces,
284  const labelListList& edgeGlobalFaces,
285  const indirectPrimitivePatch& pp,
286 
287  labelList& edgePatchID,
288  labelList& edgeZoneID,
289  boolList& edgeFlip,
290  labelList& inflateFaceID
291  );
292 
293  //- Calculate pointwise wanted and minimum thickness.
294  // thickness: wanted thickness
295  // minthickness: when to give up and not extrude
296  // Gets per patch parameters and determine pp pointwise
297  // parameters.
298  void calculateLayerThickness
299  (
300  const indirectPrimitivePatch& pp,
301  const labelList& patchIDs,
302  const layerParameters& layerParams,
303  const labelList& cellLevel,
304  const labelList& patchNLayers,
305  const scalar edge0Len,
306 
307  scalarField& thickness,
308  scalarField& minThickness,
309  scalarField& expansionRatio
310  ) const;
311 
312 
313  // Extrusion execution
314 
315  //- Synchronize displacement among coupled patches.
316  void syncPatchDisplacement
317  (
318  const indirectPrimitivePatch& pp,
319  const scalarField& minThickness,
320  pointField& patchDisp,
321  labelList& patchNLayers,
322  List<extrudeMode>& extrudeStatus
323  ) const;
324 
325  //- Get nearest point on surface to snap to
326  void getPatchDisplacement
327  (
328  const indirectPrimitivePatch& pp,
329  const scalarField& thickness,
330  const scalarField& minThickness,
331  pointField& patchDisp,
332  labelList& patchNLayers,
333  List<extrudeMode>& extrudeStatus
334  ) const;
335 
336  //- For truncateDisplacement: find strings of edges
337  bool sameEdgeNeighbour
338  (
339  const labelListList& globalEdgeFaces,
340  const label myGlobalFacei,
341  const label nbrGlobFacei,
342  const label edgeI
343  ) const;
344 
345  //- For truncateDisplacement: find strings of edges
346  void getVertexString
347  (
348  const indirectPrimitivePatch& pp,
349  const labelListList& globalEdgeFaces,
350  const label facei,
351  const label edgeI,
352  const label myGlobFacei,
353  const label nbrGlobFacei,
354  DynamicList<label>& vertices
355  ) const;
356 
357  //- Truncates displacement
358  // - for all patchFaces in the faceset displacement gets set
359  // to zero
360  // - all displacement < minThickness gets set to zero
361  // - all non-consecutive extrusions get set to 0
362  label truncateDisplacement
363  (
364  const globalIndex& globalFaces,
365  const labelListList& edgeGlobalFaces,
366  const indirectPrimitivePatch& pp,
367  const scalarField& minThickness,
368  const faceSet& illegalPatchFaces,
369  pointField& patchDisp,
370  labelList& patchNLayers,
371  List<extrudeMode>& extrudeStatus
372  ) const;
373 
374  //- Setup layer information (at points and faces) to
375  // modify mesh topology in
376  // regions where layer mesh terminates. Guarantees an
377  // optional slow decreasing of the number of layers.
378  // Returns the number of layers per face and per point
379  // to go into the actual layer addition engine.
380  void setupLayerInfoTruncation
381  (
382  const indirectPrimitivePatch& pp,
383  const labelList& patchNLayers,
384  const List<extrudeMode>& extrudeStatus,
385  const label nBufferCellsNoExtrude,
386  labelList& nPatchPointLayers,
387  labelList& nPatchFaceLayers
388  ) const;
389 
390  //- Does any of the cells use a face from faces?
391  static bool cellsUseFace
392  (
393  const polyMesh& mesh,
394  const labelList& cellLabels,
395  const labelHashSet& faces
396  );
397 
398  //- Checks the newly added cells and locally unmarks points
399  // so they will not get extruded next time round. Returns
400  // global number of unmarked points (0 if all was fine)
401  static label checkAndUnmark
402  (
403  const addPatchCellLayer& addLayer,
404  const dictionary& motionDict,
405  const bool additionalReporting,
406  const List<labelPair>& baffles,
407  const indirectPrimitivePatch& pp,
408  const fvMesh&,
409 
410  pointField& patchDisp,
411  labelList& patchNLayers,
412  List<extrudeMode>& extrudeStatus
413  );
414 
415  //- Count global number of extruded faces
416  static label countExtrusion
417  (
418  const indirectPrimitivePatch& pp,
419  const List<extrudeMode>& extrudeStatus
420  );
421 
422  //- After adding to mesh get the new baffles
423  static List<labelPair> getBafflesOnAddedMesh
424  (
425  const polyMesh& mesh,
426  const labelList& newToOldFaces,
427  const List<labelPair>& baffles
428  );
429 
430  //- Collect layer faces and layer cells into bools
431  // for ease of handling
432  static void getLayerCellsFaces
433  (
434  const polyMesh&,
435  const addPatchCellLayer&,
436  const scalarField& oldRealThickness,
437 
438  labelList& cellStatus,
439  scalarField& faceRealThickness
440  );
441 
442  //- Print layer coverage table
443  void printLayerData
444  (
445  const fvMesh& mesh,
446  const labelList& patchIDs,
447  const labelList& cellNLayers,
448  const scalarField& faceWantedThickness,
449  const scalarField& faceRealThickness
450  ) const;
451 
452  //- Write cellSet,faceSet for layers
453  bool writeLayerSets
454  (
455  const fvMesh& mesh,
456  const labelList& cellNLayers,
457  const scalarField& faceRealThickness
458  ) const;
459 
460  //- Write volFields,cellSet,faceSet for layers depending
461  // on write level
462  bool writeLayerData
463  (
464  const fvMesh& mesh,
465  const labelList& patchIDs,
466  const labelList& cellNLayers,
467  const scalarField& faceWantedThickness,
468  const scalarField& faceRealThickness
469  ) const;
470 
471 
472  // Mesh shrinking (to create space for layers)
473 
474  //- Average field (over all subset of mesh points) by
475  // summing contribution from edges. Global parallel since only
476  // does master edges for coupled edges.
477  template<class Type>
478  static void averageNeighbours
479  (
480  const polyMesh& mesh,
481  const bitSet& isMasterEdge,
482  const labelList& meshEdges,
483  const labelList& meshPoints,
484  const edgeList& edges,
485  const scalarField& invSumWeight,
486  const Field<Type>& data,
487  Field<Type>& average
488  );
489 
490  //- Calculate inverse sum of edge weights (currently always 1.0)
491  void sumWeights
492  (
493  const bitSet& isMasterEdge,
494  const labelList& meshEdges,
495  const labelList& meshPoints,
496  const edgeList& edges,
497  scalarField& invSumWeight
498  ) const;
499 
500  //- Smooth scalar field on patch
501  void smoothField
502  (
503  const motionSmoother& meshMover,
504  const bitSet& isMasterPoint,
505  const bitSet& isMasterEdge,
506  const labelList& meshEdges,
507  const scalarField& fieldMin,
508  const label nSmoothDisp,
510  ) const;
511 
512  //- Smooth normals on patch.
513  void smoothPatchNormals
514  (
515  const motionSmoother& meshMover,
516  const bitSet& isMasterPoint,
517  const bitSet& isMasterEdge,
518  const labelList& meshEdges,
519  const label nSmoothDisp,
520  pointField& normals
521  ) const;
522 
523  //- Smooth normals in interior.
524  void smoothNormals
525  (
526  const label nSmoothDisp,
527  const bitSet& isMasterPoint,
528  const bitSet& isMasterEdge,
529  const labelList& fixedPoints,
530  pointVectorField& normals
531  ) const;
532 
533  //- Stop layer growth where mesh wraps around edge with a
534  // large feature angle
535  void handleFeatureAngleLayerTerminations
536  (
537  const scalar minCos,
538  const bitSet& isMasterPoint,
539  const indirectPrimitivePatch& pp,
540  const labelList& meshEdges,
541 
542  List<extrudeMode>& extrudeStatus,
543  pointField& patchDisp,
544  labelList& patchNLayers,
545  label& nPointCounter
546  ) const;
547 
548  //- Find isolated islands (points, edges and faces and
549  // layer terminations)
550  // in the layer mesh and stop any layer growth at these points.
551  void findIsolatedRegions
552  (
553  const scalar minCosLayerTermination,
554  const bitSet& isMasterPoint,
555  const bitSet& isMasterEdge,
556  const indirectPrimitivePatch& pp,
557  const labelList& meshEdges,
558  const scalarField& minThickness,
559 
560  List<extrudeMode>& extrudeStatus,
561  pointField& patchDisp,
562  labelList& patchNLayers
563  ) const;
564 
565 
566  //- No copy construct
567  snappyLayerDriver(const snappyLayerDriver&) = delete;
568 
569  //- No copy assignment
570  void operator=(const snappyLayerDriver&) = delete;
571 
572 
573 public:
574 
575  //- Runtime type information
576  ClassName("snappyLayerDriver");
577 
578  // Constructors
579 
580  //- Construct from components
581  snappyLayerDriver
582  (
583  meshRefinement& meshRefiner,
584  const labelList& globalToMasterPatch,
585  const labelList& globalToSlavePatch,
586  const bool dryRun = false
587  );
588 
589 
590  // Member Functions
591 
592  //- Merge patch faces on same cell.
594  (
595  const layerParameters& layerParams,
596  const dictionary& motionDict,
597  const meshRefinement::FaceMergeType mergeType
598  );
599 
600  //- Add cell layers
601  void addLayers
602  (
603  const layerParameters& layerParams,
604  const dictionary& motionDict,
605  const labelList& patchIDs,
606  const label nAllowableErrors,
607  decompositionMethod& decomposer,
608  fvMeshDistribute& distributor
609  );
610 
611  //- Add layers according to the dictionary settings
612  void doLayers
613  (
614  const dictionary& shrinkDict,
615  const dictionary& motionDict,
616  const layerParameters& layerParams,
617  const meshRefinement::FaceMergeType mergeType,
618  const bool preBalance, // balance before adding?
619  decompositionMethod& decomposer,
620  fvMeshDistribute& distributor
621  );
622 };
623 
624 
625 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
626 
627 } // End namespace Foam
628 
629 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
630 
631 #ifdef NoRepository
633 #endif
634 
635 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
636 
637 #endif
638 
639 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
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:69
Foam::snappyLayerDriver::mergePatchFacesUndo
void mergePatchFacesUndo(const layerParameters &layerParams, const dictionary &motionDict, const meshRefinement::FaceMergeType mergeType)
Merge patch faces on same cell.
Definition: snappyLayerDriver.C:3221
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:3274
Foam::pointVectorField
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
Definition: pointFields.H:52
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:4637
Foam::labelHashSet
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys and label hasher.
Definition: HashSet.H:410
Foam::average
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:328
y
scalar y
Definition: LISASMDCalcMethod1.H:14