OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

autoLayerDriver.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::autoLayerDriver
00027 
00028 Description
00029     All to do with adding layers
00030 
00031 SourceFiles
00032     autoLayerDriver.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef autoLayerDriver_H
00037 #define autoLayerDriver_H
00038 
00039 #include "meshRefinement.H"
00040 #include "wallPoint.H"
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 // Forward declaration of classes
00048 class removePoints;
00049 class pointSet;
00050 class motionSmoother;
00051 class addPatchCellLayer;
00052 class pointData;
00053 class wallPoint;
00054 class faceSet;
00055 class layerParameters;
00056 
00057 /*---------------------------------------------------------------------------*\
00058                            Class autoLayerDriver Declaration
00059 \*---------------------------------------------------------------------------*/
00060 
00061 class autoLayerDriver
00062 {
00063     // Static data members
00064 
00065         //- Extrusion controls
00066         enum extrudeMode
00067         {
00068             NOEXTRUDE,      
00069             EXTRUDE,        
00070             EXTRUDEREMOVE   
00072         };
00073 
00074 
00075     // Private classes
00076 
00077         //- Combine operator class to combine normal with other normal.
00078         class nomalsCombine
00079         {
00080         public:
00081 
00082             void operator()(vector& x, const vector& y) const
00083             {
00084                 if (y != wallPoint::greatPoint)
00085                 {
00086                     if (x == wallPoint::greatPoint)
00087                     {
00088                         x = y;
00089                     }
00090                     else
00091                     {
00092                         x *= (x&y);
00093                     }
00094                 }
00095             }
00096         };
00097 
00098 
00099     // Private data
00100 
00101         //- Mesh+surface
00102         meshRefinement& meshRefiner_;
00103 
00104 
00105 
00106     // Private Member Functions
00107 
00108 
00109         // Face merging
00110 
00111             //- Merge patch faces. Undo until no checkMesh errors.
00112             label mergePatchFacesUndo
00113             (
00114                 const scalar minCos,
00115                 const scalar concaveCos,
00116                 const dictionary&
00117             );
00118 
00119             //- Remove points.
00120             autoPtr<mapPolyMesh> doRemovePoints
00121             (
00122                 removePoints& pointRemover,
00123                 const boolList& pointCanBeDeleted
00124             );
00125 
00126             //- Restore faces (which contain removed points)
00127             autoPtr<mapPolyMesh> doRestorePoints
00128             (
00129                 removePoints& pointRemover,
00130                 const labelList& facesToRestore
00131             );
00132 
00133             //- Return candidateFaces that are also in set.
00134             labelList collectFaces
00135             (
00136                 const labelList& candidateFaces,
00137                 const labelHashSet& set
00138             ) const;
00139 
00140             //- Pick up faces of cells of faces in set.
00141             labelList growFaceCellFace(const labelHashSet&) const;
00142 
00143             //- Remove points not used by any face or points used by only
00144             //  two faces where the edges are in line
00145             label mergeEdgesUndo(const scalar minCos, const dictionary&);
00146 
00147 
00148         // Layers
00149 
00150             //- For debugging: Dump displacement to .obj files
00151             static void dumpDisplacement
00152             (
00153                 const fileName&,
00154                 const indirectPrimitivePatch&,
00155                 const vectorField&,
00156                 const List<extrudeMode>&
00157             );
00158 
00159             //- Check that primitivePatch is not multiply connected.
00160             //  Collect non-manifold points in pointSet.
00161             static void checkManifold
00162             (
00163                 const indirectPrimitivePatch&,
00164                 pointSet& nonManifoldPoints
00165             );
00166 
00167             //- Check that mesh outside is not multiply connected.
00168             void checkMeshManifold() const;
00169 
00170 
00171             // Static extrusion setup
00172 
00173                 //- Unset extrusion on point. Returns true if anything unset.
00174                 static bool unmarkExtrusion
00175                 (
00176                     const label patchPointI,
00177                     pointField& patchDisp,
00178                     labelList& patchNLayers,
00179                     List<extrudeMode>& extrudeStatus
00180                 );
00181 
00182                 //- Unset extrusion on face. Returns true if anything unset.
00183                 static bool unmarkExtrusion
00184                 (
00185                     const face& localFace,
00186                     pointField& patchDisp,
00187                     labelList& patchNLayers,
00188                     List<extrudeMode>& extrudeStatus
00189                 );
00190 
00191                 //- No extrusion at non-manifold points.
00192                 void handleNonManifolds
00193                 (
00194                     const indirectPrimitivePatch& pp,
00195                     const labelList& meshEdges,
00196                     pointField& patchDisp,
00197                     labelList& patchNLayers,
00198                     List<extrudeMode>& extrudeStatus
00199                 ) const;
00200 
00201                 //- No extrusion on feature edges. Assumes non-manifold
00202                 //  edges already handled.
00203                 void handleFeatureAngle
00204                 (
00205                     const indirectPrimitivePatch& pp,
00206                     const labelList& meshEdges,
00207                     const scalar minCos,
00208                     pointField& patchDisp,
00209                     labelList& patchNLayers,
00210                     List<extrudeMode>& extrudeStatus
00211                 ) const;
00212 
00213                 //- No extrusion on warped faces
00214                 void handleWarpedFaces
00215                 (
00216                     const indirectPrimitivePatch& pp,
00217                     const scalar faceRatio,
00218                     const scalar edge0Len,
00219                     const labelList& cellLevel,
00220                     pointField& patchDisp,
00221                     labelList& patchNLayers,
00222                     List<extrudeMode>& extrudeStatus
00223                 ) const;
00224 
00225                 //- Determine the number of layers per point from the number of
00226                 //  layers per surface.
00227                 void setNumLayers
00228                 (
00229                     const labelList& patchToNLayers,
00230                     const labelList& patchIDs,
00231                     const indirectPrimitivePatch& pp,
00232                     pointField& patchDisp,
00233                     labelList& patchNLayers,
00234                     List<extrudeMode>& extrudeStatus
00235                 ) const;
00236 
00237                 //- Grow no-extrusion layer.
00238                 static void growNoExtrusion
00239                 (
00240                     const indirectPrimitivePatch& pp,
00241                     pointField& patchDisp,
00242                     labelList& patchNLayers,
00243                     List<extrudeMode>& extrudeStatus
00244                 );
00245 
00246                 //- Calculate pointwise wanted and minimum thickness.
00247                 //  thickness: wanted thickness
00248                 //  minthickness: when to give up and not extrude
00249                 //  Gets per patch parameters and determine pp pointwise
00250                 //  parameters.
00251                 void calculateLayerThickness
00252                 (
00253                     const indirectPrimitivePatch& pp,
00254                     const labelList& patchIDs,
00255 
00256                     const scalarField& patchExpansionRatio,
00257                     const bool relativeSizes,
00258                     const scalarField& patchFinalLayerThickness,
00259                     const scalarField& patchMinThickness,
00260 
00261                     const labelList& cellLevel,
00262                     const labelList& patchNLayers,
00263                     const scalar edge0Len,
00264 
00265                     scalarField& thickness,
00266                     scalarField& minThickness,
00267                     scalarField& expansionRatio
00268                 ) const;
00269 
00270 
00271             // Extrusion execution
00272 
00273                 //- Synchronize displacement among coupled patches.
00274                 void syncPatchDisplacement
00275                 (
00276                     const motionSmoother& meshMover,
00277                     const scalarField& minThickness,
00278                     pointField& patchDisp,
00279                     labelList& patchNLayers,
00280                     List<extrudeMode>& extrudeStatus
00281                 ) const;
00282 
00283                 //- Get nearest point on surface to snap to
00284                 void getPatchDisplacement
00285                 (
00286                     const motionSmoother& meshMover,
00287                     const scalarField& thickness,
00288                     const scalarField& minThickness,
00289                     pointField& patchDisp,
00290                     labelList& patchNLayers,
00291                     List<extrudeMode>& extrudeStatus
00292                 ) const;
00293 
00294                 //- Truncates displacement
00295                 // - for all patchFaces in the faceset displacement gets set
00296                 //   to zero
00297                 // - all displacement < minThickness gets set to zero
00298                 label truncateDisplacement
00299                 (
00300                     const motionSmoother& meshMover,
00301                     const scalarField& minThickness,
00302                     const faceSet& illegalPatchFaces,
00303                     pointField& patchDisp,
00304                     labelList& patchNLayers,
00305                     List<extrudeMode>& extrudeStatus
00306                 ) const;
00307 
00308                 //- Setup layer information (at points and faces) to
00309                 //  modify mesh topology in
00310                 //  regions where layer mesh terminates. Guarantees an
00311                 //  optional slow decreasing of the number of layers.
00312                 //  Returns the number of layers per face and per point
00313                 //  to go into the actual layer addition engine.
00314                 void setupLayerInfoTruncation
00315                 (
00316                     const motionSmoother& meshMover,
00317                     const labelList& patchNLayers,
00318                     const List<extrudeMode>& extrudeStatus,
00319                     const label nBufferCellsNoExtrude,
00320                     labelList& nPatchPointLayers,
00321                     labelList& nPatchFaceLayers
00322                 ) const;
00323 
00324                 //- Does any of the cells use a face from faces?
00325                 static bool cellsUseFace
00326                 (
00327                     const polyMesh& mesh,
00328                     const labelList& cellLabels,
00329                     const labelHashSet& faces
00330                 );
00331 
00332                 //- Checks the newly added cells and locally unmarks points
00333                 //  so they will not get extruded next time round. Returns
00334                 //  global number of unmarked points (0 if all was fine)
00335                 static label checkAndUnmark
00336                 (
00337                     const addPatchCellLayer& addLayer,
00338                     const dictionary& motionDict,
00339                     const indirectPrimitivePatch& pp,
00340                     const fvMesh&,
00341 
00342                     pointField& patchDisp,
00343                     labelList& patchNLayers,
00344                     List<extrudeMode>& extrudeStatus
00345                 );
00346 
00347                 //- Count global number of extruded faces
00348                 static label countExtrusion
00349                 (
00350                     const indirectPrimitivePatch& pp,
00351                     const List<extrudeMode>& extrudeStatus
00352                 );
00353 
00354                 //- Collect layer faces and layer cells into bools
00355                 //  for ease of handling
00356                 static void getLayerCellsFaces
00357                 (
00358                     const polyMesh&,
00359                     const addPatchCellLayer&,
00360                     boolList&,
00361                     boolList&
00362                 );
00363 
00364             // Mesh shrinking (to create space for layers)
00365 
00366                 //- Average field (over all subset of mesh points) by
00367                 //  summing contribution from edges. Global parallel since only
00368                 //  does master edges for coupled edges.
00369                 template<class Type>
00370                 static void averageNeighbours
00371                 (
00372                     const polyMesh& mesh,
00373                     const PackedBoolList& isMasterEdge,
00374                     const labelList& meshEdges,
00375                     const labelList& meshPoints,
00376                     const edgeList& edges,
00377                     const scalarField& invSumWeight,
00378                     const Field<Type>& data,
00379                     Field<Type>& average
00380                 );
00381 
00382                 //- Calculate inverse sum of edge weights (currently always 1.0)
00383                 void sumWeights
00384                 (
00385                     const PackedBoolList& isMasterEdge,
00386                     const labelList& meshEdges,
00387                     const labelList& meshPoints,
00388                     const edgeList& edges,
00389                     scalarField& invSumWeight
00390                 ) const;
00391 
00392                 //- Smooth scalar field on patch
00393                 void smoothField
00394                 (
00395                     const motionSmoother& meshMover,
00396                     const PackedBoolList& isMasterEdge,
00397                     const labelList& meshEdges,
00398                     const scalarField& fieldMin,
00399                     const label& nSmoothDisp,
00400                     scalarField& field
00401                 ) const;
00402 
00403                 //- Smooth normals on patch.
00404                 void smoothPatchNormals
00405                 (
00406                     const motionSmoother& meshMover,
00407                     const PackedBoolList& isMasterEdge,
00408                     const labelList& meshEdges,
00409                     const label nSmoothDisp,
00410                     pointField& normals
00411                 ) const;
00412 
00413                 //- Smooth normals in interior.
00414                 void smoothNormals
00415                 (
00416                     const label nSmoothDisp,
00417                     const PackedBoolList& isMasterEdge,
00418                     const labelList& fixedPoints,
00419                     pointVectorField& normals
00420                 ) const;
00421 
00422                 bool isMaxEdge
00423                 (
00424                     const List<pointData>&,
00425                     const label edgeI,
00426                     const scalar minCos
00427                 ) const;
00428 
00429                 //- Stop layer growth where mesh wraps around edge with a
00430                 //  large feature angle
00431                 void handleFeatureAngleLayerTerminations
00432                 (
00433                     const indirectPrimitivePatch& pp,
00434                     const scalar minCos,
00435                     List<extrudeMode>& extrudeStatus,
00436                     pointField& patchDisp,
00437                     labelList& patchNLayers,
00438                     label& nPointCounter
00439                 ) const;
00440 
00441                 //- Find isolated islands (points, edges and faces and
00442                 // layer terminations)
00443                 // in the layer mesh and stop any layer growth at these points.
00444                 void findIsolatedRegions
00445                 (
00446                     const indirectPrimitivePatch& pp,
00447                     const PackedBoolList& isMasterEdge,
00448                     const labelList& meshEdges,
00449                     const scalar minCosLayerTermination,
00450                     scalarField& field,
00451                     List<extrudeMode>& extrudeStatus,
00452                     pointField& patchDisp,
00453                     labelList& patchNLayers
00454                 ) const;
00455 
00456                 // Calculate medial axis fields
00457                 void medialAxisSmoothingInfo
00458                 (
00459                     const motionSmoother& meshMover,
00460                     const label nSmoothNormals,
00461                     const label nSmoothSurfaceNormals,
00462                     const scalar minMedianAxisAngleCos,
00463 
00464                     pointVectorField& dispVec,
00465                     pointScalarField& medialRatio,
00466                     pointScalarField& medialDist
00467                 ) const;
00468 
00469                 //- Main routine to shrink mesh
00470                 void shrinkMeshMedialDistance
00471                 (
00472                     motionSmoother& meshMover,
00473                     const dictionary& meshQualityDict,
00474                     const label nSmoothThickness,
00475                     const scalar maxThicknessToMedialRatio,
00476                     const label nAllowableErrors,
00477                     const label nSnap,
00478                     const scalar minCosLayerTermination,
00479 
00480                     const scalarField& layerThickness,
00481                     const scalarField& minThickness,
00482 
00483                     const pointVectorField& dispVec,
00484                     const pointScalarField& medialRatio,
00485                     const pointScalarField& medialDist,
00486 
00487                     List<extrudeMode>& extrudeStatus,
00488                     pointField& patchDisp,
00489                     labelList& patchNLayers
00490                 ) const;
00491 
00492 
00493 
00494         //- Disallow default bitwise copy construct
00495         autoLayerDriver(const autoLayerDriver&);
00496 
00497         //- Disallow default bitwise assignment
00498         void operator=(const autoLayerDriver&);
00499 
00500 
00501 public:
00502 
00503     //- Runtime type information
00504     ClassName("autoLayerDriver");
00505 
00506     // Constructors
00507 
00508         //- Construct from components
00509         autoLayerDriver(meshRefinement& meshRefiner);
00510 
00511 
00512     // Member Functions
00513 
00514             //- Merge patch faces on same cell.
00515             void mergePatchFacesUndo
00516             (
00517                 const layerParameters& layerParams,
00518                 const dictionary& motionDict
00519             );
00520 
00521             //- Add cell layers
00522             void addLayers
00523             (
00524                 const layerParameters& layerParams,
00525                 const dictionary& motionDict,
00526                 const label nAllowableErrors,
00527                 motionSmoother& meshMover,
00528                 decompositionMethod& decomposer,
00529                 fvMeshDistribute& distributor
00530             );
00531 
00532             //- Add layers according to the dictionary settings
00533             void doLayers
00534             (
00535                 const dictionary& shrinkDict,
00536                 const dictionary& motionDict,
00537                 const layerParameters& layerParams,
00538                 decompositionMethod& decomposer,
00539                 fvMeshDistribute& distributor
00540             );
00541 
00542 };
00543 
00544 
00545 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00546 
00547 } // End namespace Foam
00548 
00549 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00550 
00551 #ifdef NoRepository
00552 #   include "autoLayerDriverTemplates.C"
00553 #endif
00554 
00555 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00556 
00557 #endif
00558 
00559 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd