faPatch.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) 2016-2017 Wikki Ltd
9  Copyright (C) 2020-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::faPatch
29 
30 Description
31  Finite area patch class. Used for 2-D non-Euclidian finite area method.
32 
33 Author
34  Zeljko Tukovic, FMENA
35  Hrvoje Jasak, Wikki Ltd.
36 
37 SourceFiles
38  faPatch.C
39  faPatchNew.C
40  faPatchTemplates.C
41  faPatchFaMeshTemplates.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef Foam_faPatch_H
46 #define Foam_faPatch_H
47 
48 #include "patchIdentifier.H"
49 #include "labelList.H"
50 #include "pointField.H"
51 #include "typeInfo.H"
52 #include "PtrList.H"
53 #include "faPatchFieldsFwd.H"
54 #include "autoPtr.H"
55 #include "runTimeSelectionTables.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 // Forward Declarations
63 class faBoundaryMesh;
64 class faPatch;
65 
66 //- Store lists of faPatch as a PtrList
68 
70 
71 /*---------------------------------------------------------------------------*\
72  Class faPatch Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 class faPatch
76 :
77  public patchIdentifier,
78  public labelList
79 {
80  // Private Data
81 
82  //- Neighbour polyPatch index
83  const label nbrPolyPatchId_;
84 
85  //- Reference to boundary mesh
86  const faBoundaryMesh& boundaryMesh_;
87 
88  //- Demand-driven: edge-face addressing
89  mutable std::unique_ptr<labelList::subList> edgeFacesPtr_;
90 
91  //- Demand-driven: local points labels
92  mutable std::unique_ptr<labelList> pointLabelsPtr_;
93 
94  //- Demand-driven: point-edge addressing
95  mutable std::unique_ptr<labelListList> pointEdgesPtr_;
96 
97 
98  // Private Member Functions
99 
100  //- No copy construct
101  faPatch(const faPatch&) = delete;
102 
103  //- No copy assignment
104  void operator=(const faPatch&) = delete;
105 
106  //- Clear out topological patch data
107  void clearOut();
108 
109 
110 protected:
111 
112  // Protected Member Functions
113 
114  //- The faPatch geometry initialisation is called by faBoundaryMesh
115  friend class faBoundaryMesh;
116 
117  //- Calculate patch point labels
118  void calcPointLabels() const;
119 
120  //- Calculate patch point-edge addressing
121  void calcPointEdges() const;
122 
123  //- Initialise the calculation of the patch geometry
124  virtual void initGeometry(PstreamBuffers&)
125  {}
126 
127  //- Calculate the patch geometry
128  virtual void calcGeometry(PstreamBuffers&)
129  {}
131  //- Initialise the patches for moving points
132  virtual void initMovePoints(PstreamBuffers&, const pointField&)
133  {}
134 
135  //- Correct patch after moving points
136  virtual void movePoints(PstreamBuffers&, const pointField&);
137 
138  //- Initialise the update of the patch topology
139  virtual void initUpdateMesh(PstreamBuffers&)
140  {}
141 
142  //- Update of the patch topology
143  virtual void updateMesh(PstreamBuffers&)
144  {}
146 
147 public:
148 
149  //- The boundary type associated with the patch
152 
153  //- Runtime type information
154  TypeName("patch");
155 
156  // Declare run-time constructor selection tables
159  (
160  autoPtr,
161  faPatch,
162  dictionary,
163  (
164  const word& name,
165  const dictionary& dict,
166  const label index,
167  const faBoundaryMesh& bm,
168  const word& patchType
169  ),
170  (name, dict, index, bm, patchType)
171  );
172 
173 
174  // Constructors
175 
176  //- Construct from components
177  faPatch
178  (
179  const word& name,
180  const labelUList& edgeLabels,
181  const label index,
182  const faBoundaryMesh& bm,
183  const label nbrPolyPatchi,
184  const word& patchType
185  );
186 
187  //- Construct from dictionary
188  faPatch
189  (
190  const word& name,
191  const dictionary& dict,
192  const label index,
193  const faBoundaryMesh& bm,
194  const word& patchType
195  );
196 
197  //- Copy construct, resetting the boundary mesh
198  faPatch(const faPatch& p, const faBoundaryMesh& bm);
199 
200  //- Copy construct, resetting boundary mesh and addressing
201  faPatch
202  (
203  const faPatch& p,
204  const faBoundaryMesh& bm,
205  const label index,
206  const labelUList& edgeLabels,
207  const label nbrPolyPatchi
208  );
209 
210 
211  //- Construct and return a clone, resetting the boundary mesh
212  virtual autoPtr<faPatch> clone(const faBoundaryMesh& bm) const
213  {
214  return autoPtr<faPatch>::New(*this, bm);
215  }
216 
217  //- Construct and return a clone, resetting the edge list
218  //- and boundary mesh
219  virtual autoPtr<faPatch> clone
220  (
221  const faBoundaryMesh& bm,
222  const labelUList& edgeLabels,
223  const label index,
224  const label nbrPolyPatchi
225  ) const
226  {
227  return autoPtr<faPatch>::New
228  (
229  *this,
230  bm,
231  index,
232  edgeLabels,
233  nbrPolyPatchi
234  );
235  }
236 
237 
238  // Selectors
239 
240  //- Return pointer to a new patch created on freestore from dictionary
241  static autoPtr<faPatch> New
242  (
243  const word& name,
244  const dictionary& dict,
245  const label index,
246  const faBoundaryMesh& bm
247  );
248 
249  //- Return pointer to a new patch created on freestore from dictionary
250  static autoPtr<faPatch> New
251  (
252  const word& patchType,
253  const word& name,
254  const dictionary& dict,
255  const label index,
256  const faBoundaryMesh& bm
257  );
258 
259 
260  //- Destructor
261  virtual ~faPatch();
262 
263 
264  // Static Member Functions
265 
266  //- Return true if the given type is a constraint type
267  static bool constraintType(const word& patchType);
268 
269  //- Return a list of all the constraint patch types
270  static wordList constraintTypes();
271 
272 
273  // Member Functions
274 
275  //- Return the list of edges
276  const labelList& edgeLabels() const noexcept
277  {
278  return static_cast<const labelList&>(*this);
279  }
280 
281  //- Number of patch points
282  label nPoints() const
283  {
284  return pointLabels().size();
285  }
286 
287  //- Number of edge labels (boundary edges) addressed by this patch
288  label nEdges() const noexcept
289  {
290  return labelList::size();
291  }
292 
293  //- The neighbour polyPatch index
294  label ngbPolyPatchIndex() const noexcept
295  {
296  return nbrPolyPatchId_;
297  }
298 
299  //- Return boundaryMesh reference
300  const faBoundaryMesh& boundaryMesh() const noexcept;
301 
302  //- Return true if this patch is coupled
303  virtual bool coupled() const
304  {
305  return false;
306  }
307 
308  //- The offset where this patch starts in the boundary edge list.
309  // The value is the same as patch.start() - mesh.nInternalEdges()
310  label offset() const;
311 
312  //- Patch start in edge list
313  label start() const;
314 
315  //- Patch size is the number of edge labels, but can be overloaded
316  virtual label size() const
317  {
318  return labelList::size();
319  }
320 
321  //- Return label of edge in patch from global edge label
322  label whichEdge(const label edgei) const
323  {
324  return edgei - start();
325  }
326 
327  //- This patch slice from the complete list of values, which has
328  //- size mesh::nEdges(), using the virtual patch size.
329  template<class T>
330  const typename List<T>::subList patchSlice(const List<T>& values) const
331  {
332  return typename List<T>::subList(values, size(), start());
333  }
334 
335  //- This patch slice from the list of boundary values, which has
336  //- size mesh::nBoundaryEdges(), using the virtual patch size.
337  template<class T>
338  const typename List<T>::subList
339  boundarySlice(const List<T>& values) const
340  {
341  return typename List<T>::subList
342  (
344  size(),
345  offset()
346  );
347  }
348 
349 
350  //- Write
351  virtual void write(Ostream&) const;
352 
353 
354  // Topological information
355 
356  //- List of proc/face for the boundary edge neighbours
357  //- in locally reordered edge numbering.
360  //- Boundary edge neighbour processors
361  //- (does not include own proc)
362  labelList boundaryProcs() const;
363 
364  //- List of proc/size for the boundary edge neighbour processors
365  //- (does not include own proc)
367 
368 
369  // Access functions for geometrical data
370 
371  //- Return patch point labels
372  const labelList& pointLabels() const;
373 
374  //- Return patch point-edge addressing
375  const labelListList& pointEdges() const;
376 
377  //- Return normals of neighbour polyPatch faces
378  // Same as faMesh::haloFaceNormals()
380 
381  //- Return normals of neighbour polyPatch joined points
383 
384  //- Return edge-face addressing
385  const labelUList& edgeFaces() const;
386 
387  //- Return edge centres
388  const vectorField& edgeCentres() const;
389 
390  //- Return edge length vectors, like the faMesh::Le() method
391  const vectorField& edgeLengths() const;
393  //- Return edge length magnitudes, like the faMesh::magLe() method
394  const scalarField& magEdgeLengths() const;
395 
396  //- Return edge unit normals, like the faMesh::unitLe() method
398 
399  //- Return neighbour face centres
401 
402  //- Return cell-centre to face-centre vector
403  // except for coupled patches for which the cell-centre
404  // to coupled-cell-centre vector is returned
405  virtual tmp<vectorField> delta() const;
406 
407 
408  // Access functions for demand driven data
409 
410  //- Make patch weighting factors
411  virtual void makeWeights(scalarField&) const;
412 
413  //- Return patch weighting factors
414  const scalarField& weights() const;
415 
416  //- Make patch edge - neighbour face distances
417  virtual void makeDeltaCoeffs(scalarField&) const;
418 
419  void makeCorrectionVectors(vectorField&) const;
420 
421  //- Return patch edge - neighbour face distances
422  const scalarField& deltaCoeffs() const;
423 
424 
425  // Topological changes
426 
427  //- Reset the list of edges (use with caution)
428  void resetEdges(const labelUList& newEdges);
429 
430  //- Reset the list of edges (use with caution)
431  void resetEdges(labelList&& newEdges);
432 
433 
434  // Evaluation
435 
436  //- Extract internal field next to patch using specified addressing
437  // \param internalData The internal field to extract from
438  // \param addressing Addressing from patch into internal field
439  // \param [out] pfld The extracted patch field.
440  // It is always resized according to the patch size(),
441  // which can be smaller than the addressing size
442  template<class Type>
443  inline void patchInternalField
444  (
445  const UList<Type>& internalData,
446  const labelUList& addressing,
447  Field<Type>& pfld
448  ) const;
449 
450  //- Extract internal field next to patch as patch field
451  //- using edgeFaces() mapping.
452  // \param internalData The internal field to extract from
453  // \param [out] pfld The extracted patch field.
454  // It is always resized according to the patch size(),
455  // which can be smaller than the edgeFaces() size
456  template<class Type>
457  void patchInternalField
458  (
459  const UList<Type>& internalData,
460  Field<Type>& pfld
461  ) const;
462 
463  //- Return given internal field next to patch as patch field
464  //- using edgeFaces() mapping.
465  // \param internalData The internal field to extract from
466  template<class Type>
468  (
469  const UList<Type>& internalData
470  ) const;
471 
472  //- Return the patch field of the GeometricField
473  //- corresponding to this patch.
474  template<class GeometricField, class AnyType = bool>
475  const typename GeometricField::Patch& patchField
476  (
477  const GeometricField& gf
478  ) const;
479 
480  //- Lookup the named field from the local registry and
481  //- return the patch field corresponding to this patch.
482  // N.B. The dummy pointer arguments are used if this function is
483  // instantiated within a templated function to avoid a bug in gcc.
484  template<class GeometricField, class AnyType = bool>
486  (
487  const word& name,
488  const GeometricField* = nullptr,
489  const AnyType* = nullptr
490  ) const;
491 
492 
493  // Ostream Operator
494 
495  friend Ostream& operator<<(Ostream&, const faPatch&);
496 };
497 
498 
499 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
500 
501 } // End namespace Foam
502 
503 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
504 
505 #ifdef NoRepository
506  #include "faPatchTemplates.C"
507 #endif
508 
509 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
510 
511 #endif
512 
513 // ************************************************************************* //
PtrList< faPatch > faPatchList
Store lists of faPatch as a PtrList.
Definition: faPatch.H:59
const List< T >::subList patchSlice(const List< T > &values) const
This patch slice from the complete list of values, which has size mesh::nEdges(), using the virtual p...
Definition: faPatch.H:410
static autoPtr< faPatch > New(const word &name, const dictionary &dict, const label index, const faBoundaryMesh &bm)
Return pointer to a new patch created on freestore from dictionary.
Definition: faPatchNew.C:28
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
const GeometricField::Patch & patchField(const GeometricField &gf) const
Return the patch field of the GeometricField corresponding to this patch.
friend class faBoundaryMesh
The faPatch geometry initialisation is called by faBoundaryMesh.
Definition: faPatch.H:130
label nPoints() const
Number of patch points.
Definition: faPatch.H:343
const scalarField & weights() const
Return patch weighting factors.
Definition: faPatch.C:536
virtual tmp< vectorField > delta() const
Return cell-centre to face-centre vector.
Definition: faPatch.C:484
const List< T >::subList boundarySlice(const List< T > &values) const
This patch slice from the list of boundary values, which has size mesh::nBoundaryEdges(), using the virtual patch size.
Definition: faPatch.H:421
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const scalarField & deltaCoeffs() const
Return patch edge - neighbour face distances.
Definition: faPatch.C:524
Identifies a patch by name and index, with optional physical type and group information.
static bool constraintType(const word &patchType)
Return true if the given type is a constraint type.
Definition: faPatch.C:45
virtual void initMovePoints(PstreamBuffers &, const pointField &)
Initialise the patches for moving points.
Definition: faPatch.H:157
const labelList & pointLabels() const
Return patch point labels.
Definition: faPatch.C:276
virtual label size() const
Patch size is the number of edge labels, but can be overloaded.
Definition: faPatch.H:392
virtual void makeDeltaCoeffs(scalarField &) const
Make patch edge - neighbour face distances.
Definition: faPatch.C:508
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
const scalarField & magEdgeLengths() const
Return edge length magnitudes, like the faMesh::magLe() method.
Definition: faPatch.C:462
SubList< T > subList
Declare type of subList.
Definition: List.H:144
friend Ostream & operator<<(Ostream &, const faPatch &)
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
Definition: faPatch.H:151
label nEdges() const noexcept
Number of edge labels (boundary edges) addressed by this patch.
Definition: faPatch.H:351
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:56
const GeometricField::Patch & lookupPatchField(const word &name, const GeometricField *=nullptr, const AnyType *=nullptr) const
Lookup the named field from the local registry and return the patch field corresponding to this patch...
const labelList & edgeLabels() const noexcept
Return the list of edges.
Definition: faPatch.H:335
label whichEdge(const label edgei) const
Return label of edge in patch from global edge label.
Definition: faPatch.H:400
friend class List< T >
Declare friendship with the List class.
Definition: UList.H:219
List< labelPair > boundaryProcSizes() const
List of proc/size for the boundary edge neighbour processors (does not include own proc) ...
Definition: faPatch.C:246
static wordList constraintTypes()
Return a list of all the constraint patch types.
Definition: faPatch.C:54
void makeCorrectionVectors(vectorField &) const
Definition: faPatch.C:514
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
A List obtained as a section of another List.
Definition: SubList.H:50
virtual bool coupled() const
Return true if this patch is coupled.
Definition: faPatch.H:372
const vectorField & edgeCentres() const
Return edge centres.
Definition: faPatch.C:450
tmp< vectorField > edgeFaceCentres() const
Return neighbour face centres.
Definition: faPatch.C:478
void calcPointLabels() const
Calculate patch point labels.
Definition: faPatch.C:298
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void write(Ostream &) const
Write.
Definition: faPatch.C:560
const labelUList & edgeFaces() const
Return edge-face addressing.
Definition: faPatch.C:433
tmp< vectorField > edgeNormals() const
Return edge unit normals, like the faMesh::unitLe() method.
Definition: faPatch.C:468
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
virtual void updateMesh(PstreamBuffers &)
Update of the patch topology.
Definition: faPatch.H:174
label size() const noexcept
The number of elements in the container.
Definition: UList.H:671
labelList boundaryProcs() const
Boundary edge neighbour processors (does not include own proc)
Definition: faPatch.C:226
List< labelPair > boundaryConnections() const
List of proc/face for the boundary edge neighbours in locally reordered edge numbering.
Definition: faPatch.C:206
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:72
label start() const
Patch start in edge list.
Definition: faPatch.C:200
Buffers for inter-processor communications streams (UOPstream, UIPstream).
virtual ~faPatch()
Destructor.
Definition: faPatch.C:175
TypeName("patch")
Runtime type information.
tmp< vectorField > ngbPolyPatchPointNormals() const
Return normals of neighbour polyPatch joined points.
Definition: faPatch.C:398
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
virtual void makeWeights(scalarField &) const
Make patch weighting factors.
Definition: faPatch.C:530
faBoundaryMesh BoundaryMesh
The boundary type associated with the patch.
Definition: faPatch.H:183
void patchInternalField(const UList< Type > &internalData, const labelUList &addressing, Field< Type > &pfld) const
Extract internal field next to patch using specified addressing.
Forward declarations for faPatchField types.
const vectorField & edgeLengths() const
Return edge length vectors, like the faMesh::Le() method.
Definition: faPatch.C:456
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
Finite area boundary mesh.
autoPtr< List< label > > clone() const
Clone.
Definition: ListI.H:121
const labelListList & pointEdges() const
Return patch point-edge addressing.
Definition: faPatch.C:287
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Macros to ease declaration of run-time selection tables.
label index() const noexcept
The index of this patch in the boundaryMesh.
label offset() const
The offset where this patch starts in the boundary edge list.
Definition: faPatch.C:189
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
declareRunTimeSelectionTable(autoPtr, faPatch, dictionary,(const word &name, const dictionary &dict, const label index, const faBoundaryMesh &bm, const word &patchType),(name, dict, index, bm, patchType))
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
tmp< vectorField > ngbPolyPatchFaceNormals() const
Return normals of neighbour polyPatch faces.
Definition: faPatch.C:387
virtual void movePoints(PstreamBuffers &, const pointField &)
Correct patch after moving points.
Definition: faPatch.C:542
virtual void initUpdateMesh(PstreamBuffers &)
Initialise the update of the patch topology.
Definition: faPatch.H:168
void calcPointEdges() const
Calculate patch point-edge addressing.
Definition: faPatch.C:356
void resetEdges(const labelUList &newEdges)
Reset the list of edges (use with caution)
Definition: faPatch.C:546
const faBoundaryMesh & boundaryMesh() const noexcept
Return boundaryMesh reference.
Definition: faPatch.C:183
virtual void initGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
Definition: faPatch.H:145
Namespace for OpenFOAM.
label ngbPolyPatchIndex() const noexcept
The neighbour polyPatch index.
Definition: faPatch.H:359