mappedPatchBase.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) 2011-2015 OpenFOAM Foundation
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::mappedPatchBase
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  If constructed from dictionary:
32  // Region to sample (default is region0)
33  sampleRegion region0;
34 
35  // What to sample:
36  // - nearestCell : sample cell containing point
37  // - nearestOnlyCell : nearest sample cell (even if not containing
38  // point)
39  // - nearestPatchFace : nearest face on selected patch
40  // - nearestPatchFaceAMI : nearest face on selected patch
41  - patches need not conform
42  - uses AMI interpolation
43  // - nearestFace : nearest boundary face on any patch
44  // - nearestPatchPoint : nearest patch point (for coupled points
45  // this might be any of the points so you have
46  // to guarantee the point data is synchronised
47  // beforehand)
48  sampleMode nearestCell;
49 
50  // If sampleMode is nearestPatchFace : patch to find faces of
51  samplePatch movingWall;
52 
53  // If sampleMode is nearestPatchFace : specify patchgroup to find
54  // samplePatch and sampleRegion (if not provided)
55  coupleGroup baffleGroup;
56 
57  // How to supply offset (w.r.t. my patch face centres):
58  // - uniform : single offset vector
59  // - nonuniform : per-face offset vector
60  // - normal : using supplied distance and face normal
61  offsetMode uniform;
62 
63  // According to offsetMode (see above) supply one of
64  // offset, offsets or distance
65  offset (1 0 0);
66 
67  Note: if offsetMode is 'normal' it uses outwards pointing normals. So
68  supply a negative distance if sampling inside the domain.
69 
70 
71 Note
72  Storage is not optimal. It temporary collects all (patch)face centres
73  on all processors to keep the addressing calculation simple.
74 
75 SourceFiles
76  mappedPatchBase.C
77 
78 \*---------------------------------------------------------------------------*/
79 
80 #ifndef mappedPatchBase_H
81 #define mappedPatchBase_H
82 
83 #include "pointField.H"
84 #include "Tuple2.H"
85 #include "pointIndexHit.H"
87 #include "coupleGroupIdentifier.H"
88 
89 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
90 
91 namespace Foam
92 {
93 
94 class polyPatch;
95 class polyMesh;
96 class mapDistribute;
97 
98 /*---------------------------------------------------------------------------*\
99  Class mappedPatchBase Declaration
100 \*---------------------------------------------------------------------------*/
102 class mappedPatchBase
103 {
104 
105 public:
106 
107  // Type enumerations
108 
109  //- Mesh items to sample
110  enum sampleMode
111  {
112  NEARESTCELL, // nearest cell containing sample
113  NEARESTPATCHFACE, // nearest face on selected patch
114  NEARESTPATCHFACEAMI, // nearest patch face + AMI interpolation
115  NEARESTPATCHPOINT, // nearest point on selected patch
116  NEARESTFACE, // nearest face
117  NEARESTONLYCELL // nearest cell (even if not containing cell)
118  };
119 
120  //- How to project face centres
121  enum offsetMode
122  {
123  UNIFORM, // single offset vector
124  NONUNIFORM, // per-face offset vector
125  NORMAL // use face normal + distance
126  };
131 
132 
133  //- Helper class for finding nearest
134  // Nearest:
135  // - point+local index
136  // - sqr(distance)
137  // - processor
140  class nearestEqOp
141  {
142 
143  public:
145  void operator()(nearInfo& x, const nearInfo& y) const
146  {
147  if (y.first().hit())
148  {
149  if (!x.first().hit())
150  {
151  x = y;
152  }
153  else if (y.second().first() < x.second().first())
154  {
155  x = y;
156  }
157  }
158  }
159  };
161  class maxProcEqOp
162  {
163 
164  public:
166  void operator()(nearInfo& x, const nearInfo& y) const
167  {
168  if (y.first().hit())
169  {
170  if (!x.first().hit())
171  {
172  x = y;
173  }
174  else if (y.second().second() > x.second().second())
175  {
176  x = y;
177  }
178  }
179  }
180  };
181 
182 
183 protected:
184 
185  // Protected data
186 
187  //- Patch to sample
188  const polyPatch& patch_;
189 
190  //- Region to sample
191  mutable word sampleRegion_;
192 
193  //- What to sample
194  const sampleMode mode_;
195 
196  //- Patch (if in sampleMode NEARESTPATCH*)
197  mutable word samplePatch_;
198 
199  //- PatchGroup (if in sampleMode NEARESTPATCH*)
201 
202  //- How to obtain samples
204 
205  //- Offset vector (uniform)
206  vector offset_;
207 
208  //- Offset vector (nonuniform)
210 
211  //- Offset distance (normal)
212  scalar distance_;
213 
214  //- Same region
215  mutable bool sameRegion_;
216 
217 
218  // Derived information
219 
220  //- Communication schedule:
221  // - Cells/faces to sample per processor
222  // - Patch faces to receive per processor
223  // - schedule
225 
226 
227  // AMI interpolator (only for NEARESTPATCHFACEAMI)
228 
229  //- Pointer to AMI interpolator
231 
232  //- Flag to indicate that slave patch should be reversed for AMI
233  const bool AMIReverse_;
234 
235  //- Pointer to projection surface employed by AMI interpolator
237 
238  //- Dictionary storing projection surface description
240 
241 
242  // Protected Member Functions
243 
244  //- Get the points from face-centre-decomposition face centres
245  // and project them onto the face-diagonal-decomposition triangles.
246  tmp<pointField> facePoints(const polyPatch&) const;
247 
248  //- Collect single list of samples and originating processor+face.
249  void collectSamples
250  (
251  const pointField& facePoints,
252  pointField&,
253  labelList& patchFaceProcs,
254  labelList& patchFaces,
255  pointField& patchFc
256  ) const;
257 
258  //- Find cells/faces containing samples
259  void findSamples
260  (
261  const sampleMode mode, // search mode
262  const pointField&,
263  labelList& sampleProcs, // processor containing sample
264  labelList& sampleIndices, // local index of cell/face
265  pointField& sampleLocations // actual representative location
266  ) const;
267 
268  //- Get the sample points given the face points
270 
271  //- Calculate mapping
272  void calcMapping() const;
273 
274  //- Calculate AMI interpolator
275  void calcAMI() const;
276 
277  //- Helper to read field or non-uniform list from dictionary
279  (
280  const word& keyword,
281  const dictionary& dict,
282  const label size
283  );
284 
285 
286 public:
287 
288  //- Runtime type information
289  TypeName("mappedPatchBase");
290 
291 
292  // Constructors
293 
294  //- Construct from patch
295  mappedPatchBase(const polyPatch&);
296 
297  //- Construct with offsetMode=non-uniform
299  (
300  const polyPatch& pp,
301  const word& sampleRegion,
302  const sampleMode sampleMode,
303  const word& samplePatch,
304  const vectorField& offsets
305  );
306 
307  //- Construct from offsetMode=uniform
309  (
310  const polyPatch& pp,
311  const word& sampleRegion,
312  const sampleMode sampleMode,
313  const word& samplePatch,
314  const vector& offset
315  );
316 
317  //- Construct from offsetMode=normal and distance
319  (
320  const polyPatch& pp,
321  const word& sampleRegion,
322  const sampleMode sampleMode,
323  const word& samplePatch,
324  const scalar distance
325  );
326 
327  //- Construct from dictionary
328  mappedPatchBase(const polyPatch&, const dictionary&);
329 
330  //- Construct from dictionary and (collocated) sample mode
331  // (only for nearestPatchFace, nearestPatchFaceAMI, nearestPatchPoint)
332  // Assumes zero offset.
333  mappedPatchBase(const polyPatch&, const sampleMode, const dictionary&);
334 
335  //- Construct as copy, resetting patch
336  mappedPatchBase(const polyPatch&, const mappedPatchBase&);
337 
338  //- Construct as copy, resetting patch, map original data
340  (
341  const polyPatch&,
342  const mappedPatchBase&,
343  const labelUList& mapAddressing
344  );
345 
346 
347  //- Destructor
348  virtual ~mappedPatchBase();
349 
350 
351  // Member functions
352 
353  void clearOut();
354 
355  // Access
356 
357  //- What to sample
358  inline const sampleMode& mode() const;
359 
360  //- Region to sample
361  inline const word& sampleRegion() const;
362 
363  //- Patch (only if NEARESTPATCHFACE)
364  inline const word& samplePatch() const;
365 
366  //- PatchGroup (only if NEARESTPATCHFACE)
367  inline const word& coupleGroup() const;
368 
369  //- Return size of mapped mesh/patch/boundary
370  inline label sampleSize() const;
371 
372  //- Offset vector (from patch faces to destination mesh objects)
373  inline const vector& offset() const;
374 
375  //- Offset vector (from patch faces to destination mesh objects)
376  inline const vectorField& offsets() const;
377 
378  //- Cached sampleRegion != mesh.name()
379  inline bool sameRegion() const;
380 
381  //- Return reference to the parallel distribution map
382  inline const mapDistribute& map() const;
383 
384  //- Return reference to the AMI interpolator
385  inline const AMIPatchToPatchInterpolation& AMI
386  (
387  const bool forceUpdate = false
388  ) const;
389 
390  //- Return a pointer to the AMI projection surface
392 
393  //- Get the region mesh
394  const polyMesh& sampleMesh() const;
395 
396  //- Get the patch on the region
397  const polyPatch& samplePolyPatch() const;
398 
399 
400  // Helpers
401 
402  //- Get the sample points
404 
405  //- Get a point on the face given a face decomposition method:
406  // face-centre-tet : face centre. Returns index of face.
407  // face-planes : face centre. Returns index of face.
408  // face-diagonal : intersection of ray from cellcentre to
409  // facecentre with any of the triangles.
410  // Returns index (0..size-2) of triangle.
411  static pointIndexHit facePoint
412  (
413  const polyMesh&,
414  const label faceI,
416  );
417 
418 
419  // Distribute
420 
421  //- Wrapper around map/interpolate data distribution
422  template<class Type>
423  void distribute(List<Type>& lst) const;
424 
425  //- Wrapper around map/interpolate data distribution with operation
426  template<class Type, class CombineOp>
427  void distribute(List<Type>& lst, const CombineOp& cop) const;
428 
429  //- Wrapper around map/interpolate data distribution
430  template<class Type>
431  void reverseDistribute(List<Type>& lst) const;
432 
433  //- Wrapper around map/interpolate data distribution with operation
434  template<class Type, class CombineOp>
435  void reverseDistribute(List<Type>& lst, const CombineOp& cop) const;
436 
437 
438  // I/O
439 
440  //- Write as a dictionary
441  virtual void write(Ostream&) const;
442 };
443 
444 
445 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
446 
447 } // End namespace Foam
448 
449 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
450 
451 #include "mappedPatchBaseI.H"
452 
453 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
454 
455 #ifdef NoRepository
456  #include "mappedPatchBaseTemplates.C"
457 #endif
458 
459 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
460 
461 #endif
462 
463 // ************************************************************************* //
const Type2 & second() const
Return second.
Definition: Tuple2.H:106
vector offset_
Offset vector (uniform)
word samplePatch_
Patch (if in sampleMode NEARESTPATCH*)
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:47
void collectSamples(const pointField &facePoints, pointField &, labelList &patchFaceProcs, labelList &patchFaces, pointField &patchFc) const
Collect single list of samples and originating processor+face.
autoPtr< AMIPatchToPatchInterpolation > AMIPtr_
Pointer to AMI interpolator.
autoPtr< mapDistribute > mapPtr_
Communication schedule:
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:53
const word & coupleGroup() const
PatchGroup (only if NEARESTPATCHFACE)
const polyMesh & sampleMesh() const
Get the region mesh.
tmp< pointField > samplePoints() const
Get the sample points.
tmp< pointField > facePoints(const polyPatch &) const
Get the points from face-centre-decomposition face centres.
const word & samplePatch() const
Patch (only if NEARESTPATCHFACE)
Class containing processor-to-processor mapping information.
const coupleGroupIdentifier coupleGroup_
PatchGroup (if in sampleMode NEARESTPATCH*)
void distribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
A class for handling words, derived from string.
Definition: word.H:59
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Tuple2< pointIndexHit, Tuple2< scalar, label > > nearInfo
Helper class for finding nearest.
word sampleRegion_
Region to sample.
void operator()(nearInfo &x, const nearInfo &y) const
void findSamples(const sampleMode mode, const pointField &, labelList &sampleProcs, labelList &sampleIndices, pointField &sampleLocations) const
Find cells/faces containing samples.
virtual ~mappedPatchBase()
Destructor.
const Type1 & first() const
Return first.
Definition: Tuple2.H:94
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const vectorField & offsets() const
Offset vector (from patch faces to destination mesh objects)
Namespace for OpenFOAM.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
scalar distance(const vector &p1, const vector &p2)
Definition: curveTools.C:12
offsetMode offsetMode_
How to obtain samples.
void calcAMI() const
Calculate AMI interpolator.
dictionary surfDict_
Dictionary storing projection surface description.
vectorField offsets_
Offset vector (nonuniform)
const mapDistribute & map() const
Return reference to the parallel distribution map.
dictionary dict
bool sameRegion() const
Cached sampleRegion != mesh.name()
const polyPatch & samplePolyPatch() const
Get the patch on the region.
static const NamedEnum< sampleMode, 6 > sampleModeNames_
offsetMode
How to project face centres.
const sampleMode mode_
What to sample.
static const NamedEnum< offsetMode, 3 > offsetModeNames_
const autoPtr< Foam::searchableSurface > & surfPtr() const
Return a pointer to the AMI projection surface.
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
Encapsulates using patchGroups to specify coupled patch.
static tmp< pointField > readListOrField(const word &keyword, const dictionary &dict, const label size)
Helper to read field or non-uniform list from dictionary.
TypeName("mappedPatchBase")
Runtime type information.
const word & sampleRegion() const
Region to sample.
scalar distance_
Offset distance (normal)
mappedPatchBase(const polyPatch &)
Construct from patch.
const AMIPatchToPatchInterpolation & AMI(const bool forceUpdate=false) const
Return reference to the AMI interpolator.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
const sampleMode & mode() const
What to sample.
void reverseDistribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
scalar y
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
const vector & offset() const
Offset vector (from patch faces to destination mesh objects)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
sampleMode
Mesh items to sample.
autoPtr< searchableSurface > surfPtr_
Pointer to projection surface employed by AMI interpolator.
Determines a mapping between patch face centres and mesh cell or face centres and processors they&#39;re ...
void calcMapping() const
Calculate mapping.
const polyPatch & patch_
Patch to sample.
cellDecomposition
Enumeration defining the decomposition of the cell for.
Definition: polyMesh.H:98
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
A class for managing temporary objects.
Definition: PtrList.H:118
const bool AMIReverse_
Flag to indicate that slave patch should be reversed for AMI.
static pointIndexHit facePoint(const polyMesh &, const label faceI, const polyMesh::cellDecomposition)
Get a point on the face given a face decomposition method:
bool sameRegion_
Same region.
label sampleSize() const
Return size of mapped mesh/patch/boundary.
virtual void write(Ostream &) const
Write as a dictionary.