initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / directMapped / directMappedPolyPatch / directMappedPatchBase.H
bloba3d936757eaa5fc190dfb7890ff2f0194406f9a8
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::directMappedPatchBase
28 Description
29     Determines a mapping between patch face centres and mesh cell or face
30     centres and processors they're on.
32 Note
33     Storage is not optimal. It temporary collects all (patch)face centres
34     on all processors to keep the addressing calculation simple.
36 SourceFiles
37     directMappedPatchBase.C
39 \*---------------------------------------------------------------------------*/
41 #ifndef directMappedPatchBase_H
42 #define directMappedPatchBase_H
44 #include "pointField.H"
45 #include "Tuple2.H"
46 #include "pointIndexHit.H"
47 #include "mapDistribute.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 namespace Foam
55 class polyPatch;
56 class polyMesh;
58 /*---------------------------------------------------------------------------*\
59                       Class directMappedPatchBase Declaration
60 \*---------------------------------------------------------------------------*/
62 class directMappedPatchBase
65 public:
67         //- Mesh items to sample
68         enum sampleMode
69         {
70             NEARESTCELL,
71             NEARESTPATCHFACE,
72             NEARESTFACE
73         };
75 private:
77     // Private data
79         static const NamedEnum<sampleMode, 3> sampleModeNames_;
81         //- Patch to sample
82         const polyPatch& patch_;
84         //- Region to sample
85         const word sampleRegion_;
87         //- What to sample
88         const sampleMode mode_;
90         //- Patch (only if NEARESTBOUNDARY)
91         const word samplePatch_;
93         //- Offset vector
94         const vector offset_;
96         //- Same region
97         const bool sameRegion_;
100         // Derived information
102             //- Communication schedule:
103             //  - Cells/faces to sample per processor
104             //  - Patch faces to receive per processor
105             //  - schedule
106             mutable autoPtr<mapDistribute> mapPtr_;
109     // Private Member Functions
111         //- Collect single list of samples and originating processor+face.
112         void collectSamples
113         (
114             pointField&,
115             labelList& patchFaceProcs,
116             labelList& patchFaces,
117             pointField& patchFc
118         ) const;
120         //- Find cells/faces containing samples
121         void findSamples
122         (
123             const pointField&,
124             labelList& sampleProcs,     // processor containing sample
125             labelList& sampleIndices,   // local index of cell/face
126             pointField& sampleLocations // actual representative location
127         ) const;
129         //- Calculate matching
130         void calcMapping() const;
133     // Private class
135         //- Private class for finding nearest
136         //  - point+local index
137         //  - sqr(distance)
138         //  - processor
139         typedef Tuple2<pointIndexHit, Tuple2<scalar, label> > nearInfo;
141         class nearestEqOp
142         {
144         public:
146             void operator()(nearInfo& x, const nearInfo& y) const
147             {
148                 if (y.first().hit())
149                 {
150                     if (!x.first().hit())
151                     {
152                         x = y;
153                     }
154                     else if (y.second().first() < x.second().first())
155                     {
156                         x = y;
157                     }
158                 }
159             }
160         };
163 public:
165     //- Runtime type information
166     TypeName("directMappedPatchBase");
169     // Constructors
171         //- Construct from components
172         directMappedPatchBase(const polyPatch&);
174         //- Construct from dictionary
175         directMappedPatchBase(const polyPatch&, const dictionary&);
177         //- Construct as copy, resetting patch
178         directMappedPatchBase(const polyPatch&, const directMappedPatchBase&);
181     //- Destructor
182     virtual ~directMappedPatchBase();
185     // Member functions
187         void clearOut();
189         //- What to sample
190         const sampleMode& mode() const
191         {
192             return mode_;
193         }
195         //- Region to sample
196         const word& sampleRegion() const
197         {
198             return sampleRegion_;
199         }
201         //- Patch (only if NEARESTBOUNDARY)
202         const word& samplePatch() const
203         {
204             return samplePatch_;
205         }
207         //- Offset vector (from patch faces to destination mesh objects)
208         const vector& offset() const
209         {
210             return offset_;
211         }
213         //- Return reference to the parallel distribution map
214         const mapDistribute& map() const
215         {
216             if (mapPtr_.empty())
217             {
218                 calcMapping();
219             }
220             return mapPtr_();
221         }
223         //- Cached sampleRegion != mesh.name()
224         bool sameRegion() const
225         {
226             return sameRegion_;
227         }
229         //- Get the region mesh
230         const polyMesh& sampleMesh() const;
232         //- Get the patch on the region
233         const polyPatch& samplePolyPatch() const;
235         //- Write as a dictionary
236         virtual void write(Ostream&) const;
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 } // End namespace Foam
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 #endif
248 // ************************************************************************* //