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