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-2022 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 "cyclicTransform.H"
51 #include "edgeList.H"
52 #include "polyBoundaryMesh.H"
53 #include "diagTensorField.H"
54 #include "coupleGroupIdentifier.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 /*---------------------------------------------------------------------------*\
62  Class cyclicPolyPatch Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 class cyclicPolyPatch
66 :
67  public coupledPolyPatch,
68  public cyclicTransform
69 {
70  // Private Classes
71 
72  //- Data to pass from owner.initOrder to nbr.order
73  struct ownToNbrCyclicOrderData
74  {
75  point ctr;
76  vector area;
77  };
78 
79 
80  // Private Data
81 
82  //- Name of cyclic neighbour patch
83  mutable word nbrPatchName_;
84 
85  //- Optional patchGroup to find neighbour patch
86  const coupleGroupIdentifier coupleGroup_;
87 
88  //- Index of cyclic neighbour patch
89  mutable label nbrPatchID_;
90 
91  //- List of edges formed from connected points. e[0] is the point on
92  // this patch, e[1] the corresponding point on the cyclic neighbour.
93  mutable edgeList* coupledPointsPtr_;
94 
95  //- List of connected edges. e[0] is the edge on this patch,
96  // e[1] the corresponding edge on the cyclic neighbour
97  mutable edgeList* coupledEdgesPtr_;
98 
99  //- Data to pass from owner.initOrder to nbr.order
100  mutable autoPtr<ownToNbrOrderData> ownToNbrOrderDataPtr_;
101 
102  //- Data to pass from owner.initOrder to nbr.order
103  mutable autoPtr<ownToNbrCyclicOrderData> ownToNbrCyclicOrderDataPtr_;
104 
105  //- Data to pass from owner.initOrder to nbr.order if debugging
106  mutable autoPtr<ownToNbrDebugOrderData> ownToNbrDebugOrderDataPtr_;
107 
108 
109 protected:
110 
111  // Protected Member functions
112 
113  //- Initialise the calculation of the patch geometry
114  virtual void initCalcGeometry(PstreamBuffers&);
115 
116  //- Initialise the calculation of the patch geometry
117  virtual void initCalcGeometry
118  (
119  const primitivePatch& referPatch,
120  pointField& nbrCtrs,
121  vectorField& nbrAreas,
122  pointField& nbrCc
123  );
124 
125  //- Calculate the patch geometry
126  virtual void calcGeometry(PstreamBuffers&);
127 
128  //- Initialise the patches for moving points
129  virtual void initMovePoints(PstreamBuffers&, const pointField&);
130 
131  //- Correct patches after moving points
132  virtual void movePoints(PstreamBuffers&, const pointField&);
133 
134  //- Initialise the update of the patch topology
135  virtual void initTopoChange(PstreamBuffers&);
136 
137  //- Update of the patch topology
138  virtual void topoChange(PstreamBuffers&);
139 
140  //- Reset the patch name
141  virtual void rename(const wordList& newNames);
142 
143  //- Reset the patch index
144  virtual void reorder(const labelUList& newToOldIndex);
145 
146 
147 public:
148 
149  //- Declare friendship with processorCyclicPolyPatch
150  friend class processorCyclicPolyPatch;
151 
152 
153  //- Runtime type information
154  TypeName("cyclic");
155 
156 
157  // Constructors
158 
159  //- Construct from components
161  (
162  const word& name,
163  const label size,
164  const label start,
165  const label index,
166  const polyBoundaryMesh& bm,
167  const word& patchType
168  );
169 
170  //- Construct from components
172  (
173  const word& name,
174  const label size,
175  const label start,
176  const label index,
177  const polyBoundaryMesh& bm,
178  const word& patchType,
179  const word& nbrPatchName,
181  );
182 
183  //- Construct from dictionary
185  (
186  const word& name,
187  const dictionary& dict,
188  const label index,
189  const polyBoundaryMesh& bm,
190  const word& patchType,
191  const bool cyclicTransformDefaultIsNone=false
192  );
193 
194  //- Construct as copy, resetting the boundary mesh
196 
197  //- Construct given the original patch and resetting the
198  // face list and boundary mesh information
200  (
201  const cyclicPolyPatch& pp,
202  const polyBoundaryMesh& bm,
203  const label index,
204  const label newSize,
205  const label newStart,
206  const word& nbrPatchName
207  );
208 
209  //- Construct given the original patch and a map
211  (
212  const cyclicPolyPatch& pp,
213  const polyBoundaryMesh& bm,
214  const label index,
215  const labelUList& mapAddressing,
216  const label newStart
217  );
218 
219  //- Construct and return a clone, resetting the boundary mesh
220  virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
221  {
222  return autoPtr<polyPatch>(new cyclicPolyPatch(*this, bm));
223  }
224 
225  //- Construct and return a clone, resetting the face list
226  // and boundary mesh
228  (
229  const polyBoundaryMesh& bm,
230  const label index,
231  const label newSize,
232  const label newStart
233  ) const
234  {
235  return autoPtr<polyPatch>
236  (
237  new cyclicPolyPatch
238  (
239  *this,
240  bm,
241  index,
242  newSize,
243  newStart,
244  nbrPatchName_
245  )
246  );
247  }
248 
249  //- Construct and return a clone, resetting the face list
250  // and boundary mesh
252  (
253  const polyBoundaryMesh& bm,
254  const label index,
255  const labelUList& mapAddressing,
256  const label newStart
257  ) const
258  {
259  return autoPtr<polyPatch>
260  (
261  new cyclicPolyPatch(*this, bm, index, mapAddressing, newStart)
262  );
263  }
264 
265 
266  //- Destructor
267  virtual ~cyclicPolyPatch();
268 
269 
270  // Member Functions
271 
272  //- Neighbour patch name
273  const word& nbrPatchName() const;
274 
275  //- Neighbour patchID
276  virtual label nbrPatchID() const;
278  virtual bool owner() const
279  {
280  return index() < nbrPatchID();
281  }
283  virtual bool neighbour() const
284  {
285  return !owner();
286  }
288  const cyclicPolyPatch& nbrPatch() const
289  {
290  const polyPatch& pp = this->boundaryMesh()[nbrPatchID()];
291  return refCast<const cyclicPolyPatch>(pp);
292  }
293 
294  //- Return connected points (from patch local to neighbour patch local)
295  // Demand driven calculation. Does primitivePatch::clearOut after
296  // calculation!
297  const edgeList& coupledPoints() const;
298 
299  //- Return connected edges (from patch local to neighbour patch local).
300  // Demand driven calculation. Does primitivePatch::clearOut after
301  // calculation!
302  const edgeList& coupledEdges() const;
303 
304  //- Return transformation between the coupled patches
305  virtual const transformer& transform() const
306  {
308  }
309 
310  //- For a given patch face index, return the corresponding index of the
311  // face on the neighbour
312  label transformGlobalFace(const label facei) const
313  {
314  label offset = facei - start();
315  label neiStart = nbrPatch().start();
316 
317  if (offset >= 0 && offset < size())
318  {
319  return neiStart + offset;
320  }
321  else
322  {
324  << "Face " << facei << " not in patch " << name()
325  << exit(FatalError);
326  return -1;
327  }
328  }
329 
330  //- Initialise ordering for primitivePatch. Does not
331  // refer to *this (except for name() and type() etc.)
332  virtual void initOrder(PstreamBuffers&, const primitivePatch&) const;
333 
334  //- Return new ordering for primitivePatch.
335  // Ordering is -faceMap: for every face
336  // index of the new face -rotation:for every new face the clockwise
337  // shift of the original face. Return false if nothing changes
338  // (faceMap is identity, rotation is 0), true otherwise.
339  virtual bool order
340  (
342  const primitivePatch&,
344  labelList& rotation
345  ) const;
346 
347  //- Write the polyPatch data as a dictionary
348  virtual void write(Ostream&) const;
349 };
350 
351 
352 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
353 
354 } // End namespace Foam
355 
356 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
357 
358 #endif
359 
360 // ************************************************************************* //
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
dictionary dict
virtual void initTopoChange(PstreamBuffers &)
Initialise the update of the patch topology.
const word & name() const
Return name.
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space...
Definition: transformer.H:83
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:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:297
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
virtual void initMovePoints(PstreamBuffers &, const pointField &)
Initialise the patches for moving points.
const word & nbrPatchName() const
Neighbour patch name.
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
cyclicPolyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType)
Construct from components.
virtual const transformer & transform() const
Return transformation between the coupled patches.
virtual void topoChange(PstreamBuffers &)
Update of the patch topology.
const cyclicPolyPatch & nbrPatch() const
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.
virtual void reorder(const labelUList &newToOldIndex)
Reset the patch index.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
virtual void rename(const wordList &newNames)
Reset the patch name.
A list of faces which address into the list of points.
virtual bool owner() const
Does this side own the patch ?
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.
const transformer & transform() const
Return transformation between the coupled patches.
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:54
Buffers for inter-processor communications streams (UOPstream, UIPstream).
virtual bool neighbour() const
Does the coupled side own the patch ?
autoPtr< PrimitivePatch< FaceList, PointField > > clone() const
Construct and return a clone.
virtual ~cyclicPolyPatch()
Destructor.
label index() const
Return the index of this patch in the boundaryMesh.
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:306
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialise ordering for primitivePatch. Does not.
Cyclic plane transformation.
label transformGlobalFace(const label facei) const
For a given patch face index, return the corresponding index of the.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
virtual void initCalcGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
virtual label nbrPatchID() const
Neighbour patchID.
Namespace for OpenFOAM.