ensightSurfaceReader.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) 2015-2024 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::ensightSurfaceReader
28 
29 Description
30  Ensight format surface reader
31 
32  \verbatim
33  readOptions
34  {
35  ensight
36  {
37  debug false;
38  masterOnly false;
39  }
40  }
41  \endverbatim
42 
43  Format options for ensight:
44  \table
45  Property | Description | Required | Default
46  debug | Add debug flag | no | false
47  masterOnly | Read files on master and broadcast values | no | true
48  \endtable
49 
50 SourceFiles
51  ensightSurfaceReader.C
52  ensightSurfaceReaderTemplates.C
53 
54 \*---------------------------------------------------------------------------*/
55 
56 #ifndef Foam_ensightSurfaceReader_H
57 #define Foam_ensightSurfaceReader_H
58 
59 #include "surfaceReader.H"
60 #include "ensightCase.H"
61 #include "ensightFaces.H"
62 #include "ensightReadFile.H"
63 #include "Pair.H"
64 #include "Tuple2.H"
65 
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 
68 namespace Foam
69 {
70 
71 /*---------------------------------------------------------------------------*\
72  Class ensightSurfaceReader Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 class ensightSurfaceReader
76 :
77  public surfaceReader
78 {
79 protected:
80 
81  // Data Types
82 
83  //- Handling of node/element id types (off, assign, ignore, given)
84  enum idTypes : unsigned char
85  {
86  NONE = 0,
87  IGNORE = 1,
88  GIVEN = 2
89  };
90 
91 
92  //- Tuple of face type (tria3, quad4, nsided) and count
94 
95 
96  // Protected Data
97 
98  //- Read on master and broadcast (in parallel)
101  //- Format flag
103 
104  //- Base directory
106 
107  //- The timeset/fileset (if any) associated with the mesh
109 
110  //- Name of mesh file, including any subdirectory
112 
113  //- The timeset/fileset (if any) associated with fields
116  //- Field names
118 
119  //- Field file names
121 
122  //- Start time index
123  label timeStartIndex_;
124 
125  //- Time increment
126  label timeIncrement_;
127 
128  //- Numbers for files
131  //- Times
133 
134  //- Pointer to the surface
136 
137  //- List of face-type/count tuples
139 
141  // Static Member Functions
142 
143  //- Helper function to read an ascii line from file,
144  //- skipping blank lines and comments.
145  // \return True if reading was successful
146  static bool readLine(ISstream& is, std::string& line);
147 
148  //- Check a section header
149  static void checkSection
150  (
151  const word& expected,
152  const string& buffer,
153  const ISstream& is // For errors
154  );
156  //- Read and check a section header
157  static void debugSection(const word& expected, ISstream& is);
158 
159  //- Helper function to return Type from string
160  template<class Type>
161  static void readFrom(const std::string& buffer, Type& value);
162 
163 
164  // Protected Member Functions
166  //- Read (and discard) geometry file header.
167  // \return information about node/element id handling
169 
170  //- Read the case file
171  void readCase(ISstream& is);
172 
173  //- Read and return surface geometry. Updates faceTypeInfo_
175  (
176  const fileName& geometryFile,
178  const label timeIndex = 0
179  );
181  //- Helper function to return a field
182  template<class Type>
184  (
185  const fileName& dataFile,
186  const word& fieldName,
187  const label timeIndex = 0
188  ) const;
189 
190  //- Helper function to return a field
191  template<class Type>
193  (
194  const label timeIndex,
195  const label fieldIndex
196  ) const;
197 
198 
199 public:
200 
201  // Generated Methods
202 
203  //- No copy construct
205 
206  //- No copy assignment
207  void operator=(const ensightSurfaceReader&) = delete;
208 
209 
210  //- Runtime type information
211  TypeName("ensight");
212 
213 
214  // Constructors
215 
216  //- Construct from fileName, with reader options
217  explicit ensightSurfaceReader
218  (
219  const fileName& fName,
220  const dictionary& options = dictionary()
221  );
222 
223 
224  //- Destructor
225  virtual ~ensightSurfaceReader() = default;
226 
227 
228  // Member Functions
229 
230  //- Return a reference to the surface geometry
231  virtual const meshedSurface& geometry(const label timeIndex);
232 
233  //- Return a list of the available times
234  virtual instantList times() const;
235 
236  //- Return a list of the available fields at a given time
237  virtual wordList fieldNames(const label timeIndex) const;
238 
239  //- Return a scalar field at a given time
240  virtual tmp<Field<scalar>> field
241  (
242  const label timeIndex,
243  const label fieldIndex,
244  const scalar& refValue = pTraits<scalar>::zero
245  ) const;
246 
247  //- Return a vector field at a given time
248  virtual tmp<Field<vector>> field
249  (
250  const label timeIndex,
251  const label fieldIndex,
252  const vector& refValue = pTraits<vector>::zero
253  ) const;
254 
255  //- Return a sphericalTensor field at a given time
257  (
258  const label timeIndex,
259  const label fieldIndex,
261  ) const;
262 
263  //- Return a symmTensor field at a given time
265  (
266  const label timeIndex,
267  const label fieldIndex,
268  const symmTensor& refValue = pTraits<symmTensor>::zero
269  ) const;
270 
271  //- Return a tensor field at a given time
272  virtual tmp<Field<tensor>> field
273  (
274  const label timeIndex,
275  const label fieldIndex,
276  const tensor& refValue = pTraits<tensor>::zero
277  ) const;
278 };
279 
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 } // End namespace Foam
284 
285 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286 
287 #ifdef NoRepository
289 #endif
290 
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 
293 
294 #endif
295 
296 // ************************************************************************* //
Use "given" values (not supported)
virtual wordList fieldNames(const label timeIndex) const
Return a list of the available fields at a given time.
A line primitive.
Definition: line.H:52
A class for handling file names.
Definition: fileName.H:72
fileName baseDir_
Base directory.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:54
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
static bool readLine(ISstream &is, std::string &line)
Helper function to read an ascii line from file, skipping blank lines and comments.
virtual tmp< Field< scalar > > field(const label timeIndex, const label fieldIndex, const scalar &refValue=pTraits< scalar >::zero) const
Return a scalar field at a given time.
IOstreamOption::streamFormat readFormat_
Format flag.
List< string > fieldFileNames_
Field file names.
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
bool masterOnly_
Read on master and broadcast (in parallel)
List< word > fieldNames_
Field names.
static void debugSection(const word &expected, ISstream &is)
Read and check a section header.
fileName meshFileName_
Name of mesh file, including any subdirectory.
TypeName("ensight")
Runtime type information.
static void readFrom(const std::string &buffer, Type &value)
Helper function to return Type from string.
static void checkSection(const word &expected, const string &buffer, const ISstream &is)
Check a section header.
autoPtr< meshedSurface > surfPtr_
Pointer to the surface.
A class for handling words, derived from Foam::string.
Definition: word.H:63
A variant of IFstream with specialised handling for Ensight reading of strings, integers and floats (...
Ensight format surface reader.
idTypes
Handling of node/element id types (off, assign, ignore, given)
label timeStartIndex_
Start time index.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
label timeIncrement_
Time increment.
List< labelPair > fieldTimesets_
The timeset/fileset (if any) associated with fields.
virtual instantList times() const
Return a list of the available times.
tmp< Field< Type > > readField(const fileName &dataFile, const word &fieldName, const label timeIndex=0) const
Helper function to return a field.
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:51
Tuple2< ensightFaces::elemType, label > faceInfoTuple
Tuple of face type (tria3, quad4, nsided) and count.
List< faceInfoTuple > faceTypeInfo_
List of face-type/count tuples.
virtual const meshedSurface & geometry(const label timeIndex)
Return a reference to the surface geometry.
Pair< idTypes > readGeometryHeader(ensightReadFile &is) const
Read (and discard) geometry file header.
labelList fileNumbers_
Numbers for files.
void readCase(ISstream &is)
Read the case file.
streamFormat
Data format (ascii | binary)
labelPair meshTimeset_
The timeset/fileset (if any) associated with the mesh.
virtual ~ensightSurfaceReader()=default
Destructor.
ensightSurfaceReader(const ensightSurfaceReader &)=delete
No copy construct.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Tensor of scalars, i.e. Tensor<scalar>.
void operator=(const ensightSurfaceReader &)=delete
No copy assignment.
meshedSurface readGeometry(const fileName &geometryFile, const label timeIndex=0)
Read and return surface geometry. Updates faceTypeInfo_.
Namespace for OpenFOAM.
label timeIndex
Definition: getTimeIndex.H:24