cyclicPolyPatch.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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  const transformType defaultTransform = UNKNOWN
234  );
235 
236  //- Construct as copy, resetting the boundary mesh
238 
239  //- Construct given the original patch and resetting the
240  // face list and boundary mesh information
242  (
243  const cyclicPolyPatch& pp,
244  const polyBoundaryMesh& bm,
245  const label index,
246  const label newSize,
247  const label newStart,
248  const word& neighbPatchName
249  );
250 
251  //- Construct given the original patch and a map
253  (
254  const cyclicPolyPatch& pp,
255  const polyBoundaryMesh& bm,
256  const label index,
257  const labelUList& mapAddressing,
258  const label newStart
259  );
260 
261  //- Construct and return a clone, resetting the boundary mesh
262  virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
263  {
264  return autoPtr<polyPatch>(new cyclicPolyPatch(*this, bm));
265  }
266 
267  //- Construct and return a clone, resetting the face list
268  // and boundary mesh
270  (
271  const polyBoundaryMesh& bm,
272  const label index,
273  const label newSize,
274  const label newStart
275  ) const
276  {
277  return autoPtr<polyPatch>
278  (
279  new cyclicPolyPatch
280  (
281  *this,
282  bm,
283  index,
284  newSize,
285  newStart,
286  neighbPatchName_
287  )
288  );
289  }
290 
291  //- Construct and return a clone, resetting the face list
292  // and boundary mesh
294  (
295  const polyBoundaryMesh& bm,
296  const label index,
297  const labelUList& mapAddressing,
298  const label newStart
299  ) const
300  {
301  return autoPtr<polyPatch>
302  (
303  new cyclicPolyPatch(*this, bm, index, mapAddressing, newStart)
304  );
305  }
306 
307 
308  //- Destructor
309  virtual ~cyclicPolyPatch();
310 
311 
312  // Member Functions
313 
314  //- Neighbour patch name
315  const word& neighbPatchName() const;
316 
317  //- Neighbour patchID
318  virtual label neighbPatchID() const;
320  virtual bool owner() const
321  {
322  return index() < neighbPatchID();
323  }
325  virtual bool neighbour() const
326  {
327  return !owner();
328  }
330  const cyclicPolyPatch& neighbPatch() const
331  {
332  const polyPatch& pp = this->boundaryMesh()[neighbPatchID()];
333  return refCast<const cyclicPolyPatch>(pp);
334  }
335 
336  //- Return connected points (from patch local to neighbour patch local)
337  // Demand driven calculation. Does primitivePatch::clearOut after
338  // calculation!
339  const edgeList& coupledPoints() const;
340 
341  //- Return connected edges (from patch local to neighbour patch local).
342  // Demand driven calculation. Does primitivePatch::clearOut after
343  // calculation!
344  const edgeList& coupledEdges() const;
345 
346  //- Transform a patch-based position from other side to this side
347  virtual void transformPosition(pointField& l) const;
348 
349  //- Transform a patch-based position from other side to this side
350  virtual void transformPosition(point&, const label facei) const;
351 
352 
353  // Transformation
355  label transformGlobalFace(const label facei) const
356  {
357  label offset = facei-start();
358  label neighbStart = neighbPatch().start();
359 
360  if (offset >= 0 && offset < size())
361  {
362  return neighbStart+offset;
363  }
364  else
365  {
367  << "Face " << facei << " not in patch " << name()
368  << exit(FatalError);
369  return -1;
370  }
371  }
372 
373  //- Axis of rotation for rotational cyclics
374  const vector& rotationAxis() const
375  {
376  return rotationAxis_;
377  }
378 
379  //- Point on axis of rotation for rotational cyclics
380  const point& rotationCentre() const
381  {
382  return rotationCentre_;
383  }
384 
385  //- Translation vector for translational cyclics
386  const vector& separationVector() const
387  {
388  return separationVector_;
389  }
390 
391 
392  //- Initialize ordering for primitivePatch. Does not
393  // refer to *this (except for name() and type() etc.)
394  virtual void initOrder(PstreamBuffers&, const primitivePatch&) const;
395 
396  //- Return new ordering for primitivePatch.
397  // Ordering is -faceMap: for every face
398  // index of the new face -rotation:for every new face the clockwise
399  // shift of the original face. Return false if nothing changes
400  // (faceMap is identity, rotation is 0), true otherwise.
401  virtual bool order
402  (
404  const primitivePatch&,
406  labelList& rotation
407  ) const;
408 
409 
410  //- Write the polyPatch data as a dictionary
411  virtual void write(Ostream&) const;
412 };
413 
414 
415 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
416 
417 } // End namespace Foam
418 
419 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
420 
421 #endif
422 
423 // ************************************************************************* //
virtual void initGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
dictionary dict
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
const word & name() const
Return name.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const edgeList & coupledPoints() const
Return connected points (from patch local to neighbour patch local)
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:278
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
virtual void updateMesh(PstreamBuffers &)
Update of the patch topology.
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...
virtual autoPtr< PrimitivePatch< FaceList, PointField > > clone() const
Construct and return a clone.
const edgeList & coupledEdges() const
Return connected edges (from patch local to neighbour patch local).
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
const vector & rotationAxis() const
Axis of rotation for rotational cyclics.
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 ?
const point & rotationCentre() const
Point on axis of rotation for rotational cyclics.
TypeName("cyclic")
Runtime type information.
A class for handling words, derived from string.
Definition: word.H:59
Cyclic plane patch.
virtual void movePoints(PstreamBuffers &, const pointField &)
Correct patches after moving points.
Encapsulates using patchGroups to specify coupled patch.
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
Foam::polyBoundaryMesh.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Buffers for inter-processor communications streams (UOPstream, UIPstream).
const vector & separationVector() const
Translation vector for translational cyclics.
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.
virtual label neighbPatchID() const
Neighbour patchID.
label index() const
Return the index of this patch in the boundaryMesh.
const word & neighbPatchName() const
Neighbour patch name.
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:303
virtual transformType transform() const
Type of transform.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialize ordering for primitivePatch. Does not.
label transformGlobalFace(const label facei) const
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
const cyclicPolyPatch & neighbPatch() const
virtual void calcTransforms()
Recalculate the transformation tensors.
Namespace for OpenFOAM.