OpenFOAM logo
Open Source CFD Toolkit

motionSmoother.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-2005 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     motionSmoother
00027 
00028 Description
00029     Given a displacement moves the mesh by scaling the displacement back
00030     until there are no more mesh errors. Holds displacement field
00031     (read upon construction since need boundary conditions) and scaling factor
00032     and optional patch number on which to scale back displacement.
00033 
00034     E.g.
00035         
00036         // Construct iterative mesh mover.
00037         motionSmoother meshMover(mesh, labelList(1, patchI));
00038 
00039         // Set wanted displacement:
00040         meshMover.displacement() = ..
00041 
00042         for (label iter = 0; iter < maxIter; iter++)
00043         {
00044             if (meshMover.scaleMesh(true))
00045             {
00046                 Info<< "Successfully moved mesh" << endl;
00047                 return true;
00048             }
00049         }
00050 
00051 SourceFiles
00052     motionSmoother.C
00053     motionSmootherTemplates.C
00054 
00055 \*---------------------------------------------------------------------------*/
00056 
00057 #ifndef motionSmoother_H
00058 #define motionSmoother_H
00059 
00060 #include "pointFields.H"
00061 #include "labelHashSet.H"
00062 #include "PackedList.H"
00063 #include "indirectPrimitivePatch.H"
00064 #include "className.H"
00065 
00066 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00067 
00068 namespace Foam
00069 {
00070 
00071 // Class forward declarations
00072 class twoDPointCorrector;
00073 
00074 /*---------------------------------------------------------------------------*\
00075                            Class motionSmoother Declaration
00076 \*---------------------------------------------------------------------------*/
00077 
00078 class motionSmoother
00079 {
00080     // Private class
00081 
00083         template <class T>
00084         class minEqOp
00085         {
00086 
00087         public:
00088 
00089             void operator()(T& x, const T& y) const
00090             {
00091                 x = min(x, y);
00092             }
00093         };
00094 
00095 
00096     // Private data
00097 
00098         //- Reference to polyMesh. Non-const since we move mesh.
00099         polyMesh& mesh_;
00100 
00101         //- Reference to pointMesh
00102         pointMesh& pMesh_;
00103 
00104         //- Reference to face subset of all adaptPatchIDs
00105         indirectPrimitivePatch& pp_;
00106 
00107         //- Indices of fixedValue patches that we're allowed to modify the
00108         // displacement on.
00109         const labelList adaptPatchIDs_;
00110 
00111 
00112         // Smoothing parameters
00113 
00114         //- Amount by which to reduce displacement on points in error.
00115         const scalar reduction_;
00116 
00117         //- Number of smoothing iterations on scale_ to distribute error.
00118         const label nSmoothScale_;
00119 
00120 
00121         // Mesh check params
00122 
00123             //- Max non-ortho
00124             const scalar maxNonOrtho_;
00125 
00126             //- Minimum allowed pyramid volume for accepting a mesh.
00127             const scalar minVol_;
00128 
00129             //- Max allowed concave angle (in degrees, 0 is straight,
00130             //  <0 would be convex)
00131             const scalar maxConcave_;
00132 
00133             //- Min face area
00134             const scalar minArea_;
00135 
00136 
00137         // Internal data
00138 
00139         //- Displacement field
00140         pointVectorField displacement_;
00141 
00142         //- Scale factor for displacement
00143         pointScalarField scale_;
00144 
00145         //- Starting mesh position
00146         pointField oldPoints_;
00147 
00148         //- Is mesh point on boundary or not
00149         PackedList<1> isInternalPoint_;
00150 
00151         //- Is motion limited to twoD
00152         Switch twoDMotion_;
00153 
00154         //- Only if twoDMotion_ : 2-D motion corrector pointer
00155         twoDPointCorrector* correct2DPtr_;
00156         
00157 
00158     // Private Member Functions
00159 
00160         //- (unweighted) average of all values on points connected via edges
00161         //  to pointI
00162         template <class Type>
00163         static Type avg
00164         (
00165             const GeometricField<Type, pointPatchField, pointMesh>& fld,
00166             const edgeList& edges,
00167             const pointField& points,
00168             const labelList& edgeLabels,
00169             const label pointI
00170         );
00171 
00172         //- Distance weighted average. Is average with inverse distance
00173         //  weighting and varying edge-diffusivity.
00174         template <class Type>
00175         static Type avg
00176         (
00177             const GeometricField<Type, pointPatchField, pointMesh>& fld,
00178             const scalarField& edgeGamma,
00179             const edgeList& edges,
00180             const pointField& points,
00181             const labelList& edgeLabels,
00182             const label pointI
00183         );
00184 
00185         static void checkFld(const pointScalarField& fld);
00186 
00187         //- Get points used by given faces
00188         labelHashSet getPoints(const labelHashSet&) const;
00189 
00190         //- explicit smoothing and min on all internal points
00191         void minSmooth(const pointScalarField&, pointScalarField&) const;
00192 
00193         //- same but only on selected points (usually patch points)
00194         void minSmooth
00195         (
00196             const labelList& meshPoints,
00197             const pointScalarField& fld,
00198             pointScalarField& newFld
00199         ) const;
00200 
00201         //- Scale certain (internal) points of a field
00202         void scaleField
00203         (
00204             const labelHashSet& pointLabels,
00205             const scalar scale,
00206             pointScalarField& fld
00207         ) const;
00208 
00209         //- As above but points have to be in meshPoints as well
00210         //  (usually to scale patch points)
00211         void scaleField
00212         (
00213             const labelList& meshPoints,
00214             const labelHashSet& pointLabels,
00215             const scalar scale,
00216             pointScalarField& fld
00217         ) const;
00218 
00219         //- Helper function. Is point internal?
00220         bool isInternalPoint(const label pointI) const;
00221 
00222         //- Disallow default bitwise copy construct
00223         motionSmoother(const motionSmoother&);
00224 
00225         //- Disallow default bitwise assignment
00226         void operator=(const motionSmoother&);
00227 
00228 
00229 public:
00230 
00231     ClassName("motionSmoother");
00232 
00233     // Constructors
00234 
00235         //- Construct from mesh, optional fixedValue patch
00236         //  where displacement will be adapted and parameters: number of
00237         //  error distribution cycles, minimum pyramid vol, max. concaveness
00238         //  check. Will read displacement field.
00239         motionSmoother
00240         (
00241             polyMesh&,
00242             pointMesh&,
00243             indirectPrimitivePatch& pp,         // 'outside' points
00244             const labelList& adaptPatchIDs,     // patches forming 'outside'
00245             const scalar reduction = 0.5,       // scale back displacement
00246             const label nSmoothScale = 1,       // number of smoothing iters
00247             const scalar maxNonOrtho = 90,      // max non-ortho
00248             const scalar minVol = SMALL,        // min allowed cell vol
00249             const scalar maxConcave = 180,      // max allowed face concavity
00250             const scalar minArea = VSMALL       // min face area
00251         );
00252 
00253 
00254     // Destructor
00255 
00256         ~motionSmoother();
00257 
00258 
00259     // Member Functions
00260 
00261         // Access
00262 
00263             //- Reference to mesh
00264             const polyMesh& mesh() const;
00265 
00266             //- Reference to pointMesh
00267             const pointMesh& pMesh() const;
00268 
00269             //- Reference to patch
00270             const indirectPrimitivePatch& patch() const;
00271 
00272             scalar maxNonOrtho() const;
00273 
00274             scalar minVol() const;
00275 
00276             scalar maxConcave() const;
00277 
00278             scalar minArea() const;
00279 
00280 
00281             //- Reference to displacement field
00282             pointVectorField& displacement();
00283 
00284             //- Reference to displacement field
00285             const pointVectorField& displacement() const;
00286 
00287             //- Reference to scale field
00288             const pointScalarField& scale() const;
00289 
00290             //- Starting mesh position
00291             const pointField& oldPoints() const;
00292 
00293             bool twoDMotion() const
00294             {
00295                 return twoDMotion_;
00296             }
00297 
00298             twoDPointCorrector& twoDCorrector()
00299             {
00300                 if (!correct2DPtr_)
00301                 {
00302                     FatalErrorIn("motionSmoother::correct2D()")
00303                         << "No 2D motion. Check constant/dynamicMeshDict"
00304                         <<  " and empty 3D boundaries" << abort(FatalError);
00305                 }
00306                 return *correct2DPtr_;
00307             }
00308 
00309 
00310 
00311         // Edit
00312 
00313             //- Take over existing mesh position.
00314             void correct();
00315 
00316 
00317             //- Move mesh. Does 2D correction (modifies passed pointField) and
00318             //  polyMesh::movePoints. Returns swept volumes.
00319             tmp<scalarField> movePoints(pointField&);
00320 
00321             //- Move mesh with given scale. Return true if mesh ok or has
00322             //  less than nAllow errors, false
00323             //  otherwise and locally update scale. Smoothmesh=false means only
00324             //  patch points get moved.
00325             //  Parallel ok (as long as displacement field is consistent
00326             //  across patches)
00327             bool scaleMesh
00328             (
00329                 const bool smoothMesh = true,
00330                 const label nAllow = 0
00331             );
00332 
00333             //- Update topology
00334             void updateMesh();
00335 
00336             //- Check mesh with current settings. Collects incorrect faces
00337             //  in set. Returns true if one or more faces in error.
00338             //  Parallel ok.
00339             bool checkMesh(labelHashSet&) const;
00340 
00341 
00342             // Helper functions to manipulate displacement vector.
00343 
00344                 //- Point-jacobi smoothing of internal points
00345                 template <class Type>
00346                 void smooth
00347                 (
00348                     GeometricField<Type, pointPatchField, pointMesh>&
00349                 ) const;
00350 
00351                 //- Fully explicit smoothing of internal points with varying
00352                 //  diffusivity.
00353                 template <class Type>
00354                 void smooth
00355                 (
00356                     const GeometricField<Type, pointPatchField, pointMesh>& fld,
00357                     const scalarField& edgeGamma,
00358                     GeometricField<Type, pointPatchField, pointMesh>& newFld
00359                 ) const;
00360 
00361                 //- Sychronizes patch points on pointField
00362                 template<class Type, class CombineOp>
00363                 static void syncField
00364                 (
00365                     GeometricField<Type, pointPatchField, pointMesh>&,
00366                     const Type& zero,
00367                     const CombineOp& cop
00368                 );
00369 
00370 };
00371 
00372 
00373 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00374 
00375 } // End namespace Foam
00376 
00377 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00378 
00379 #ifdef NoRepository
00380 #   include "motionSmootherTemplates.C"
00381 #endif
00382 
00383 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00384 
00385 #endif
00386 
00387 // ************************************************************************* //
For further information go to www.openfoam.org