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-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 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 Foam_cyclicPolyPatch_H
50 #define Foam_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.
97  // From first half of the patch to the corresponding point
98  // on the second half.
99  mutable std::unique_ptr<edgeList> coupledPointsPtr_;
100 
101  //- List of connected edges.
102  // From first half of the patch to the corresponding edge
103  // on the second half.
104  mutable std::unique_ptr<edgeList> coupledEdgesPtr_;
105 
106  //- Temporary storage of owner side patch during ordering.
107  // Saved as autoPtr instead of std::unique_ptr to allow
108  // extra nullptr checking
109  mutable autoPtr<primitivePatch> ownerPatchPtr_;
110 
111 
112  // Private Member Functions
113 
114  //- Find amongst selected faces the one with the largest area
115  static label findMaxArea(const pointField&, const faceList&);
116 
117  void calcTransforms
118  (
119  const primitivePatch& half0,
120  const pointField& half0Ctrs,
121  const vectorField& half0Areas,
122  const pointField& half1Ctrs,
123  const vectorField& half1Areas
124  );
125 
126  // Face ordering
127 
128  // Given a split of faces into left and right half calculate the
129  // centres and anchor points. Transform the left points so they
130  // align with the right ones
131  void getCentresAndAnchors
132  (
133  const primitivePatch& pp0,
134  const primitivePatch& pp1,
135 
136  pointField& half0Ctrs,
137  pointField& half1Ctrs,
138  pointField& anchors0,
139  scalarField& tols
140  ) const;
141 
142  //- Return normal of face at max distance from rotation axis
143  vector findFaceMaxRadius(const pointField& faceCentres) const;
144 
145 
146 protected:
147 
148  // Protected Member functions
149 
150  //- Recalculate the transformation tensors
151  virtual void calcTransforms();
152 
153  //- Initialise the calculation of the patch geometry
154  virtual void initGeometry(PstreamBuffers&);
155 
156  //- Initialise the calculation of the patch geometry
157  virtual void initGeometry
158  (
159  const primitivePatch& referPatch,
160  pointField& nbrCtrs,
161  vectorField& nbrAreas,
162  pointField& nbrCc
163  );
164 
165  //- Calculate the patch geometry
166  virtual void calcGeometry(PstreamBuffers&);
167 
168  //- Calculate the patch geometry
169  virtual void calcGeometry
170  (
171  const primitivePatch& referPatch,
172  const pointField& thisCtrs,
173  const vectorField& thisAreas,
174  const pointField& thisCc,
175  const pointField& nbrCtrs,
176  const vectorField& nbrAreas,
177  const pointField& nbrCc
178  );
179 
180  //- Initialise the patches for moving points
181  virtual void initMovePoints(PstreamBuffers&, const pointField&);
182 
183  //- Correct patches after moving points
184  virtual void movePoints(PstreamBuffers&, const pointField&);
185 
186  //- Initialise the update of the patch topology
187  virtual void initUpdateMesh(PstreamBuffers&);
188 
189  //- Update of the patch topology
190  virtual void updateMesh(PstreamBuffers&);
191 
192 public:
193 
194  //- Declare friendship with processorCyclicPolyPatch
195  friend class processorCyclicPolyPatch;
196 
197 
198  //- Runtime type information
199  TypeName("cyclic");
200 
201 
202  // Constructors
203 
204  //- Construct from components
206  (
207  const word& name,
208  const label size,
209  const label start,
210  const label index,
211  const polyBoundaryMesh& bm,
212  const word& patchType,
214  );
215 
216  //- Construct from components
218  (
219  const word& name,
220  const label size,
221  const label start,
222  const label index,
223  const polyBoundaryMesh& bm,
224  const word& neighbPatchName,
225  const transformType transform, // transformation type
226  const vector& rotationAxis, // for rotation only
227  const point& rotationCentre, // for rotation only
228  const vector& separationVector // for translation only
229  );
230 
231  //- Construct from dictionary
233  (
234  const word& name,
235  const dictionary& dict,
236  const label index,
237  const polyBoundaryMesh& bm,
238  const word& patchType
239  );
240 
241  //- Copy construct, resetting the boundary mesh
243 
244  //- Copy construct, resetting nbrPatchID and faceCells
246  (
247  const cyclicPolyPatch&,
248  label nbrPatchID,
249  const labelList& faceCells
250  );
251 
252  //- Construct given the original patch and resetting the
253  //- face list and boundary mesh information
255  (
256  const cyclicPolyPatch& pp,
257  const polyBoundaryMesh& bm,
258  const label index,
259  const label newSize,
260  const label newStart,
261  const word& neighbPatchName
262  );
263 
264  //- Construct given the original patch and a map
266  (
267  const cyclicPolyPatch& pp,
268  const polyBoundaryMesh& bm,
269  const label index,
270  const labelUList& mapAddressing,
271  const label newStart
272  );
273 
274  //- Construct and return a clone, resetting the boundary mesh
275  virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
276  {
277  return autoPtr<polyPatch>(new cyclicPolyPatch(*this, bm));
278  }
279 
280  //- Construct and return a clone, resetting the face list
281  // and boundary mesh
282  virtual autoPtr<polyPatch> clone
283  (
284  const polyBoundaryMesh& bm,
285  const label index,
286  const label newSize,
287  const label newStart
288  ) const
289  {
290  return autoPtr<polyPatch>
291  (
292  new cyclicPolyPatch
293  (
294  *this,
295  bm,
296  index,
297  newSize,
298  newStart,
299  neighbPatchName_
300  )
301  );
302  }
303 
304  //- Construct and return a clone, resetting the face list
305  // and boundary mesh
306  virtual autoPtr<polyPatch> clone
307  (
308  const polyBoundaryMesh& bm,
309  const label index,
310  const labelUList& mapAddressing,
311  const label newStart
312  ) const
313  {
314  return autoPtr<polyPatch>
315  (
316  new cyclicPolyPatch(*this, bm, index, mapAddressing, newStart)
317  );
318  }
319 
320 
321  //- Destructor
322  virtual ~cyclicPolyPatch();
323 
324 
325  // Member Functions
326 
327  // Implicit Functions
328 
329  //- Return number of new internal of this polyPatch faces
330  virtual void newInternalProcFaces
331  (
332  label& newFaces,
333  label& newProcFaces
334  ) const
335  {
336  newFaces = this->size();
337  newProcFaces = neighbPatch().size() - this->size();
338  }
339 
340  //- Return nbrCells
341  virtual const labelUList& nbrCells() const
342  {
343  return neighbPatch().faceCells();
344  }
345 
346  virtual label neighbPolyPatchID() const
347  {
348  return this->neighbPatchID();
349  }
350 
351  virtual refPtr<labelListList> mapCollocatedFaces() const
352  {
353  refPtr<labelListList> tMap(new labelListList(this->size()));
354  labelListList& map = tMap.ref();
355  forAll (map, i)
356  {
357  labelList& subMap = map[i];
358  subMap.setSize(1);
359  subMap[0] = i;
360  }
361  return tMap;
362  }
363 
364  //- Return implicit master
365  virtual bool masterImplicit() const
366  {
367  return owner();
368  }
369 
370  //- Neighbour patch name
371  const word& neighbPatchName() const;
372 
373  //- Neighbour patchID
374  virtual label neighbPatchID() const;
375 
376  virtual bool owner() const
377  {
378  return index() < neighbPatchID();
379  }
380 
381  virtual bool neighbour() const
382  {
383  return !owner();
384  }
385 
386  const cyclicPolyPatch& neighbPatch() const
387  {
388  const polyPatch& pp = this->boundaryMesh()[neighbPatchID()];
389  return refCast<const cyclicPolyPatch>(pp);
390  }
391 
392  //- Return connected points (from patch local to neighbour patch local)
393  // Demand driven calculation. Does primitivePatch::clearOut after
394  // calculation!
395  const edgeList& coupledPoints() const;
396 
397  //- Return connected edges (from patch local to neighbour patch local).
398  // Demand driven calculation. Does primitivePatch::clearOut after
399  // calculation!
400  const edgeList& coupledEdges() const;
401 
402  //- Transform a patch-based position from other side to this side
403  virtual void transformPosition(pointField& l) const;
404 
405  //- Transform a patch-based position from other side to this side
406  virtual void transformPosition(point&, const label facei) const;
407 
408 
409  // Transformation
410 
411  label transformGlobalFace(const label facei) const
412  {
413  label offset = facei-start();
414  label neighbStart = neighbPatch().start();
415 
416  if (offset >= 0 && offset < size())
417  {
418  return neighbStart+offset;
419  }
420  else
421  {
423  << "Face " << facei << " not in patch " << name()
424  << exit(FatalError);
425  return -1;
426  }
427  }
428 
429  //- Axis of rotation for rotational cyclics
430  const vector& rotationAxis() const noexcept
431  {
432  return rotationAxis_;
433  }
434 
435  //- Point on axis of rotation for rotational cyclics
436  const point& rotationCentre() const noexcept
437  {
438  return rotationCentre_;
439  }
440 
441  //- Translation vector for translational cyclics
442  const vector& separationVector() const noexcept
443  {
444  return separationVector_;
445  }
446 
447 
448  //- Initialize ordering for primitivePatch. Does not
449  // refer to *this (except for name() and type() etc.)
450  virtual void initOrder(PstreamBuffers&, const primitivePatch&) const;
451 
452  //- Return new ordering for primitivePatch.
453  // Ordering is -faceMap: for every face
454  // index of the new face -rotation:for every new face the clockwise
455  // shift of the original face. Return false if nothing changes
456  // (faceMap is identity, rotation is 0), true otherwise.
457  virtual bool order
458  (
460  const primitivePatch&,
462  labelList& rotation
463  ) const;
464 
465 
466  //- Write the polyPatch data as a dictionary
467  virtual void write(Ostream&) const;
468 };
469 
470 
471 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
472 
473 } // End namespace Foam
474 
475 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
476 
477 #endif
478 
479 // ************************************************************************* //
virtual void initGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
const vector & separationVector() const noexcept
Translation vector for translational cyclics.
dictionary dict
const vector & rotationAxis() const noexcept
Axis of rotation for rotational cyclics.
friend class polyBoundaryMesh
Definition: polyPatch.H:107
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
const edgeList & coupledPoints() const
Return connected points (from patch local to neighbour patch local)
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
label start() const noexcept
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:441
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
List< edge > edgeList
List of edge.
Definition: edgeList.H:32
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
virtual void updateMesh(PstreamBuffers &)
Update of the patch topology.
virtual const labelUList & nbrCells() const
Return nbrCells.
virtual void initMovePoints(PstreamBuffers &, const pointField &)
Initialise the patches for moving points.
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.
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:52
const edgeList & coupledEdges() const
Return connected edges (from patch local to neighbour patch local).
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
virtual autoPtr< polyPatch > clone(const polyBoundaryMesh &bm) const
Construct and return a clone, resetting the boundary mesh.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
virtual void initUpdateMesh(PstreamBuffers &)
Initialise the update of the patch topology.
A list of faces which address into the list of points.
virtual bool owner() const
Does this side own the patch ?
void setSize(const label n)
Alias for resize()
Definition: List.H:316
TypeName("cyclic")
Runtime type information.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundaryMesh reference.
Definition: polyPatch.C:309
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:365
virtual bool masterImplicit() const
Return implicit master.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Cyclic plane patch.
label offset() const noexcept
The offset where this patch starts in the boundary face list.
Definition: polyPatch.C:302
virtual void movePoints(PstreamBuffers &, const pointField &)
Correct patches after moving points.
Vector< scalar > vector
Definition: vector.H:57
polyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType)
Construct from components.
Definition: polyPatch.C:75
Encapsulates using "patchGroups" to specify coupled patch.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
const word & name() const noexcept
The patch name.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
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...
virtual bool neighbour() const
Does the coupled side own the patch ?
virtual void transformPosition(pointField &l) const
Transform a patch-based position from other side to this side.
virtual ~cyclicPolyPatch()
Destructor.
vector point
Point is a vector.
Definition: point.H:37
virtual label neighbPatchID() const
Neighbour patchID.
const word & neighbPatchName() const
Neighbour patch name.
virtual transformType transform() const
Type of transform.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialize ordering for primitivePatch. Does not.
label index() const noexcept
The index of this patch in the boundaryMesh.
virtual label neighbPolyPatchID() const
Return nbr patchID.
List< label > labelList
A List of labels.
Definition: List.H:62
label transformGlobalFace(const label facei) const
const cyclicPolyPatch & neighbPatch() const
virtual refPtr< labelListList > mapCollocatedFaces() const
Return mapped collocated faces.
virtual void calcTransforms()
Recalculate the transformation tensors.
const point & rotationCentre() const noexcept
Point on axis of rotation for rotational cyclics.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
virtual void newInternalProcFaces(label &newFaces, label &newProcFaces) const
Return number of new internal of this polyPatch faces.
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:315