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-2022 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  Note:
73  Storage is not optimal. It temporary collects all (patch)face centres
74  on all processors to keep the addressing calculation simple.
75 
76 SourceFiles
77  mappedPatchBase.C
78 
79 \*---------------------------------------------------------------------------*/
80 
81 #ifndef mappedPatchBase_H
82 #define mappedPatchBase_H
83 
84 #include "pointField.H"
85 #include "Tuple2.H"
86 #include "pointIndexHit.H"
87 #include "AMIInterpolation.H"
88 #include "coupleGroupIdentifier.H"
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
92 namespace Foam
93 {
94 
95 class polyPatch;
96 class polyMesh;
97 class distributionMap;
98 
99 /*---------------------------------------------------------------------------*\
100  Class mappedPatchBase Declaration
101 \*---------------------------------------------------------------------------*/
103 class mappedPatchBase
104 {
105 
106 public:
107 
108  // Type enumerations
109 
110  //- Mesh items to sample
111  enum sampleMode
112  {
113  NEARESTCELL, // nearest cell containing sample
114  NEARESTPATCHFACE, // nearest face on selected patch
115  NEARESTPATCHFACEAMI, // nearest patch face + AMI interpolation
116  NEARESTPATCHPOINT, // nearest point on selected patch
117  NEARESTFACE, // nearest face
118  NEARESTONLYCELL // nearest cell (even if not containing cell)
119  };
120 
121  //- How to project face centres
122  enum offsetMode
123  {
124  UNIFORM, // single offset vector
125  NONUNIFORM, // per-face offset vector
126  NORMAL // use face normal + distance
127  };
132 
133 
134  //- Helper class for finding nearest
135  // Nearest:
136  // - point+local index
137  // - sqr(distance)
138  // - processor
141  class nearestEqOp
142  {
143 
144  public:
146  void operator()(nearInfo& x, const nearInfo& y) const
147  {
148  if (y.first().hit())
149  {
150  if (!x.first().hit())
151  {
152  x = y;
153  }
154  else if (y.second().first() < x.second().first())
155  {
156  x = y;
157  }
158  }
159  }
160  };
162  class maxProcEqOp
163  {
164 
165  public:
167  void operator()(nearInfo& x, const nearInfo& y) const
168  {
169  if (y.first().hit())
170  {
171  if (!x.first().hit())
172  {
173  x = y;
174  }
175  else if (y.second().second() > x.second().second())
176  {
177  x = y;
178  }
179  }
180  }
181  };
182 
183 
184 protected:
185 
186  // Protected data
187 
188  //- Patch to sample
189  const polyPatch& patch_;
190 
191  //- Region to sample
192  mutable word sampleRegion_;
193 
194  //- What to sample
195  const sampleMode mode_;
196 
197  //- Patch (if in sampleMode NEARESTPATCH*)
198  mutable word samplePatch_;
199 
200  //- PatchGroup (if in sampleMode NEARESTPATCH*)
202 
203  //- How to obtain samples
205 
206  //- Offset vector (uniform)
207  vector offset_;
208 
209  //- Offset vector (nonuniform)
211 
212  //- Offset distance (normal)
213  scalar distance_;
214 
215  //- Same region
216  mutable bool sameRegion_;
217 
218 
219  // Derived information
220 
221  //- Communication schedule:
222  //
223  // - Cells/faces to sample per processor
224  // - Patch faces to receive per processor
225  // - schedule
227 
228 
229  // AMI interpolator (only for NEARESTPATCHFACEAMI)
230 
231  //- Pointer to AMI interpolator
233 
234  //- Flag to indicate that slave patch should be reversed for AMI
235  const bool AMIReverse_;
236 
237  //- Pointer to projection surface employed by AMI interpolator
239 
240  //- Dictionary storing projection surface description
242 
243 
244  // Protected Member Functions
245 
246  //- Get the points from face-centre-decomposition face centres
247  // and project them onto the face-diagonal-decomposition triangles.
248  tmp<pointField> facePoints(const polyPatch&) const;
249 
250  //- Collect single list of samples and originating processor+face.
251  void collectSamples
252  (
253  const pointField& facePoints,
254  pointField&,
255  labelList& patchFaceProcs,
256  labelList& patchFaces,
257  pointField& patchFc
258  ) const;
259 
260  //- Find cells/faces containing samples
261  void findSamples
262  (
263  const sampleMode mode, // search mode
264  const pointField&,
265  labelList& sampleProcs, // processor containing sample
266  labelList& sampleIndices, // local index of cell/face
267  pointField& sampleLocations // actual representative location
268  ) const;
269 
270  //- Get the sample points given the face points
272 
273  //- Calculate mapping
274  void calcMapping() const;
275 
276  //- Calculate AMI interpolator
277  void calcAMI() const;
278 
279  //- Helper to read field or non-uniform list from dictionary
281  (
282  const word& keyword,
283  const dictionary& dict,
284  const label size
285  );
286 
287 
288 public:
289 
290  //- Runtime type information
291  TypeName("mappedPatchBase");
292 
293 
294  // Constructors
295 
296  //- Construct from patch
297  mappedPatchBase(const polyPatch&);
298 
299  //- Construct with offsetMode=non-uniform
301  (
302  const polyPatch& pp,
303  const word& sampleRegion,
304  const sampleMode sampleMode,
305  const word& samplePatch,
306  const vectorField& offsets
307  );
308 
309  //- Construct from offsetMode=uniform
311  (
312  const polyPatch& pp,
313  const word& sampleRegion,
314  const sampleMode sampleMode,
315  const word& samplePatch,
316  const vector& offset
317  );
318 
319  //- Construct from offsetMode=normal and distance
321  (
322  const polyPatch& pp,
323  const word& sampleRegion,
324  const sampleMode sampleMode,
325  const word& samplePatch,
326  const scalar distance
327  );
328 
329  //- Construct from dictionary
330  mappedPatchBase(const polyPatch&, const dictionary&);
331 
332  //- Construct from dictionary and (collocated) sample mode
333  // (only for nearestPatchFace, nearestPatchFaceAMI, nearestPatchPoint)
334  // Assumes zero offset.
335  mappedPatchBase(const polyPatch&, const sampleMode, const dictionary&);
336 
337  //- Construct as copy, resetting patch
338  mappedPatchBase(const polyPatch&, const mappedPatchBase&);
339 
340  //- Construct as copy, resetting patch, map original data
342  (
343  const polyPatch&,
344  const mappedPatchBase&,
345  const labelUList& mapAddressing
346  );
347 
348 
349  //- Destructor
350  virtual ~mappedPatchBase();
351 
352 
353  // Member Functions
354 
355  void clearOut();
356 
357  // Access
358 
359  //- What to sample
360  inline const sampleMode& mode() const;
361 
362  //- Region to sample
363  inline const word& sampleRegion() const;
364 
365  //- Patch (only if NEARESTPATCHFACE)
366  inline const word& samplePatch() const;
367 
368  //- PatchGroup (only if NEARESTPATCHFACE)
369  inline const word& coupleGroup() const;
370 
371  //- Return size of mapped mesh/patch/boundary
372  inline label sampleSize() const;
373 
374  //- Offset vector (from patch faces to destination mesh objects)
375  inline const vector& offset() const;
376 
377  //- Offset vector (from patch faces to destination mesh objects)
378  inline const vectorField& offsets() const;
379 
380  //- Cached sampleRegion != mesh.name()
381  inline bool sameRegion() const;
382 
383  //- Return reference to the parallel distribution map
384  inline const distributionMap& map() const;
385 
386  //- Return reference to the AMI interpolator
387  inline const AMIInterpolation& AMI
388  (
389  const bool forceUpdate = false
390  ) const;
391 
392  //- Return a pointer to the AMI projection surface
394 
395  //- Get the region mesh
396  const polyMesh& sampleMesh() const;
397 
398  //- Get the patch on the region
399  const polyPatch& samplePolyPatch() const;
400 
401 
402  // Helpers
403 
404  //- Get the sample points
406 
407  //- Get a point on the face given a face decomposition method:
408  // face-centre-tet : face centre. Returns index of face.
409  // face-planes : face centre. Returns index of face.
410  // face-diagonal : intersection of ray from cellcentre to
411  // facecentre with any of the triangles.
412  // Returns index (0..size-2) of triangle.
413  static pointIndexHit facePoint
414  (
415  const polyMesh&,
416  const label facei,
418  );
419 
420 
421  // Distribute
422 
423  //- Wrapper around map/interpolate data distribution
424  template<class Type>
425  void distribute(List<Type>& lst) const;
426 
427  //- Wrapper around map/interpolate data distribution with operation
428  template<class Type, class CombineOp>
429  void distribute(List<Type>& lst, const CombineOp& cop) const;
430 
431  //- Wrapper around map/interpolate data distribution
432  template<class Type>
433  void reverseDistribute(List<Type>& lst) const;
434 
435  //- Wrapper around map/interpolate data distribution with operation
436  template<class Type, class CombineOp>
437  void reverseDistribute(List<Type>& lst, const CombineOp& cop) const;
438 
439 
440  // I/O
441 
442  //- Write as a dictionary
443  virtual void write(Ostream&) const;
444 };
445 
446 
447 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
448 
449 } // End namespace Foam
450 
451 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
452 
453 #include "mappedPatchBaseI.H"
454 
455 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
456 
457 #ifdef NoRepository
458  #include "mappedPatchBaseTemplates.C"
459 #endif
460 
461 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
462 
463 #endif
464 
465 // ************************************************************************* //
word samplePatch_
Patch (if in sampleMode NEARESTPATCH*)
dictionary dict
vector offset_
Offset vector (uniform)
void operator()(nearInfo &x, const nearInfo &y) const
bool sameRegion() const
Cached sampleRegion != mesh.name()
word sampleRegion_
Region to sample.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
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:116
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
cellDecomposition
Enumeration defining the decomposition of the cell for.
Definition: polyMesh.H:100
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.
const distributionMap & map() const
Return reference to the parallel distribution map.
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:128
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:76
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.
autoPtr< distributionMap > mapPtr_
Communication schedule:
mappedPatchBase(const polyPatch &)
Construct from patch.
Namespace for OpenFOAM.
const sampleMode mode_
What to sample.