cyclicPolyPatch.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-2015 OpenFOAM Foundation
9  Copyright (C) 2019 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 Class
28  Foam::cyclicPolyPatch
29 
30 Description
31  Cyclic plane patch.
32 
33  Note: morph patch face ordering uses geometric matching so with the
34  following restrictions:
35  -coupled patches should be flat planes.
36  -no rotation in patch plane
37 
38  Uses coupledPolyPatch::calcFaceTol to calculate
39  tolerance per face which might need tweaking.
40 
41  Switch on 'cyclicPolyPatch' debug flag to write .obj files to show
42  the matching.
43 
44 SourceFiles
45  cyclicPolyPatch.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef cyclicPolyPatch_H
50 #define cyclicPolyPatch_H
51 
52 #include "coupledPolyPatch.H"
53 #include "edgeList.H"
54 #include "polyBoundaryMesh.H"
55 #include "diagTensorField.H"
56 #include "coupleGroupIdentifier.H"
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 
63 /*---------------------------------------------------------------------------*\
64  Class cyclicPolyPatch Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class cyclicPolyPatch
68 :
69  public coupledPolyPatch
70 {
71  // Private data
72 
73  //- Name of other half
74  mutable word neighbPatchName_;
75 
76  //- Optional patchGroup to find neighbPatch
77  const coupleGroupIdentifier coupleGroup_;
78 
79  //- Index of other half
80  mutable label neighbPatchID_;
81 
82  // For rotation
83 
84  //- Axis of rotation for rotational cyclics
85  vector rotationAxis_;
86 
87  //- Point on axis of rotation for rotational cyclics
88  point rotationCentre_;
89 
90  // For translation
91 
92  //- Translation vector
93  vector separationVector_;
94 
95 
96  //- List of edges formed from connected points. e[0] is the point on
97  // the first half of the patch, e[1] the corresponding point on the
98  // second half.
99  mutable edgeList* coupledPointsPtr_;
100 
101  //- List of connected edges. e[0] is the edge on the first half of the
102  // patch, e[1] the corresponding edge on the second half.
103  mutable edgeList* coupledEdgesPtr_;
104 
105  //- Temporary storage of owner side patch during ordering.
106  mutable autoPtr<primitivePatch> ownerPatchPtr_;
107 
108 
109  // Private Member Functions
110 
111  //- Find amongst selected faces the one with the largest area
112  static label findMaxArea(const pointField&, const faceList&);
113 
114  void calcTransforms
115  (
116  const primitivePatch& half0,
117  const pointField& half0Ctrs,
118  const vectorField& half0Areas,
119  const pointField& half1Ctrs,
120  const vectorField& half1Areas
121  );
122 
123  // Face ordering
124 
125  // Given a split of faces into left and right half calculate the
126  // centres and anchor points. Transform the left points so they
127  // align with the right ones
128  void getCentresAndAnchors
129  (
130  const primitivePatch& pp0,
131  const primitivePatch& pp1,
132 
133  pointField& half0Ctrs,
134  pointField& half1Ctrs,
135  pointField& anchors0,
136  scalarField& tols
137  ) const;
138 
139  //- Return normal of face at max distance from rotation axis
140  vector findFaceMaxRadius(const pointField& faceCentres) const;
141 
142 
143 protected:
144 
145  // Protected Member functions
146 
147  //- Recalculate the transformation tensors
148  virtual void calcTransforms();
149 
150  //- Initialise the calculation of the patch geometry
151  virtual void initGeometry(PstreamBuffers&);
152 
153  //- Initialise the calculation of the patch geometry
154  virtual void initGeometry
155  (
156  const primitivePatch& referPatch,
157  pointField& nbrCtrs,
158  vectorField& nbrAreas,
159  pointField& nbrCc
160  );
161 
162  //- Calculate the patch geometry
163  virtual void calcGeometry(PstreamBuffers&);
164 
165  //- Calculate the patch geometry
166  virtual void calcGeometry
167  (
168  const primitivePatch& referPatch,
169  const pointField& thisCtrs,
170  const vectorField& thisAreas,
171  const pointField& thisCc,
172  const pointField& nbrCtrs,
173  const vectorField& nbrAreas,
174  const pointField& nbrCc
175  );
176 
177  //- Initialise the patches for moving points
178  virtual void initMovePoints(PstreamBuffers&, const pointField&);
179 
180  //- Correct patches after moving points
181  virtual void movePoints(PstreamBuffers&, const pointField&);
182 
183  //- Initialise the update of the patch topology
184  virtual void initUpdateMesh(PstreamBuffers&);
185 
186  //- Update of the patch topology
187  virtual void updateMesh(PstreamBuffers&);
188 
189 public:
190 
191  //- Declare friendship with processorCyclicPolyPatch
192  friend class processorCyclicPolyPatch;
193 
194 
195  //- Runtime type information
196  TypeName("cyclic");
197 
198 
199  // Constructors
200 
201  //- Construct from components
203  (
204  const word& name,
205  const label size,
206  const label start,
207  const label index,
208  const polyBoundaryMesh& bm,
209  const word& patchType,
211  );
212 
213  //- Construct from components
215  (
216  const word& name,
217  const label size,
218  const label start,
219  const label index,
220  const polyBoundaryMesh& bm,
221  const word& neighbPatchName,
222  const transformType transform, // transformation type
223  const vector& rotationAxis, // for rotation only
224  const point& rotationCentre, // for rotation only
225  const vector& separationVector // for translation only
226  );
227 
228  //- Construct from dictionary
230  (
231  const word& name,
232  const dictionary& dict,
233  const label index,
234  const polyBoundaryMesh& bm,
235  const word& patchType
236  );
237 
238  //- Copy construct, resetting the boundary mesh
240 
241  //- Copy construct, resetting nbrPatchID and faceCells
243  (
244  const cyclicPolyPatch&,
245  label nbrPatchID,
246  const labelList& faceCells
247  );
248 
249  //- Construct given the original patch and resetting the
250  //- face list and boundary mesh information
252  (
253  const cyclicPolyPatch& pp,
254  const polyBoundaryMesh& bm,
255  const label index,
256  const label newSize,
257  const label newStart,
258  const word& neighbPatchName
259  );
260 
261  //- Construct given the original patch and a map
263  (
264  const cyclicPolyPatch& pp,
265  const polyBoundaryMesh& bm,
266  const label index,
267  const labelUList& mapAddressing,
268  const label newStart
269  );
270 
271  //- Construct and return a clone, resetting the boundary mesh
272  virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
273  {
274  return autoPtr<polyPatch>(new cyclicPolyPatch(*this, bm));
275  }
276 
277  //- Construct and return a clone, resetting the face list
278  // and boundary mesh
280  (
281  const polyBoundaryMesh& bm,
282  const label index,
283  const label newSize,
284  const label newStart
285  ) const
286  {
287  return autoPtr<polyPatch>
288  (
289  new cyclicPolyPatch
290  (
291  *this,
292  bm,
293  index,
294  newSize,
295  newStart,
296  neighbPatchName_
297  )
298  );
299  }
300 
301  //- Construct and return a clone, resetting the face list
302  // and boundary mesh
304  (
305  const polyBoundaryMesh& bm,
306  const label index,
307  const labelUList& mapAddressing,
308  const label newStart
309  ) const
310  {
311  return autoPtr<polyPatch>
312  (
313  new cyclicPolyPatch(*this, bm, index, mapAddressing, newStart)
314  );
315  }
316 
317 
318  //- Destructor
319  virtual ~cyclicPolyPatch();
320 
321 
322  // Member Functions
323 
324  // Implicit Functions
325 
326  //- Return number of new internal of this polyPatch faces
327  virtual void newInternalProcFaces
328  (
329  label& newFaces,
330  label& newProcFaces
331  ) const
332  {
333  newFaces = this->size();
334  newProcFaces = neighbPatch().size() - this->size();
335  }
336 
337  //- Return nbrCells
338  virtual const labelUList& nbrCells() const
339  {
340  return neighbPatch().faceCells();
341  }
342 
343  virtual label neighbPolyPatchID() const
344  {
345  return this->neighbPatchID();
346  }
347 
349  {
350  refPtr<labelListList> tMap(new labelListList(this->size()));
351  labelListList& map = tMap.ref();
352  forAll (map, i)
353  {
354  labelList& subMap = map[i];
355  subMap.setSize(1);
356  subMap[0] = i;
357  }
358  return tMap;
359  }
360 
361  //- Return implicit master
362  virtual bool masterImplicit() const
363  {
364  return owner();
365  }
366 
367  //- Neighbour patch name
368  const word& neighbPatchName() const;
369 
370  //- Neighbour patchID
371  virtual label neighbPatchID() const;
372 
373  virtual bool owner() const
374  {
375  return index() < neighbPatchID();
376  }
377 
378  virtual bool neighbour() const
379  {
380  return !owner();
381  }
382 
383  const cyclicPolyPatch& neighbPatch() const
384  {
385  const polyPatch& pp = this->boundaryMesh()[neighbPatchID()];
386  return refCast<const cyclicPolyPatch>(pp);
387  }
388 
389  //- Return connected points (from patch local to neighbour patch local)
390  // Demand driven calculation. Does primitivePatch::clearOut after
391  // calculation!
392  const edgeList& coupledPoints() const;
393 
394  //- Return connected edges (from patch local to neighbour patch local).
395  // Demand driven calculation. Does primitivePatch::clearOut after
396  // calculation!
397  const edgeList& coupledEdges() const;
398 
399  //- Transform a patch-based position from other side to this side
400  virtual void transformPosition(pointField& l) const;
401 
402  //- Transform a patch-based position from other side to this side
403  virtual void transformPosition(point&, const label facei) const;
404 
405 
406  // Transformation
407 
408  label transformGlobalFace(const label facei) const
409  {
410  label offset = facei-start();
411  label neighbStart = neighbPatch().start();
412 
413  if (offset >= 0 && offset < size())
414  {
415  return neighbStart+offset;
416  }
417  else
418  {
420  << "Face " << facei << " not in patch " << name()
421  << exit(FatalError);
422  return -1;
423  }
424  }
425 
426  //- Axis of rotation for rotational cyclics
427  const vector& rotationAxis() const
428  {
429  return rotationAxis_;
430  }
431 
432  //- Point on axis of rotation for rotational cyclics
433  const point& rotationCentre() const
434  {
435  return rotationCentre_;
436  }
437 
438  //- Translation vector for translational cyclics
439  const vector& separationVector() const
440  {
441  return separationVector_;
442  }
443 
444 
445  //- Initialize ordering for primitivePatch. Does not
446  // refer to *this (except for name() and type() etc.)
447  virtual void initOrder(PstreamBuffers&, const primitivePatch&) const;
448 
449  //- Return new ordering for primitivePatch.
450  // Ordering is -faceMap: for every face
451  // index of the new face -rotation:for every new face the clockwise
452  // shift of the original face. Return false if nothing changes
453  // (faceMap is identity, rotation is 0), true otherwise.
454  virtual bool order
455  (
457  const primitivePatch&,
459  labelList& rotation
460  ) const;
461 
462 
463  //- Write the polyPatch data as a dictionary
464  virtual void write(Ostream&) const;
465 };
466 
467 
468 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
469 
470 } // End namespace Foam
471 
472 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
473 
474 #endif
475 
476 // ************************************************************************* //
Foam::coupleGroupIdentifier
Encapsulates using "patchGroups" to specify coupled patch.
Definition: coupleGroupIdentifier.H:57
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::cyclicPolyPatch::updateMesh
virtual void updateMesh(PstreamBuffers &)
Update of the patch topology.
Definition: cyclicPolyPatch.C:1022
Foam::cyclicPolyPatch::initMovePoints
virtual void initMovePoints(PstreamBuffers &, const pointField &)
Initialise the patches for moving points.
Definition: cyclicPolyPatch.C:996
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
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
Foam::cyclicPolyPatch::transformGlobalFace
label transformGlobalFace(const label facei) const
Definition: cyclicPolyPatch.H:407
Foam::cyclicPolyPatch
Cyclic plane patch.
Definition: cyclicPolyPatch.H:66
Foam::cyclicPolyPatch::rotationAxis
const vector & rotationAxis() const
Axis of rotation for rotational cyclics.
Definition: cyclicPolyPatch.H:426
Foam::cyclicPolyPatch::neighbPolyPatchID
virtual label neighbPolyPatchID() const
Return nbr patchID.
Definition: cyclicPolyPatch.H:342
Foam::cyclicPolyPatch::initGeometry
virtual void initGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
Definition: cyclicPolyPatch.C:942
Foam::cyclicPolyPatch::neighbPatch
const cyclicPolyPatch & neighbPatch() const
Definition: cyclicPolyPatch.H:382
Foam::cyclicPolyPatch::mapCollocatedFaces
virtual refPtr< labelListList > mapCollocatedFaces() const
Return mapped collocated faces.
Definition: cyclicPolyPatch.H:347
Foam::cyclicPolyPatch::order
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
Definition: cyclicPolyPatch.C:1264
coupleGroupIdentifier.H
Foam::PstreamBuffers
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Definition: PstreamBuffers.H:88
Foam::cyclicPolyPatch::masterImplicit
virtual bool masterImplicit() const
Return implicit master.
Definition: cyclicPolyPatch.H:361
Foam::cyclicPolyPatch::newInternalProcFaces
virtual void newInternalProcFaces(label &newFaces, label &newProcFaces) const
Return number of new internal of this polyPatch faces.
Definition: cyclicPolyPatch.H:327
Foam::polyPatch::offset
label offset() const
The offset where this patch starts in the boundary face list.
Definition: polyPatch.C:309
Foam::cyclicPolyPatch::initUpdateMesh
virtual void initUpdateMesh(PstreamBuffers &)
Initialise the update of the patch topology.
Definition: cyclicPolyPatch.C:1016
Foam::coupledPolyPatch
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
Definition: coupledPolyPatch.H:54
Foam::cyclicPolyPatch::rotationCentre
const point & rotationCentre() const
Point on axis of rotation for rotational cyclics.
Definition: cyclicPolyPatch.H:432
diagTensorField.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::cyclicPolyPatch::coupledPoints
const edgeList & coupledPoints() const
Return connected points (from patch local to neighbour patch local)
Definition: cyclicPolyPatch.C:1030
coupledPolyPatch.H
Foam::Field< vector >
Foam::polyPatch::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:315
Foam::cyclicPolyPatch::calcGeometry
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
Definition: cyclicPolyPatch.C:980
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::cyclicPolyPatch::nbrCells
virtual const labelUList & nbrCells() const
Return nbrCells.
Definition: cyclicPolyPatch.H:337
Foam::coupledPolyPatch::UNKNOWN
Definition: coupledPolyPatch.H:62
Foam::cyclicPolyPatch::clone
virtual autoPtr< polyPatch > clone(const polyBoundaryMesh &bm) const
Construct and return a clone, resetting the boundary mesh.
Definition: cyclicPolyPatch.H:271
Foam::cyclicPolyPatch::coupledEdges
const edgeList & coupledEdges() const
Return connected edges (from patch local to neighbour patch local).
Definition: cyclicPolyPatch.C:1111
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::cyclicPolyPatch::owner
virtual bool owner() const
Does this side own the patch ?
Definition: cyclicPolyPatch.H:372
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
edgeList.H
Foam::cyclicPolyPatch::transformPosition
virtual void transformPosition(pointField &l) const
Transform a patch-based position from other side to this side.
Definition: cyclicPolyPatch.C:872
Foam::cyclicPolyPatch::TypeName
TypeName("cyclic")
Runtime type information.
Foam::cyclicPolyPatch::~cyclicPolyPatch
virtual ~cyclicPolyPatch()
Destructor.
Definition: cyclicPolyPatch.C:815
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::patchIdentifier::index
label index() const noexcept
The index of this patch in the boundaryMesh.
Definition: patchIdentifier.H:147
Foam::polyPatch::faceCells
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:371
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:361
Foam::coupledPolyPatch::transform
virtual transformType transform() const
Type of transform.
Definition: coupledPolyPatch.H:263
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::cyclicPolyPatch::movePoints
virtual void movePoints(PstreamBuffers &, const pointField &)
Correct patches after moving points.
Definition: cyclicPolyPatch.C:1006
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
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::polyPatch::faceCentres
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:321
Foam::cyclicPolyPatch::write
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
Definition: cyclicPolyPatch.C:1454
Foam::Vector< scalar >
Foam::List< edge >
Foam::UList< label >
Foam::cyclicPolyPatch::calcTransforms
virtual void calcTransforms()
Recalculate the transformation tensors.
Definition: cyclicPolyPatch.C:78
polyBoundaryMesh.H
Foam::patchIdentifier::name
const word & name() const noexcept
The patch name.
Definition: patchIdentifier.H:135
Foam::cyclicPolyPatch::neighbour
virtual bool neighbour() const
Does the coupled side own the patch ?
Definition: cyclicPolyPatch.H:377
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::refPtr::ref
T & ref() const
Definition: refPtrI.H:203
Foam::coupledPolyPatch::transformType
transformType
Definition: coupledPolyPatch.H:60
Foam::cyclicPolyPatch::neighbPatchID
virtual label neighbPatchID() const
Neighbour patchID.
Definition: cyclicPolyPatch.C:837
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56
Foam::cyclicPolyPatch::neighbPatchName
const word & neighbPatchName() const
Neighbour patch name.
Definition: cyclicPolyPatch.C:824
Foam::cyclicPolyPatch::separationVector
const vector & separationVector() const
Translation vector for translational cyclics.
Definition: cyclicPolyPatch.H:438
Foam::refPtr
A class for managing references or pointers (no reference counting)
Definition: PtrList.H:60
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:79
Foam::cyclicPolyPatch::cyclicPolyPatch
cyclicPolyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType, const transformType transform=UNKNOWN)
Construct from components.
Definition: cyclicPolyPatch.C:593