polySurface.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) 2019-2024 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::polySurface
28 
29 Description
30  A surface mesh consisting of general polygon faces and capable of
31  holding fields.
32 
33 SourceFiles
34  polySurface.C
35  polySurfaceClear.C
36  polySurfaceIO.C
37  polySurfaceTemplates.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_polySurface_H
42 #define Foam_polySurface_H
43 
44 #include "objectRegistry.H"
45 #include "primitivePatch.H"
46 #include "meshedSurf.H"
47 #include "polySurfaceFieldsFwd.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 class dimensionSet;
56 class surfZone;
57 class polySurfaceGeoMesh;
58 class polySurfacePointGeoMesh;
59 
60 template<class Face> class MeshedSurface;
61 
62 
63 /*---------------------------------------------------------------------------*\
64  Class polySurface Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class polySurface
68 :
69  public objectRegistry,
70  public PrimitivePatch<::Foam::List<face>, pointField>,
71  public meshedSurf
72 {
73 public:
74 
75  //- Enumeration for the field association
77  {
78  NO_DATA = 0,
79  FACE_DATA = 1,
80  POINT_DATA = 2,
82  };
83 
84 
85 private:
86 
87  // Private Typedefs
88 
89  //- Internal mesh storage type
90  typedef
92  MeshReference;
93 
94 
95  // Private Data
96 
97  //- Per-face zone/region information
98  labelList zoneIds_;
99 
100 
101  // Private Member Functions
102 
103  //- Calculate per-face zone/region information
104  void calculateZoneIds(const UList<surfZone>& zones);
105 
106 
107 protected:
108 
109  // Protected Member Functions
110 
111  //- Non-const access to points
113  {
114  return const_cast<pointField&>(MeshReference::points());
115  }
116 
117  //- Non-const access to the faces
119  {
120  return
121  static_cast<faceList&>
122  (
123  static_cast<MeshReference&>(*this)
124  );
125  }
126 
127  //- Const access to the faces
128  const faceList& storedFaces() const
129  {
130  return
131  static_cast<const faceList&>
132  (
133  static_cast<const MeshReference&>(*this)
134  );
135  }
136 
138 public:
139 
140  // Public Typedefs
141 
142  //- Typedef required for GeoMesh
143  typedef polySurface Mesh;
144 
145  //- Placeholder only, for GeoMesh
146  typedef bool BoundaryMesh;
147 
148  //- Name for point fields sub-registry
149  static const word pointDataName;
150 
151 
152  //- Runtime type information
153  TypeName("polySurface");
155 
156  // Generated Methods
157 
158  //- No copy construct
159  polySurface(const polySurface&) = delete;
160 
161  //- No copy assignment
162  void operator=(const polySurface&) = delete;
163 
165  // Constructors
166 
167  //- Default construct with NO_READ, NO_WRITE
168  //- optionally with a checkIn on the parent registry.
169  // Created without a PointData sub-registry
170  explicit polySurface(const IOobject& io, bool doCheckIn = false);
171 
172  //- Default construct with specified name on the given registry,
173  //- optionally with a checkIn on the parent registry.
174  // Created without a PointData sub-registry
176  (
177  const word& surfName,
178  const objectRegistry& obr,
179  bool doCheckIn = false
180  );
181 
182  //- Copy construct from MeshedSurface<face> contents
183  //- with NO_READ, NO_WRITE
184  //- optionally with a checkIn on the parent registry.
185  // Created without a PointData sub-registry
187  (
188  const IOobject& io,
189  const MeshedSurface<face>& surf,
190  bool doCheckIn = false
191  );
192 
193  //- Move construct from MeshedSurface<face> contents
194  //- with NO_READ, NO_WRITE
195  //- optionally with a checkIn on the parent registry.
196  // Created without a PointData sub-registry
198  (
199  const IOobject& io,
200  MeshedSurface<face>&& surf,
201  bool doCheckIn = false
202  );
203 
204 
205  //- Destructor
206  virtual ~polySurface();
207 
208 
209  // Factory Methods
210 
211  //- Get or create (NO_READ, NO_WRITE) named surface on registry
212  static polySurface& New(const word& surfName, const objectRegistry&);
213 
214  //- Remove named surface from specified registry
215  static bool Delete(const word& surfName, const objectRegistry&);
216 
217 
218  // Member Functions
219 
220  // Resolve iterator ambiguity in favour of Patch (not registry)
221 
222  using MeshReference::end;
223  using MeshReference::cend;
224  using MeshReference::begin;
225  using MeshReference::cbegin;
226 
227 
228  // Access
229 
230  //- Return the number of points
231  virtual label nPoints() const
232  {
233  return MeshReference::points().size();
234  }
235 
236  //- Return the number of faces
237  virtual label nFaces() const
238  {
239  return MeshReference::size();
240  }
241 
242  //- Return number of faces
243  virtual label size() const
244  {
245  return MeshReference::size();
246  }
247 
248 
249  //- Return points
250  virtual const pointField& points() const
251  {
252  return MeshReference::points();
253  }
254 
255  //- Return faces
256  virtual const faceList& faces() const
257  {
258  return this->storedFaces();
259  }
260 
261  //- Const access to per-face zone/region information (demand-driven)
262  virtual const labelList& zoneIds() const
263  {
264  return zoneIds_;
265  }
266 
267  //- Return face area vectors (normals)
268  const vectorField& Sf() const
269  {
270  return MeshReference::faceAreas();
271  }
273  //- Return face area magnitudes
274  const scalarField& magSf() const
275  {
277  }
278 
279  //- Face centres
280  const vectorField& Cf() const
281  {
283  }
284 
285 
286  // Modification
287 
288  //- Update with new contents.
289  //- Removes existing fields if sizes have changed
290  void copySurface
291  (
292  const pointField& points,
293  const faceList& faces,
295  bool unused=false
296  );
298  //- Update with new contents.
299  //- Removes existing fields if sizes have changed
300  void copySurface
301  (
302  const meshedSurf& surf,
304  bool unused=false
305  );
306 
307  //- Update with new contents.
308  //- Removes existing fields if sizes have changed
309  void copySurface
310  (
311  const MeshedSurface<face>& surf,
313  bool unused=false
314  );
315 
316  //- Transfer the contents (and annul the parameters).
317  //- Removes existing fields.
318  void transfer
319  (
320  pointField&& points,
323  );
324 
325  //- Transfer the contents (and annul the parameters).
326  //- Removes existing fields.
327  void transfer
328  (
331  bool validate=false
332  );
333 
334 
335  // Fields
336 
337  //- Number of main entries, without PointData sub-registry
338  label nFaceData() const;
339 
340  //- Number of entries on PointData sub-registry (if it exists)
341  label nPointData() const;
342 
343  //- Query the field association (FACE or POINT)
344  FieldAssociation queryFieldAssociation(const word& fieldName) const;
345 
346  //- Find the field object with the given name and required
347  //- FieldAssociation (FACE or POINT).
348  // For FACE_POINT_DATA, face data are checked first.
349  // \return nullptr is the field was not found
351  (
352  const word& fieldName,
353  const FieldAssociation association
354  ) const;
355 
356  //- General finding of the field object (FACE or POINT)
357  // Later specializations are used to restrict the scope.
358  // \return nullptr is the field was not found
359  template<class GeoMeshType = void>
360  const regIOobject* findFieldObject(const word& fieldName) const;
361 
362  //- General finding of the registry with the field object
363  //- (FACE or POINT).
364  // Later specializations are used to restrict the scope.
365  // \return nullptr is the field was not found
366  template<class GeoMeshType = void>
367  const objectRegistry* whichRegistry(const word& fieldName) const;
368 
369  //- Regular data are stored directly on the registry
370  template<class DataType>
371  inline const objectRegistry& fieldData() const
372  {
373  return static_cast<const objectRegistry&>(*this);
374  }
375 
376  //- Face data are stored directly on the registry
377  const objectRegistry& faceData() const;
378 
379  //- Point data are stored in a sub-registry
380  // Note that this method will automatically create the corresponding
381  // sub-registry if it did not previously exist.
382  // Use the nPointData() methods instead if you wish to test for
383  // content without this side-effect.
384  const objectRegistry& pointData() const;
385 
386 
387  //- Create/store named zero field as face or point data
388  //- (template parameter).
389  //
390  // - Default is face-data (polySurfaceGeoMesh as template).
391  // - For point-data use polySurfacePointGeoMesh as template.
392  //
393  // \return reference to the field
394  template<class Type, class GeoMeshType = polySurfaceGeoMesh>
396  newField
397  (
398  const word& fieldName,
399  const dimensionSet& dims
400  );
401 
402  //- Copy/store named field as face or point data (template parameter).
403  //
404  // - Default is face-data (polySurfaceGeoMesh as template).
405  // - For point-data use polySurfacePointGeoMesh as template.
406  //
407  // \return reference to the field
408  template<class Type, class GeoMeshType = polySurfaceGeoMesh>
410  storeField
411  (
412  const word& fieldName,
413  const dimensionSet& dims,
414  const Field<Type>& values
415  );
416 
417  //- Move/store named field as face or point data (template parameter).
418  //
419  // - Default is face-data (polySurfaceGeoMesh as template).
420  // - For point-data use polySurfacePointGeoMesh as template.
421  //
422  // \return reference to the field
423  template<class Type, class GeoMeshType = polySurfaceGeoMesh>
425  storeField
426  (
427  const word& fieldName,
428  const dimensionSet& dims,
430  );
431 
432 
433  // Writing
434 
435  //- Write - this is a no-op
436  virtual bool writeObject
437  (
438  IOstreamOption streamOpt,
439  const bool writeOnProc
440  ) const;
441 
442 
443  // Storage Management
444 
445  //- Clear geometry
446  void clearGeom();
447 
448  //- Clear addressing
449  void clearAddressing();
450 
451  //- Clear all geometry and addressing unnecessary for CFD
452  void clearOut();
453 
454  //- Clear primitive data (points, faces and cells)
456 
457  //- Clear stored fields
458  void clearFields();
459 };
460 
461 
462 //- Find face field object (on main registry).
463 template<>
464 const regIOobject* polySurface::findFieldObject<polySurfaceGeoMesh>
465 (
466  const word& fieldName
467 ) const;
468 
469 
470 //- Find point field object (on sub-registry)
471 template<>
472 const regIOobject* polySurface::findFieldObject<polySurfacePointGeoMesh>
473 (
474  const word& fieldName
475 ) const;
476 
477 
478 //- Return field object (on main registry).
479 //- Face data field found on main registry?
480 template<>
481 const objectRegistry* polySurface::whichRegistry<polySurfaceGeoMesh>
482 (
483  const word& fieldName
484 ) const;
485 
486 
487 //- Point data field found on sub-registry?
488 template<>
489 const objectRegistry* polySurface::whichRegistry<polySurfaceGeoMesh>
490 (
491  const word& fieldName
492 ) const;
493 
494 
495 //- Point data are stored in a sub-registry
496 template<>
497 inline const objectRegistry&
498 polySurface::fieldData<polySurfacePointGeoMesh>() const
499 {
500  return pointData();
501 }
502 
503 
504 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
505 
506 } // End namespace Foam
507 
508 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
509 
510 #ifdef NoRepository
511  #include "polySurfaceTemplates.C"
512 #endif
513 
514 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
515 
516 #endif
517 
518 // ************************************************************************* //
A surface mesh consisting of general polygon faces and capable of holding fields. ...
Definition: polySurface.H:62
Data associated with points.
Definition: polySurface.H:77
const Field< point_type > & faceAreas() const
Return face area vectors for patch.
const_iterator cend() const noexcept
Return const_iterator to end traversing the constant UList.
Definition: UListI.H:443
const vectorField & Sf() const
Return face area vectors (normals)
Definition: polySurface.H:321
TypeName("polySurface")
Runtime type information.
void clearAddressing()
Clear addressing.
const objectRegistry & fieldData() const
Regular data are stored directly on the registry.
Definition: polySurface.H:455
virtual const faceList & faces() const
Return faces.
Definition: polySurface.H:305
Data associated with faces or points.
Definition: polySurface.H:78
static bool Delete(const word &surfName, const objectRegistry &)
Remove named surface from specified registry.
Definition: polySurface.C:170
void operator=(const polySurface &)=delete
No copy assignment.
DimensionedField< Type, GeoMeshType > & storeField(const word &fieldName, const dimensionSet &dims, const Field< Type > &values)
Copy/store named field as face or point data (template parameter).
void clearGeom()
Clear geometry.
static polySurface & New(const word &surfName, const objectRegistry &)
Get or create (NO_READ, NO_WRITE) named surface on registry.
Definition: polySurface.C:152
A simple container for options an IOstream can normally have.
virtual label nPoints() const
Return the number of points.
Definition: polySurface.H:272
const vectorField & Cf() const
Face centres.
Definition: polySurface.H:337
const Field< scalar > & magFaceAreas() const
Return face area magnitudes for patch.
StringType validate(const std::string &str, const UnaryPredicate &accept, const bool invert=false)
Return a copy of the input string with validated characters.
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:43
FieldAssociation queryFieldAssociation(const word &fieldName) const
Query the field association (FACE or POINT)
Definition: polySurface.C:229
const objectRegistry & pointData() const
Point data are stored in a sub-registry.
Definition: polySurface.C:221
List< face > faceList
List of faces.
Definition: faceListFwd.H:39
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
virtual label size() const
Return number of faces.
Definition: polySurface.H:288
A list of faces which address into the list of points.
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
bool BoundaryMesh
Placeholder only, for GeoMesh.
Definition: polySurface.H:159
faceList & storedFaces()
Non-const access to the faces.
Definition: polySurface.H:125
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
void clearPrimitives()
Clear primitive data (points, faces and cells)
label nPointData() const
Number of entries on PointData sub-registry (if it exists)
Definition: polySurface.C:201
No associated data.
Definition: polySurface.H:75
A class for handling words, derived from Foam::string.
Definition: word.H:63
void clearFields()
Clear stored fields.
const Field< point_type > & faceCentres() const
Return face centres for patch.
FieldAssociation
Enumeration for the field association.
Definition: polySurface.H:73
label nFaceData() const
Number of main entries, without PointData sub-registry.
Definition: polySurface.C:189
const Field< point_type > & points() const noexcept
Return reference to global points.
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:385
polySurface(const polySurface &)=delete
No copy construct.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
const objectRegistry & faceData() const
Face data are stored directly on the registry.
Definition: polySurface.C:215
const objectRegistry * whichRegistry(const word &fieldName) const
General finding of the registry with the field object (FACE or POINT).
label size() const noexcept
The number of elements in the container.
Definition: UList.H:702
const regIOobject * findFieldObject(const word &fieldName, const FieldAssociation association) const
Find the field object with the given name and required FieldAssociation (FACE or POINT).
Definition: polySurface.C:260
Data associated with faces.
Definition: polySurface.H:76
virtual const labelList & zoneIds() const
Const access to per-face zone/region information (demand-driven)
Definition: polySurface.H:313
const scalarField & magSf() const
Return face area magnitudes.
Definition: polySurface.H:329
virtual ~polySurface()
Destructor.
Definition: polySurface.C:181
polySurface Mesh
Typedef required for GeoMesh.
Definition: polySurface.H:154
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write - this is a no-op.
Definition: polySurfaceIO.C:26
void transfer(pointField &&points, faceList &&faces, labelList &&zoneIds=labelList())
Transfer the contents (and annul the parameters). Removes existing fields.
Definition: polySurface.C:389
void copySurface(const pointField &points, const faceList &faces, bool unused=false)
Update with new contents. Removes existing fields if sizes have changed.
Definition: polySurface.C:298
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
static const word pointDataName
Name for point fields sub-registry.
Definition: polySurface.H:164
pointField & storedPoints()
Non-const access to points.
Definition: polySurface.H:117
DimensionedField< Type, GeoMeshType > & newField(const word &fieldName, const dimensionSet &dims)
Create/store named zero field as face or point data (template parameter).
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:68
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant UList.
Definition: UListI.H:399
Field< vector > vectorField
Specialisation of Field<T> for vector.
iterator end() noexcept
Return an iterator to end traversing the UList.
Definition: UListI.H:429
List< label > labelList
A List of labels.
Definition: List.H:61
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Registry of regIOobjects.
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
virtual label nFaces() const
Return the number of faces.
Definition: polySurface.H:280
virtual const pointField & points() const
Return points.
Definition: polySurface.H:297
Namespace for OpenFOAM.