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 \*---------------------------------------------------------------------------*/
101 
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  };
127 
129 
131 
132 
133  //- Helper class for finding nearest
134  // Nearest:
135  // - point+local index
136  // - sqr(distance)
137  // - processor
139 
140  class nearestEqOp
141  {
142 
143  public:
144 
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  };
160 
161  class maxProcEqOp
162  {
163 
164  public:
165 
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,
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 // ************************************************************************* //
Foam::coupleGroupIdentifier
Encapsulates using patchGroups to specify coupled patch.
Definition: coupleGroupIdentifier.H:62
Foam::mappedPatchBase::write
virtual void write(Ostream &) const
Write as a dictionary.
Definition: mappedPatchBase.C:1387
Foam::mappedPatchBase::clearOut
void clearOut()
Definition: mappedPatchBase.C:1227
pointIndexHit.H
Foam::polyMesh::cellDecomposition
cellDecomposition
Enumeration defining the decomposition of the cell for.
Definition: polyMesh.H:98
Foam::mappedPatchBase::UNIFORM
@ UNIFORM
Definition: mappedPatchBase.H:122
Foam::mappedPatchBase::AMIReverse_
const bool AMIReverse_
Flag to indicate that slave patch should be reversed for AMI.
Definition: mappedPatchBase.H:232
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::mappedPatchBase::NEARESTPATCHFACEAMI
@ NEARESTPATCHFACEAMI
Definition: mappedPatchBase.H:113
Tuple2.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::mappedPatchBase::map
const mapDistribute & map() const
Return reference to the parallel distribution map.
Definition: mappedPatchBaseI.H:144
Foam::mappedPatchBase::NEARESTFACE
@ NEARESTFACE
Definition: mappedPatchBase.H:115
Foam::mappedPatchBase::samplePolyPatch
const polyPatch & samplePolyPatch() const
Get the patch on the region.
Definition: mappedPatchBase.C:1246
coupleGroupIdentifier.H
Foam::mappedPatchBase::NEARESTPATCHPOINT
@ NEARESTPATCHPOINT
Definition: mappedPatchBase.H:114
Foam::mappedPatchBase::mappedPatchBase
mappedPatchBase(const polyPatch &)
Construct from patch.
Definition: mappedPatchBase.C:933
Foam::mappedPatchBase::collectSamples
void collectSamples(const pointField &facePoints, pointField &, labelList &patchFaceProcs, labelList &patchFaces, pointField &patchFc) const
Collect single list of samples and originating processor+face.
Definition: mappedPatchBase.C:119
Foam::mappedPatchBase::offset_
vector offset_
Offset vector (uniform)
Definition: mappedPatchBase.H:205
mappedPatchBaseTemplates.C
Foam::mappedPatchBase::mode_
const sampleMode mode_
What to sample.
Definition: mappedPatchBase.H:193
Foam::mappedPatchBase::readListOrField
static tmp< pointField > readListOrField(const word &keyword, const dictionary &dict, const label size)
Helper to read field or non-uniform list from dictionary.
Definition: mappedPatchBase.C:864
Foam::mappedPatchBase::samplePatch_
word samplePatch_
Patch (if in sampleMode NEARESTPATCH*)
Definition: mappedPatchBase.H:196
Foam::mappedPatchBase
Determines a mapping between patch face centres and mesh cell or face centres and processors they're ...
Definition: mappedPatchBase.H:101
Foam::mappedPatchBase::nearestEqOp
Definition: mappedPatchBase.H:139
patchFaces
labelList patchFaces(const polyBoundaryMesh &patches, const wordList &names)
Definition: extrudeMesh.C:148
Foam::mappedPatchBase::NEARESTONLYCELL
@ NEARESTONLYCELL
Definition: mappedPatchBase.H:116
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::mappedPatchBase::coupleGroup_
const coupleGroupIdentifier coupleGroup_
PatchGroup (if in sampleMode NEARESTPATCH*)
Definition: mappedPatchBase.H:199
Foam::mappedPatchBase::~mappedPatchBase
virtual ~mappedPatchBase()
Destructor.
Definition: mappedPatchBase.C:1221
Foam::mappedPatchBase::offset
const vector & offset() const
Offset vector (from patch faces to destination mesh objects)
Definition: mappedPatchBaseI.H:126
Foam::mappedPatchBase::surfPtr
const autoPtr< Foam::searchableSurface > & surfPtr() const
Return a pointer to the AMI projection surface.
Definition: mappedPatchBase.C:771
Foam::mappedPatchBase::mapPtr_
autoPtr< mapDistribute > mapPtr_
Communication schedule:
Definition: mappedPatchBase.H:223
Foam::mappedPatchBase::sampleRegion_
word sampleRegion_
Region to sample.
Definition: mappedPatchBase.H:190
Foam::mappedPatchBase::samplePoints
tmp< pointField > samplePoints() const
Get the sample points.
Definition: mappedPatchBase.C:1300
Foam::mappedPatchBase::nearestEqOp::operator()
void operator()(nearInfo &x, const nearInfo &y) const
Definition: mappedPatchBase.H:144
Foam::mappedPatchBase::sampleSize
label sampleSize() const
Return size of mapped mesh/patch/boundary.
Definition: mappedPatchBaseI.H:91
Foam::mappedPatchBase::sampleMesh
const polyMesh & sampleMesh() const
Get the region mesh.
Definition: mappedPatchBase.C:1237
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:53
Foam::mappedPatchBase::surfPtr_
autoPtr< searchableSurface > surfPtr_
Pointer to projection surface employed by AMI interpolator.
Definition: mappedPatchBase.H:235
Foam::mappedPatchBase::sampleModeNames_
static const NamedEnum< sampleMode, 6 > sampleModeNames_
Definition: mappedPatchBase.H:127
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::mappedPatchBase::distribute
void distribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
Definition: mappedPatchBaseTemplates.C:27
Foam::mapDistribute
Class containing processor-to-processor mapping information.
Definition: mapDistribute.H:152
Foam::mappedPatchBase::nearInfo
Tuple2< pointIndexHit, Tuple2< scalar, label > > nearInfo
Helper class for finding nearest.
Definition: mappedPatchBase.H:137
Foam::mappedPatchBase::mode
const sampleMode & mode() const
What to sample.
Definition: mappedPatchBaseI.H:27
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::mappedPatchBase::offsets_
vectorField offsets_
Offset vector (nonuniform)
Definition: mappedPatchBase.H:208
AMIPatchToPatchInterpolation.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::mappedPatchBase::distance_
scalar distance_
Offset distance (normal)
Definition: mappedPatchBase.H:211
Foam::mappedPatchBase::calcAMI
void calcAMI() const
Calculate AMI interpolator.
Definition: mappedPatchBase.C:803
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::mappedPatchBase::coupleGroup
const word & coupleGroup() const
PatchGroup (only if NEARESTPATCHFACE)
Definition: mappedPatchBaseI.H:85
Foam::mappedPatchBase::sampleRegion
const word & sampleRegion() const
Region to sample.
Definition: mappedPatchBaseI.H:33
Foam::mappedPatchBase::maxProcEqOp::operator()
void operator()(nearInfo &x, const nearInfo &y) const
Definition: mappedPatchBase.H:165
Foam::distance
scalar distance(const vector &p1, const vector &p2)
Definition: curveTools.C:12
Foam::mappedPatchBase::TypeName
TypeName("mappedPatchBase")
Runtime type information.
pointField.H
Foam::mappedPatchBase::calcMapping
void calcMapping() const
Calculate mapping.
Definition: mappedPatchBase.C:519
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::mappedPatchBase::offsetModeNames_
static const NamedEnum< offsetMode, 3 > offsetModeNames_
Definition: mappedPatchBase.H:129
Foam::mappedPatchBase::facePoint
static pointIndexHit facePoint(const polyMesh &, const label faceI, const polyMesh::cellDecomposition)
Get a point on the face given a face decomposition method:
Definition: mappedPatchBase.C:1307
Foam::mappedPatchBase::NEARESTPATCHFACE
@ NEARESTPATCHFACE
Definition: mappedPatchBase.H:112
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::AMIInterpolation
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
Definition: AMIInterpolation.H:77
Foam::mappedPatchBase::AMI
const AMIPatchToPatchInterpolation & AMI(const bool forceUpdate=false) const
Return reference to the AMI interpolator.
Definition: mappedPatchBaseI.H:156
Foam::UList
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
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::mappedPatchBase::offsetMode_
offsetMode offsetMode_
How to obtain samples.
Definition: mappedPatchBase.H:202
Foam::mappedPatchBase::NEARESTCELL
@ NEARESTCELL
Definition: mappedPatchBase.H:111
Foam::mappedPatchBase::offsetMode
offsetMode
How to project face centres.
Definition: mappedPatchBase.H:120
Foam::mappedPatchBase::sameRegion
bool sameRegion() const
Cached sampleRegion != mesh.name()
Definition: mappedPatchBaseI.H:138
mappedPatchBaseI.H
Foam::mappedPatchBase::findSamples
void findSamples(const sampleMode mode, const pointField &, labelList &sampleProcs, labelList &sampleIndices, pointField &sampleLocations) const
Find cells/faces containing samples.
Definition: mappedPatchBase.C:191
Foam::mappedPatchBase::facePoints
tmp< pointField > facePoints(const polyPatch &) const
Get the points from face-centre-decomposition face centres.
Definition: mappedPatchBase.C:91
Foam::mappedPatchBase::surfDict_
dictionary surfDict_
Dictionary storing projection surface description.
Definition: mappedPatchBase.H:238
Foam::mappedPatchBase::maxProcEqOp
Definition: mappedPatchBase.H:160
Foam::mappedPatchBase::AMIPtr_
autoPtr< AMIPatchToPatchInterpolation > AMIPtr_
Pointer to AMI interpolator.
Definition: mappedPatchBase.H:229
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::mappedPatchBase::patch_
const polyPatch & patch_
Patch to sample.
Definition: mappedPatchBase.H:187
Foam::mappedPatchBase::sameRegion_
bool sameRegion_
Same region.
Definition: mappedPatchBase.H:214
Foam::Tuple2
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:47
Foam::mappedPatchBase::NORMAL
@ NORMAL
Definition: mappedPatchBase.H:124
Foam::mappedPatchBase::NONUNIFORM
@ NONUNIFORM
Definition: mappedPatchBase.H:123
Foam::mappedPatchBase::sampleMode
sampleMode
Mesh items to sample.
Definition: mappedPatchBase.H:109
Foam::NamedEnum< sampleMode, 6 >
y
scalar y
Definition: LISASMDCalcMethod1.H:14
Foam::mappedPatchBase::offsets
const vectorField & offsets() const
Offset vector (from patch faces to destination mesh objects)
Definition: mappedPatchBaseI.H:132
Foam::mappedPatchBase::samplePatch
const word & samplePatch() const
Patch (only if NEARESTPATCHFACE)
Definition: mappedPatchBaseI.H:59
Foam::mappedPatchBase::reverseDistribute
void reverseDistribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
Definition: mappedPatchBaseTemplates.C:84