FreeFOAM The Cross-Platform CFD Toolkit
directMappedPatchBase.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::directMappedPatchBase
26 
27 Description
28  Determines a mapping between patch face centres and mesh cell or face
29  centres and processors they're on.
30 
31 Note
32  Storage is not optimal. It temporary collects all (patch)face centres
33  on all processors to keep the addressing calculation simple.
34 
35 SourceFiles
36  directMappedPatchBase.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef directMappedPatchBase_H
41 #define directMappedPatchBase_H
42 
43 #include <OpenFOAM/pointField.H>
44 #include <OpenFOAM/Tuple2.H>
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 class polyPatch;
53 class polyMesh;
54 class mapDistribute;
55 
56 /*---------------------------------------------------------------------------*\
57  Class directMappedPatchBase Declaration
58 \*---------------------------------------------------------------------------*/
59 
61 {
62 
63 public:
64 
65  //- Mesh items to sample
67  {
68  NEARESTCELL, // nearest cell
69  NEARESTPATCHFACE, // faces on selected patch
70  NEARESTFACE // nearest face
71  };
72 
73 
74  //- Helper class for finding nearest
75  // - point+local index
76  // - sqr(distance)
77  // - processor
79 
81  {
82 
83  public:
84 
85  void operator()(nearInfo& x, const nearInfo& y) const
86  {
87  if (y.first().hit())
88  {
89  if (!x.first().hit())
90  {
91  x = y;
92  }
93  else if (y.second().first() < x.second().first())
94  {
95  x = y;
96  }
97  }
98  }
99  };
100 
101 private:
102 
103  // Private data
104 
105  static const NamedEnum<sampleMode, 3> sampleModeNames_;
106 
107  //- Patch to sample
108  const polyPatch& patch_;
109 
110  //- Region to sample
111  const word sampleRegion_;
112 
113  //- What to sample
114  const sampleMode mode_;
115 
116  //- Patch (only if NEARESTPATCHFACE)
117  const word samplePatch_;
118 
119  //- For backwards compatibility : reading/writing of uniform offset.
120  const bool uniformOffset_;
121 
122  //- Offset vector (uniform)
123  const vector offset_;
124 
125  //- Offset vector
126  const vectorField offsets_;
127 
128  //- Same region
129  const bool sameRegion_;
130 
131 
132  // Derived information
133 
134  //- Communication schedule:
135  // - Cells/faces to sample per processor
136  // - Patch faces to receive per processor
137  // - schedule
138  mutable autoPtr<mapDistribute> mapPtr_;
139 
140 
141  // Private Member Functions
142 
143  //- Collect single list of samples and originating processor+face.
144  void collectSamples
145  (
146  pointField&,
147  labelList& patchFaceProcs,
148  labelList& patchFaces,
149  pointField& patchFc
150  ) const;
151 
152  //- Find cells/faces containing samples
153  void findSamples
154  (
155  const pointField&,
156  labelList& sampleProcs, // processor containing sample
157  labelList& sampleIndices, // local index of cell/face
158  pointField& sampleLocations // actual representative location
159  ) const;
160 
161  //- Calculate matching
162  void calcMapping() const;
163 
164 
165 public:
166 
167  //- Runtime type information
168  TypeName("directMappedPatchBase");
169 
170 
171  // Constructors
172 
173  //- Construct from patch
175 
176  //- Construct from components
178  (
179  const polyPatch& pp,
180  const word& sampleRegion,
181  const sampleMode sampleMode,
182  const word& samplePatch,
183  const vectorField& offset
184  );
185 
186  //- Construct from components
188  (
189  const polyPatch& pp,
190  const word& sampleRegion,
191  const sampleMode sampleMode,
192  const word& samplePatch,
193  const vector& offset
194  );
195 
196  //- Construct from dictionary
198 
199  //- Construct as copy, resetting patch
201 
202 
203  //- Destructor
204  virtual ~directMappedPatchBase();
205 
206 
207  // Member functions
208 
209  void clearOut();
210 
211  //- What to sample
212  const sampleMode& mode() const
213  {
214  return mode_;
215  }
216 
217  //- Region to sample
218  const word& sampleRegion() const
219  {
220  return sampleRegion_;
221  }
222 
223  //- Patch (only if NEARESTPATCHFACE)
224  const word& samplePatch() const
225  {
226  return samplePatch_;
227  }
228 
229  //- Offset vector (from patch faces to destination mesh objects)
230  const vectorField& offsets() const
231  {
232  return offsets_;
233  }
234 
235  //- Return reference to the parallel distribution map
236  const mapDistribute& map() const
237  {
238  if (mapPtr_.empty())
239  {
240  calcMapping();
241  }
242  return mapPtr_();
243  }
244 
245  //- Cached sampleRegion != mesh.name()
246  bool sameRegion() const
247  {
248  return sameRegion_;
249  }
250 
251  //- Get the region mesh
252  const polyMesh& sampleMesh() const;
253 
254  //- Get the patch on the region
255  const polyPatch& samplePolyPatch() const;
256 
257  //- Write as a dictionary
258  virtual void write(Ostream&) const;
259 };
260 
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 } // End namespace Foam
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 #endif
269 
270 // ************************ vim: set sw=4 sts=4 et: ************************ //