surfMesh.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-2016 OpenFOAM Foundation
9  Copyright (C) 2016-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::surfMesh
29 
30 Description
31  A surface mesh consisting of general polygon faces that has
32  IO capabilities and a registry for storing fields.
33 
34 Note
35  In many places the Foam::polySurface class may be more flexible.
36 
37 SourceFiles
38  surfMesh.C
39  surfMeshClear.C
40  surfMeshIO.C
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef Foam_surfMesh_H
45 #define Foam_surfMesh_H
46 
47 #include "surfaceRegistry.H"
49 #include "primitivePatch.H"
50 #include "surfZoneIOList.H"
51 #include "surfFieldsFwd.H"
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 // Forward Declarations
59 class dimensionSet;
60 class meshedSurf;
61 template<class Face> class MeshedSurface;
62 
63 /*---------------------------------------------------------------------------*\
64  Class surfMesh Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class surfMesh
68 :
69  public surfaceRegistry,
71  public PrimitivePatch<::Foam::UList<face>, const pointField&>
72 {
73 public:
74 
75  // Public Data Types
76 
77  //- Enumeration defining the state of the mesh after a read update.
78  // Used for post-processing applications, where the mesh
79  // needs to update based on the files written in time directories
81  {
86  };
87 
88 
89 private:
90 
91  // Private Typedefs
92 
93  //- Memory and IO management
94  typedef
96  Allocator;
97 
98  //- Internal mesh storage type
99  typedef
101  MeshReference;
102 
103 
104  // Private Data
105 
106  //- The surface zones
107  surfZoneIOList surfZones_;
108 
109 
110 protected:
111 
112  // Protected Member Functions
113 
114  //- Non-const access to global points
116  {
117  return Allocator::storedIOPoints();
118  }
119 
120  //- Non-const access to the faces
122  {
123  return Allocator::storedIOFaces();
124  }
125 
126  //- Non-const access to the surface zones
128  {
129  return surfZones_;
130  }
131 
132  //- Update point/face references
133  void updateRefs();
134 
135 
136 public:
138  // Public Typedefs
139 
140  //- Typedef required for GeoMesh
141  typedef surfMesh Mesh;
142 
143  //- Placeholder only, but do not remove - it is needed for GeoMesh
144  typedef bool BoundaryMesh;
145 
146 
147  //- Declare type-name, virtual type (with debug switch)
148  TypeName("surfMesh");
149 
150  //- Return the mesh sub-directory name (normally "surfMesh")
151  static word meshSubDir;
152 
153 
154  // Generated Methods
156  //- No copy construct
157  surfMesh(const surfMesh&) = delete;
158 
159  //- No copy assignment
160  void operator=(const surfMesh&) = delete;
161 
162 
163  // Constructors
164 
165  //- Read construct from IOobject.
166  // Writing = NO_WRITE
167  explicit surfMesh(const IOobject& io);
168 
169  //- Read construct from IOobject, with alternative surface name
170  // Writing = NO_WRITE
171  surfMesh(const IOobject& io, const word& surfName);
172 
173  //- Construct empty with specified name on the given registry.
174  surfMesh(const word& surfName, const objectRegistry& obr);
175 
176  //- Copy construct from MeshedSurface<face>
177  surfMesh
178  (
179  const IOobject& io,
180  const MeshedSurface<face>& surf,
181  const word& surfName = word::null
182  );
183 
184  //- Move construct from MeshedSurface<face>
185  surfMesh
186  (
187  const IOobject& io,
188  MeshedSurface<face>&& surf,
189  const word& surfName = word::null
190  );
191 
192 
193  //- Destructor
194  virtual ~surfMesh();
195 
196 
197  // Member Functions
198 
199  // Database
200 
201  //- Return the local mesh directory (dbDir()/meshSubDir)
202  fileName meshDir() const;
203 
204  //- Return the current instance directory for points
205  // Used when constructing geometric mesh data dependent on points
206  const fileName& pointsInstance() const;
207 
208  //- Return the current instance directory for faces
209  const fileName& facesInstance() const;
210 
211  //- Set the instance for mesh files
212  void setInstance
213  (
214  const fileName& inst,
216  );
217 
218  //- Adjust the write option for all components
220 
221 
222  // Access
223 
224  //- Return the number of raw points
225  virtual label nPoints() const;
226 
227  //- Return the number of raw faces
228  virtual label nFaces() const;
229 
230  //- Return number of faces
231  virtual label size() const
232  {
233  return nFaces();
234  }
235 
236 
237  //- Return points
238  virtual const pointField& points() const;
239 
240  //- Return faces
241  virtual const faceList& faces() const;
242 
243  //- Return surface zones
244  virtual const surfZoneList& surfZones() const
245  {
246  return surfZones_;
247  }
248 
249  //- Return face area vectors (normals)
250  const vectorField& Sf() const
251  {
252  return MeshReference::faceAreas();
253  }
254 
255  //- Return face area magnitudes
256  const scalarField& magSf() const
257  {
259  }
260 
261  //- Face centres
262  const vectorField& Cf() const
263  {
265  }
266 
267 
268  // Zones
269 
270  //- Add surface zones, optionally validating the zone coverage
271  void addZones
272  (
273  const surfZoneList& zones,
274  bool validate = true
275  );
276 
277  //- Remove surface zones
278  void removeZones();
279 
280  //- Check the surface zone definitions
281  void checkZones(const bool verbose=true);
282 
283 
284  // Modification
285 
286  //- Update with new contents
287  void copySurface
288  (
289  const pointField& points,
290  const faceList& faces,
291  bool validate=false
292  );
293 
294  //- Update with new contents
295  void copySurface
296  (
297  const meshedSurf& surf,
298  bool validate=false
299  );
300 
301  //- Update with new contents
302  void copySurface
303  (
304  const MeshedSurface<face>& surf,
305  bool validate=false
306  );
307 
308  //- Transfer the contents of the argument and annul the argument
309  // Optionally validate the zone coverage.
310  void transfer
311  (
312  MeshedSurface<face>& surf,
313  bool validate=false
314  );
315 
316  //- Update mesh based on the files saved in time directories
317  virtual readUpdateState readUpdate();
318 
319 
320  // Fields
322  //- Create/store named zero field as face or point data
323  //- (template parameter).
324  //
325  // - Default is face-data (surfGeoMesh as template).
326  // - For point-data use surfPointGeoMesh as template.
327  //
328  // \return reference to the field
329  template<class Type, class GeoMeshType = surfGeoMesh>
331  newField
332  (
333  const word& fieldName,
334  const dimensionSet& dims
335  );
336 
337  //- Copy/store named field as face or point data (template parameter).
338  //
339  // - Default is face-data (surfGeoMesh as template).
340  // - For point-data use surfPointGeoMesh as template.
341  //
342  // \return reference to the field
343  template<class Type, class GeoMeshType = surfGeoMesh>
345  storeField
346  (
347  const word& fieldName,
348  const dimensionSet& dims,
349  const Field<Type>& values
350  );
351 
352  //- Move/store named field as face or point data (template parameter).
353  //
354  // - Default is face-data (surfGeoMesh as template).
355  // - For point-data use surfPointGeoMesh as template.
356  //
357  // \return reference to the field
358  template<class Type, class GeoMeshType = surfGeoMesh>
360  storeField
361  (
362  const word& fieldName,
363  const dimensionSet& dims,
365  );
366 
367 
368  // Writing
369 
370  //- Avoid masking the normal objectRegistry write
372 
373  //- Write all components using given format, version and compression
374  virtual bool writeObject
375  (
376  IOstreamOption streamOpt,
377  const bool writeOnProc
378  ) const;
379 
380 
381  //- Write to file, choosing writer based on its extension.
382  // Uses MeshedSurfaceProxy for writing.
383  void write
384  (
385  const fileName& name,
386  IOstreamOption streamOpt = IOstreamOption(),
387  const dictionary& options = dictionary::null
388  ) const;
389 
390  //- Write to file, choosing writer for given fileType.
391  // Uses MeshedSurfaceProxy for writing.
392  void write
393  (
394  const fileName& name,
395  const word& fileType,
396  IOstreamOption streamOpt = IOstreamOption(),
397  const dictionary& options = dictionary::null
398  ) const;
399 
400 
401  // Storage Management
402 
403  //- Release the geometry and return as a MeshedSurface<face>.
405 
406  //- Clear geometry
407  void clearGeom();
408 
409  //- Clear addressing
410  void clearAddressing();
411 
412  //- Clear all geometry and addressing unnecessary for CFD
413  void clearOut();
414 
415  //- Clear primitive data (points, faces and cells)
416  void clearPrimitives();
417 
418  //- Clear stored fields
419  void clearFields();
420 
421  //- Remove all files from mesh instance
422  void removeFiles(const fileName& instanceDir) const;
423 
424  //- Remove all files from mesh instance()
425  void removeFiles() const;
426 };
427 
428 
429 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
430 
431 } // End namespace Foam
432 
433 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
434 
435 #ifdef NoRepository
436  #include "surfMeshTemplates.C"
437 #endif
438 
439 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
440 
441 #endif
442 
443 // ************************************************************************* //
bool BoundaryMesh
Placeholder only, but do not remove - it is needed for GeoMesh.
Definition: surfMesh.H:160
void updateRefs()
Update point/face references.
Definition: surfMesh.C:63
const Field< point_type > & faceAreas() const
Return face area vectors for patch.
writeOption
Enumeration defining write preferences.
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: surfMesh.C:431
virtual label size() const
Return number of faces.
Definition: surfMesh.H:286
A class for handling file names.
Definition: fileName.H:72
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: surfMesh.H:78
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
surfZoneList & storedZones()
Non-const access to the surface zones.
Definition: surfMesh.H:137
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
DimensionedField< Type, GeoMeshType > & newField(const word &fieldName, const dimensionSet &dims)
Create/store named zero field as face or point data (template parameter).
void write(const fileName &name, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null) const
Write to file, choosing writer based on its extension.
Definition: surfMesh.C:560
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: surfMesh.C:425
const vectorField & Sf() const
Return face area vectors (normals)
Definition: surfMesh.H:313
void clearFields()
Clear stored fields.
Definition: surfMeshClear.C:65
faceList & storedFaces()
Non-const access to the faces.
Definition: surfMesh.H:129
void clearGeom()
Clear geometry.
Definition: surfMeshClear.C:40
surfMesh(const surfMesh &)=delete
No copy construct.
A simple container for options an IOstream can normally have.
void addZones(const surfZoneList &zones, bool validate=true)
Add surface zones, optionally validating the zone coverage.
Definition: surfMesh.C:523
const Field< scalar > & magFaceAreas() const
Return face area magnitudes for patch.
virtual readUpdateState readUpdate()
Update mesh based on the files saved in time directories.
Definition: surfMeshIO.C:51
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
Wraps the normal objectRegistry with a local instance for surfaces.
faceCompactIOList & storedIOFaces() noexcept
Non-const access to the faces.
void clearPrimitives()
Clear primitive data (points, faces and cells)
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 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
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh")
Definition: surfMesh.H:171
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
pointIOField & storedIOPoints() noexcept
Non-const access to the points.
virtual const faceList & faces() const
Return faces.
Definition: surfMesh.C:455
const Field< point_type > & faceCentres() const
Return face centres for patch.
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:486
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
static const word null
An empty word.
Definition: word.H:84
void transfer(MeshedSurface< face > &surf, bool validate=false)
Transfer the contents of the argument and annul the argument.
Definition: surfMesh.C:379
void removeZones()
Remove surface zones.
Definition: surfMeshClear.C:27
virtual label nPoints() const
Return the number of raw points.
Definition: surfMesh.C:437
IOobject for a surfZoneList.
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
Definition: surfMeshClear.C:56
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).
const scalarField & magSf() const
Return face area magnitudes.
Definition: surfMesh.H:321
A surface mesh consisting of general polygon faces that has IO capabilities and a registry for storin...
Definition: surfMesh.H:62
void checkZones(const bool verbose=true)
Check the surface zone definitions.
Definition: surfMesh.C:461
void removeFiles() const
Remove all files from mesh instance()
Definition: surfMesh.C:553
surfMesh Mesh
Typedef required for GeoMesh.
Definition: surfMesh.H:155
void operator=(const surfMesh &)=delete
No copy assignment.
void setInstance(const fileName &inst, IOobjectOption::writeOption wOpt=IOobjectOption::AUTO_WRITE)
Set the instance for mesh files.
Definition: surfMeshIO.C:28
virtual const surfZoneList & surfZones() const
Return surface zones.
Definition: surfMesh.H:305
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write all components using given format, version and compression.
Definition: surfMeshIO.C:188
List< surfZone > surfZoneList
List of surfZone.
Definition: surfZoneList.H:32
Automatically write from objectRegistry::writeObject()
pointField & storedPoints()
Non-const access to global points.
Definition: surfMesh.H:121
Field< vector > vectorField
Specialisation of Field<T> for vector.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual label nFaces() const
Return the number of raw faces.
Definition: surfMesh.C:443
virtual const pointField & points() const
Return points.
Definition: surfMesh.C:449
TypeName("surfMesh")
Declare type-name, virtual type (with debug switch)
virtual ~surfMesh()
Destructor.
Definition: surfMesh.C:282
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Registry of regIOobjects.
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: surfMesh.C:419
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
autoPtr< MeshedSurface< face > > releaseGeom()
Release the geometry and return as a MeshedSurface<face>.
Definition: surfMesh.C:400
A helper class for storing points and faces with IO capabilities.
const vectorField & Cf() const
Face centres.
Definition: surfMesh.H:329
void clearAddressing()
Clear addressing.
Definition: surfMeshClear.C:48
Namespace for OpenFOAM.
void setWriteOption(IOobjectOption::writeOption wOpt)
Adjust the write option for all components.
Definition: surfMeshIO.C:43
void copySurface(const pointField &points, const faceList &faces, bool validate=false)
Update with new contents.
Definition: surfMesh.C:291