ENH: snappyHexMesh: optional parameter for additional printing in layering
[OpenFOAM-2.0.x.git] / src / mesh / autoMesh / autoHexMesh / autoHexMeshDriver / autoLayerDriver.H
blob6bbe54a7089d1cb8762844787684da334ff34c9e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 Class
25     Foam::autoLayerDriver
27 Description
28     All to do with adding layers
30 SourceFiles
31     autoLayerDriver.C
33 \*---------------------------------------------------------------------------*/
35 #ifndef autoLayerDriver_H
36 #define autoLayerDriver_H
38 #include "meshRefinement.H"
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 namespace Foam
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;
54 /*---------------------------------------------------------------------------*\
55                            Class autoLayerDriver Declaration
56 \*---------------------------------------------------------------------------*/
58 class autoLayerDriver
60     // Static data members
62         //- Extrusion controls
63         enum extrudeMode
64         {
65             NOEXTRUDE,      /*!< Do not extrude. No layers added. */
66             EXTRUDE,        /*!< Extrude */
67             EXTRUDEREMOVE   /*!< Extrude but afterwards remove added */
68                             /*!< faces locally */
69         };
72     // Private classes
74         //- Combine operator class to combine normal with other normal.
75         class nomalsCombine
76         {
77         public:
79             void operator()(vector& x, const vector& y) const
80             {
81                 if (y != point::max)
82                 {
83                     if (x == point::max)
84                     {
85                         x = y;
86                     }
87                     else
88                     {
89                         x *= (x&y);
90                     }
91                 }
92             }
93         };
96     // Private data
98         //- Mesh+surface
99         meshRefinement& meshRefiner_;
101         //- From surface region to patch
102         const labelList globalToPatch_;
106     // Private Member Functions
108         // Layers
110             //- For debugging: Dump displacement to .obj files
111             static void dumpDisplacement
112             (
113                 const fileName&,
114                 const indirectPrimitivePatch&,
115                 const vectorField&,
116                 const List<extrudeMode>&
117             );
119             //- Check that primitivePatch is not multiply connected.
120             //  Collect non-manifold points in pointSet.
121             static void checkManifold
122             (
123                 const indirectPrimitivePatch&,
124                 pointSet& nonManifoldPoints
125             );
127             //- Check that mesh outside is not multiply connected.
128             void checkMeshManifold() const;
131             // Static extrusion setup
133                 //- Unset extrusion on point. Returns true if anything unset.
134                 static bool unmarkExtrusion
135                 (
136                     const label patchPointI,
137                     pointField& patchDisp,
138                     labelList& patchNLayers,
139                     List<extrudeMode>& extrudeStatus
140                 );
142                 //- Unset extrusion on face. Returns true if anything unset.
143                 static bool unmarkExtrusion
144                 (
145                     const face& localFace,
146                     pointField& patchDisp,
147                     labelList& patchNLayers,
148                     List<extrudeMode>& extrudeStatus
149                 );
151                 //- No extrusion at non-manifold points.
152                 void handleNonManifolds
153                 (
154                     const indirectPrimitivePatch& pp,
155                     const labelList& meshEdges,
156                     const labelListList& edgeGlobalFaces,
157                     pointField& patchDisp,
158                     labelList& patchNLayers,
159                     List<extrudeMode>& extrudeStatus
160                 ) const;
162                 //- No extrusion on feature edges. Assumes non-manifold
163                 //  edges already handled.
164                 void handleFeatureAngle
165                 (
166                     const indirectPrimitivePatch& pp,
167                     const labelList& meshEdges,
168                     const scalar minCos,
169                     pointField& patchDisp,
170                     labelList& patchNLayers,
171                     List<extrudeMode>& extrudeStatus
172                 ) const;
174                 //- No extrusion on warped faces
175                 void handleWarpedFaces
176                 (
177                     const indirectPrimitivePatch& pp,
178                     const scalar faceRatio,
179                     const scalar edge0Len,
180                     const labelList& cellLevel,
181                     pointField& patchDisp,
182                     labelList& patchNLayers,
183                     List<extrudeMode>& extrudeStatus
184                 ) const;
186                 //- Determine the number of layers per point from the number of
187                 //  layers per surface.
188                 void setNumLayers
189                 (
190                     const labelList& patchToNLayers,
191                     const labelList& patchIDs,
192                     const indirectPrimitivePatch& pp,
193                     pointField& patchDisp,
194                     labelList& patchNLayers,
195                     List<extrudeMode>& extrudeStatus
196                 ) const;
198                 //- Grow no-extrusion layer.
199                 void growNoExtrusion
200                 (
201                     const indirectPrimitivePatch& pp,
202                     pointField& patchDisp,
203                     labelList& patchNLayers,
204                     List<extrudeMode>& extrudeStatus
205                 ) const;
207                 //- See what patches boundaryedges should be extruded into
208                 void determineSidePatches
209                 (
210                     const globalIndex& globalFaces,
211                     const labelListList& edgeGlobalFaces,
212                     const indirectPrimitivePatch& pp,
214                     labelList& sidePatchID
215                 );
217                 //- Calculate pointwise wanted and minimum thickness.
218                 //  thickness: wanted thickness
219                 //  minthickness: when to give up and not extrude
220                 //  Gets per patch parameters and determine pp pointwise
221                 //  parameters.
222                 void calculateLayerThickness
223                 (
224                     const indirectPrimitivePatch& pp,
225                     const labelList& patchIDs,
227                     const scalarField& patchExpansionRatio,
228                     const bool relativeSizes,
229                     const scalarField& patchFinalLayerThickness,
230                     const scalarField& patchMinThickness,
232                     const labelList& cellLevel,
233                     const labelList& patchNLayers,
234                     const scalar edge0Len,
236                     scalarField& thickness,
237                     scalarField& minThickness,
238                     scalarField& expansionRatio
239                 ) const;
242             // Extrusion execution
244                 //- Synchronize displacement among coupled patches.
245                 void syncPatchDisplacement
246                 (
247                     const motionSmoother& meshMover,
248                     const scalarField& minThickness,
249                     pointField& patchDisp,
250                     labelList& patchNLayers,
251                     List<extrudeMode>& extrudeStatus
252                 ) const;
254                 //- Get nearest point on surface to snap to
255                 void getPatchDisplacement
256                 (
257                     const motionSmoother& meshMover,
258                     const scalarField& thickness,
259                     const scalarField& minThickness,
260                     pointField& patchDisp,
261                     labelList& patchNLayers,
262                     List<extrudeMode>& extrudeStatus
263                 ) const;
265                 //- for truncateDisplacement: find strings of edges
266                 bool sameEdgeNeighbour
267                 (
268                     const labelListList& globalEdgeFaces,
269                     const label myGlobalFaceI,
270                     const label nbrGlobFaceI,
271                     const label edgeI
272                 ) const;
274                 //- for truncateDisplacement: find strings of edges
275                 void getVertexString
276                 (
277                     const indirectPrimitivePatch& pp,
278                     const labelListList& globalEdgeFaces,
279                     const label faceI,
280                     const label edgeI,
281                     const label myGlobFaceI,
282                     const label nbrGlobFaceI,
283                     DynamicList<label>& vertices
284                 ) const;
286                 //- Truncates displacement
287                 // - for all patchFaces in the faceset displacement gets set
288                 //   to zero
289                 // - all displacement < minThickness gets set to zero
290                 // - all non-consecutive extrusions get set to 0
291                 label truncateDisplacement
292                 (
293                     const globalIndex& globalFaces,
294                     const labelListList& edgeGlobalFaces,
295                     const motionSmoother& meshMover,
296                     const scalarField& minThickness,
297                     const faceSet& illegalPatchFaces,
298                     pointField& patchDisp,
299                     labelList& patchNLayers,
300                     List<extrudeMode>& extrudeStatus
301                 ) const;
303                 //- Setup layer information (at points and faces) to
304                 //  modify mesh topology in
305                 //  regions where layer mesh terminates. Guarantees an
306                 //  optional slow decreasing of the number of layers.
307                 //  Returns the number of layers per face and per point
308                 //  to go into the actual layer addition engine.
309                 void setupLayerInfoTruncation
310                 (
311                     const motionSmoother& meshMover,
312                     const labelList& patchNLayers,
313                     const List<extrudeMode>& extrudeStatus,
314                     const label nBufferCellsNoExtrude,
315                     labelList& nPatchPointLayers,
316                     labelList& nPatchFaceLayers
317                 ) const;
319                 //- Does any of the cells use a face from faces?
320                 static bool cellsUseFace
321                 (
322                     const polyMesh& mesh,
323                     const labelList& cellLabels,
324                     const labelHashSet& faces
325                 );
327                 //- Checks the newly added cells and locally unmarks points
328                 //  so they will not get extruded next time round. Returns
329                 //  global number of unmarked points (0 if all was fine)
330                 static label checkAndUnmark
331                 (
332                     const addPatchCellLayer& addLayer,
333                     const dictionary& motionDict,
334                     const bool additionalReporting,
335                     const List<labelPair>& baffles,
336                     const indirectPrimitivePatch& pp,
337                     const fvMesh&,
339                     pointField& patchDisp,
340                     labelList& patchNLayers,
341                     List<extrudeMode>& extrudeStatus
342                 );
344                 //- Count global number of extruded faces
345                 static label countExtrusion
346                 (
347                     const indirectPrimitivePatch& pp,
348                     const List<extrudeMode>& extrudeStatus
349                 );
351                 //- Collect layer faces and layer cells into bools
352                 //  for ease of handling
353                 static void getLayerCellsFaces
354                 (
355                     const polyMesh&,
356                     const addPatchCellLayer&,
357                     boolList&,
358                     boolList&
359                 );
361             // Mesh shrinking (to create space for layers)
363                 //- Average field (over all subset of mesh points) by
364                 //  summing contribution from edges. Global parallel since only
365                 //  does master edges for coupled edges.
366                 template<class Type>
367                 static void averageNeighbours
368                 (
369                     const polyMesh& mesh,
370                     const PackedBoolList& isMasterEdge,
371                     const labelList& meshEdges,
372                     const labelList& meshPoints,
373                     const edgeList& edges,
374                     const scalarField& invSumWeight,
375                     const Field<Type>& data,
376                     Field<Type>& average
377                 );
379                 //- Calculate inverse sum of edge weights (currently always 1.0)
380                 void sumWeights
381                 (
382                     const PackedBoolList& isMasterEdge,
383                     const labelList& meshEdges,
384                     const labelList& meshPoints,
385                     const edgeList& edges,
386                     scalarField& invSumWeight
387                 ) const;
389                 //- Smooth scalar field on patch
390                 void smoothField
391                 (
392                     const motionSmoother& meshMover,
393                     const PackedBoolList& isMasterEdge,
394                     const labelList& meshEdges,
395                     const scalarField& fieldMin,
396                     const label nSmoothDisp,
397                     scalarField& field
398                 ) const;
400                 //- Smooth normals on patch.
401                 void smoothPatchNormals
402                 (
403                     const motionSmoother& meshMover,
404                     const PackedBoolList& isMasterEdge,
405                     const labelList& meshEdges,
406                     const label nSmoothDisp,
407                     pointField& normals
408                 ) const;
410                 //- Smooth normals in interior.
411                 void smoothNormals
412                 (
413                     const label nSmoothDisp,
414                     const PackedBoolList& isMasterEdge,
415                     const labelList& fixedPoints,
416                     pointVectorField& normals
417                 ) const;
419                 bool isMaxEdge
420                 (
421                     const List<pointData>&,
422                     const label edgeI,
423                     const scalar minCos
424                 ) const;
426                 //- Stop layer growth where mesh wraps around edge with a
427                 //  large feature angle
428                 void handleFeatureAngleLayerTerminations
429                 (
430                     const indirectPrimitivePatch& pp,
431                     const scalar minCos,
432                     List<extrudeMode>& extrudeStatus,
433                     pointField& patchDisp,
434                     labelList& patchNLayers,
435                     label& nPointCounter
436                 ) const;
438                 //- Find isolated islands (points, edges and faces and
439                 // layer terminations)
440                 // in the layer mesh and stop any layer growth at these points.
441                 void findIsolatedRegions
442                 (
443                     const indirectPrimitivePatch& pp,
444                     const PackedBoolList& isMasterEdge,
445                     const labelList& meshEdges,
446                     const scalar minCosLayerTermination,
447                     scalarField& field,
448                     List<extrudeMode>& extrudeStatus,
449                     pointField& patchDisp,
450                     labelList& patchNLayers
451                 ) const;
453                 // Calculate medial axis fields
454                 void medialAxisSmoothingInfo
455                 (
456                     const motionSmoother& meshMover,
457                     const label nSmoothNormals,
458                     const label nSmoothSurfaceNormals,
459                     const scalar minMedianAxisAngleCos,
461                     pointVectorField& dispVec,
462                     pointScalarField& medialRatio,
463                     pointScalarField& medialDist
464                 ) const;
466                 //- Main routine to shrink mesh
467                 void shrinkMeshMedialDistance
468                 (
469                     motionSmoother& meshMover,
470                     const dictionary& meshQualityDict,
471                     const List<labelPair>& baffles,
472                     const label nSmoothThickness,
473                     const scalar maxThicknessToMedialRatio,
474                     const label nAllowableErrors,
475                     const label nSnap,
476                     const scalar minCosLayerTermination,
478                     const scalarField& layerThickness,
479                     const scalarField& minThickness,
481                     const pointVectorField& dispVec,
482                     const pointScalarField& medialRatio,
483                     const pointScalarField& medialDist,
485                     List<extrudeMode>& extrudeStatus,
486                     pointField& patchDisp,
487                     labelList& patchNLayers
488                 ) const;
492         //- Disallow default bitwise copy construct
493         autoLayerDriver(const autoLayerDriver&);
495         //- Disallow default bitwise assignment
496         void operator=(const autoLayerDriver&);
499 public:
501     //- Runtime type information
502     ClassName("autoLayerDriver");
504     // Constructors
506         //- Construct from components
507         autoLayerDriver
508         (
509             meshRefinement& meshRefiner,
510             const labelList& globalToPatch
511         );
514     // Member Functions
516             //- Merge patch faces on same cell.
517             void mergePatchFacesUndo
518             (
519                 const layerParameters& layerParams,
520                 const dictionary& motionDict
521             );
523             //- Add cell layers
524             void addLayers
525             (
526                 const layerParameters& layerParams,
527                 const dictionary& motionDict,
528                 const labelList& patchIDs,
529                 const label nAllowableErrors,
530                 decompositionMethod& decomposer,
531                 fvMeshDistribute& distributor
532             );
534             //- Add layers according to the dictionary settings
535             void doLayers
536             (
537                 const dictionary& shrinkDict,
538                 const dictionary& motionDict,
539                 const layerParameters& layerParams,
540                 const bool preBalance,              // balance before adding?
541                 decompositionMethod& decomposer,
542                 fvMeshDistribute& distributor
543             );
548 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
550 } // End namespace Foam
552 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
554 #ifdef NoRepository
555 #   include "autoLayerDriverTemplates.C"
556 #endif
558 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
560 #endif
562 // ************************************************************************* //