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-2021 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 neigbour
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 initUpdateMesh(PstreamBuffers&);
136 
137  //- Update of the patch topology
138  virtual void updateMesh(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
180  );
181 
182  //- Construct from dictionary
184  (
185  const word& name,
186  const dictionary& dict,
187  const label index,
188  const polyBoundaryMesh& bm,
189  const word& patchType
190  );
191 
192  //- Construct as copy, resetting the boundary mesh
194 
195  //- Construct given the original patch and resetting the
196  // face list and boundary mesh information
198  (
199  const cyclicPolyPatch& pp,
200  const polyBoundaryMesh& bm,
201  const label index,
202  const label newSize,
203  const label newStart,
204  const word& nbrPatchName
205  );
206 
207  //- Construct given the original patch and a map
209  (
210  const cyclicPolyPatch& pp,
211  const polyBoundaryMesh& bm,
212  const label index,
213  const labelUList& mapAddressing,
214  const label newStart
215  );
216 
217  //- Construct and return a clone, resetting the boundary mesh
218  virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
219  {
220  return autoPtr<polyPatch>(new cyclicPolyPatch(*this, bm));
221  }
222 
223  //- Construct and return a clone, resetting the face list
224  // and boundary mesh
226  (
227  const polyBoundaryMesh& bm,
228  const label index,
229  const label newSize,
230  const label newStart
231  ) const
232  {
233  return autoPtr<polyPatch>
234  (
235  new cyclicPolyPatch
236  (
237  *this,
238  bm,
239  index,
240  newSize,
241  newStart,
242  nbrPatchName_
243  )
244  );
245  }
246 
247  //- Construct and return a clone, resetting the face list
248  // and boundary mesh
250  (
251  const polyBoundaryMesh& bm,
252  const label index,
253  const labelUList& mapAddressing,
254  const label newStart
255  ) const
256  {
257  return autoPtr<polyPatch>
258  (
259  new cyclicPolyPatch(*this, bm, index, mapAddressing, newStart)
260  );
261  }
262 
263 
264  //- Destructor
265  virtual ~cyclicPolyPatch();
266 
267 
268  // Member Functions
269 
270  //- Neighbour patch name
271  const word& nbrPatchName() const;
272 
273  //- Neighbour patchID
274  virtual label nbrPatchID() const;
276  virtual bool owner() const
277  {
278  return index() < nbrPatchID();
279  }
281  virtual bool neighbour() const
282  {
283  return !owner();
284  }
286  const cyclicPolyPatch& nbrPatch() const
287  {
288  const polyPatch& pp = this->boundaryMesh()[nbrPatchID()];
289  return refCast<const cyclicPolyPatch>(pp);
290  }
291 
292  //- Return connected points (from patch local to neighbour patch local)
293  // Demand driven calculation. Does primitivePatch::clearOut after
294  // calculation!
295  const edgeList& coupledPoints() const;
296 
297  //- Return connected edges (from patch local to neighbour patch local).
298  // Demand driven calculation. Does primitivePatch::clearOut after
299  // calculation!
300  const edgeList& coupledEdges() const;
301 
302  //- Return transformation between the coupled patches
303  virtual const transformer& transform() const
304  {
306  }
307 
308  //- For a given patch face index, return the corresponding index of the
309  // face on the neighbour
310  label transformGlobalFace(const label facei) const
311  {
312  label offset = facei - start();
313  label neiStart = nbrPatch().start();
314 
315  if (offset >= 0 && offset < size())
316  {
317  return neiStart + offset;
318  }
319  else
320  {
322  << "Face " << facei << " not in patch " << name()
323  << exit(FatalError);
324  return -1;
325  }
326  }
327 
328  //- Initialise ordering for primitivePatch. Does not
329  // refer to *this (except for name() and type() etc.)
330  virtual void initOrder(PstreamBuffers&, const primitivePatch&) const;
331 
332  //- Return new ordering for primitivePatch.
333  // Ordering is -faceMap: for every face
334  // index of the new face -rotation:for every new face the clockwise
335  // shift of the original face. Return false if nothing changes
336  // (faceMap is identity, rotation is 0), true otherwise.
337  virtual bool order
338  (
340  const primitivePatch&,
342  labelList& rotation
343  ) const;
344 
345  //- Write the polyPatch data as a dictionary
346  virtual void write(Ostream&) const;
347 };
348 
349 
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351 
352 } // End namespace Foam
353 
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
355 
356 #endif
357 
358 // ************************************************************************* //
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.
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:323
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:291
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.
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.
const cyclicPolyPatch & nbrPatch() const
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.
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 initUpdateMesh(PstreamBuffers &)
Initialise the update of the patch topology.
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 ?
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:309
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialise ordering for primitivePatch. Does not.
Cyclic plane tranformation.
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.