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

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