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