Merge branch 'upstream/OpenFOAM' into master
[freefoam.git] / src / autoMesh / autoHexMesh / autoHexMeshDriver / autoLayerDriver.H
blob616d9a853320f7871fa0e4978e0d91279b824b6f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::autoLayerDriver
28 Description
29     All to do with adding layers
31 SourceFiles
32     autoLayerDriver.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef autoLayerDriver_H
37 #define autoLayerDriver_H
39 #include <autoMesh/meshRefinement.H>
40 #include <meshTools/wallPoint.H>
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
47 // Forward declaration of classes
48 class removePoints;
49 class pointSet;
50 class motionSmoother;
51 class addPatchCellLayer;
52 class pointData;
53 class wallPoint;
54 class faceSet;
55 class layerParameters;
57 /*---------------------------------------------------------------------------*\
58                            Class autoLayerDriver Declaration
59 \*---------------------------------------------------------------------------*/
61 class autoLayerDriver
63     // Static data members
65         //- Extrusion controls
66         enum extrudeMode
67         {
68             NOEXTRUDE,      /*!< Do not extrude. No layers added. */
69             EXTRUDE,        /*!< Extrude */
70             EXTRUDEREMOVE   /*!< Extrude but afterwards remove added */
71                             /*!< faces locally */
72         };
75     // Private classes
77         //- Combine operator class to combine normal with other normal.
78         class nomalsCombine
79         {
80         public:
82             void operator()(vector& x, const vector& y) const
83             {
84                 if (y != wallPoint::greatPoint)
85                 {
86                     if (x == wallPoint::greatPoint)
87                     {
88                         x = y;
89                     }
90                     else
91                     {
92                         x *= (x&y);
93                     }
94                 }
95             }
96         };
99     // Private data
101         //- Mesh+surface
102         meshRefinement& meshRefiner_;
106     // Private Member Functions
109         // Face merging
111             //- Merge patch faces. Undo until no checkMesh errors.
112             label mergePatchFacesUndo
113             (
114                 const scalar minCos,
115                 const scalar concaveCos,
116                 const dictionary&
117             );
119             //- Remove points.
120             autoPtr<mapPolyMesh> doRemovePoints
121             (
122                 removePoints& pointRemover,
123                 const boolList& pointCanBeDeleted
124             );
126             //- Restore faces (which contain removed points)
127             autoPtr<mapPolyMesh> doRestorePoints
128             (
129                 removePoints& pointRemover,
130                 const labelList& facesToRestore
131             );
133             //- Return candidateFaces that are also in set.
134             labelList collectFaces
135             (
136                 const labelList& candidateFaces,
137                 const labelHashSet& set
138             ) const;
140             //- Pick up faces of cells of faces in set.
141             labelList growFaceCellFace(const labelHashSet&) const;
143             //- Remove points not used by any face or points used by only
144             //  two faces where the edges are in line
145             label mergeEdgesUndo(const scalar minCos, const dictionary&);
148         // Layers
150             //- For debugging: Dump displacement to .obj files
151             static void dumpDisplacement
152             (
153                 const fileName&,
154                 const indirectPrimitivePatch&,
155                 const vectorField&,
156                 const List<extrudeMode>&
157             );
159             //- Check that primitivePatch is not multiply connected.
160             //  Collect non-manifold points in pointSet.
161             static void checkManifold
162             (
163                 const indirectPrimitivePatch&,
164                 pointSet& nonManifoldPoints
165             );
167             //- Check that mesh outside is not multiply connected.
168             void checkMeshManifold() const;
171             // Static extrusion setup
173                 //- Unset extrusion on point. Returns true if anything unset.
174                 static bool unmarkExtrusion
175                 (
176                     const label patchPointI,
177                     pointField& patchDisp,
178                     labelList& patchNLayers,
179                     List<extrudeMode>& extrudeStatus
180                 );
182                 //- Unset extrusion on face. Returns true if anything unset.
183                 static bool unmarkExtrusion
184                 (
185                     const face& localFace,
186                     pointField& patchDisp,
187                     labelList& patchNLayers,
188                     List<extrudeMode>& extrudeStatus
189                 );
191                 //- No extrusion at non-manifold points.
192                 void handleNonManifolds
193                 (
194                     const indirectPrimitivePatch& pp,
195                     const labelList& meshEdges,
196                     pointField& patchDisp,
197                     labelList& patchNLayers,
198                     List<extrudeMode>& extrudeStatus
199                 ) const;
201                 //- No extrusion on feature edges. Assumes non-manifold
202                 //  edges already handled.
203                 void handleFeatureAngle
204                 (
205                     const indirectPrimitivePatch& pp,
206                     const labelList& meshEdges,
207                     const scalar minCos,
208                     pointField& patchDisp,
209                     labelList& patchNLayers,
210                     List<extrudeMode>& extrudeStatus
211                 ) const;
213                 //- No extrusion on warped faces
214                 void handleWarpedFaces
215                 (
216                     const indirectPrimitivePatch& pp,
217                     const scalar faceRatio,
218                     const scalar edge0Len,
219                     const labelList& cellLevel,
220                     pointField& patchDisp,
221                     labelList& patchNLayers,
222                     List<extrudeMode>& extrudeStatus
223                 ) const;
225                 //- Determine the number of layers per point from the number of
226                 //  layers per surface.
227                 void setNumLayers
228                 (
229                     const labelList& patchToNLayers,
230                     const labelList& patchIDs,
231                     const indirectPrimitivePatch& pp,
232                     pointField& patchDisp,
233                     labelList& patchNLayers,
234                     List<extrudeMode>& extrudeStatus
235                 ) const;
237                 //- Grow no-extrusion layer.
238                 static void growNoExtrusion
239                 (
240                     const indirectPrimitivePatch& pp,
241                     pointField& patchDisp,
242                     labelList& patchNLayers,
243                     List<extrudeMode>& extrudeStatus
244                 );
246                 //- Calculate pointwise wanted and minimum thickness.
247                 //  thickness: wanted thickness
248                 //  minthickness: when to give up and not extrude
249                 //  Gets per patch parameters and determine pp pointwise
250                 //  parameters.
251                 void calculateLayerThickness
252                 (
253                     const indirectPrimitivePatch& pp,
254                     const labelList& patchIDs,
256                     const scalarField& patchExpansionRatio,
257                     const bool relativeSizes,
258                     const scalarField& patchFinalLayerThickness,
259                     const scalarField& patchMinThickness,
261                     const labelList& cellLevel,
262                     const labelList& patchNLayers,
263                     const scalar edge0Len,
265                     scalarField& thickness,
266                     scalarField& minThickness,
267                     scalarField& expansionRatio
268                 ) const;
271             // Extrusion execution
273                 //- Synchronize displacement among coupled patches.
274                 void syncPatchDisplacement
275                 (
276                     const motionSmoother& meshMover,
277                     const scalarField& minThickness,
278                     pointField& patchDisp,
279                     labelList& patchNLayers,
280                     List<extrudeMode>& extrudeStatus
281                 ) const;
283                 //- Get nearest point on surface to snap to
284                 void getPatchDisplacement
285                 (
286                     const motionSmoother& meshMover,
287                     const scalarField& thickness,
288                     const scalarField& minThickness,
289                     pointField& patchDisp,
290                     labelList& patchNLayers,
291                     List<extrudeMode>& extrudeStatus
292                 ) const;
294                 //- Truncates displacement
295                 // - for all patchFaces in the faceset displacement gets set
296                 //   to zero
297                 // - all displacement < minThickness gets set to zero
298                 label truncateDisplacement
299                 (
300                     const motionSmoother& meshMover,
301                     const scalarField& minThickness,
302                     const faceSet& illegalPatchFaces,
303                     pointField& patchDisp,
304                     labelList& patchNLayers,
305                     List<extrudeMode>& extrudeStatus
306                 ) const;
308                 //- Setup layer information (at points and faces) to
309                 //  modify mesh topology in
310                 //  regions where layer mesh terminates. Guarantees an
311                 //  optional slow decreasing of the number of layers.
312                 //  Returns the number of layers per face and per point
313                 //  to go into the actual layer addition engine.
314                 void setupLayerInfoTruncation
315                 (
316                     const motionSmoother& meshMover,
317                     const labelList& patchNLayers,
318                     const List<extrudeMode>& extrudeStatus,
319                     const label nBufferCellsNoExtrude,
320                     labelList& nPatchPointLayers,
321                     labelList& nPatchFaceLayers
322                 ) const;
324                 //- Does any of the cells use a face from faces?
325                 static bool cellsUseFace
326                 (
327                     const polyMesh& mesh,
328                     const labelList& cellLabels,
329                     const labelHashSet& faces
330                 );
332                 //- Checks the newly added cells and locally unmarks points
333                 //  so they will not get extruded next time round. Returns
334                 //  global number of unmarked points (0 if all was fine)
335                 static label checkAndUnmark
336                 (
337                     const addPatchCellLayer& addLayer,
338                     const dictionary& motionDict,
339                     const indirectPrimitivePatch& pp,
340                     const fvMesh&,
342                     pointField& patchDisp,
343                     labelList& patchNLayers,
344                     List<extrudeMode>& extrudeStatus
345                 );
347                 //- Count global number of extruded faces
348                 static label countExtrusion
349                 (
350                     const indirectPrimitivePatch& pp,
351                     const List<extrudeMode>& extrudeStatus
352                 );
354                 //- Collect layer faces and layer cells into bools
355                 //  for ease of handling
356                 static void getLayerCellsFaces
357                 (
358                     const polyMesh&,
359                     const addPatchCellLayer&,
360                     boolList&,
361                     boolList&
362                 );
364             // Mesh shrinking (to create space for layers)
366                 //- Average field (over all subset of mesh points) by
367                 //  summing contribution from edges. Global parallel since only
368                 //  does master edges for coupled edges.
369                 template<class Type>
370                 static void averageNeighbours
371                 (
372                     const polyMesh& mesh,
373                     const PackedBoolList& isMasterEdge,
374                     const labelList& meshEdges,
375                     const labelList& meshPoints,
376                     const edgeList& edges,
377                     const scalarField& invSumWeight,
378                     const Field<Type>& data,
379                     Field<Type>& average
380                 );
382                 //- Calculate inverse sum of edge weights (currently always 1.0)
383                 void sumWeights
384                 (
385                     const PackedBoolList& isMasterEdge,
386                     const labelList& meshEdges,
387                     const labelList& meshPoints,
388                     const edgeList& edges,
389                     scalarField& invSumWeight
390                 ) const;
392                 //- Smooth scalar field on patch
393                 void smoothField
394                 (
395                     const motionSmoother& meshMover,
396                     const PackedBoolList& isMasterEdge,
397                     const labelList& meshEdges,
398                     const scalarField& fieldMin,
399                     const label& nSmoothDisp,
400                     scalarField& field
401                 ) const;
403                 //- Smooth normals on patch.
404                 void smoothPatchNormals
405                 (
406                     const motionSmoother& meshMover,
407                     const PackedBoolList& isMasterEdge,
408                     const labelList& meshEdges,
409                     const label nSmoothDisp,
410                     pointField& normals
411                 ) const;
413                 //- Smooth normals in interior.
414                 void smoothNormals
415                 (
416                     const label nSmoothDisp,
417                     const PackedBoolList& isMasterEdge,
418                     const labelList& fixedPoints,
419                     pointVectorField& normals
420                 ) const;
422                 bool isMaxEdge
423                 (
424                     const List<pointData>&,
425                     const label edgeI,
426                     const scalar minCos
427                 ) const;
429                 //- Stop layer growth where mesh wraps around edge with a
430                 //  large feature angle
431                 void handleFeatureAngleLayerTerminations
432                 (
433                     const indirectPrimitivePatch& pp,
434                     const scalar minCos,
435                     List<extrudeMode>& extrudeStatus,
436                     pointField& patchDisp,
437                     labelList& patchNLayers,
438                     label& nPointCounter
439                 ) const;
441                 //- Find isolated islands (points, edges and faces and
442                 // layer terminations)
443                 // in the layer mesh and stop any layer growth at these points.
444                 void findIsolatedRegions
445                 (
446                     const indirectPrimitivePatch& pp,
447                     const PackedBoolList& isMasterEdge,
448                     const labelList& meshEdges,
449                     const scalar minCosLayerTermination,
450                     scalarField& field,
451                     List<extrudeMode>& extrudeStatus,
452                     pointField& patchDisp,
453                     labelList& patchNLayers
454                 ) const;
456                 // Calculate medial axis fields
457                 void medialAxisSmoothingInfo
458                 (
459                     const motionSmoother& meshMover,
460                     const label nSmoothNormals,
461                     const label nSmoothSurfaceNormals,
462                     const scalar minMedianAxisAngleCos,
464                     pointVectorField& dispVec,
465                     pointScalarField& medialRatio,
466                     pointScalarField& medialDist
467                 ) const;
469                 //- Main routine to shrink mesh
470                 void shrinkMeshMedialDistance
471                 (
472                     motionSmoother& meshMover,
473                     const dictionary& meshQualityDict,
474                     const label nSmoothThickness,
475                     const scalar maxThicknessToMedialRatio,
476                     const label nAllowableErrors,
477                     const label nSnap,
478                     const scalar minCosLayerTermination,
480                     const scalarField& layerThickness,
481                     const scalarField& minThickness,
483                     const pointVectorField& dispVec,
484                     const pointScalarField& medialRatio,
485                     const pointScalarField& medialDist,
487                     List<extrudeMode>& extrudeStatus,
488                     pointField& patchDisp,
489                     labelList& patchNLayers
490                 ) const;
494         //- Disallow default bitwise copy construct
495         autoLayerDriver(const autoLayerDriver&);
497         //- Disallow default bitwise assignment
498         void operator=(const autoLayerDriver&);
501 public:
503     //- Runtime type information
504     ClassName("autoLayerDriver");
506     // Constructors
508         //- Construct from components
509         autoLayerDriver(meshRefinement& meshRefiner);
512     // Member Functions
514             //- Merge patch faces on same cell.
515             void mergePatchFacesUndo
516             (
517                 const layerParameters& layerParams,
518                 const dictionary& motionDict
519             );
521             //- Add cell layers
522             void addLayers
523             (
524                 const layerParameters& layerParams,
525                 const dictionary& motionDict,
526                 const label nAllowableErrors,
527                 motionSmoother& meshMover,
528                 decompositionMethod& decomposer,
529                 fvMeshDistribute& distributor
530             );
532             //- Add layers according to the dictionary settings
533             void doLayers
534             (
535                 const dictionary& shrinkDict,
536                 const dictionary& motionDict,
537                 const layerParameters& layerParams,
538                 decompositionMethod& decomposer,
539                 fvMeshDistribute& distributor
540             );
545 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
547 } // End namespace Foam
549 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
551 #ifdef NoRepository
552 #   include <autoMesh/autoLayerDriverTemplates.C>
553 #endif
555 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
557 #endif
559 // ************************ vim: set sw=4 sts=4 et: ************************ //