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

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