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 Foam_MeshedSurfaceProxy_H
44 #define Foam_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 noexcept { return faces_.size(); }
167 
168  //- Return const access to the points
169  const pointField& points() const noexcept { return points_; }
170 
171  //- Return const access to the faces
172  const UList<Face>& surfFaces() const noexcept { return faces_; }
173 
174  //- Const access to the surface zones.
175  // If zones are defined, they must be contiguous and cover the
176  // entire surface
177  const UList<surfZone>& surfZones() const noexcept { return zones_; }
178 
179  //- Const access to the faceMap, zero-sized when unused
180  const labelUList& faceMap() const noexcept { return faceMap_; }
181 
182  //- Const access to the faceIds, zero-sized when unused
183  const labelUList& faceIds() const noexcept { return faceIds_; }
184 
185  //- Can/should use faceMap?
186  bool useFaceMap() const noexcept
187  {
188  return faceMap_.size() == faces_.size();
189  }
190 
191  //- Possible to use faceIds?
192  bool useFaceIds() const noexcept
193  {
194  return faceIds_.size() == faces_.size();
195  }
196 
197  //- Count number of triangles.
198  inline label nTriangles() const;
199 
201  // Write
202 
203  //- Write to file, choosing writer based on the file extension.
204  virtual void write
205  (
206  const fileName& name,
207  IOstreamOption streamOpt = IOstreamOption(),
208  const dictionary& options = dictionary::null
209  ) const
210  {
211  write(name, *this, streamOpt, options);
212  }
213 
214  //- Write to file with given format type.
215  // If the format type is "", uses the file extension.
216  virtual void write
217  (
218  const fileName& name,
219  const word& fileType,
220  IOstreamOption streamOpt = IOstreamOption(),
221  const dictionary& options = dictionary::null
222  ) const
223  {
224  write(name, fileType, *this, streamOpt, options);
225  }
226 
227  //- Write to database
228  virtual void write
229  (
230  const Time& t,
231  const word& surfName = word::null
232  ) const;
233 };
234 
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 } // End namespace Foam
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 #ifdef NoRepository
243  #include "MeshedSurfaceProxy.C"
244 #endif
245 
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 
248 #endif
249 
250 // ************************************************************************* //
label nTriangles() const
Count number of triangles.
A class for handling file names.
Definition: fileName.H:72
ClassName("MeshedSurfaceProxy")
Declare type-name (with debug switch)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
declareMemberFunctionSelectionTable(void, MeshedSurfaceProxy, write, fileExtension,(const fileName &name, const MeshedSurfaceProxy< Face > &surf, IOstreamOption streamOpt, const dictionary &options),(name, surf, streamOpt, options))
A simple container for options an IOstream can normally have.
static bool canWriteType(const word &fileType, bool verbose=false)
Can this file format type be written via MeshedSurfaceProxy?
bool useFaceIds() const noexcept
Possible to use faceIds?
const pointField & points() const noexcept
Return const access to the points.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Face face_type
The face type.
const labelUList & faceMap() const noexcept
Const access to the faceMap, zero-sized when unused.
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
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.
label size() const noexcept
The surface size is the number of faces.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
bool useFaceMap() const noexcept
Can/should use faceMap?
A class for handling words, derived from Foam::string.
Definition: word.H:63
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:474
const UList< surfZone > & surfZones() const noexcept
Const access to the surface zones.
static const word null
An empty word.
Definition: word.H:84
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.
const direction noexcept
Definition: Scalar.H:258
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats...
Definition: MeshedSurface.H:75
static const UList< label > & null()
Return a UList reference to a nullObject.
Definition: UListI.H:90
point point_type
The point type.
Macros to ease declaration of member function selection tables.
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
const labelUList & faceIds() const noexcept
Const access to the faceIds, zero-sized when unused.
virtual ~MeshedSurfaceProxy()=default
Destructor.
Macros to ease declaration of run-time selection tables.
const UList< Face > & surfFaces() const noexcept
Return const access to the faces.
static wordHashSet writeTypes()
The file format types that can be written via MeshedSurfaceProxy.
Namespace for OpenFOAM.