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