processorCyclicPolyPatch.C
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) 2019-2023 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 \*---------------------------------------------------------------------------*/
28 
31 #include "SubField.H"
32 #include "cyclicPolyPatch.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(processorCyclicPolyPatch, 0);
40 }
41 
42 
43 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
44 
46 (
47  const word& cyclicPolyPatchName,
48  const label myProcNo,
49  const label neighbProcNo
50 )
51 {
52  return word
53  (
55  + "through"
56  + cyclicPolyPatchName
57  );
58 }
59 
60 
62 (
63  const word& cyclicPolyPatchName,
64  const polyBoundaryMesh& bm
65 )
66 {
67  return bm.indices
68  (
69  wordRe
70  (
71  "procBoundary.*to.*through" + cyclicPolyPatchName,
73  )
74  );
75 }
76 
77 
78 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
79 
81 (
82  const label size,
83  const label start,
84  const label index,
85  const polyBoundaryMesh& bm,
86  const int myProcNo,
87  const int neighbProcNo,
88  const word& referPatchName,
89  const transformType transform,
90  const word& patchType
91 )
92 :
94  (
95  newName(referPatchName, myProcNo, neighbProcNo),
96  size,
97  start,
98  index,
99  bm,
100  myProcNo,
101  neighbProcNo,
102  transform,
103  patchType
104  ),
105  referPatchName_(referPatchName),
106  tag_(-1),
107  referPatchID_(-1)
108 {}
109 
110 
112 (
113  const word& name,
114  const dictionary& dict,
115  const label index,
116  const polyBoundaryMesh& bm,
117  const word& patchType
118 )
119 :
120  processorPolyPatch(name, dict, index, bm, patchType),
121  referPatchName_(dict.lookup("referPatch")),
122  tag_(dict.getOrDefault<int>("tag", -1)),
123  referPatchID_(-1)
124 {}
125 
126 
128 (
130  const polyBoundaryMesh& bm
131 )
132 :
133  processorPolyPatch(pp, bm),
134  referPatchName_(pp.referPatchName()),
135  tag_(pp.tag()),
136  referPatchID_(-1)
137 {}
138 
139 
141 (
143  const polyBoundaryMesh& bm,
144  const label index,
145  const label newSize,
146  const label newStart
147 )
148 :
149  processorPolyPatch(pp, bm, index, newSize, newStart),
150  referPatchName_(pp.referPatchName_),
151  tag_(pp.tag()),
152  referPatchID_(-1)
153 {}
154 
155 
157 (
159  const polyBoundaryMesh& bm,
160  const label index,
161  const label newSize,
162  const label newStart,
163  const word& referPatchName
164 )
165 :
166  processorPolyPatch(pp, bm, index, newSize, newStart),
167  referPatchName_(referPatchName),
168  tag_(-1),
169  referPatchID_(-1)
170 {}
171 
172 
174 (
176  const polyBoundaryMesh& bm,
177  const label index,
178  const labelUList& mapAddressing,
179  const label newStart
180 )
181 :
182  processorPolyPatch(pp, bm, index, mapAddressing, newStart),
183  referPatchName_(pp.referPatchName()),
184  tag_(-1),
185  referPatchID_(-1)
186 {}
187 
188 
189 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
190 
192 {
193  if (referPatchID_ == -1)
194  {
195  referPatchID_ = this->boundaryMesh().findPatchID
196  (
197  referPatchName_
198  );
199 
200  if (referPatchID_ == -1)
201  {
203  << "Illegal referPatch name " << referPatchName_ << nl
204  << "Valid patch names: "
205  << this->boundaryMesh().names() << nl
206  << exit(FatalError);
207  }
208  }
209 
210  return referPatchID_;
211 }
212 
213 
215 {
216  if (tag_ == -1)
217  {
218  // Get unique tag to use for all comms. Make sure that both sides
219  // use the same tag
220  const cyclicPolyPatch& cycPatch = refCast<const cyclicPolyPatch>
221  (
222  referPatch()
223  );
224 
225  if (owner())
226  {
227  tag_ = string::hasher()(cycPatch.name()) % 32768u;
228  }
229  else
230  {
231  tag_ = string::hasher()(cycPatch.neighbPatch().name()) % 32768u;
232  }
233 
234  if (tag_ == UPstream::msgType() || tag_ == -1)
235  {
237  << "Tag calculated from cyclic patch name " << tag_
238  << " is the same as the current message type "
239  << UPstream::msgType() << " or -1" << nl
240  << "Please set a non-conflicting, unique, tag by hand"
241  << " using the 'tag' entry"
242  << exit(FatalError);
243  }
244  if (debug)
245  {
246  Pout<< "processorCyclicPolyPatch " << name() << " uses tag " << tag_
247  << endl;
248  }
249  }
250  return tag_;
251 }
252 
253 
255 {
256  // Send over processorPolyPatch data
258 }
259 
260 
262 {
263  // Receive and initialise processorPolyPatch data
265 
266  if (UPstream::parRun())
267  {
268  // Where do we store the calculated transformation?
269  // - on the processor patch?
270  // - on the underlying cyclic patch?
271  // - or do we not auto-calculate the transformation but
272  // have option of reading it.
273 
274  // Update underlying cyclic halves. Need to do both since only one
275  // half might be present as a processorCyclic.
276  coupledPolyPatch& pp = const_cast<coupledPolyPatch&>(referPatch());
277  pp.calcGeometry
278  (
279  *this,
280  faceCentres(),
281  faceAreas(),
282  faceCellCentres(),
283  neighbFaceCentres(),
284  neighbFaceAreas(),
285  neighbFaceCellCentres()
286  );
287 
288  if (isA<cyclicPolyPatch>(pp))
289  {
290  const cyclicPolyPatch& cpp = refCast<const cyclicPolyPatch>(pp);
291  const_cast<cyclicPolyPatch&>(cpp.neighbPatch()).calcGeometry
292  (
293  *this,
294  neighbFaceCentres(),
295  neighbFaceAreas(),
296  neighbFaceCellCentres(),
297  faceCentres(),
298  faceAreas(),
299  faceCellCentres()
300  );
301  }
302  }
303 }
304 
305 
307 (
308  PstreamBuffers& pBufs,
309  const pointField& p
310 )
311 {
312  // Recalculate geometry
313  initGeometry(pBufs);
314 }
315 
316 
318 (
319  PstreamBuffers& pBufs,
320  const pointField&
321 )
322 {
323  calcGeometry(pBufs);
324 }
325 
328 {
330 }
331 
332 
334 {
335  referPatchID_ = -1;
337 }
338 
339 
341 (
342  PstreamBuffers& pBufs,
343  const primitivePatch& pp
344 ) const
345 {
346  // Send the patch points and faces across. Note that this is exactly the
347  // same as the processorPolyPatch::initOrder in COINCIDENTFULLMATCH
348  // mode.
349  UOPstream toNeighbour(neighbProcNo(), pBufs);
350  toNeighbour << pp.localPoints()
351  << pp.localFaces();
352 }
353 
354 
356 (
357  PstreamBuffers& pBufs,
358  const primitivePatch& pp,
360  labelList& rotation
361 ) const
362 {
363  // Receive the remote patch
364  vectorField masterPts;
365  faceList masterFaces;
366  autoPtr<primitivePatch> masterPtr;
367  {
368  UIPstream fromNeighbour(neighbProcNo(), pBufs);
369  fromNeighbour >> masterPts >> masterFaces;
370  masterPtr.reset
371  (
372  new primitivePatch(SubList<face>(masterFaces), masterPts)
373  );
374  }
375 
376  const cyclicPolyPatch& cycPatch =
377  refCast<const cyclicPolyPatch>(referPatch());
378 
379  // (ab)use the cyclicPolyPatch ordering:
380  // - owner side stores geometry
381  // - neighbour side does ordering according to owner side
382  cycPatch.neighbPatch().initOrder(pBufs, masterPtr());
383 
384  return cycPatch.order(pBufs, pp, faceMap, rotation);
385 }
386 
387 
389 {
391  os.writeEntry("referPatch", referPatchName_);
392  os.writeEntryIfDifferent<label>("tag", -1, tag_);
393 }
394 
395 
396 // ************************************************************************* //
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
const List< face_type > & localFaces() const
Return patch faces addressing into local point list.
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
const Field< point_type > & localPoints() const
Return pointField of points in patch.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface...
Definition: boundaryMesh.H:58
static word newName(const label myProcNo, const label neighbProcNo)
Return the name of a processorPolyPatch ("procBoundary..") constructed from the pair of processor IDs...
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1049
void movePoints(PstreamBuffers &, const pointField &)
Correct patches after moving points.
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:321
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1229
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialize ordering for primitivePatch. Does not.
Lookup type of boundary radiation properties.
Definition: lookup.H:57
Macros for easy insertion into run-time selection tables.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Neighbour processor patch.
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) patch indices for all matches.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Definition: autoPtrI.H:37
Input inter-processor communications stream using MPI send/recv etc. - operating on external buffer...
Definition: UIPstream.H:287
A list of faces which address into the list of points.
A List obtained as a section of another List.
Definition: SubList.H:50
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
Regular expression.
Definition: wordRe.H:110
virtual void initUpdateMesh(PstreamBuffers &)
Initialise the update of the patch topology.
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Cyclic plane patch.
virtual label referPatchID() const
The referring patchID. Searches for referPatchName() on the first call.
virtual void updateMesh(PstreamBuffers &)
Update of the patch topology.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
Ostream & writeEntryIfDifferent(const word &key, const T &value1, const T &value2)
Write a keyword/value entry only when the two values differ.
Definition: Ostream.H:336
void initGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
Output inter-processor communications stream using MPI send/recv etc. - operating on external buffer...
Definition: UOPstream.H:395
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
virtual void updateMesh(PstreamBuffers &)
Update of the patch topology.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
PrimitivePatch< SubList< face >, const pointField & > primitivePatch
A PrimitivePatch with a SubList addressing for the faces, const reference for the point field...
void initGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
int neighbProcNo() const noexcept
Return neighbour processor number.
void initMovePoints(PstreamBuffers &, const pointField &)
Initialise the patches for moving points.
static labelList patchIDs(const word &cyclicPolyPatchName, const polyBoundaryMesh &bm)
Return the indices of a processorCyclicPolyPatchs.
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
processorCyclicPolyPatch(const label size, const label start, const label index, const polyBoundaryMesh &bm, const int myProcNo, const int neighbProcNo, const word &referPatchName, const transformType transform=UNKNOWN, const word &patchType=typeName)
Construct from components.
virtual int tag() const
Return message tag to use for communication.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
volScalarField & p
const cyclicPolyPatch & neighbPatch() const
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
static word newName(const word &cyclicPolyPatchName, const label myProcNo, const label neighbProcNo)
Return the name of a processorCyclicPolyPatch constructed from the cyclicPolyPatch name and the pair ...
int myProcNo() const noexcept
Return processor number.
virtual void initUpdateMesh(PstreamBuffers &)
Initialise the update of the patch topology.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)