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-2024 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  //- Cached area fraction
92  std::unique_ptr<scalarField> areaFractionPtr_;
93 
94 
95 protected:
96 
97  // Protected Member Functions
98 
99  //- Inherit movePoints from primitivePatch
101 
102  // The polyPatch geometry initialisation is called by polyBoundaryMesh
103  friend class polyBoundaryMesh;
104 
105  //- Initialise the calculation of the patch geometry
106  virtual void initGeometry(PstreamBuffers&)
107  {}
108 
109  //- Calculate the patch geometry
110  virtual void calcGeometry(PstreamBuffers&)
111  {}
113  //- Initialise the patches for moving points
114  virtual void initMovePoints(PstreamBuffers&, const pointField&)
115  {}
116 
117  //- Correct patches after moving points
118  virtual void movePoints(PstreamBuffers&, const pointField& p);
119 
120  //- Initialise the update of the patch topology
121  virtual void initUpdateMesh(PstreamBuffers&)
122  {}
124  //- Update of the patch topology
125  virtual void updateMesh(PstreamBuffers&);
126 
127  //- Clear geometry
128  virtual void clearGeom();
130 
131 public:
132 
133  //- Runtime type information
134  TypeName("patch");
135 
136  //- Debug switch to disallow the use of genericPolyPatch
137  static int disallowGenericPolyPatch;
138 
139 
140  // Declare run-time constructor selection tables
141 
143  (
144  autoPtr,
145  polyPatch,
146  word,
147  (
148  const word& name,
149  const label size,
150  const label start,
151  const label index,
152  const polyBoundaryMesh& bm,
153  const word& patchType
154  ),
155  (name, size, start, index, bm, patchType)
156  );
157 
159  (
160  autoPtr,
161  polyPatch,
162  dictionary,
163  (
164  const word& name,
165  const dictionary& dict,
166  const label index,
167  const polyBoundaryMesh& bm,
168  const word& patchType
169  ),
170  (name, dict, index, bm, patchType)
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  const word& patchType
185  );
186 
187  //- Construct from components
188  polyPatch
189  (
190  const word& name,
191  const label size,
192  const label start,
193  const label index,
194  const polyBoundaryMesh& bm,
195  const word& physicalType,
196  const wordList& inGroups
197  );
198 
199  //- Construct from dictionary
200  polyPatch
201  (
202  const word& name,
203  const dictionary& dict,
204  const label index,
205  const polyBoundaryMesh& bm,
206  const word& patchType
207  );
208 
209  //- Copy construct, resetting the boundary mesh
210  polyPatch(const polyPatch&, const polyBoundaryMesh&);
211 
212  //- Construct given the original patch and resetting the
213  //- face list and boundary mesh information
214  polyPatch
215  (
216  const polyPatch& pp,
217  const polyBoundaryMesh& bm,
218  const label index,
219  const label newSize,
220  const label newStart
221  );
222 
223  //- Construct given the original patch and a map
224  polyPatch
225  (
226  const polyPatch& pp,
227  const polyBoundaryMesh& bm,
228  const label index,
229  const labelUList& mapAddressing,
230  const label newStart
231  );
232 
233  //- Copy construct
234  polyPatch(const polyPatch& p);
235 
236  //- Copy construct, setting faceCells
237  // \note The faceCells are held by the caller
238  polyPatch(const polyPatch& p, const labelList& faceCells);
239 
240  //- Construct and return a clone, setting faceCells
241  // \note The faceCells are held by the caller
242  virtual autoPtr<polyPatch> clone(const labelList& faceCells) const
243  {
244  return autoPtr<polyPatch>::New(*this, faceCells);
245  }
246 
247  //- Construct and return a clone, resetting the boundary mesh
248  virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
249  {
250  return autoPtr<polyPatch>::New(*this, bm);
251  }
252 
253  //- Construct and return a clone,
254  //- resetting the face list and boundary mesh
255  virtual autoPtr<polyPatch> clone
256  (
257  const polyBoundaryMesh& bm,
258  const label index,
259  const label newSize,
260  const label newStart
261  ) const
262  {
263  return autoPtr<polyPatch>::New(*this, bm, index, newSize, newStart);
264  }
265 
266  //- Construct and return a clone,
267  //- resetting the face list and boundary mesh
268  virtual autoPtr<polyPatch> clone
269  (
270  const polyBoundaryMesh& bm,
271  const label index,
272  const labelUList& mapAddressing,
273  const label newStart
274  ) const
275  {
277  (*this, bm, index, mapAddressing, newStart);
278  }
279 
280 
281  // Selectors
282 
283  //- Return pointer to a new patch created on freestore from components
284  static autoPtr<polyPatch> New
285  (
286  const word& patchType,
287  const word& name,
288  const label size,
289  const label start,
290  const label index,
291  const polyBoundaryMesh& bm
292  );
293 
294  //- Return pointer to a new patch created on freestore from dictionary
295  static autoPtr<polyPatch> New
296  (
297  const word& name,
298  const dictionary& dict,
299  const label index,
300  const polyBoundaryMesh& bm
301  );
302 
303  //- Return pointer to a new patch created on freestore from dictionary
304  static autoPtr<polyPatch> New
305  (
306  const word& patchType,
307  const word& name,
308  const dictionary& dict,
309  const label index,
310  const polyBoundaryMesh& bm
311  );
312 
313 
314  //- Destructor
315  virtual ~polyPatch();
316 
317 
318  // Member Functions
319 
320  // Implicit treatment functions
321 
322  //- Return number of new internal of this polyPatch faces
323  virtual void newInternalProcFaces(label&, label&) const
324  {
326  }
327 
328  //- Return nbrCells
329  virtual const labelUList& nbrCells() const
330  {
332  return labelUList::null();
333  }
334 
335  //- Return nbr patchID
336  virtual label neighbPolyPatchID() const
337  {
339  return -1;
340  }
341 
342  //- Return mapped collocated faces
343  virtual refPtr<labelListList> mapCollocatedFaces() const
344  {
346  return nullptr;
347  }
348 
349  //- Return implicit master
350  virtual bool masterImplicit() const
351  {
353  return false;
354  }
355 
356  //- Return neighbour region name
357  virtual word neighbRegionID() const
358  {
359  return word("none");
360  }
361 
362 
363  //- The offset where this patch starts in the boundary face list
364  // The value is the same as patch.start() - mesh.nInternalFaces()
365  label offset() const noexcept;
366 
367  //- Return start label of this patch in the polyMesh face list
368  label start() const noexcept
369  {
370  return start_;
371  }
372 
373  //- Return start/size range of this patch
374  labelRange range() const
375  {
376  return labelRange(start_, this->size());
377  }
378 
379  //- Return boundaryMesh reference
380  const polyBoundaryMesh& boundaryMesh() const noexcept;
381 
382  //- Return true if this patch is geometrically coupled (i.e. faces and
383  // points correspondence)
384  virtual bool coupled() const
385  {
386  return false;
387  }
388 
389  //- Return true if the given type is a constraint type
390  static bool constraintType(const word& patchType);
391 
392  //- Return a list of all the constraint patch types
393  static wordList constraintTypes();
395  //- Extract face cell data
396  template<class T>
398  (
399  const UList<T>& internalValues
400  ) const
401  {
402  return UIndirectList<T>(internalValues, faceCells());
403  }
404 
405  //- This patch slice from the complete list, which has size
406  //- mesh::nFaces(), using the number of patch faces.
407  template<class T>
408  const typename List<T>::subList
409  patchSlice(const UList<T>& values) const
410  {
411  return typename List<T>::subList(values, this->size(), start_);
412  }
413 
414  //- This patch slice from the list of boundary values, which has size
415  //- mesh::nBoundaryFaces(), using the number of patch faces.
416  template<class T>
417  const typename List<T>::subList
418  boundarySlice(const List<T>& values) const
419  {
420  return typename List<T>::subList(values, this->size(), offset());
421  }
422 
423  //- Slice Field to patch, using the number of patch faces.
424  template<class T>
425  const typename Field<T>::subField
426  patchSlice(const Field<T>& values) const
427  {
428  return typename Field<T>::subField(values, this->size(), start_);
429  }
431 
432  //- Write the polyPatch data as a dictionary
433  virtual void write(Ostream& os) const;
434 
435 
436  // Geometric data; point list required
437 
438  //- Return face centres
439  const vectorField::subField faceCentres() const;
440 
441  //- Return face normals
442  const vectorField::subField faceAreas() const;
443 
444  //- Return face cell centres
447  //- Calculate the area fraction as the ratio of the stored face
448  //- area and the area given by the face points.
450 
451  //- Return the cached area fraction.
452  //- Usually only set for the non-overlap patches on ACMI.
455  //- Set uniform cached area fraction
456  void areaFraction(const scalar fraction);
457 
458  //- Set cached area fraction (non-uniform)
459  void areaFraction(const tmp<scalarField>& fraction);
460 
461 
462  // Addressing into mesh
463 
464  //- Return face-cell addressing
465  const labelUList& faceCells() const;
466 
467  //- Return global edge index for local edges
468  const labelList& meshEdges() const;
470  //- Clear addressing
471  virtual void clearAddressing();
472 
473 
474  // Other patch operations
475 
476  //- Return label of face in patch from global face label
477  label whichFace(const label facei) const noexcept
478  {
479  return facei - start_;
480  }
481 
482 
483  //- Initialize ordering for primitivePatch. Does not
484  // refer to *this (except for name() and type() etc.)
485  virtual void initOrder(PstreamBuffers&, const primitivePatch&) const;
486 
487  //- Return new ordering for primitivePatch.
488  // Ordering is -faceMap: for every face
489  // index of the new face -rotation:for every new face the clockwise
490  // shift of the original face. Return false if nothing changes
491  // (faceMap is identity, rotation is 0), true otherwise.
492  virtual bool order
493  (
495  const primitivePatch&,
497  labelList& rotation
498  ) const;
499 
500  //- For dynamic mesh cases - return true if this patch will change the
501  //- topology
502  virtual bool changeTopology() const
503  {
504  return false;
505  }
506 
507  //- Collect topology changes in a polyTopoChange object
508  virtual bool setTopology(polyTopoChange&)
509  {
510  return false;
511  }
512 
514  // Member Operators
515 
516  //- Copy assignment
517  void operator=(const polyPatch& p);
518 
519 
520  // Ostream Operator
521 
522  friend Ostream& operator<<(Ostream&, const polyPatch&);
523 };
524 
525 
526 // Global Functions
527 
528 //- The labelRange of a polyPatch
529 template<>
530 struct labelRangeOp<polyPatch>
531 {
532  labelRange operator()(const polyPatch& pp) const
533  {
534  return pp.range();
535  }
536 };
537 
538 
539 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
540 
541 } // End namespace Foam
542 
543 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
544 
545 #endif
546 
547 // ************************************************************************* //
virtual bool changeTopology() const
For dynamic mesh cases - return true if this patch will change the topology.
Definition: polyPatch.H:631
dictionary dict
virtual word neighbRegionID() const
Return neighbour region name.
Definition: polyPatch.H:430
label whichFace(const label facei) const noexcept
Return label of face in patch from global face label.
Definition: polyPatch.H:598
virtual void newInternalProcFaces(label &, label &) const
Return number of new internal of this polyPatch faces.
Definition: polyPatch.H:386
const UIndirectList< T > patchInternalList(const UList< T > &internalValues) const
Extract face cell data.
Definition: polyPatch.H:489
friend class polyBoundaryMesh
Definition: polyPatch.H:112
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:446
static int disallowGenericPolyPatch
Debug switch to disallow the use of genericPolyPatch.
Definition: polyPatch.H:164
virtual void initUpdateMesh(PstreamBuffers &)
Initialise the update of the patch topology.
Definition: polyPatch.H:140
Identifies a patch by name and index, with optional physical type and group information.
virtual bool masterImplicit() const
Return implicit master.
Definition: polyPatch.H:421
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:420
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:129
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:454
virtual const labelUList & nbrCells() const
Return nbrCells.
Definition: polyPatch.H:394
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 cached area fraction. Usually only set for the non-overlap patches on ACMI.
Definition: polyPatch.C:352
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:458
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:469
virtual void write(Ostream &os) const
Write the polyPatch data as a dictionary.
Definition: polyPatch.C:430
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundaryMesh reference.
Definition: polyPatch.C:295
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:382
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual ~polyPatch()
Destructor.
Definition: polyPatch.C:247
label offset() const noexcept
The offset where this patch starts in the boundary face list.
Definition: polyPatch.C:288
tmp< vectorField > faceCellCentres() const
Return face cell centres.
Definition: polyPatch.C:313
virtual void updateMesh(PstreamBuffers &)
Update of the patch topology.
Definition: polyPatch.C:59
const Field< point_type > & points() const noexcept
Return reference to global points.
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:289
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
virtual label neighbPolyPatchID() const
Return nbr patchID.
Definition: polyPatch.H:403
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:307
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
Definition: polyPatch.H:123
virtual refPtr< labelListList > mapCollocatedFaces() const
Return mapped collocated faces.
Definition: polyPatch.H:412
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:399
virtual bool setTopology(polyTopoChange &)
Collect topology changes in a polyTopoChange object.
Definition: polyPatch.H:639
Buffers for inter-processor communications streams (UOPstream, UIPstream).
virtual void initGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
Definition: polyPatch.H:117
static wordList constraintTypes()
Return a list of all the constraint patch types.
Definition: polyPatch.C:266
Basic run-time type information using word as the type&#39;s name. Used to enhance the standard RTTI to c...
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:502
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:255
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
Definition: polyPatch.C:444
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:52
Direct mesh changes based on v1.3 polyTopoChange syntax.
static const UList< label > & null() noexcept
Return a null UList (reference to a nullObject). Behaves like an empty UList.
Definition: UList.H:233
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:439
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:513
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:696
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:301