polyPatch.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::polyPatch
26 
27 Description
28  A patch is a list of labels that address the faces in the global face list.
29 
30  The patch can calculate its own edges based on the global faces.
31  Patch also contains all addressing between the faces.
32 
33 SourceFiles
34  polyPatch.C
35  polyPatchNew.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef polyPatch_H
40 #define polyPatch_H
41 
42 #include "patchIdentifier.H"
43 #include "primitivePatch.H"
44 #include "typeInfo.H"
45 #include "runTimeSelectionTables.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 // Forward declaration of friend functions and operators
55 
56 class polyMesh;
57 class polyBoundaryMesh;
58 class polyPatch;
59 class PstreamBuffers;
60 
61 Ostream& operator<<(Ostream&, const polyPatch&);
62 
63 
64 /*---------------------------------------------------------------------------*\
65  Class polyPatch Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class polyPatch
69 :
70  public patchIdentifier,
71  public primitivePatch
72 {
73  // Private Data
74 
75  //- Start label of this patch in the polyMesh face list
76  label start_;
77 
78  //- Reference to boundary mesh
79  const polyBoundaryMesh& boundaryMesh_;
80 
81 
82  // Demand-driven private data
83 
84  //- face-cell addressing
85  mutable labelList::subList* faceCellsPtr_;
86 
87  //- Global edge addressing
88  mutable labelList* mePtr_;
89 
90 
91 protected:
92 
93  // Protected Member Functions
94 
95  // The polyPatch geometry initialisation is called by polyBoundaryMesh
96  friend class polyBoundaryMesh;
97 
98  //- Initialise the calculation of the patch geometry
99  virtual void initCalcGeometry(PstreamBuffers&)
100  {}
101 
102  //- Calculate the patch geometry
103  virtual void calcGeometry(PstreamBuffers&)
104  {}
105 
106  //- Correct patches after moving points
107  virtual void movePoints(const pointField& p);
108 
109  //- Initialise the patches for moving points
110  virtual void initMovePoints(PstreamBuffers&, const pointField&)
111  {}
112 
113  //- Correct patches after moving points
114  virtual void movePoints(PstreamBuffers&, const pointField& p);
115 
116  //- Initialise the update of the patch topology
117  virtual void initTopoChange(PstreamBuffers&)
118  {}
119 
120  //- Update of the patch topology
121  virtual void topoChange(PstreamBuffers&);
122 
123  //- Clear geometry
124  virtual void clearGeom();
125 
126  //- Reset the patch name
127  virtual void rename(const wordList& newNames);
128 
129  //- Reset the patch index
130  virtual void reorder(const labelUList& newToOldIndex);
131 
132 
133 public:
134 
135  //- Runtime type information
136  TypeName("patch");
137 
138  //- Debug switch to disallow the use of genericPolyPatch
139  static int disallowGenericPolyPatch;
140 
141 
142  // Declare run-time constructor selection tables
143 
145  (
146  autoPtr,
147  polyPatch,
148  word,
149  (
150  const word& name,
151  const label size,
152  const label start,
153  const label index,
154  const polyBoundaryMesh& bm
155  ),
156  (name, size, start, index, bm)
157  );
158 
160  (
161  autoPtr,
162  polyPatch,
163  dictionary,
164  (
165  const word& name,
166  const dictionary& dict,
167  const label index,
168  const polyBoundaryMesh& bm
169  ),
170  (name, dict, index, bm)
171  );
172 
173 
174  // Constructors
175 
176  //- Construct from components
177  polyPatch
178  (
179  const word& name,
180  const label size,
181  const label start,
182  const label index,
183  const polyBoundaryMesh& bm
184  );
185 
186  //- Construct from dictionary
187  polyPatch
188  (
189  const word& name,
190  const dictionary& dict,
191  const label index,
192  const polyBoundaryMesh& bm
193  );
194 
195  //- Copy constructor, resetting the boundary mesh
196  polyPatch(const polyPatch&, const polyBoundaryMesh&);
197 
198  //- Construct given the original patch and resetting the
199  // face list and boundary mesh information
200  polyPatch
201  (
202  const polyPatch& pp,
203  const polyBoundaryMesh& bm,
204  const label index,
205  const label newSize,
206  const label newStart
207  );
208 
209  //- Copy constructor
210  polyPatch(const polyPatch&);
211 
212  //- Construct and return a clone, resetting the boundary mesh
213  virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
214  {
215  return autoPtr<polyPatch>(new polyPatch(*this, bm));
216  }
217 
218  //- Construct and return a clone, resetting the face list
219  // and boundary mesh
220  virtual autoPtr<polyPatch> clone
221  (
222  const polyBoundaryMesh& bm,
223  const label index,
224  const label newSize,
225  const label newStart
226  ) const
227  {
228  return autoPtr<polyPatch>
229  (
230  new polyPatch(*this, bm, index, newSize, newStart)
231  );
232  }
233 
234 
235  // Selectors
236 
237  //- Return a pointer to a new patch created on freestore from
238  // components
239  static autoPtr<polyPatch> New
240  (
241  const word& patchType,
242  const word& name,
243  const label size,
244  const label start,
245  const label index,
246  const polyBoundaryMesh& bm
247  );
248 
249  //- Return a pointer to a new patch created on freestore from
250  // dictionary
251  static autoPtr<polyPatch> New
252  (
253  const word& name,
254  const dictionary& dict,
255  const label index,
256  const polyBoundaryMesh& bm
257  );
258 
259  //- Return a pointer to a new patch created on freestore from
260  // dictionary
261  static autoPtr<polyPatch> New
262  (
263  const word& patchType,
264  const word& name,
265  const dictionary& dict,
266  const label index,
267  const polyBoundaryMesh& bm
268  );
269 
270 
271  //- Destructor
272  virtual ~polyPatch();
273 
274 
275  // Member Functions
276 
277  //- Return start label of this patch in the polyMesh face list
278  label start() const
279  {
280  return start_;
281  }
282 
283  //- Return boundaryMesh reference
284  const polyBoundaryMesh& boundaryMesh() const;
285 
286  //- Return mesh reference
287  const polyMesh& mesh() const;
288 
289  //- Return false as this patch is not a constraint type
290  virtual bool constraint() const
291  {
292  return false;
293  }
294 
295  //- Return true if this patch is geometrically coupled (i.e. faces and
296  // points correspondence)
297  virtual bool coupled() const
298  {
299  return false;
300  }
301 
302  //- Extract face cell data
303  template<class T>
305  (
306  const UList<T>& internalValues
307  ) const
308  {
309  return UIndirectList<T>(internalValues, faceCells());
310  }
311 
312  //- Slice list to patch
313  template<class T>
314  const typename List<T>::subList patchSlice(const UList<T>& l) const
315  {
316  return typename List<T>::subList(l, this->size(), start_);
317  }
318 
319  //- Slice Field to patch
320  template<class T>
321  const typename Field<T>::subField patchSlice(const Field<T>& l) const
322  {
323  return typename Field<T>::subField(l, this->size(), start_);
324  }
325 
326 
327  //- Write the polyPatch data as a dictionary
328  virtual void write(Ostream&) const;
329 
330 
331  // Geometric data; point list required
332 
333  //- Return face centres
334  const vectorField::subField faceCentres() const;
335 
336  //- Return face areas
337  const vectorField::subField faceAreas() const;
338 
339  //- Return face area magnitudes
340  const scalarField::subField magFaceAreas() const;
341 
342  //- Return face cell centres
344 
345 
346  // Addressing into mesh
347 
348  //- Return face-cell addressing
349  const labelUList& faceCells() const;
350 
351  //- Return global edge index for local edges
352  const labelList& meshEdges() const;
353 
354  //- Clear addressing
355  virtual void clearAddressing();
356 
357 
358  // Other patch operations
359 
360  //- Return label of face in patch from global face label
361  inline label whichFace(const label l) const
362  {
363  return l - start_;
364  }
365 
366 
367  //- Initialise ordering for primitivePatch. Does not
368  // refer to *this (except for name() and type() etc.)
369  virtual void initOrder(PstreamBuffers&, const primitivePatch&) const;
370 
371  //- Return new ordering for primitivePatch.
372  // Ordering is -faceMap: for every face
373  // index of the new face -rotation:for every new face the clockwise
374  // shift of the original face. Return false if nothing changes
375  // (faceMap is identity, rotation is 0), true otherwise.
376  virtual bool order
377  (
379  const primitivePatch&,
381  labelList& rotation
382  ) const;
383 
384  //- Reset the size and start of the patch
385  void reset(const label size, const label start);
386 
387 
388  // Member Operators
389 
390  //- Assignment
391  void operator=(const polyPatch&);
392 
393 
394  // Ostream Operator
395 
396  friend Ostream& operator<<(Ostream&, const polyPatch&);
397 };
398 
399 
400 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
401 
402 } // End namespace Foam
403 
404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
405 
406 #endif
407 
408 // ************************************************************************* //
SubField< Type > subField
Declare type of subField.
Definition: Field.H:101
SubList< T > subList
Declare type of subList.
Definition: List.H:195
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).
Pre-declare related SubField type.
Definition: SubField.H:63
A List obtained as a section of another List.
Definition: SubList.H:56
A List with indirect addressing.
Definition: UIndirectList.H:61
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Identifies patch by name, patch index and physical type.
label index() const
Return the index of this patch in the boundaryMesh.
const word & name() const
Return name.
Foam::polyBoundaryMesh.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:71
label whichFace(const label l) const
Return label of face in patch from global face label.
Definition: polyPatch.H:360
const vectorField::subField faceAreas() const
Return face areas.
Definition: polyPatch.C:233
static autoPtr< polyPatch > New(const word &patchType, const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm)
Return a pointer to a new patch created on freestore from.
Definition: polyPatchNew.C:32
const UIndirectList< T > patchInternalList(const UList< T > &internalValues) const
Extract face cell data.
Definition: polyPatch.H:304
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
Definition: polyPatch.C:306
void reset(const label size, const label start)
Reset the size and start of the patch.
Definition: polyPatch.C:332
TypeName("patch")
Runtime type information.
virtual void rename(const wordList &newNames)
Reset the patch name.
Definition: polyPatch.C:81
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:296
const polyMesh & mesh() const
Return mesh reference.
Definition: polyPatch.C:221
virtual void clearGeom()
Clear geometry.
Definition: polyPatch.C:75
virtual void reorder(const labelUList &newToOldIndex)
Reset the patch index.
Definition: polyPatch.C:87
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialise ordering for primitivePatch. Does not.
Definition: polyPatch.C:315
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:277
virtual bool constraint() const
Return false as this patch is not a constraint type.
Definition: polyPatch.H:289
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:215
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:227
const List< T >::subList patchSlice(const UList< T > &l) const
Slice list to patch.
Definition: polyPatch.H:313
virtual void movePoints(const pointField &p)
Correct patches after moving points.
Definition: polyPatch.C:56
polyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm)
Construct from components.
Definition: polyPatch.C:96
virtual ~polyPatch()
Destructor.
Definition: polyPatch.C:207
void operator=(const polyPatch &)
Assignment.
Definition: polyPatch.C:348
virtual void initCalcGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
Definition: polyPatch.H:98
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
Definition: polyPatch.C:320
virtual void clearAddressing()
Clear addressing.
Definition: polyPatch.C:297
virtual void initTopoChange(PstreamBuffers &)
Initialise the update of the patch topology.
Definition: polyPatch.H:116
static int disallowGenericPolyPatch
Debug switch to disallow the use of genericPolyPatch.
Definition: polyPatch.H:138
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
Definition: polyPatch.H:102
tmp< vectorField > faceCellCentres() const
Return face cell centres.
Definition: polyPatch.C:245
const scalarField::subField magFaceAreas() const
Return face area magnitudes.
Definition: polyPatch.C:239
virtual void initMovePoints(PstreamBuffers &, const pointField &)
Initialise the patches for moving points.
Definition: polyPatch.H:109
friend Ostream & operator<<(Ostream &, const polyPatch &)
virtual void topoChange(PstreamBuffers &)
Update of the patch topology.
Definition: polyPatch.C:68
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:264
declareRunTimeSelectionTable(autoPtr, polyPatch, word,(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm),(name, size, start, index, bm))
const labelList & meshEdges() const
Return global edge index for local edges.
Definition: polyPatch.C:278
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
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)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
Macros to ease declaration of run-time selection tables.
dictionary dict
volScalarField & p
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...