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