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