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  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::mappedPatchBase
29 
30 Description
31  Determines a mapping between patch face centres and mesh cell or face
32  centres and processors they're on.
33 
34  If constructed from dictionary:
35  \verbatim
36  // Region to sample (default is region0)
37  sampleRegion region0;
38 
39  // What to sample:
40  // - nearestCell : sample cell containing point
41  // - nearestOnlyCell : nearest sample cell (even if not containing
42  // point)
43  // - nearestPatchFace : nearest face on selected patch
44  // - nearestPatchFaceAMI : nearest face on selected patch
45  - patches need not conform
46  - uses AMI interpolation
47  // - nearestFace : nearest boundary face on any patch
48  // - nearestPatchPoint : nearest patch point (for coupled points
49  // this might be any of the points so you have
50  // to guarantee the point data is synchronised
51  // beforehand)
52  sampleMode nearestCell;
53 
54  // If sampleMode is nearestPatchFace : patch to find faces of
55  samplePatch movingWall;
56 
57  // If sampleMode is nearestPatchFace : specify patchgroup to find
58  // samplePatch and sampleRegion (if not provided)
59  coupleGroup baffleGroup;
60 
61  // How to supply offset (w.r.t. my patch face centres):
62  // - uniform : single offset vector
63  // - nonuniform : per-face offset vector
64  // - normal : using supplied distance and face normal
65  offsetMode uniform;
66 
67  // According to offsetMode (see above) supply one of
68  // offset, offsets or distance
69  offset (1 0 0);
70  \endverbatim
71 
72  Note: if offsetMode is \c normal it uses outwards pointing normals. So
73  supply a negative distance if sampling inside the domain.
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  //- Flag to indicate that slave patch should be reversed for AMI
235  const bool AMIReverse_;
236 
237  //- Pointer to AMI interpolator
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 
283 public:
284 
285  //- Runtime type information
286  TypeName("mappedPatchBase");
287 
288 
289  // Constructors
290 
291  //- Construct from patch
292  mappedPatchBase(const polyPatch&);
293 
294  //- Construct with offsetMode=non-uniform
296  (
297  const polyPatch& pp,
298  const word& sampleRegion,
299  const sampleMode sampleMode,
300  const word& samplePatch,
301  const vectorField& offsets
302  );
303 
304  //- Construct from offsetMode=uniform
306  (
307  const polyPatch& pp,
308  const word& sampleRegion,
309  const sampleMode sampleMode,
310  const word& samplePatch,
311  const vector& offset
312  );
313 
314  //- Construct from offsetMode=normal and distance
316  (
317  const polyPatch& pp,
318  const word& sampleRegion,
319  const sampleMode sampleMode,
320  const word& samplePatch,
321  const scalar distance
322  );
323 
324  //- Construct from dictionary
325  mappedPatchBase(const polyPatch&, const dictionary&);
326 
327  //- Construct from dictionary and (collocated) sample mode
328  // (only for nearestPatchFace, nearestPatchFaceAMI, nearestPatchPoint)
329  // Assumes zero offset.
330  mappedPatchBase(const polyPatch&, const sampleMode, const dictionary&);
331 
332  //- Construct as copy, resetting patch
333  mappedPatchBase(const polyPatch&, const mappedPatchBase&);
334 
335  //- Construct as copy, resetting patch, map original data
337  (
338  const polyPatch&,
339  const mappedPatchBase&,
340  const labelUList& mapAddressing
341  );
342 
343 
344  //- Destructor
345  virtual ~mappedPatchBase();
346 
347 
348  // Member functions
349 
350  void clearOut();
351 
352  // Access
353 
354  //- What to sample
355  inline const sampleMode& mode() const;
356 
357  //- Region to sample
358  inline const word& sampleRegion() const;
359 
360  //- Patch (only if NEARESTPATCHFACE)
361  inline const word& samplePatch() const;
362 
363  //- PatchGroup (only if NEARESTPATCHFACE)
364  inline const word& coupleGroup() const;
365 
366  //- Return size of mapped mesh/patch/boundary
367  inline label sampleSize() const;
368 
369  //- Offset vector (from patch faces to destination mesh objects)
370  inline const vector& offset() const;
371 
372  //- Offset vector (from patch faces to destination mesh objects)
373  inline const vectorField& offsets() const;
374 
375  //- Cached sampleRegion != mesh.name()
376  inline bool sameRegion() const;
377 
378  //- Return reference to the parallel distribution map
379  inline const mapDistribute& map() const;
380 
381  //- Return reference to the AMI interpolator
382  inline const AMIPatchToPatchInterpolation& AMI
383  (
384  const bool forceUpdate = false
385  ) const;
386 
387  //- Return a pointer to the AMI projection surface
389 
390  //- Get the region mesh
391  const polyMesh& sampleMesh() const;
392 
393  //- Get the patch on the region
394  const polyPatch& samplePolyPatch() const;
395 
396 
397  // Helpers
398 
399  //- Get the sample points
401 
402  //- Get a point on the face given a face decomposition method:
403  // face-centre-tet : face centre. Returns index of face.
404  // face-planes : face centre. Returns index of face.
405  // face-diagonal : intersection of ray from cellcentre to
406  // facecentre with any of the triangles.
407  // Returns index (0..size-2) of triangle.
408  static pointIndexHit facePoint
409  (
410  const polyMesh&,
411  const label facei,
413  );
414 
415 
416  // Distribute
417 
418  //- Wrapper around map/interpolate data distribution
419  template<class Type>
420  void distribute(List<Type>& lst) const;
421 
422  //- Wrapper around map/interpolate data distribution with operation
423  template<class Type, class CombineOp>
424  void distribute(List<Type>& lst, const CombineOp& cop) const;
425 
426  //- Wrapper around map/interpolate data distribution
427  template<class Type>
428  void reverseDistribute(List<Type>& lst) const;
429 
430  //- Wrapper around map/interpolate data distribution with operation
431  template<class Type, class CombineOp>
432  void reverseDistribute(List<Type>& lst, const CombineOp& cop) const;
433 
434 
435  // I/O
436 
437  //- Write as a dictionary
438  virtual void write(Ostream&) const;
439 };
440 
441 
442 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
443 
444 } // End namespace Foam
445 
446 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
447 
448 #include "mappedPatchBaseI.H"
449 
450 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
451 
452 #ifdef NoRepository
453  #include "mappedPatchBaseTemplates.C"
454 #endif
455 
456 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
457 
458 #endif
459 
460 // ************************************************************************* //
Foam::coupleGroupIdentifier
Encapsulates using "patchGroups" to specify coupled patch.
Definition: coupleGroupIdentifier.H:58
Foam::mappedPatchBase::write
virtual void write(Ostream &) const
Write as a dictionary.
Definition: mappedPatchBase.C:1302
Foam::mappedPatchBase::clearOut
void clearOut()
Definition: mappedPatchBase.C:1138
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:234
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:1161
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:839
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:116
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::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:1132
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:761
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:1215
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:1148
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::Field< vector >
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:67
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
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:793
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:517
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:79
Foam::mappedPatchBase::AMI
const AMIPatchToPatchInterpolation & AMI(const bool forceUpdate=false) const
Return reference to the AMI interpolator.
Definition: mappedPatchBaseI.H:166
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:188
Foam::mappedPatchBase::facePoints
tmp< pointField > facePoints(const polyPatch &) const
Get the points from face-centre-decomposition face centres.
Definition: mappedPatchBase.C:88
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:237
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:1222
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