FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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