MeshedSurfaceProxy.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::MeshedSurfaceProxy
29 
30 Description
31  A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh
32  to various file formats.
33 
34  The constructor interface is fat and ugly, but is largely encapsulated
35  by conversion operators in other classes.
36 
37 SourceFiles
38  MeshedSurfaceProxy.C
39  MeshedSurfaceProxys.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef MeshedSurfaceProxy_H
44 #define MeshedSurfaceProxy_H
45 
46 #include "pointField.H"
47 #include "surfZoneList.H"
48 #include "surfaceFormatsCore.H"
49 #include "runTimeSelectionTables.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // Forward Declarations
58 template<class Face> class MeshedSurface;
59 
60 /*---------------------------------------------------------------------------*\
61  Class MeshedSurfaceProxy Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 template<class Face>
65 class MeshedSurfaceProxy
66 :
67  public fileFormats::surfaceFormatsCore
68 {
69  // Private Data
70 
71  const pointField& points_;
72 
73  const UList<Face>& faces_;
74 
75  const UList<surfZone>& zones_;
76 
77  const UList<label>& faceMap_;
78 
79  const UList<label>& faceIds_;
80 
81 
82 public:
83 
84  // Public Typedefs
85 
86  //- The face type
87  typedef Face face_type;
88 
89  //- The point type
90  typedef point point_type;
91 
92 
93  //- Declare type-name (with debug switch)
94  ClassName("MeshedSurfaceProxy");
95 
96 
97  // Static Functions
98 
99  //- The file format types that can be written via MeshedSurfaceProxy
100  static wordHashSet writeTypes();
101 
102  //- Can this file format type be written via MeshedSurfaceProxy?
103  static bool canWriteType(const word& fileType, bool verbose=false);
104 
105 
106  // Constructors
107 
108  //- Construct from component references
110  (
111  const pointField& pointLst,
112  const UList<Face>& faceLst,
113  const UList<surfZone>& zoneLst = UList<surfZone>::null(),
115  const labelUList& faceIdLst = labelUList::null()
116  );
117 
118 
119  //- Destructor
120  virtual ~MeshedSurfaceProxy() = default;
121 
122 
123  // Member Function Selectors
124 
126  (
127  void,
129  write,
131  (
132  const fileName& name,
133  const MeshedSurfaceProxy<Face>& surf,
134  IOstreamOption streamOpt,
135  const dictionary& options
136  ),
137  (name, surf, streamOpt, options)
138  );
139 
140  //- Write to file, select based on its extension
141  static void write
142  (
143  const fileName& name,
144  const MeshedSurfaceProxy& surf,
145  IOstreamOption streamOpt = IOstreamOption(),
146  const dictionary& options = dictionary::null
147  );
148 
149  //- Write to file with given format type.
150  // If the format type is "", uses the file extension.
151  static void write
152  (
153  const fileName& name,
154  const word& fileType,
155  const MeshedSurfaceProxy& surf,
156  IOstreamOption streamOpt = IOstreamOption(),
157  const dictionary& options = dictionary::null
158  );
159 
160 
161  // Member Functions
162 
163  // Access
164 
165  //- The surface size is the number of faces
166  label size() const
167  {
168  return faces_.size();
169  }
170 
171  //- Return const access to the points
172  const pointField& points() const
173  {
174  return points_;
175  }
176 
177  //- Return const access to the faces
178  const UList<Face>& surfFaces() const
179  {
180  return faces_;
181  }
182 
183  //- Const access to the surface zones.
184  // If zones are defined, they must be contiguous and cover the
185  // entire surface
186  const UList<surfZone>& surfZones() const
187  {
188  return zones_;
189  }
190 
191  //- Const access to the faceMap, zero-sized when unused
192  const labelUList& faceMap() const
193  {
194  return faceMap_;
195  }
196 
197  //- Const access to the faceIds, zero-sized when unused
198  const labelUList& faceIds() const
199  {
200  return faceIds_;
201  }
202 
203  //- Can/should use faceMap?
204  bool useFaceMap() const
205  {
206  return faceMap_.size() == faces_.size();
207  }
208 
209  //- Possible to use faceIds?
210  bool useFaceIds() const
211  {
212  return faceIds_.size() == faces_.size();
213  }
214 
215  //- Count number of triangles.
216  inline label nTriangles() const;
217 
218 
219  // Write
220 
221  //- Write to file, choosing writer based on the file extension.
222  virtual void write
223  (
224  const fileName& name,
225  IOstreamOption streamOpt = IOstreamOption(),
226  const dictionary& options = dictionary::null
227  ) const
228  {
229  write(name, *this, streamOpt, options);
230  }
231 
232  //- Write to file with given format type.
233  // If the format type is "", uses the file extension.
234  virtual void write
235  (
236  const fileName& name,
237  const word& fileType,
238  IOstreamOption streamOpt = IOstreamOption(),
239  const dictionary& options = dictionary::null
240  ) const
241  {
242  write(name, fileType, *this, streamOpt, options);
243  }
244 
245  //- Write to database
246  virtual void write
247  (
248  const Time& t,
249  const word& surfName = word::null
250  ) const;
251 };
252 
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 } // End namespace Foam
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 #ifdef NoRepository
261  #include "MeshedSurfaceProxy.C"
262 #endif
263 
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 
266 #endif
267 
268 // ************************************************************************* //
Foam::MeshedSurfaceProxy::ClassName
ClassName("MeshedSurfaceProxy")
Declare type-name (with debug switch)
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::MeshedSurfaceProxy::MeshedSurfaceProxy
MeshedSurfaceProxy(const pointField &pointLst, const UList< Face > &faceLst, const UList< surfZone > &zoneLst=UList< surfZone >::null(), const labelUList &faceMap=labelUList::null(), const labelUList &faceIdLst=labelUList::null())
Construct from component references.
Definition: MeshedSurfaceProxy.C:237
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::MeshedSurfaceProxy::useFaceMap
bool useFaceMap() const
Can/should use faceMap?
Definition: MeshedSurfaceProxy.H:203
MeshedSurfaceProxy.C
Foam::MeshedSurfaceProxy::nTriangles
label nTriangles() const
Count number of triangles.
Definition: MeshedSurfaceProxy.C:256
Foam::vtk::fileExtension
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
Foam::MeshedSurfaceProxy::size
label size() const
The surface size is the number of faces.
Definition: MeshedSurfaceProxy.H:165
Foam::MeshedSurfaceProxy::point_type
point point_type
The point type.
Definition: MeshedSurfaceProxy.H:89
Foam::MeshedSurfaceProxy::points
const pointField & points() const
Return const access to the points.
Definition: MeshedSurfaceProxy.H:171
Foam::MeshedSurfaceProxy::write
static void write(const fileName &name, const MeshedSurfaceProxy &surf, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null)
Write to file, select based on its extension.
Definition: MeshedSurfaceProxy.C:64
Foam::MeshedSurfaceProxy::~MeshedSurfaceProxy
virtual ~MeshedSurfaceProxy()=default
Destructor.
Foam::MeshedSurfaceProxy::useFaceIds
bool useFaceIds() const
Possible to use faceIds?
Definition: MeshedSurfaceProxy.H:209
Foam::HashSet< word, Hash< word > >
Foam::MeshedSurfaceProxy
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
Definition: MeshedSurface.H:82
Foam::MeshedSurfaceProxy::faceMap
const labelUList & faceMap() const
Const access to the faceMap, zero-sized when unused.
Definition: MeshedSurfaceProxy.H:191
Foam::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:392
Foam::Field< vector >
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::MeshedSurfaceProxy::declareMemberFunctionSelectionTable
declareMemberFunctionSelectionTable(void, MeshedSurfaceProxy, write, fileExtension,(const fileName &name, const MeshedSurfaceProxy< Face > &surf, IOstreamOption streamOpt, const dictionary &options),(name, surf, streamOpt, options))
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
pointField.H
Foam::MeshedSurfaceProxy::faceIds
const labelUList & faceIds() const
Const access to the faceIds, zero-sized when unused.
Definition: MeshedSurfaceProxy.H:197
Foam::MeshedSurfaceProxy::writeTypes
static wordHashSet writeTypes()
The file format types that can be written via MeshedSurfaceProxy.
Definition: MeshedSurfaceProxy.C:39
Foam::MeshedSurfaceProxy::face_type
Face face_type
The face type.
Definition: MeshedSurfaceProxy.H:86
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::Vector< scalar >
Foam::UList< Face >
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
surfZoneList.H
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
memberFunctionSelectionTables.H
Macros to ease declaration of member function selection tables.
Foam::MeshedSurfaceProxy::surfFaces
const UList< Face > & surfFaces() const
Return const access to the faces.
Definition: MeshedSurfaceProxy.H:177
Foam::UList::null
static const UList< T > & null()
Return a UList reference to a nullObject.
Definition: UListI.H:53
surfaceFormatsCore.H
Foam::MeshedSurfaceProxy::canWriteType
static bool canWriteType(const word &fileType, bool verbose=false)
Can this file format type be written via MeshedSurfaceProxy?
Definition: MeshedSurfaceProxy.C:47
Foam::MeshedSurfaceProxy::surfZones
const UList< surfZone > & surfZones() const
Const access to the surface zones.
Definition: MeshedSurfaceProxy.H:185