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