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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::cyclicPolyPatch
28 
29 Description
30  Cyclic plane patch.
31 
32  Note: morph patch face ordering uses geometric matching so with the
33  following restrictions:
34  -coupled patches should be flat planes.
35  -no rotation in patch plane
36 
37  Uses coupledPolyPatch::calcFaceTol to calculate
38  tolerance per face which might need tweaking.
39 
40  Switch on 'cyclicPolyPatch' debug flag to write .obj files to show
41  the matching.
42 
43 SourceFiles
44  cyclicPolyPatch.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef cyclicPolyPatch_H
49 #define cyclicPolyPatch_H
50 
51 #include "coupledPolyPatch.H"
52 #include "edgeList.H"
53 #include "polyBoundaryMesh.H"
54 #include "diagTensorField.H"
55 #include "coupleGroupIdentifier.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 /*---------------------------------------------------------------------------*\
63  Class cyclicPolyPatch Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class cyclicPolyPatch
67 :
68  public coupledPolyPatch
69 {
70  // Private data
71 
72  //- Name of other half
73  mutable word neighbPatchName_;
74 
75  //- Optional patchGroup to find neighbPatch
76  const coupleGroupIdentifier coupleGroup_;
77 
78  //- Index of other half
79  mutable label neighbPatchID_;
80 
81  // For rotation
82 
83  //- Axis of rotation for rotational cyclics
84  vector rotationAxis_;
85 
86  //- Point on axis of rotation for rotational cyclics
87  point rotationCentre_;
88 
89  // For translation
90 
91  //- Translation vector
92  vector separationVector_;
93 
94 
95  //- List of edges formed from connected points. e[0] is the point on
96  // the first half of the patch, e[1] the corresponding point on the
97  // second half.
98  mutable edgeList* coupledPointsPtr_;
99 
100  //- List of connected edges. e[0] is the edge on the first half of the
101  // patch, e[1] the corresponding edge on the second half.
102  mutable edgeList* coupledEdgesPtr_;
103 
104  //- Temporary storage of owner side patch during ordering.
105  mutable autoPtr<primitivePatch> ownerPatchPtr_;
106 
107 
108  // Private Member Functions
109 
110  //- Find amongst selected faces the one with the largest area
111  static label findMaxArea(const pointField&, const faceList&);
112 
113  void calcTransforms
114  (
115  const primitivePatch& half0,
116  const pointField& half0Ctrs,
117  const vectorField& half0Areas,
118  const pointField& half1Ctrs,
119  const vectorField& half1Areas
120  );
121 
122  // Face ordering
123 
124  // Given a split of faces into left and right half calculate the
125  // centres and anchor points. Transform the left points so they
126  // align with the right ones
127  void getCentresAndAnchors
128  (
129  const primitivePatch& pp0,
130  const primitivePatch& pp1,
131 
132  pointField& half0Ctrs,
133  pointField& half1Ctrs,
134  pointField& anchors0,
135  scalarField& tols
136  ) const;
137 
138  //- Return normal of face at max distance from rotation axis
139  vector findFaceMaxRadius(const pointField& faceCentres) const;
140 
141 
142 protected:
143 
144  // Protected Member functions
145 
146  //- Recalculate the transformation tensors
147  virtual void calcTransforms();
148 
149  //- Initialise the calculation of the patch geometry
150  virtual void initGeometry(PstreamBuffers&);
151 
152  //- Initialise the calculation of the patch geometry
153  virtual void initGeometry
154  (
155  const primitivePatch& referPatch,
156  pointField& nbrCtrs,
157  vectorField& nbrAreas,
158  pointField& nbrCc
159  );
160 
161  //- Calculate the patch geometry
162  virtual void calcGeometry(PstreamBuffers&);
163 
164  //- Calculate the patch geometry
165  virtual void calcGeometry
166  (
167  const primitivePatch& referPatch,
168  const pointField& thisCtrs,
169  const vectorField& thisAreas,
170  const pointField& thisCc,
171  const pointField& nbrCtrs,
172  const vectorField& nbrAreas,
173  const pointField& nbrCc
174  );
175 
176  //- Initialise the patches for moving points
177  virtual void initMovePoints(PstreamBuffers&, const pointField&);
178 
179  //- Correct patches after moving points
180  virtual void movePoints(PstreamBuffers&, const pointField&);
181 
182  //- Initialise the update of the patch topology
183  virtual void initUpdateMesh(PstreamBuffers&);
184 
185  //- Update of the patch topology
186  virtual void updateMesh(PstreamBuffers&);
187 
188 public:
189 
190  //- Declare friendship with processorCyclicPolyPatch
191  friend class processorCyclicPolyPatch;
192 
193 
194  //- Runtime type information
195  TypeName("cyclic");
196 
197 
198  // Constructors
199 
200  //- Construct from components
202  (
203  const word& name,
204  const label size,
205  const label start,
206  const label index,
207  const polyBoundaryMesh& bm,
208  const word& patchType,
210  );
211 
212  //- Construct from components
214  (
215  const word& name,
216  const label size,
217  const label start,
218  const label index,
219  const polyBoundaryMesh& bm,
220  const word& neighbPatchName,
221  const transformType transform, // transformation type
222  const vector& rotationAxis, // for rotation only
223  const point& rotationCentre, // for rotation only
224  const vector& separationVector // for translation only
225  );
226 
227  //- Construct from dictionary
229  (
230  const word& name,
231  const dictionary& dict,
232  const label index,
233  const polyBoundaryMesh& bm,
234  const word& patchType
235  );
236 
237  //- Construct as copy, resetting the boundary mesh
239 
240  //- Construct given the original patch and resetting the
241  // face list and boundary mesh information
243  (
244  const cyclicPolyPatch& pp,
245  const polyBoundaryMesh& bm,
246  const label index,
247  const label newSize,
248  const label newStart,
249  const word& neighbPatchName
250  );
251 
252  //- Construct given the original patch and a map
254  (
255  const cyclicPolyPatch& pp,
256  const polyBoundaryMesh& bm,
257  const label index,
258  const labelUList& mapAddressing,
259  const label newStart
260  );
261 
262  //- Construct and return a clone, resetting the boundary mesh
263  virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
264  {
265  return autoPtr<polyPatch>(new cyclicPolyPatch(*this, bm));
266  }
267 
268  //- Construct and return a clone, resetting the face list
269  // and boundary mesh
271  (
272  const polyBoundaryMesh& bm,
273  const label index,
274  const label newSize,
275  const label newStart
276  ) const
277  {
278  return autoPtr<polyPatch>
279  (
280  new cyclicPolyPatch
281  (
282  *this,
283  bm,
284  index,
285  newSize,
286  newStart,
287  neighbPatchName_
288  )
289  );
290  }
291 
292  //- Construct and return a clone, resetting the face list
293  // and boundary mesh
295  (
296  const polyBoundaryMesh& bm,
297  const label index,
298  const labelUList& mapAddressing,
299  const label newStart
300  ) const
301  {
302  return autoPtr<polyPatch>
303  (
304  new cyclicPolyPatch(*this, bm, index, mapAddressing, newStart)
305  );
306  }
307 
308 
309  //- Destructor
310  virtual ~cyclicPolyPatch();
311 
312 
313  // Member Functions
314 
315  //- Neighbour patch name
316  const word& neighbPatchName() const;
317 
318  //- Neighbour patchID
319  virtual label neighbPatchID() const;
320 
321  virtual bool owner() const
322  {
323  return index() < neighbPatchID();
324  }
325 
326  virtual bool neighbour() const
327  {
328  return !owner();
329  }
330 
331  const cyclicPolyPatch& neighbPatch() const
332  {
333  const polyPatch& pp = this->boundaryMesh()[neighbPatchID()];
334  return refCast<const cyclicPolyPatch>(pp);
335  }
336 
337  //- Return connected points (from patch local to neighbour patch local)
338  // Demand driven calculation. Does primitivePatch::clearOut after
339  // calculation!
340  const edgeList& coupledPoints() const;
341 
342  //- Return connected edges (from patch local to neighbour patch local).
343  // Demand driven calculation. Does primitivePatch::clearOut after
344  // calculation!
345  const edgeList& coupledEdges() const;
346 
347  //- Transform a patch-based position from other side to this side
348  virtual void transformPosition(pointField& l) const;
349 
350  //- Transform a patch-based position from other side to this side
351  virtual void transformPosition(point&, const label facei) const;
352 
353 
354  // Transformation
355 
356  label transformGlobalFace(const label facei) const
357  {
358  label offset = facei-start();
359  label neighbStart = neighbPatch().start();
360 
361  if (offset >= 0 && offset < size())
362  {
363  return neighbStart+offset;
364  }
365  else
366  {
368  << "Face " << facei << " not in patch " << name()
369  << exit(FatalError);
370  return -1;
371  }
372  }
373 
374  //- Axis of rotation for rotational cyclics
375  const vector& rotationAxis() const
376  {
377  return rotationAxis_;
378  }
379 
380  //- Point on axis of rotation for rotational cyclics
381  const point& rotationCentre() const
382  {
383  return rotationCentre_;
384  }
385 
386  //- Translation vector for translational cyclics
387  const vector& separationVector() const
388  {
389  return separationVector_;
390  }
391 
392 
393  //- Initialize ordering for primitivePatch. Does not
394  // refer to *this (except for name() and type() etc.)
395  virtual void initOrder(PstreamBuffers&, const primitivePatch&) const;
396 
397  //- Return new ordering for primitivePatch.
398  // Ordering is -faceMap: for every face
399  // index of the new face -rotation:for every new face the clockwise
400  // shift of the original face. Return false if nothing changes
401  // (faceMap is identity, rotation is 0), true otherwise.
402  virtual bool order
403  (
405  const primitivePatch&,
407  labelList& rotation
408  ) const;
409 
410 
411  //- Write the polyPatch data as a dictionary
412  virtual void write(Ostream&) const;
413 };
414 
415 
416 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
417 
418 } // End namespace Foam
419 
420 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
421 
422 #endif
423 
424 // ************************************************************************* //
Foam::coupleGroupIdentifier
Encapsulates using "patchGroups" to specify coupled patch.
Definition: coupleGroupIdentifier.H:58
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:1000
Foam::cyclicPolyPatch::initMovePoints
virtual void initMovePoints(PstreamBuffers &, const pointField &)
Initialise the patches for moving points.
Definition: cyclicPolyPatch.C:974
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::processorCyclicPolyPatch
Neighbour processor patch.
Definition: processorCyclicPolyPatch.H:52
Foam::cyclicPolyPatch::transformGlobalFace
label transformGlobalFace(const label facei) const
Definition: cyclicPolyPatch.H:355
Foam::cyclicPolyPatch
Cyclic plane patch.
Definition: cyclicPolyPatch.H:65
Foam::cyclicPolyPatch::rotationAxis
const vector & rotationAxis() const
Axis of rotation for rotational cyclics.
Definition: cyclicPolyPatch.H:374
Foam::cyclicPolyPatch::initGeometry
virtual void initGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
Definition: cyclicPolyPatch.C:920
Foam::cyclicPolyPatch::neighbPatch
const cyclicPolyPatch & neighbPatch() const
Definition: cyclicPolyPatch.H:330
Foam::cyclicPolyPatch::order
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
Definition: cyclicPolyPatch.C:1242
coupleGroupIdentifier.H
Foam::PstreamBuffers
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Definition: PstreamBuffers.H:87
Foam::polyPatch::offset
label offset() const
The offset where this patch starts in the boundary face list.
Definition: polyPatch.C:301
Foam::cyclicPolyPatch::initUpdateMesh
virtual void initUpdateMesh(PstreamBuffers &)
Initialise the update of the patch topology.
Definition: cyclicPolyPatch.C:994
Foam::coupledPolyPatch
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
Definition: coupledPolyPatch.H:53
Foam::cyclicPolyPatch::rotationCentre
const point & rotationCentre() const
Point on axis of rotation for rotational cyclics.
Definition: cyclicPolyPatch.H:380
diagTensorField.H
Foam::cyclicPolyPatch::coupledPoints
const edgeList & coupledPoints() const
Return connected points (from patch local to neighbour patch local)
Definition: cyclicPolyPatch.C:1008
coupledPolyPatch.H
Foam::Field< vector >
Foam::polyPatch::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:307
Foam::cyclicPolyPatch::calcGeometry
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
Definition: cyclicPolyPatch.C:958
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::coupledPolyPatch::UNKNOWN
Definition: coupledPolyPatch.H:61
Foam::cyclicPolyPatch::clone
virtual autoPtr< polyPatch > clone(const polyBoundaryMesh &bm) const
Construct and return a clone, resetting the boundary mesh.
Definition: cyclicPolyPatch.H:262
Foam::cyclicPolyPatch::coupledEdges
const edgeList & coupledEdges() const
Return connected edges (from patch local to neighbour patch local).
Definition: cyclicPolyPatch.C:1089
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::cyclicPolyPatch::owner
virtual bool owner() const
Does this side own the patch ?
Definition: cyclicPolyPatch.H:320
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:121
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:850
Foam::cyclicPolyPatch::TypeName
TypeName("cyclic")
Runtime type information.
Foam::cyclicPolyPatch::~cyclicPolyPatch
virtual ~cyclicPolyPatch()
Destructor.
Definition: cyclicPolyPatch.C:793
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:313
Foam::coupledPolyPatch::transform
virtual transformType transform() const
Type of transform.
Definition: coupledPolyPatch.H:258
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:984
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::cyclicPolyPatch::initOrder
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialize ordering for primitivePatch. Does not.
Definition: cyclicPolyPatch.C:1220
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::polyPatch::faceCentres
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:313
Foam::cyclicPolyPatch::write
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
Definition: cyclicPolyPatch.C:1432
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::cyclicPolyPatch::neighbour
virtual bool neighbour() const
Does the coupled side own the patch ?
Definition: cyclicPolyPatch.H:325
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::coupledPolyPatch::transformType
transformType
Definition: coupledPolyPatch.H:59
Foam::patchIdentifier::name
const word & name() const
The patch name.
Definition: patchIdentifier.H:134
Foam::cyclicPolyPatch::neighbPatchID
virtual label neighbPatchID() const
Neighbour patchID.
Definition: cyclicPolyPatch.C:815
Foam::cyclicPolyPatch::neighbPatchName
const word & neighbPatchName() const
Neighbour patch name.
Definition: cyclicPolyPatch.C:802
Foam::patchIdentifier::index
label index() const
The index of this patch in the boundaryMesh.
Definition: patchIdentifier.H:158
Foam::cyclicPolyPatch::separationVector
const vector & separationVector() const
Translation vector for translational cyclics.
Definition: cyclicPolyPatch.H:386
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:85
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