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