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

autoSnapDriver.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::autoSnapDriver
00027 
00028 Description
00029     All to do with snapping to surface
00030 
00031 SourceFiles
00032     autoSnapDriver.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef autoSnapDriver_H
00037 #define autoSnapDriver_H
00038 
00039 #include "meshRefinement.H"
00040 
00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00042 
00043 namespace Foam
00044 {
00045 
00046 // Forward declaration of classes
00047 class motionSmoother;
00048 class snapParameters;
00049 
00050 /*---------------------------------------------------------------------------*\
00051                            Class autoSnapDriver Declaration
00052 \*---------------------------------------------------------------------------*/
00053 
00054 class autoSnapDriver
00055 {
00056     // Private classes
00057 
00058         //- Combine operator class for equalizing displacements.
00059         class minMagEqOp
00060         {
00061         public:
00062 
00063             void operator()(vector& x, const vector& y) const
00064             {
00065                 if (magSqr(y) < magSqr(x))
00066                 {
00067                     x = y;
00068                 }
00069             }
00070         };
00071 
00072 
00073     // Private data
00074 
00075         //- Mesh+surface
00076         meshRefinement& meshRefiner_;
00077 
00078         //- From surface region to patch
00079         const labelList globalToPatch_;
00080 
00081 
00082     // Private Member Functions
00083 
00084 
00085         // Snapping
00086 
00087             //- Get faces to repatch. Returns map from face to patch.
00088             Map<label> getZoneBafflePatches(const bool allowBoundary) const;
00089 
00090             //- Calculates (geometric) shared points
00091             static label getCollocatedPoints
00092             (
00093                 const scalar tol,
00094                 const pointField&,
00095                 PackedBoolList&
00096             );
00097 
00098             //- Calculate displacement per patch point to smooth out patch.
00099             //  Quite complicated in determining which points to move where.
00100             pointField smoothPatchDisplacement
00101             (
00102                 const motionSmoother&,
00103                 const List<labelPair>&
00104             ) const;
00105 
00106             //- Check that face zones are synced
00107             void checkCoupledFaceZones() const;
00108 
00109             //- Per edge distance to patch
00110             static tmp<scalarField> edgePatchDist
00111             (
00112                 const pointMesh&,
00113                 const indirectPrimitivePatch&
00114             );
00115 
00116             //- Write displacement as .obj file.
00117             static void dumpMove
00118             (
00119                 const fileName&,
00120                 const pointField&,
00121                 const pointField&
00122             );
00123 
00124             //- Check displacement is outwards pointing
00125             static bool outwardsDisplacement
00126             (
00127                 const indirectPrimitivePatch&,
00128                 const vectorField&
00129             );
00130 
00131 
00132         //- Disallow default bitwise copy construct
00133         autoSnapDriver(const autoSnapDriver&);
00134 
00135         //- Disallow default bitwise assignment
00136         void operator=(const autoSnapDriver&);
00137 
00138 
00139 public:
00140 
00141     //- Runtime type information
00142     ClassName("autoSnapDriver");
00143 
00144 
00145     // Constructors
00146 
00147         //- Construct from components
00148         autoSnapDriver
00149         (
00150             meshRefinement& meshRefiner,
00151             const labelList& globalToPatch
00152         );
00153 
00154 
00155     // Member Functions
00156 
00157         // Snapping
00158 
00159             //- Create baffles for faces straddling zoned surfaces. Return
00160             //  baffles.
00161             autoPtr<mapPolyMesh> createZoneBaffles(List<labelPair>&);
00162 
00163             //- Merge baffles.
00164             autoPtr<mapPolyMesh> mergeZoneBaffles(const List<labelPair>&);
00165 
00166             //- Calculate edge length per patch point.
00167             scalarField calcSnapDistance
00168             (
00169                 const snapParameters& snapParams,
00170                 const indirectPrimitivePatch&
00171             ) const;
00172 
00173             //- Smooth the mesh (patch and internal) to increase visibility
00174             //  of surface points (on castellated mesh) w.r.t. surface.
00175             void preSmoothPatch
00176             (
00177                 const snapParameters& snapParams,
00178                 const label nInitErrors,
00179                 const List<labelPair>& baffles,
00180                 motionSmoother&
00181             ) const;
00182 
00183             //- Get points both on patch and facezone.
00184             labelList getZoneSurfacePoints
00185             (
00186                 const indirectPrimitivePatch&,
00187                 const word& zoneName
00188             ) const;
00189 
00190             //- Per patch point calculate point on nearest surface. Set as
00191             //  boundary conditions of motionSmoother displacement field. Return
00192             //  displacement of patch points.
00193             vectorField calcNearestSurface
00194             (
00195                 const scalarField& snapDist,
00196                 motionSmoother& meshMover
00197             ) const;
00198 
00199             //- Smooth the displacement field to the internal.
00200             void smoothDisplacement
00201             (
00202                 const snapParameters& snapParams,
00203                 motionSmoother&
00204             ) const;
00205 
00206             //- Do the hard work: move the mesh according to displacement,
00207             //  locally relax the displacement.
00208             void scaleMesh
00209             (
00210                 const snapParameters& snapParams,
00211                 const label nInitErrors,
00212                 const List<labelPair>& baffles,
00213                 motionSmoother&
00214             );
00215 
00216             //- Repatch faces according to surface nearest the face centre
00217             autoPtr<mapPolyMesh> repatchToSurface
00218             (
00219                 const snapParameters& snapParams,
00220                 const labelList& adaptPatchIDs
00221             );
00222 
00223 
00224             void doSnap
00225             (
00226                 const dictionary& snapDict,
00227                 const dictionary& motionDict,
00228                 const snapParameters& snapParams
00229             );
00230 
00231 };
00232 
00233 
00234 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00235 
00236 } // End namespace Foam
00237 
00238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00239 
00240 #endif
00241 
00242 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd