polyPatch.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2015-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::polyPatch
29 
30 Description
31  A patch is a list of labels that address the faces in the global face list.
32 
33  The patch can calculate its own edges based on the global faces.
34  Patch also contains all addressing between the faces.
35 
36 SourceFiles
37  polyPatch.C
38  polyPatchNew.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef Foam_polyPatch_H
43 #define Foam_polyPatch_H
44 
45 #include "patchIdentifier.H"
46 #include "primitivePatch.H"
47 #include "typeInfo.H"
48 #include "runTimeSelectionTables.H"
49 #include "SubField.H"
50 #include "PtrList.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // Forward Declarations
58 class polyBoundaryMesh;
59 class polyPatch;
60 class polyTopoChange;
61 class PstreamBuffers;
62 
63 //- Store lists of polyPatch as a PtrList
65 
67 
68 /*---------------------------------------------------------------------------*\
69  Class polyPatch Declaration
70 \*---------------------------------------------------------------------------*/
71 
72 class polyPatch
73 :
74  public patchIdentifier,
75  public primitivePatch
76 {
77  // Private Data
78 
79  //- Start label of this patch in the polyMesh face list
80  label start_;
81 
82  //- Reference to boundary mesh
83  const polyBoundaryMesh& boundaryMesh_;
84 
85  //- Demand-driven: face-cell addressing
86  mutable std::unique_ptr<labelList::subList> faceCellsPtr_;
87 
88  //- Demand-driven: global edge addressing
89  mutable std::unique_ptr<labelList> mePtr_;
90 
91 
92 protected:
93 
94  // Protected Member Functions
95 
96  //- Inherit movePoints from primitivePatch
98 
99  // The polyPatch geometry initialisation is called by polyBoundaryMesh
100  friend class polyBoundaryMesh;
101 
102  //- Initialise the calculation of the patch geometry
103  virtual void initGeometry(PstreamBuffers&)
104  {}
105 
106  //- Calculate the patch geometry
108  {}
109 
110  //- Initialise the patches for moving points
111  virtual void initMovePoints(PstreamBuffers&, const pointField&)
112  {}
113 
114  //- Correct patches after moving points
115  virtual void movePoints(PstreamBuffers&, const pointField& p);
116 
117  //- Initialise the update of the patch topology
119  {}
120 
121  //- Update of the patch topology
122  virtual void updateMesh(PstreamBuffers&);
123 
124  //- Clear geometry
125  virtual void clearGeom();
126 
127 
128 public:
129 
130  //- Runtime type information
131  TypeName("patch");
132 
133  //- Debug switch to disallow the use of genericPolyPatch
134  static int disallowGenericPolyPatch;
136 
137  // Declare run-time constructor selection tables
138 
140  (
141  autoPtr,
142  polyPatch,
143  word,
144  (
145  const word& name,
146  const label size,
147  const label start,
148  const label index,
149  const polyBoundaryMesh& bm,
150  const word& patchType
151  ),
152  (name, size, start, index, bm, patchType)
153  );
154 
156  (
157  autoPtr,
158  polyPatch,
160  (
161  const word& name,
162  const dictionary& dict,
163  const label index,
164  const polyBoundaryMesh& bm,
165  const word& patchType
166  ),
167  (name, dict, index, bm, patchType)
168  );
169 
170 
171  // Constructors
172 
173  //- Construct from components
174  polyPatch
175  (
176  const word& name,
177  const label size,
178  const label start,
179  const label index,
180  const polyBoundaryMesh& bm,
181  const word& patchType
182  );
183 
184  //- Construct from components
185  polyPatch
186  (
187  const word& name,
188  const label size,
189  const label start,
190  const label index,
191  const polyBoundaryMesh& bm,
192  const word& physicalType,
193  const wordList& inGroups
194  );
195 
196  //- Construct from dictionary
197  polyPatch
198  (
199  const word& name,
200  const dictionary& dict,
201  const label index,
202  const polyBoundaryMesh& bm,
203  const word& patchType
204  );
205 
206  //- Copy construct, resetting the boundary mesh
207  polyPatch(const polyPatch&, const polyBoundaryMesh&);
208 
209  //- Construct given the original patch and resetting the
210  //- face list and boundary mesh information
211  polyPatch
212  (
213  const polyPatch& pp,
214  const polyBoundaryMesh& bm,
215  const label index,
216  const label newSize,
217  const label newStart
218  );
219 
220  //- Construct given the original patch and a map
221  polyPatch
222  (
223  const polyPatch& pp,
224  const polyBoundaryMesh& bm,
225  const label index,
226  const labelUList& mapAddressing,
227  const label newStart
228  );
229 
230  //- Copy construct
231  polyPatch(const polyPatch& p);
232 
233  //- Copy construct, setting faceCells
234  // \note The faceCells are held by the caller
235  polyPatch(const polyPatch& p, const labelList& faceCells);
236 
237  //- Construct and return a clone, setting faceCells
238  // \note The faceCells are held by the caller
239  virtual autoPtr<polyPatch> clone(const labelList& faceCells) const
240  {
241  return autoPtr<polyPatch>::New(*this, faceCells);
242  }
243 
244  //- Construct and return a clone, resetting the boundary mesh
245  virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
246  {
247  return autoPtr<polyPatch>::New(*this, bm);
248  }
249 
250  //- Construct and return a clone,
251  //- resetting the face list and boundary mesh
252  virtual autoPtr<polyPatch> clone
253  (
254  const polyBoundaryMesh& bm,
255  const label index,
256  const label newSize,
257  const label newStart
258  ) const
259  {
260  return autoPtr<polyPatch>::New(*this, bm, index, newSize, newStart);
261  }
262 
263  //- Construct and return a clone,
264  //- resetting the face list and boundary mesh
265  virtual autoPtr<polyPatch> clone
266  (
267  const polyBoundaryMesh& bm,
268  const label index,
269  const labelUList& mapAddressing,
270  const label newStart
271  ) const
272  {
274  (*this, bm, index, mapAddressing, newStart);
275  }
276 
277 
278  // Selectors
279 
280  //- Return pointer to a new patch created on freestore from components
281  static autoPtr<polyPatch> New
282  (
283  const word& patchType,
284  const word& name,
285  const label size,
286  const label start,
287  const label index,
288  const polyBoundaryMesh& bm
289  );
290 
291  //- Return pointer to a new patch created on freestore from dictionary
293  (
294  const word& name,
295  const dictionary& dict,
296  const label index,
297  const polyBoundaryMesh& bm
298  );
299 
300  //- Return pointer to a new patch created on freestore from dictionary
301  static autoPtr<polyPatch> New
302  (
303  const word& patchType,
304  const word& name,
305  const dictionary& dict,
306  const label index,
307  const polyBoundaryMesh& bm
308  );
309 
310 
311  //- Destructor
312  virtual ~polyPatch();
313 
314 
315  // Member Functions
316 
317  // Implicit treatment functions
318 
319  //- Return number of new internal of this polyPatch faces
320  virtual void newInternalProcFaces(label&, label&) const
321  {
323  }
324 
325  //- Return nbrCells
326  virtual const labelUList& nbrCells() const
327  {
329  return labelUList::null();
330  }
331 
332  //- Return nbr patchID
333  virtual label neighbPolyPatchID() const
334  {
336  return -1;
337  }
338 
339  //- Return mapped collocated faces
340  virtual refPtr<labelListList> mapCollocatedFaces() const
341  {
343  return nullptr;
344  }
345 
346  //- Return implicit master
347  virtual bool masterImplicit() const
348  {
350  return false;
351  }
352 
353  //- Return neighbour region name
354  virtual word neighbRegionID() const
355  {
356  return word("none");
357  }
358 
359 
360  //- The offset where this patch starts in the boundary face list
361  // The value is the same as patch.start() - mesh.nInternalFaces()
362  label offset() const noexcept;
363 
364  //- Return start label of this patch in the polyMesh face list
365  label start() const noexcept
366  {
367  return start_;
368  }
369 
370  //- Return start/size range of this patch
371  labelRange range() const
372  {
373  return labelRange(start_, this->size());
374  }
375 
376  //- Return boundaryMesh reference
377  const polyBoundaryMesh& boundaryMesh() const noexcept;
378 
379  //- Return true if this patch is geometrically coupled (i.e. faces and
380  // points correspondence)
381  virtual bool coupled() const
382  {
383  return false;
384  }
385 
386  //- Return true if the given type is a constraint type
387  static bool constraintType(const word& patchType);
388 
389  //- Return a list of all the constraint patch types
390  static wordList constraintTypes();
391 
392  //- Extract face cell data
393  template<class T>
395  (
396  const UList<T>& internalValues
397  ) const
398  {
399  return UIndirectList<T>(internalValues, faceCells());
400  }
401 
402  //- This patch slice from the complete list, which has size
403  //- mesh::nFaces(), using the number of patch faces.
404  template<class T>
405  const typename List<T>::subList
406  patchSlice(const UList<T>& values) const
407  {
408  return typename List<T>::subList(values, this->size(), start_);
409  }
410 
411  //- This patch slice from the list of boundary values, which has size
412  //- mesh::nBoundaryFaces(), using the number of patch faces.
413  template<class T>
414  const typename List<T>::subList
415  boundarySlice(const List<T>& values) const
416  {
417  return typename List<T>::subList(values, this->size(), offset());
418  }
419 
420  //- Slice Field to patch, using the number of patch faces.
421  template<class T>
422  const typename Field<T>::subField
423  patchSlice(const Field<T>& values) const
424  {
425  return typename Field<T>::subField(values, this->size(), start_);
426  }
427 
428 
429  //- Write the polyPatch data as a dictionary
430  virtual void write(Ostream& os) const;
431 
432 
433  // Geometric data; point list required
434 
435  //- Return face centres
436  const vectorField::subField faceCentres() const;
437 
438  //- Return face normals
439  const vectorField::subField faceAreas() const;
440 
441  //- Return face cell centres
443 
444  //- Return the area fraction as the ratio of the stored face area
445  //- and the area given by the face points
447 
448 
449  // Addressing into mesh
450 
451  //- Return face-cell addressing
452  const labelUList& faceCells() const;
453 
454  //- Return global edge index for local edges
455  const labelList& meshEdges() const;
456 
457  //- Clear addressing
458  virtual void clearAddressing();
459 
460 
461  // Other patch operations
462 
463  //- Return label of face in patch from global face label
464  label whichFace(const label facei) const noexcept
465  {
466  return facei - start_;
467  }
468 
469 
470  //- Initialize ordering for primitivePatch. Does not
471  // refer to *this (except for name() and type() etc.)
472  virtual void initOrder(PstreamBuffers&, const primitivePatch&) const;
473 
474  //- Return new ordering for primitivePatch.
475  // Ordering is -faceMap: for every face
476  // index of the new face -rotation:for every new face the clockwise
477  // shift of the original face. Return false if nothing changes
478  // (faceMap is identity, rotation is 0), true otherwise.
479  virtual bool order
480  (
482  const primitivePatch&,
484  labelList& rotation
485  ) const;
486 
487  //- For dynamic mesh cases - return true if this patch will change the
488  //- topology
489  virtual bool changeTopology() const
490  {
491  return false;
492  }
493 
494  //- Collect topology changes in a polyTopoChange object
495  virtual bool setTopology(polyTopoChange&)
496  {
497  return false;
498  }
499 
500 
501  // Member Operators
502 
503  //- Copy assignment
504  void operator=(const polyPatch& p);
505 
506 
507  // Ostream Operator
509  friend Ostream& operator<<(Ostream&, const polyPatch&);
510 };
511 
512 
513 // Global Functions
514 
515 //- The labelRange of a polyPatch
516 template<>
517 struct labelRangeOp<polyPatch>
518 {
519  labelRange operator()(const polyPatch& pp) const
520  {
521  return pp.range();
522  }
523 };
524 
525 
526 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
527 
528 } // End namespace Foam
529 
530 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
531 
532 #endif
533 
534 // ************************************************************************* //
virtual bool changeTopology() const
For dynamic mesh cases - return true if this patch will change the topology.
Definition: polyPatch.H:610
dictionary dict
virtual word neighbRegionID() const
Return neighbour region name.
Definition: polyPatch.H:425
label whichFace(const label facei) const noexcept
Return label of face in patch from global face label.
Definition: polyPatch.H:577
virtual void newInternalProcFaces(label &, label &) const
Return number of new internal of this polyPatch faces.
Definition: polyPatch.H:381
const UIndirectList< T > patchInternalList(const UList< T > &internalValues) const
Extract face cell data.
Definition: polyPatch.H:484
friend class polyBoundaryMesh
Definition: polyPatch.H:107
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
label start() const noexcept
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:441
static int disallowGenericPolyPatch
Debug switch to disallow the use of genericPolyPatch.
Definition: polyPatch.H:159
virtual void initUpdateMesh(PstreamBuffers &)
Initialise the update of the patch topology.
Definition: polyPatch.H:135
Identifies a patch by name and index, with optional physical type and group information.
virtual bool masterImplicit() const
Return implicit master.
Definition: polyPatch.H:416
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:52
const wordList & inGroups() const noexcept
The (optional) groups that the patch belongs to.
friend Ostream & operator<<(Ostream &, const polyPatch &)
SubList< T > subList
Declare type of subList.
Definition: List.H:144
virtual void clearAddressing()
Clear addressing.
Definition: polyPatch.C:403
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:52
virtual void initMovePoints(PstreamBuffers &, const pointField &)
Initialise the patches for moving points.
Definition: polyPatch.H:124
SubField is a Field obtained as a section of another Field, without its own allocation. SubField is derived from a SubList rather than a List.
Definition: Field.H:63
labelRange range() const
Return start/size range of this patch.
Definition: polyPatch.H:449
virtual const labelUList & nbrCells() const
Return nbrCells.
Definition: polyPatch.H:389
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
virtual void clearGeom()
Clear geometry.
Definition: polyPatch.C:66
virtual void movePoints(PstreamBuffers &, const pointField &p)
Correct patches after moving points.
Definition: polyPatch.C:53
tmp< scalarField > areaFraction() const
Return the area fraction as the ratio of the stored face area and the area given by the face points...
Definition: polyPatch.C:346
virtual void movePoints(const Field< point_type > &)
Correct patch after moving points.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
PtrList< polyPatch > polyPatchList
Store lists of polyPatch as a PtrList.
Definition: polyPatch.H:56
declareRunTimeSelectionTable(autoPtr, polyPatch, word,(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType),(name, size, start, index, bm, patchType))
A list of faces which address into the list of points.
A List obtained as a section of another List.
Definition: SubList.H:50
void operator=(const polyPatch &p)
Copy assignment.
Definition: polyPatch.C:440
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:464
virtual void write(Ostream &os) const
Write the polyPatch data as a dictionary.
Definition: polyPatch.C:412
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundaryMesh reference.
Definition: polyPatch.C:309
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:365
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual ~polyPatch()
Destructor.
Definition: polyPatch.C:261
label offset() const noexcept
The offset where this patch starts in the boundary face list.
Definition: polyPatch.C:302
tmp< vectorField > faceCellCentres() const
Return face cell centres.
Definition: polyPatch.C:327
virtual void updateMesh(PstreamBuffers &)
Update of the patch topology.
Definition: polyPatch.C:59
polyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType)
Construct from components.
Definition: polyPatch.C:75
virtual autoPtr< polyPatch > clone(const labelList &faceCells) const
Construct and return a clone, setting faceCells.
Definition: polyPatch.H:284
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
virtual label neighbPolyPatchID() const
Return nbr patchID.
Definition: polyPatch.H:398
const word & name() const noexcept
The patch name.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
const vectorField::subField faceAreas() const
Return face normals.
Definition: polyPatch.C:321
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
Definition: polyPatch.H:118
virtual refPtr< labelListList > mapCollocatedFaces() const
Return mapped collocated faces.
Definition: polyPatch.H:407
const word & physicalType() const noexcept
The (optional) physical type of the patch.
OBJstream os(runTime.globalPath()/outputName)
const labelList & meshEdges() const
Return global edge index for local edges.
Definition: polyPatch.C:382
static const UList< label > & null()
Return a UList reference to a nullObject.
Definition: UListI.H:90
virtual bool setTopology(polyTopoChange &)
Collect topology changes in a polyTopoChange object.
Definition: polyPatch.H:618
Buffers for inter-processor communications streams (UOPstream, UIPstream).
virtual void initGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
Definition: polyPatch.H:112
static wordList constraintTypes()
Return a list of all the constraint patch types.
Definition: polyPatch.C:280
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
const List< T >::subList patchSlice(const UList< T > &values) const
This patch slice from the complete list, which has size mesh::nFaces(), using the number of patch fac...
Definition: polyPatch.H:497
Conversion/extraction to labelRange operation (functor).
Definition: labelRange.H:243
static bool constraintType(const word &patchType)
Return true if the given type is a constraint type.
Definition: polyPatch.C:269
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
Definition: polyPatch.C:426
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
A List with indirect addressing. Like IndirectList but does not store addressing. ...
Definition: faMatrix.H:56
Direct mesh changes based on v1.3 polyTopoChange syntax.
SubField< Type > subField
Declare type of subField.
Definition: Field.H:128
static autoPtr< polyPatch > New(const word &patchType, const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm)
Return pointer to a new patch created on freestore from components.
Definition: polyPatchNew.C:28
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
TypeName("patch")
Runtime type information.
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialize ordering for primitivePatch. Does not.
Definition: polyPatch.C:421
Macros to ease declaration of run-time selection tables.
label index() const noexcept
The index of this patch in the boundaryMesh.
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
const List< T >::subList boundarySlice(const List< T > &values) const
This patch slice from the list of boundary values, which has size mesh::nBoundaryFaces(), using the number of patch faces.
Definition: polyPatch.H:508
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:315