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-2022 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 "ensightFaces.H"
61 #include "ensightReadFile.H"
62 #include "Pair.H"
63 #include "Tuple2.H"
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 namespace Foam
68 {
69 
70 /*---------------------------------------------------------------------------*\
71  Class ensightSurfaceReader Declaration
72 \*---------------------------------------------------------------------------*/
73 
74 class ensightSurfaceReader
75 :
76  public surfaceReader
77 {
78 protected:
79 
80  // Data Types
81 
82  //- Handling of node/element id types (off, assign, ignore, given)
83  enum idTypes : unsigned char
84  {
85  NONE = 0,
86  IGNORE = 1,
87  GIVEN = 2
88  };
89 
90 
91  //- Tuple of face type (tria3, quad4, nsided) and count
93 
94 
95  // Protected Data
96 
97  //- Read on master and broadcast (in parallel)
99 
100  //- Format flag
102 
103  //- Base directory
105 
106  //- Name of mesh file, including any subdirectory
108 
109  //- Field names
111 
112  //- Field file names
115  //- Number of time steps
116  label nTimeSteps_;
117 
118  //- Start time index
120 
121  //- Time increment
122  label timeIncrement_;
123 
124  //- Times
126 
127  //- Pointer to the surface
130  //- List of face-type/count tuples
132 
133 
134  // Private Member Functions
135 
136  //- Helper function to skip forward n steps in stream
137  void skip(const label n, Istream& is) const;
138 
139  //- Helper function to read an ascii line from file
140  void readLine(ISstream& is, string& buffer) const;
141 
142  //- Read and check a section header
143  void debugSection(const word& expected, ISstream& is) const;
145  //- Replace the '*' mask chars with a 0 padded string.
146  static fileName replaceMask
147  (
148  const fileName& fName,
149  const label timeIndex
150  );
151 
152  //- Read (and discard) geometry file header.
153  // \return information about node/element id handling
155 
156  //- Read the case file
157  void readCase(ISstream& is);
158 
159  //- Read and return surface geometry. Updates faceTypeInfo_
160  meshedSurface readGeometry(const fileName& geometryFile);
161 
162  //- Helper function to return Type after skipping n tokens
163  template<class Type>
164  void readFromLine(const label nSkip, Istream& is, Type& value) const;
165 
166  //- Helper function to return Type after skipping n tokens
167  template<class Type>
168  void readFromLine
169  (
170  const label nSkip,
171  const string& buffer,
172  Type& value
173  ) const;
174 
175  //- Helper function to return a field
176  template<class Type>
178  (
179  const fileName& dataFile,
180  const word& fieldName
181  ) const;
182 
183  //- Helper function to return a field
184  template<class Type>
186  (
187  const label timeIndex,
188  const label fieldIndex
189  ) const;
190 
191 
192 public:
193 
194  //- Runtime type information
195  TypeName("ensight");
196 
197 
198  // Constructors
199 
200  //- Construct from fileName, with reader options
201  explicit ensightSurfaceReader
202  (
203  const fileName& fName,
204  const dictionary& options = dictionary()
205  );
206 
207 
208  //- Destructor
209  virtual ~ensightSurfaceReader() = default;
210 
211 
212  // Member Functions
213 
214  //- Return a reference to the surface geometry
215  virtual const meshedSurface& geometry(const label timeIndex);
216 
217  //- Return a list of the available times
218  virtual instantList times() const;
219 
220  //- Return a list of the available fields at a given time
221  virtual wordList fieldNames(const label timeIndex) const;
222 
223  //- Return a scalar field at a given time
224  virtual tmp<Field<scalar>> field
225  (
226  const label timeIndex,
227  const label fieldIndex,
228  const scalar& refValue = pTraits<scalar>::zero
229  ) const;
230 
231  //- Return a vector field at a given time
232  virtual tmp<Field<vector>> field
233  (
234  const label timeIndex,
235  const label fieldIndex,
236  const vector& refValue = pTraits<vector>::zero
237  ) const;
238 
239  //- Return a sphericalTensor field at a given time
241  (
242  const label timeIndex,
243  const label fieldIndex,
245  ) const;
246 
247  //- Return a symmTensor field at a given time
249  (
250  const label timeIndex,
251  const label fieldIndex,
252  const symmTensor& refValue = pTraits<symmTensor>::zero
253  ) const;
254 
255  //- Return a tensor field at a given time
256  virtual tmp<Field<tensor>> field
257  (
258  const label timeIndex,
259  const label fieldIndex,
260  const tensor& refValue = pTraits<tensor>::zero
261  ) const;
262 };
263 
264 
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 
267 } // End namespace Foam
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 #ifdef NoRepository
273 #endif
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 
278 #endif
279 
280 // ************************************************************************* //
Use "given" values (not supported)
virtual wordList fieldNames(const label timeIndex) const
Return a list of the available fields at a given time.
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
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.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
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.
void readLine(ISstream &is, string &buffer) const
Helper function to read an ascii line from file.
tmp< Field< Type > > readField(const fileName &dataFile, const word &fieldName) const
Helper function to return a field.
fileName meshFileName_
Name of mesh file, including any subdirectory.
TypeName("ensight")
Runtime type information.
autoPtr< meshedSurface > surfPtr_
Pointer to the surface.
void debugSection(const word &expected, ISstream &is) const
Read and check a section header.
ensightSurfaceReader(const fileName &fName, const dictionary &options=dictionary())
Construct from fileName, with reader options.
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: instant.H:46
A class for handling words, derived from Foam::string.
Definition: word.H:63
A variant of IFstream with specialised read() for strings, integers and floats. Correctly handles bin...
idTypes
Handling of node/element id types (off, assign, ignore, given)
void skip(const label n, Istream &is) const
Helper function to skip forward n steps in stream.
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.
label nTimeSteps_
Number of time steps.
virtual instantList times() const
Return a list of the available times.
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.
void readCase(ISstream &is)
Read the case file.
streamFormat
Data format (ascii | binary)
static fileName replaceMask(const fileName &fName, const label timeIndex)
Replace the &#39;*&#39; mask chars with a 0 padded string.
virtual ~ensightSurfaceReader()=default
Destructor.
label n
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
void readFromLine(const label nSkip, Istream &is, Type &value) const
Helper function to return Type after skipping n tokens.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
meshedSurface readGeometry(const fileName &geometryFile)
Read and return surface geometry. Updates faceTypeInfo_.
Tensor of scalars, i.e. Tensor<scalar>.
Namespace for OpenFOAM.
label timeIndex
Definition: getTimeIndex.H:24