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-2022 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
91  MeshReference;
92 
93 
94  // Private Data
95 
96  //- Per-face zone/region information
97  labelList zoneIds_;
98 
99 
100  // Private Member Functions
101 
102  //- Calculate per-face zone/region information
103  void calculateZoneIds(const UList<surfZone>& zones);
104 
105  //- No copy construct
106  polySurface(const polySurface&) = delete;
107 
108  //- No copy assignment
109  void operator=(const polySurface&) = delete;
110 
111 
112 protected:
113 
114  // Protected Member Functions
115 
116  //- Non-const access to points
118  {
119  return const_cast<pointField&>(MeshReference::points());
120  }
121 
122  //- Non-const access to the faces
124  {
125  return static_cast<faceList&>(static_cast<MeshReference&>(*this));
126  }
127 
128  //- Const access to the faces
129  const faceList& storedFaces() const
130  {
131  return
132  static_cast<const faceList&>
133  (
134  static_cast<const MeshReference&>(*this)
135  );
136  }
137 
138 
139 public:
140 
141  // Public Typedefs
143  //- Typedef required for GeoMesh
144  typedef polySurface Mesh;
145 
146  //- Placeholder only, for GeoMesh
147  typedef bool BoundaryMesh;
148 
149  //- Name for point fields sub-registry
150  static const word pointDataName;
151 
152 
153  //- Runtime type information
154  TypeName("polySurface");
155 
156 
157  // Constructors
158 
159  //- Construct null with NO_READ, NO_WRITE
160  //- optionally with a checkIn on the parent registry.
161  // Created without a PointData sub-registry
162  explicit polySurface(const IOobject& io, bool doCheckIn = false);
163 
164  //- Construct null with specified name on the given registry,
165  //- optionally with a checkIn on the parent registry.
166  // Created without a PointData sub-registry
168  (
169  const word& surfName,
170  const objectRegistry& obr,
171  bool doCheckIn = false
172  );
173 
174  //- Copy construct from MeshedSurface<face> contents
175  //- with NO_READ, NO_WRITE
176  //- optionally with a checkIn on the parent registry.
177  // Created without a PointData sub-registry
179  (
180  const IOobject& io,
181  const MeshedSurface<face>& surf,
182  bool doCheckIn = false
183  );
184 
185  //- Move construct from MeshedSurface<face> contents
186  //- with NO_READ, NO_WRITE
187  //- optionally with a checkIn on the parent registry.
188  // Created without a PointData sub-registry
190  (
191  const IOobject& io,
192  MeshedSurface<face>&& surf,
193  bool doCheckIn = false
194  );
195 
196 
197  //- Destructor
198  virtual ~polySurface();
199 
200 
201  // Member Functions
202 
203  // Resolve iterator ambiguity in favour of Patch (not registry)
204 
205  using MeshReference::end;
206  using MeshReference::cend;
207  using MeshReference::begin;
208  using MeshReference::cbegin;
209 
210 
211  // Access
212 
213  //- Return the number of points
214  virtual label nPoints() const
215  {
216  return MeshReference::points().size();
217  }
218 
219  //- Return the number of faces
220  virtual label nFaces() const
221  {
222  return MeshReference::size();
223  }
224 
225  //- Return number of faces
226  virtual label size() const
227  {
228  return MeshReference::size();
229  }
230 
231 
232  //- Return points
233  virtual const pointField& points() const
234  {
235  return MeshReference::points();
236  }
237 
238  //- Return faces
239  virtual const faceList& faces() const
240  {
241  return this->storedFaces();
242  }
243 
244  //- Const access to per-face zone/region information (demand-driven)
245  virtual const labelList& zoneIds() const
246  {
247  return zoneIds_;
248  }
249 
250  //- Return face area vectors (normals)
251  const vectorField& Sf() const
252  {
253  return MeshReference::faceAreas();
254  }
255 
256  //- Return face area magnitudes
257  const scalarField& magSf() const
258  {
260  }
261 
262  //- Face centres
263  const vectorField& Cf() const
264  {
266  }
268 
269  // Modification
270 
271  //- Update with new contents
272  void copySurface
273  (
274  const pointField& points,
275  const faceList& faces,
276  bool unused=false
277  );
278 
279  //- Update with new contents
280  void copySurface
281  (
282  const meshedSurf& surf,
283  bool unused=false
284  );
285 
286  //- Update with new contents
287  void copySurface
288  (
289  const MeshedSurface<face>& surf,
290  bool unused=false
291  );
293  //- Transfer the contents of the argument and annul the argument
294  // Optionally validate the zone coverage.
295  void transfer
296  (
297  pointField&& points,
298  faceList&& faces,
300  );
301 
302  //- Transfer the contents of the argument and annul the argument
303  // Optionally validate the zone coverage.
304  void transfer
305  (
306  MeshedSurface<face>& surf,
307  bool validate=false
308  );
309 
310 
311  // Fields
312 
313  //- Number of main entries, without PointData sub-registry
314  label nFaceData() const;
315 
316  //- Number of entries on PointData sub-registry (if it exists)
317  label nPointData() const;
318 
319  //- Query the field association (FACE or POINT)
320  FieldAssociation queryFieldAssociation(const word& fieldName) const;
321 
322  //- Find the field object with the given name and required
323  //- FieldAssociation (FACE or POINT).
324  // For FACE_POINT_DATA, face data are checked first.
325  // \return nullptr is the field was not found
327  (
328  const word& fieldName,
329  const FieldAssociation association
330  ) const;
331 
332  //- General finding of the field object (FACE or POINT)
333  // Later specializations are used to restrict the scope.
334  // \return nullptr is the field was not found
335  template<class GeoMeshType = void>
336  const regIOobject* findFieldObject(const word& fieldName) const;
337 
338  //- General finding of the registry with the field object
339  //- (FACE or POINT).
340  // Later specializations are used to restrict the scope.
341  // \return nullptr is the field was not found
342  template<class GeoMeshType = void>
343  const objectRegistry* whichRegistry(const word& fieldName) const;
344 
345  //- Regular data are stored directly on the registry
346  template<class DataType>
347  inline const objectRegistry& fieldData() const
348  {
349  return static_cast<const objectRegistry&>(*this);
350  }
351 
352  //- Face data are stored directly on the registry
353  const objectRegistry& faceData() const;
354 
355  //- Point data are stored in a sub-registry
356  // Note that this method with automatically create the corresponding
357  // sub-registry if it did not previously exist.
358  // Use the nPointData() methods instead if you wish to test for
359  // content without this side-effect.
360  const objectRegistry& pointData() const;
361 
362 
363  //- Copy/store named field as face or point data (template parameter).
364  //
365  // Default is face-data (polySurfaceGeoMesh as template).
366  // For point data use (polySurfacePointGeoMesh as template).
367  template<class Type, class GeoMeshType = polySurfaceGeoMesh>
368  void storeField
369  (
370  const word& fieldName,
371  const dimensionSet& dims,
372  const Field<Type>& values
373  );
374 
375  //- Move/store named field as face or point data (template parameter).
376  //
377  // Default is face-data (polySurfaceGeoMesh as template).
378  // For point data use (polySurfacePointGeoMesh as template).
379  template<class Type, class GeoMeshType = polySurfaceGeoMesh>
380  void storeField
381  (
382  const word& fieldName,
383  const dimensionSet& dims,
385  );
386 
387 
388  // Writing
389 
390  //- Write - this is a no-op
391  virtual bool writeObject
392  (
393  IOstreamOption streamOpt,
394  const bool writeOnProc
395  ) const;
396 
397 
398  // Storage Management
399 
400  //- Clear geometry
401  void clearGeom();
402 
403  //- Clear addressing
404  void clearAddressing();
405 
406  //- Clear all geometry and addressing unnecessary for CFD
407  void clearOut();
408 
409  //- Clear primitive data (points, faces and cells)
410  void clearPrimitives();
411 
412  //- Clear stored fields
413  void clearFields();
414 };
415 
416 
417 //- Find face field object (on main registry).
418 template<>
419 const regIOobject* polySurface::findFieldObject<polySurfaceGeoMesh>
420 (
421  const word& fieldName
422 ) const;
423 
424 
425 //- Find point field object (on sub-registry)
426 template<>
427 const regIOobject* polySurface::findFieldObject<polySurfacePointGeoMesh>
428 (
429  const word& fieldName
430 ) const;
431 
432 
433 //- Return field object (on main registry).
434 //- Face data field found on main registry?
435 template<>
436 const objectRegistry* polySurface::whichRegistry<polySurfaceGeoMesh>
437 (
438  const word& fieldName
439 ) const;
440 
441 
442 //- Point data field found on sub-registry?
443 template<>
444 const objectRegistry* polySurface::whichRegistry<polySurfaceGeoMesh>
445 (
446  const word& fieldName
447 ) const;
448 
449 
450 //- Point data are stored in a sub-registry
451 template<>
452 inline const objectRegistry&
453 polySurface::fieldData<polySurfacePointGeoMesh>() const
454 {
455  return pointData();
456 }
457 
458 
459 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
460 
461 } // End namespace Foam
462 
463 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
464 
465 #ifdef NoRepository
466  #include "polySurfaceTemplates.C"
467 #endif
468 
469 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
470 
471 #endif
472 
473 // ************************************************************************* //
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:449
const vectorField & Sf() const
Return face area vectors (normals)
Definition: polySurface.H:300
TypeName("polySurface")
Runtime type information.
void clearAddressing()
Clear addressing.
const objectRegistry & fieldData() const
Regular data are stored directly on the registry.
Definition: polySurface.H:429
virtual const faceList & faces() const
Return faces.
Definition: polySurface.H:284
Data associated with faces or points.
Definition: polySurface.H:78
void clearGeom()
Clear geometry.
A simple container for options an IOstream can normally have.
virtual label nPoints() const
Return the number of points.
Definition: polySurface.H:251
const vectorField & Cf() const
Face centres.
Definition: polySurface.H:316
const Field< scalar > & magFaceAreas() const
Return face area magnitudes for patch.
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:205
const objectRegistry & pointData() const
Point data are stored in a sub-registry.
Definition: polySurface.C:197
StringType validate(const std::string &str, const UnaryPredicate &accept, const bool invert=false)
Return a copy of the input string with validated characters.
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:267
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:164
faceList & storedFaces()
Non-const access to the faces.
Definition: polySurface.H:134
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:177
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:163
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:391
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:191
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:671
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:235
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:292
const scalarField & magSf() const
Return face area magnitudes.
Definition: polySurface.H:308
virtual ~polySurface()
Destructor.
Definition: polySurface.C:155
polySurface Mesh
Typedef required for GeoMesh.
Definition: polySurface.H:159
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 of the argument and annul the argument.
Definition: polySurface.C:364
void copySurface(const pointField &points, const faceList &faces, bool unused=false)
Update with new contents.
Definition: polySurface.C:273
static const word pointDataName
Name for point fields sub-registry.
Definition: polySurface.H:169
pointField & storedPoints()
Non-const access to points.
Definition: polySurface.H:126
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant UList.
Definition: UListI.H:405
iterator end() noexcept
Return an iterator to end traversing the UList.
Definition: UListI.H:435
List< label > labelList
A List of labels.
Definition: List.H:62
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.
void storeField(const word &fieldName, const dimensionSet &dims, const Field< Type > &values)
Copy/store named field as face or point data (template parameter).
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
virtual label nFaces() const
Return the number of faces.
Definition: polySurface.H:259
virtual const pointField & points() const
Return points.
Definition: polySurface.H:276
Namespace for OpenFOAM.