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-2026 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 nbrPatchIndex_;
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  );
168 
169  //- Construct from components
171  (
172  const word& name,
173  const label size,
174  const label start,
175  const label index,
176  const polyBoundaryMesh& bm,
177  const word& nbrPatchName,
179  );
180 
181  //- Construct from dictionary
183  (
184  const word& name,
185  const dictionary& dict,
186  const label index,
187  const polyBoundaryMesh& bm,
188  const bool cyclicTransformDefaultIsNone=false
189  );
190 
191  //- Construct as copy, resetting the boundary mesh
193 
194  //- Construct given the original patch and resetting the
195  // face list and boundary mesh information
197  (
198  const cyclicPolyPatch& pp,
199  const polyBoundaryMesh& bm,
200  const label index,
201  const label newSize,
202  const label newStart,
203  const word& nbrPatchName
204  );
205 
206  //- Construct and return a clone, resetting the boundary mesh
207  virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
208  {
209  return autoPtr<polyPatch>(new cyclicPolyPatch(*this, bm));
210  }
211 
212  //- Construct and return a clone, resetting the face list
213  // and boundary mesh
214  virtual autoPtr<polyPatch> clone
215  (
216  const polyBoundaryMesh& bm,
217  const label index,
218  const label newSize,
219  const label newStart
220  ) const
221  {
222  return autoPtr<polyPatch>
223  (
224  new cyclicPolyPatch
225  (
226  *this,
227  bm,
228  index,
229  newSize,
230  newStart,
231  nbrPatchName_
232  )
233  );
234  }
235 
236 
237  //- Destructor
238  virtual ~cyclicPolyPatch();
239 
240 
241  // Member Functions
242 
243  //- Return true as this patch is a constraint type
244  virtual bool constraint() const
245  {
246  return true;
247  }
248 
249  //- Neighbour patch name
250  const word& nbrPatchName() const;
251 
252  //- Neighbour patchID
253  virtual label nbrPatchIndex() const;
254 
255  virtual bool owner() const
256  {
257  return index() < nbrPatchIndex();
258  }
259 
260  virtual bool neighbour() const
261  {
262  return !owner();
263  }
264 
265  const cyclicPolyPatch& nbrPatch() const
266  {
267  const polyPatch& pp = this->boundaryMesh()[nbrPatchIndex()];
268  return refCast<const cyclicPolyPatch>(pp);
269  }
270 
271  //- Return connected points (from patch local to neighbour patch local)
272  // Demand driven calculation. Does primitivePatch::clearOut after
273  // calculation!
274  const edgeList& coupledPoints() const;
275 
276  //- Return connected edges (from patch local to neighbour patch local).
277  // Demand driven calculation. Does primitivePatch::clearOut after
278  // calculation!
279  const edgeList& coupledEdges() const;
280 
281  //- Return transformation between the coupled patches
282  virtual const transformer& transform() const
283  {
285  }
286 
287  //- For a given patch face index, return the corresponding index of the
288  // face on the neighbour
289  label transformGlobalFace(const label facei) const
290  {
291  label offset = facei - start();
292  label neiStart = nbrPatch().start();
293 
294  if (offset >= 0 && offset < size())
295  {
296  return neiStart + offset;
297  }
298  else
299  {
301  << "Face " << facei << " not in patch " << name()
302  << exit(FatalError);
303  return -1;
304  }
305  }
306 
307  //- Initialise ordering for primitivePatch. Does not
308  // refer to *this (except for name() and type() etc.)
309  virtual void initOrder(PstreamBuffers&, const primitivePatch&) const;
310 
311  //- Return new ordering for primitivePatch.
312  // Ordering is -faceMap: for every face
313  // index of the new face -rotation:for every new face the clockwise
314  // shift of the original face. Return false if nothing changes
315  // (faceMap is identity, rotation is 0), true otherwise.
316  virtual bool order
317  (
319  const primitivePatch&,
321  labelList& rotation
322  ) const;
323 
324  //- Write the polyPatch data as a dictionary
325  virtual void write(Ostream&) const;
326 };
327 
328 
329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 
331 } // End namespace Foam
332 
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 
335 #endif
336 
337 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
autoPtr< PrimitivePatch< SubList< face >, const pointField & > > clone() const
Construct and return a clone.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
Encapsulates using patchGroups to specify coupled patch.
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
Cyclic plane patch.
const cyclicPolyPatch & nbrPatch() const
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
virtual void initMovePoints(PstreamBuffers &, const pointField &)
Initialise the patches for moving points.
virtual void rename(const wordList &newNames)
Reset the patch name.
virtual bool owner() const
Does this side own the patch ?
const edgeList & coupledEdges() const
Return connected edges (from patch local to neighbour patch local).
const word & nbrPatchName() const
Neighbour patch name.
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
const edgeList & coupledPoints() const
Return connected points (from patch local to neighbour patch local)
virtual void reorder(const labelUList &newToOldIndex)
Reset the patch index.
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialise ordering for primitivePatch. Does not.
virtual void initCalcGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
virtual const transformer & transform() const
Return transformation between the coupled patches.
virtual bool constraint() const
Return true as this patch is a constraint type.
virtual label nbrPatchIndex() const
Neighbour patchID.
label transformGlobalFace(const label facei) const
For a given patch face index, return the corresponding index of the.
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
cyclicPolyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm)
Construct from components.
virtual void movePoints(PstreamBuffers &, const pointField &)
Correct patches after moving points.
TypeName("cyclic")
Runtime type information.
virtual void initTopoChange(PstreamBuffers &)
Initialise the update of the patch topology.
virtual ~cyclicPolyPatch()
Destructor.
virtual bool neighbour() const
Does the coupled side own the patch ?
virtual void topoChange(PstreamBuffers &)
Update of the patch topology.
Cyclic plane transformation.
const transformer & transform() const
Return transformation between the coupled patches.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
label index() const
Return the index of this patch in the boundaryMesh.
const word & name() const
Return name.
Foam::polyBoundaryMesh.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:71
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:277
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:215
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space.
Definition: transformer.H:84
A class for handling words, derived from string.
Definition: word.H:63
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const dimensionSet area
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
error FatalError
void offset(label &lst, const label o)
dictionary dict