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

directMappedPatchBase.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::directMappedPatchBase
00027 
00028 Description
00029     Determines a mapping between patch face centres and mesh cell or face
00030     centres and processors they're on.
00031 
00032 Note
00033     Storage is not optimal. It temporary collects all (patch)face centres
00034     on all processors to keep the addressing calculation simple.
00035 
00036 SourceFiles
00037     directMappedPatchBase.C
00038 
00039 \*---------------------------------------------------------------------------*/
00040 
00041 #ifndef directMappedPatchBase_H
00042 #define directMappedPatchBase_H
00043 
00044 #include "pointField.H"
00045 #include "Tuple2.H"
00046 #include "pointIndexHit.H"
00047 #include "mapDistribute.H"
00048 
00049 
00050 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00051 
00052 namespace Foam
00053 {
00054 
00055 class polyPatch;
00056 class polyMesh;
00057 
00058 /*---------------------------------------------------------------------------*\
00059                       Class directMappedPatchBase Declaration
00060 \*---------------------------------------------------------------------------*/
00061 
00062 class directMappedPatchBase
00063 {
00064 
00065 public:
00066 
00067         //- Mesh items to sample
00068         enum sampleMode
00069         {
00070             NEARESTCELL,
00071             NEARESTPATCHFACE,
00072             NEARESTFACE
00073         };
00074 
00075 private:
00076 
00077     // Private data
00078 
00079         static const NamedEnum<sampleMode, 3> sampleModeNames_;
00080 
00081         //- Patch to sample
00082         const polyPatch& patch_;
00083 
00084         //- Region to sample
00085         const word sampleRegion_;
00086 
00087         //- What to sample
00088         const sampleMode mode_;
00089 
00090         //- Patch (only if NEARESTBOUNDARY)
00091         const word samplePatch_;
00092 
00093         //- Offset vector
00094         const vector offset_;
00095 
00096         //- Same region
00097         const bool sameRegion_;
00098 
00099 
00100         // Derived information
00101 
00102             //- Communication schedule:
00103             //  - Cells/faces to sample per processor
00104             //  - Patch faces to receive per processor
00105             //  - schedule
00106             mutable autoPtr<mapDistribute> mapPtr_;
00107 
00108 
00109     // Private Member Functions
00110 
00111         //- Collect single list of samples and originating processor+face.
00112         void collectSamples
00113         (
00114             pointField&,
00115             labelList& patchFaceProcs,
00116             labelList& patchFaces,
00117             pointField& patchFc
00118         ) const;
00119 
00120         //- Find cells/faces containing samples
00121         void findSamples
00122         (
00123             const pointField&,
00124             labelList& sampleProcs,     // processor containing sample
00125             labelList& sampleIndices,   // local index of cell/face
00126             pointField& sampleLocations // actual representative location
00127         ) const;
00128 
00129         //- Calculate matching
00130         void calcMapping() const;
00131 
00132 
00133     // Private class
00134 
00135         //- Private class for finding nearest
00136         //  - point+local index
00137         //  - sqr(distance)
00138         //  - processor
00139         typedef Tuple2<pointIndexHit, Tuple2<scalar, label> > nearInfo;
00140 
00141         class nearestEqOp
00142         {
00143 
00144         public:
00145 
00146             void operator()(nearInfo& x, const nearInfo& y) const
00147             {
00148                 if (y.first().hit())
00149                 {
00150                     if (!x.first().hit())
00151                     {
00152                         x = y;
00153                     }
00154                     else if (y.second().first() < x.second().first())
00155                     {
00156                         x = y;
00157                     }
00158                 }
00159             }
00160         };
00161 
00162 
00163 public:
00164 
00165     //- Runtime type information
00166     TypeName("directMappedPatchBase");
00167 
00168 
00169     // Constructors
00170 
00171         //- Construct from components
00172         directMappedPatchBase(const polyPatch&);
00173 
00174         //- Construct from dictionary
00175         directMappedPatchBase(const polyPatch&, const dictionary&);
00176 
00177         //- Construct as copy, resetting patch
00178         directMappedPatchBase(const polyPatch&, const directMappedPatchBase&);
00179 
00180 
00181     //- Destructor
00182     virtual ~directMappedPatchBase();
00183 
00184 
00185     // Member functions
00186 
00187         void clearOut();
00188 
00189         //- What to sample
00190         const sampleMode& mode() const
00191         {
00192             return mode_;
00193         }
00194 
00195         //- Region to sample
00196         const word& sampleRegion() const
00197         {
00198             return sampleRegion_;
00199         }
00200 
00201         //- Patch (only if NEARESTBOUNDARY)
00202         const word& samplePatch() const
00203         {
00204             return samplePatch_;
00205         }
00206 
00207         //- Offset vector (from patch faces to destination mesh objects)
00208         const vector& offset() const
00209         {
00210             return offset_;
00211         }
00212 
00213         //- Return reference to the parallel distribution map
00214         const mapDistribute& map() const
00215         {
00216             if (mapPtr_.empty())
00217             {
00218                 calcMapping();
00219             }
00220             return mapPtr_();
00221         }
00222 
00223         //- Cached sampleRegion != mesh.name()
00224         bool sameRegion() const
00225         {
00226             return sameRegion_;
00227         }
00228 
00229         //- Get the region mesh
00230         const polyMesh& sampleMesh() const;
00231 
00232         //- Get the patch on the region
00233         const polyPatch& samplePolyPatch() const;
00234 
00235         //- Write as a dictionary
00236         virtual void write(Ostream&) const;
00237 };
00238 
00239 
00240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00241 
00242 } // End namespace Foam
00243 
00244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00245 
00246 #endif
00247 
00248 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd