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-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::mappedPatchBase
29
30Description
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 // Optional world to sample (default is all)
37 //sampleWorld solidSim;
38
39 // Optional explicit coupling (requires functionObject to synchronise
40 // databases. Default is close coupling (bc to bc)
41 //sampleDatabase true;
42
43 // Region to sample (default is region0)
44 sampleRegion region0;
45
46 // What to sample:
47 // - nearestCell : sample cell containing point
48 // - nearestOnlyCell : nearest sample cell (even if not containing
49 // point)
50 // - nearestPatchFace : nearest face on selected patch
51 // - nearestPatchFaceAMI : nearest face on selected patch
52 - patches need not conform
53 - uses AMI interpolation
54 // - nearestFace : nearest boundary face on any patch
55 // - nearestPatchPoint : nearest patch point (for coupled points
56 // this might be any of the points so you have
57 // to guarantee the point data is synchronised
58 // beforehand)
59 sampleMode nearestCell;
60
61 // If sampleMode is nearestPatchFace : patch to find faces of
62 samplePatch movingWall;
63
64 // If sampleMode is nearestPatchFace : specify patchgroup to find
65 // samplePatch and sampleRegion (if not provided)
66 coupleGroup baffleGroup;
67
68 // How to supply offset (w.r.t. my patch face centres):
69 // - uniform : single offset vector
70 // - nonuniform : per-face offset vector
71 // - normal : using supplied distance and face normal
72 offsetMode uniform;
73
74 // According to offsetMode (see above) supply one of
75 // offset, offsets or distance
76 offset (1 0 0);
77 \endverbatim
78
79 Note: if offsetMode is \c normal it uses outwards pointing normals. So
80 supply a negative distance if sampling inside the domain.
81
82Note
83 Storage is not optimal. It temporary collects all (patch)face centres
84 on all processors to keep the addressing calculation simple.
85
86SourceFiles
87 mappedPatchBase.C
88
89\*---------------------------------------------------------------------------*/
90
91#ifndef mappedPatchBase_H
92#define mappedPatchBase_H
93
94#include "pointField.H"
95#include "Tuple2.H"
96#include "pointIndexHit.H"
99
100// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
101
102namespace Foam
103{
104
105class polyPatch;
106class polyMesh;
107class mapDistribute;
108
109/*---------------------------------------------------------------------------*\
110 Class mappedPatchBase Declaration
111\*---------------------------------------------------------------------------*/
113class mappedPatchBase
114{
115public:
116
117 // Type enumerations
118
119 //- Mesh items to sample
120 enum sampleMode
128 };
129
130 //- How to project face centres
131 enum offsetMode
134 NONUNIFORM,
136 };
141
142
143 //- Helper class for finding nearest
144 // Nearest:
145 // - point+local index
146 // - sqr(distance)
147 // - processor
150 class nearestEqOp
151 {
152 public:
154 void operator()(nearInfo& x, const nearInfo& y) const
155 {
156 if (y.first().hit())
157 {
158 if (!x.first().hit())
159 {
160 x = y;
161 }
162 else if (y.second().first() < x.second().first())
163 {
164 x = y;
165 }
166 }
167 }
168 };
170 class maxProcEqOp
171 {
172 public:
174 void operator()(nearInfo& x, const nearInfo& y) const
175 {
176 if (y.first().hit())
177 {
178 if (!x.first().hit())
179 {
180 x = y;
181 }
182 else if (y.second().second() > x.second().second())
183 {
184 x = y;
185 }
186 }
187 }
188 };
189
190
191 //- nearest + world
192 // Used to only look at entries from same world
195 class nearestWorldEqOp
196 {
197 public:
199 void operator()(nearInfoWorld& x, const nearInfoWorld& y) const
200 {
201 // Is there a hit and is it sampling the same world
202 const nearInfo& xi = x.first();
203 const nearInfo& yi = y.first();
204 if (yi.first().hit())
205 {
206 if (x.second() == y.second())
207 {
208 if (!xi.first().hit())
209 {
210 x = y;
211 }
212 else if (yi.second().first() < xi.second().first())
213 {
214 x = y;
215 }
216 }
217 }
218 }
219 };
220
221
222protected:
223
224 // Protected Data
225
226 //- Patch to sample
227 const polyPatch& patch_;
228
229 //- World to sample
230 mutable word sampleWorld_;
231
232 //- Region to sample
233 mutable word sampleRegion_;
234
235 //- What to sample
236 const sampleMode mode_;
237
238 //- Patch (if in sampleMode NEARESTPATCH*)
239 mutable word samplePatch_;
240
241 //- PatchGroup (if in sampleMode NEARESTPATCH*)
243
244 //- Empty or location of database
246
247 //- How to obtain samples
249
250 //- Offset vector (uniform)
252
253 //- Offset vector (nonuniform)
255
256 //- Offset distance (normal)
257 scalar distance_;
258
259 //- Communicator
260 label communicator_;
261
262 //- Same region
263 mutable bool sameRegion_;
264
265
266 // Derived information
267
268 //- Communication schedule:
269 //
270 // - Cells/faces to sample per processor
271 // - Patch faces to receive per processor
272 // - schedule
274
275
276 // AMI interpolator (only for NEARESTPATCHFACEAMI)
277
278 //- Flag to indicate that slave patch should be reversed for AMI
279 const bool AMIReverse_;
280
281 //- Pointer to AMI interpolator
283
284 //- Pointer to projection surface employed by AMI interpolator
286
287 //- Dictionary storing projection surface description
289
290
291 // Protected Member Functions
292
293 //- Add a world-world connection
294 bool addWorldConnection();
295
296 //- Get the communicator for the world-world connection
297 label getWorldCommunicator() const;
298
299 //- Lookup mesh
300 const polyMesh& lookupMesh(const word& region) const;
301
302 //- Lookup patch
304 (
305 const word& sampleRegion,
306 const word& samplePatch
307 ) const;
308
309
310 //- Get the points from face-centre-decomposition face centres
311 //- and project them onto the face-diagonal-decomposition triangles.
313
314 //- Collect single list of samples and originating processor+face +
315 //- wanted world
316 void collectSamples
317 (
318 const label mySampleWorld, // My wanted sampling world
319 const pointField& facePoints,
320 pointField& samples, // Per sample: coordinate
321 labelList& patchFaceWorlds, // Per sample: wanted world
322 labelList& patchFaceProcs, // Per sample: originating proc
323 labelList& patchFaces, // Per sample: originating face
324 pointField& patchFc
325 ) const;
326
327 //- Find (local) cells/faces containing samples
329 (
330 const sampleMode mode,
331 const label sampleWorld, // my world as index
332 const word& sampleRegion,
333 const word& samplePatch,
335
336 List<nearInfoWorld>& nearest
337 ) const;
338
339 //- Find (global) cells/faces containing samples
340 void findSamples
341 (
342 const sampleMode mode, // search mode
343 const label myWorldIndex, // my world (in index form)
344
345 const pointField&,
346 const labelList& wantedWorlds,
347 const labelList& origProcs, // per sample the originating proc
348
349 labelList& sampleProcs, // processor containing sample
350 labelList& sampleIndices, // local index of cell/face
351 pointField& sampleLocations // actual representative location
352 ) const;
353
354 //- Get the sample points given the face points
356
357 //- Calculate mapping
358 void calcMapping() const;
359
360 //- Calculate AMI interpolator
361 void calcAMI() const;
362
363
364 // Database Handling
365
366 //- Read optional database name from dictionary
368
369 //- Lookup (sub)objectRegistry by following names of sub registries.
370 //- Creates non-existing intermediate ones.
371 static const objectRegistry& subRegistry
372 (
373 const objectRegistry& obr,
374 const wordList& names,
375 const label index
376 );
377
378 //- Attempt to detect an IOField<Type> and write to dictionary
379 template<class Type>
380 static bool writeIOField
381 (
382 const regIOobject& obj,
384 );
385
386 //- Attempt to read an IOField<Type> and store on objectRegistry
387 template<class Type>
388 static bool constructIOField
389 (
390 const word& name,
391 token& tok,
392 Istream& is,
393 objectRegistry& obr
394 );
395
396public:
397
398 //- Runtime type information
399 TypeName("mappedPatchBase");
400
401
402 // Constructors
403
404 //- Construct from patch
405 explicit mappedPatchBase(const polyPatch&);
406
407 //- Construct with offsetMode=non-uniform
409 (
410 const polyPatch& pp,
411 const word& sampleRegion,
413 const word& samplePatch,
414 const vectorField& offsets
415 );
416
417 //- Construct from offsetMode=uniform
419 (
420 const polyPatch& pp,
421 const word& sampleRegion,
423 const word& samplePatch,
424 const vector& uniformOffset
425 );
426
427 //- Construct from offsetMode=normal and distance
429 (
430 const polyPatch& pp,
431 const word& sampleRegion,
433 const word& samplePatch,
434 const scalar normalDistance
435 );
436
437 //- Construct from dictionary
438 mappedPatchBase(const polyPatch&, const dictionary&);
439
440 //- Construct from dictionary and (collocated) sample mode
441 // (only for nearestPatchFace, nearestPatchFaceAMI, nearestPatchPoint)
442 // Assumes zero offset.
443 mappedPatchBase(const polyPatch&, const sampleMode, const dictionary&);
444
445 //- Construct as copy, resetting patch
447
448 //- Construct as copy, resetting patch, map original data
450 (
451 const polyPatch&,
452 const mappedPatchBase&,
453 const labelUList& mapAddressing
454 );
455
456
457 //- Destructor
458 virtual ~mappedPatchBase();
459
460
461 // Member Functions
462
463 // Edit
464
465 void clearOut();
466
467 //- Change to normal offset with given distance
468 void setOffset(const scalar normalDist);
469
470 //- Change to uniform offset with value
471 void setOffset(const vector& uniformOffset);
472
473 //- Change to non-uniform offsets
474 void setOffset(const vectorField& offsets);
475
476
477 // Access
478
479 //- What to sample
480 inline sampleMode mode() const noexcept;
481
482 //- World to sample
483 inline const word& sampleWorld() const noexcept;
484
485 //- Region to sample
486 inline const word& sampleRegion() const;
487
488 //- Patch (only if NEARESTPATCHFACE)
489 inline const word& samplePatch() const;
490
491 //- PatchGroup (only if NEARESTPATCHFACE)
492 inline const word& coupleGroup() const;
493
494 //- Return size of mapped mesh/patch/boundary
495 inline label sampleSize() const;
496
497 //- Offset vector (from patch faces to destination mesh objects)
498 inline const vector& offset() const noexcept;
499
500 //- Offset vectors (from patch faces to destination mesh objects)
501 inline const vectorField& offsets() const noexcept;
502
503 //- Get the communicator (worldComm or world-to-world)
504 inline label getCommunicator() const;
505
506 //- Identical to getCommunicator()
507 inline label comm() const;
508
509 //- Is sample world the local world?
510 inline bool sameWorld() const;
511
512 //- Is my world ordered before the sampleWorld?
513 inline bool masterWorld() const;
514
515 //- Cached sampleRegion != mesh.name()
516 inline bool sameRegion() const noexcept;
517
518 //- Return reference to the parallel distribution map
519 inline const mapDistribute& map() const;
520
521 //- Return reference to the AMI interpolator
523 (
524 const bool forceUpdate = false
525 ) const;
526
527 //- Is it owner
528 inline bool owner() const;
529
530 //- Return a pointer to the AMI projection surface
531 const autoPtr<Foam::searchableSurface>& surfPtr() const;
532
533 //- Get the region mesh
534 const polyMesh& sampleMesh() const;
535
536 //- Get the patch on the region
537 const polyPatch& samplePolyPatch() const;
538
539
540 // Helpers
541
542 //- Get the sample points
543 tmp<pointField> samplePoints() const;
544
545 //- Get a point on the face given a face decomposition method:
546 // face-centre-tet : face centre. Returns index of face.
547 // face-planes : face centre. Returns index of face.
548 // face-diagonal : intersection of ray from cellcentre to
549 // facecentre with any of the triangles.
550 // Returns index (0..size-2) of triangle.
552 (
553 const polyMesh&,
554 const label facei,
555 const polyMesh::cellDecomposition
556 );
557
558
559 // For database storage
561 inline const fileName& sampleDatabasePath() const
562 {
563 return *sampleDatabasePtr_;
564 }
566 inline bool sampleDatabase() const
567 {
568 return bool(sampleDatabasePtr_);
569 }
570
571 //- Helper: return path to store data to be sent to processor i
572 static fileName sendPath(const fileName& root, const label proci);
573
574 virtual fileName sendPath(const label proci) const;
575
576 //- Helper: return path to store data to be received from
577 //- processor i
578 static fileName receivePath
579 (
580 const fileName& root,
581 const label proci
582 );
583
584 virtual fileName receivePath(const label proci) const;
585
586 //- Lookup (sub)objectRegistry from '/' separated path (relative to
587 //- objectRegistry). Creates non-existing intermediate ones.
588 static const objectRegistry& subRegistry
589 (
590 const objectRegistry& obr,
591 const fileName& path
592 );
593
594 //- Store an IOField on the objectRegistry relative to obr
595 template<class Type>
596 static void storeField
597 (
598 objectRegistry& obr,
599 const word& fieldName,
600 const Field<Type>& values
601 );
602
603 //- Convert objectRegistry contents into dictionary
604 static void writeDict
605 (
606 const objectRegistry& obr,
608 );
609
610 //- (recursively) construct and register IOFields from dictionary
611 static void readDict(const dictionary& d, objectRegistry& obr);
612
613
614 // Distribute
615
616 //- Wrapper around map/interpolate data distribution
617 template<class Type>
618 void distribute(List<Type>& lst) const;
619
620 //- Wrapper around map/interpolate data distribution with operation
621 template<class Type, class CombineOp>
622 void distribute(List<Type>& lst, const CombineOp& cop) const;
623
624 //- Wrapper around map/interpolate data distribution
625 template<class Type>
626 void reverseDistribute(List<Type>& lst) const;
627
628 //- Wrapper around map/interpolate data distribution with operation
629 template<class Type, class CombineOp>
630 void reverseDistribute(List<Type>& lst, const CombineOp& cop) const;
631
632
633 // I/O
634
635 //- Write as a dictionary
636 virtual void write(Ostream& os) const;
637};
638
639
640// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
641
642} // End namespace Foam
643
644// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
645
646#include "mappedPatchBaseI.H"
647
648// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
649
650#ifdef NoRepository
652#endif
653
654// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
655
656#endif
657
658// ************************************************************************* //
scalar y
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:66
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:58
const T1 & first() const noexcept
Return first.
Definition: Tuple2.H:118
const T2 & second() const noexcept
Return second.
Definition: Tuple2.H:130
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Encapsulates using "patchGroups" to specify coupled patch.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
Class containing processor-to-processor mapping information.
void operator()(nearInfo &x, const nearInfo &y) const
void operator()(nearInfo &x, const nearInfo &y) const
void operator()(nearInfoWorld &x, const nearInfoWorld &y) const
Determines a mapping between patch face centres and mesh cell or face centres and processors they're ...
const fileName & sampleDatabasePath() const
label communicator_
Communicator.
tmp< pointField > facePoints(const polyPatch &) const
label getWorldCommunicator() const
Get the communicator for the world-world connection.
const mapDistribute & map() const
Return reference to the parallel distribution map.
bool sameRegion() const noexcept
Cached sampleRegion != mesh.name()
scalar distance_
Offset distance (normal)
const vector & offset() const noexcept
Offset vector (from patch faces to destination mesh objects)
void reverseDistribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
TypeName("mappedPatchBase")
Runtime type information.
static const objectRegistry & subRegistry(const objectRegistry &obr, const wordList &names, const label index)
bool owner() const
Is it owner.
const polyPatch & patch_
Patch to sample.
autoPtr< searchableSurface > surfPtr_
Pointer to projection surface employed by AMI interpolator.
vectorField offsets_
Offset vector (nonuniform)
const vectorField & offsets() const noexcept
Offset vectors (from patch faces to destination mesh objects)
void findSamples(const sampleMode mode, const label myWorldIndex, const pointField &, const labelList &wantedWorlds, const labelList &origProcs, labelList &sampleProcs, labelList &sampleIndices, pointField &sampleLocations) const
Find (global) cells/faces containing samples.
Tuple2< pointIndexHit, Tuple2< scalar, label > > nearInfo
Helper class for finding nearest.
static void readDict(const dictionary &d, objectRegistry &obr)
(recursively) construct and register IOFields from dictionary
sampleMode
Mesh items to sample.
@ NEARESTPATCHPOINT
nearest point on selected patch
@ NEARESTONLYCELL
nearest cell (even if not containing cell)
@ NEARESTCELL
nearest cell containing sample
@ NEARESTPATCHFACE
nearest face on selected patch
@ NEARESTPATCHFACEAMI
nearest patch face + AMI interpolation
@ NEARESTFACE
nearest face
void findLocalSamples(const sampleMode mode, const label sampleWorld, const word &sampleRegion, const word &samplePatch, const pointField &samplePoints, List< nearInfoWorld > &nearest) const
Find (local) cells/faces containing samples.
const bool AMIReverse_
Flag to indicate that slave patch should be reversed for AMI.
void calcAMI() const
Calculate AMI interpolator.
static fileName sendPath(const fileName &root, const label proci)
Helper: return path to store data to be sent to processor i.
static autoPtr< fileName > readDatabase(const dictionary &dict)
Read optional database name from dictionary.
static const Enum< sampleMode > sampleModeNames_
const polyPatch & lookupPatch(const word &sampleRegion, const word &samplePatch) const
Lookup patch.
bool sampleDatabase() const
const sampleMode mode_
What to sample.
const polyMesh & sampleMesh() const
Get the region mesh.
bool sameRegion_
Same region.
word sampleRegion_
Region to sample.
static bool writeIOField(const regIOobject &obj, dictionary &dict)
Attempt to detect an IOField<Type> and write to dictionary.
label sampleSize() const
Return size of mapped mesh/patch/boundary.
label comm() const
Identical to getCommunicator()
tmp< pointField > samplePoints() const
Get the sample points.
bool addWorldConnection()
Add a world-world connection.
word samplePatch_
Patch (if in sampleMode NEARESTPATCH*)
autoPtr< mapDistribute > mapPtr_
Communication schedule:
const polyPatch & samplePolyPatch() const
Get the patch on the region.
void collectSamples(const label mySampleWorld, const pointField &facePoints, pointField &samples, labelList &patchFaceWorlds, labelList &patchFaceProcs, labelList &patchFaces, pointField &patchFc) const
const autoPtr< Foam::searchableSurface > & surfPtr() const
Return a pointer to the AMI projection surface.
bool masterWorld() const
Is my world ordered before the sampleWorld?
static fileName receivePath(const fileName &root, const label proci)
label getCommunicator() const
Get the communicator (worldComm or world-to-world)
offsetMode
How to project face centres.
@ NORMAL
use face normal + distance
@ UNIFORM
single offset vector
@ NONUNIFORM
per-face offset vector
const word & sampleWorld() const noexcept
World to sample.
const AMIPatchToPatchInterpolation & AMI(const bool forceUpdate=false) const
Return reference to the AMI interpolator.
dictionary surfDict_
Dictionary storing projection surface description.
void distribute(List< Type > &lst) const
Wrapper around map/interpolate data distribution.
static bool constructIOField(const word &name, token &tok, Istream &is, objectRegistry &obr)
Attempt to read an IOField<Type> and store on objectRegistry.
const word & samplePatch() const
Patch (only if NEARESTPATCHFACE)
static const Enum< offsetMode > offsetModeNames_
virtual ~mappedPatchBase()
Destructor.
void calcMapping() const
Calculate mapping.
static pointIndexHit facePoint(const polyMesh &, const label facei, const polyMesh::cellDecomposition)
Get a point on the face given a face decomposition method:
Tuple2< nearInfo, label > nearInfoWorld
nearest + world
sampleMode mode() const noexcept
What to sample.
const coupleGroupIdentifier coupleGroup_
PatchGroup (if in sampleMode NEARESTPATCH*)
const word & sampleRegion() const
Region to sample.
void setOffset(const scalar normalDist)
Change to normal offset with given distance.
const autoPtr< fileName > sampleDatabasePtr_
Empty or location of database.
const polyMesh & lookupMesh(const word &region) const
Lookup mesh.
vector offset_
Offset vector (uniform)
offsetMode offsetMode_
How to obtain samples.
static void storeField(objectRegistry &obr, const word &fieldName, const Field< Type > &values)
Store an IOField on the objectRegistry relative to obr.
bool sameWorld() const
Is sample world the local world?
static void writeDict(const objectRegistry &obr, dictionary &dict)
Convert objectRegistry contents into dictionary.
autoPtr< AMIPatchToPatchInterpolation > AMIPtr_
Pointer to AMI interpolator.
const word & coupleGroup() const
PatchGroup (only if NEARESTPATCHFACE)
word sampleWorld_
World to sample.
Registry of regIOobjects.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
A class for managing temporary objects.
Definition: tmp.H:65
A token holds an item read from Istream.
Definition: token.H:69
A class for handling words, derived from Foam::string.
Definition: word.H:68
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
bool
Definition: EEqn.H:20
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
const direction noexcept
Definition: Scalar.H:223
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
runTime write()
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73
scalarField samples(nIntervals, Zero)