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-2021 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 SourceFiles
33  ensightSurfaceReader.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef ensightSurfaceReader_H
38 #define ensightSurfaceReader_H
39 
40 #include "surfaceReader.H"
41 #include "ensightReadFile.H"
42 #include "StringStream.H"
43 #include "Pair.H"
44 #include "Tuple2.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class ensightSurfaceReader Declaration
53 \*---------------------------------------------------------------------------*/
54 
56 :
57  public surfaceReader
58 {
59 protected:
60 
61  // Protected Data
62 
63  //- Handling of node/element id types (off, assign, ignore, given)
64  enum idTypes : unsigned char
65  {
66  NONE = 0,
67  IGNORE = 1,
68  GIVEN = 2
69  };
70 
71  //- Format flag
73 
74  //- Base directory
76 
77  //- Name of mesh file, including any subdirectory
79 
80  //- Field names
82 
83  //- Field file names
85 
86  //- Number of time steps
87  label nTimeSteps_;
88 
89  //- Start time index
90  label timeStartIndex_;
91 
92  //- Time increment
93  label timeIncrement_;
94 
95  //- Times
97 
98  //- Pointer to the surface
100 
102 
103 
104  // Protected Member Functions
105 
106  //- Helper function to skip forward n steps in stream
107  void skip(const label n, Istream& is) const;
108 
109  //- Helper function to read an ascii line from file
110  void readLine(IFstream& is, string& buffer) const;
111 
112  //- Read and check a section header
113  void debugSection(const word& expected, IFstream& is) const;
114 
115  //- Replace the '*' mask chars with a 0 padded string.
116  static fileName replaceMask
117  (
118  const fileName& fName,
119  const label timeIndex
120  );
121 
122  //- Read (and discard) geometry file header.
123  // \return information about node/element id handling
125 
126  //- Read the case file
127  void readCase(IFstream& is);
128 
129  //- Helper function to return Type after skipping n tokens
130  template<class Type>
131  void readFromLine
132  (
133  const label nSkip,
134  IStringStream& is,
135  Type& value
136  ) const;
137 
138  //- Helper function to return Type after skipping n tokens
139  template<class Type>
140  void readFromLine
141  (
142  const label nSkip,
143  const string& buffer,
144  Type& value
145  ) const;
146 
147  //- Helper function to return a field
148  template<class Type>
150  (
151  const label timeIndex,
152  const label fieldIndex
153  ) const;
154 
155 
156 public:
157 
158  //- Runtime type information
159  TypeName("ensight");
160 
161 
162  // Constructors
163 
164  //- Construct from fileName
165  explicit ensightSurfaceReader(const fileName& fName);
166 
167 
168  //- Destructor
169  virtual ~ensightSurfaceReader() = default;
170 
171 
172  // Member Functions
173 
174  //- Return a reference to the surface geometry
175  virtual const meshedSurface& geometry(const label timeIndex);
176 
177  //- Return a list of the available times
178  virtual instantList times() const;
179 
180  //- Return a list of the available fields at a given time
181  virtual wordList fieldNames(const label timeIndex) const;
182 
183  //- Return a scalar field at a given time
184  virtual tmp<Field<scalar>> field
185  (
186  const label timeIndex,
187  const label fieldIndex,
188  const scalar& refValue = pTraits<scalar>::zero
189  ) const;
190 
191  //- Return a scalar field at a given time
192  virtual tmp<Field<vector>> field
193  (
194  const label timeIndex,
195  const label fieldIndex,
196  const vector& refValue = pTraits<vector>::zero
197  ) const;
198 
199  //- Return a sphericalTensor field at a given time
201  (
202  const label timeIndex,
203  const label fieldIndex,
205  ) const;
206 
207  //- Return a symmTensor field at a given time
209  (
210  const label timeIndex,
211  const label fieldIndex,
212  const symmTensor& refValue = pTraits<symmTensor>::zero
213  ) const;
214 
215  //- Return a tensor field at a given time
216  virtual tmp<Field<tensor>> field
217  (
218  const label timeIndex,
219  const label fieldIndex,
220  const tensor& refValue = pTraits<tensor>::zero
221  ) const;
222 };
223 
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 } // End namespace Foam
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 #ifdef NoRepository
233 #endif
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 #endif
238 
239 // ************************************************************************* //
Foam::ensightSurfaceReader::meshFileName_
fileName meshFileName_
Name of mesh file, including any subdirectory.
Definition: ensightSurfaceReader.H:77
Foam::Tensor< scalar >
Foam::SymmTensor< scalar >
Foam::ensightSurfaceReader::schema_
List< Tuple2< string, label > > schema_
Definition: ensightSurfaceReader.H:100
Foam::surfaceReader
Base class for surface readers.
Definition: surfaceReader.H:53
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::ensightSurfaceReader::replaceMask
static fileName replaceMask(const fileName &fName, const label timeIndex)
Replace the '*' mask chars with a 0 padded string.
Definition: ensightSurfaceReader.C:128
Tuple2.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
ensightSurfaceReaderTemplates.C
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:53
Foam::ensightSurfaceReader::idTypes
idTypes
Handling of node/element id types (off, assign, ignore, given)
Definition: ensightSurfaceReader.H:63
Foam::ensightSurfaceReader::skip
void skip(const label n, Istream &is) const
Helper function to skip forward n steps in stream.
Definition: ensightSurfaceReader.C:64
Foam::ensightSurfaceReader::readLine
void readLine(IFstream &is, string &buffer) const
Helper function to read an ascii line from file.
Definition: ensightSurfaceReader.C:87
StringStream.H
Input/output from string buffers.
Foam::ensightSurfaceReader::readCase
void readCase(IFstream &is)
Read the case file.
Definition: ensightSurfaceReader.C:232
Pair.H
surfaceReader.H
Foam::ensightSurfaceReader::fieldNames
virtual wordList fieldNames(const label timeIndex) const
Return a list of the available fields at a given time.
Definition: ensightSurfaceReader.C:629
Foam::ensightSurfaceReader::timeStartIndex_
label timeStartIndex_
Start time index.
Definition: ensightSurfaceReader.H:89
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::ensightSurfaceReader::ensightSurfaceReader
ensightSurfaceReader(const fileName &fName)
Construct from fileName.
Definition: ensightSurfaceReader.C:342
Foam::ensightSurfaceReader::times
virtual instantList times() const
Return a list of the available times.
Definition: ensightSurfaceReader.C:622
Foam::ensightReadFile
Ensight output with specialized read() for strings, integers and floats. Correctly handles binary rea...
Definition: ensightReadFile.H:49
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::ensightSurfaceReader::~ensightSurfaceReader
virtual ~ensightSurfaceReader()=default
Destructor.
Foam::ensightSurfaceReader::baseDir_
fileName baseDir_
Base directory.
Definition: ensightSurfaceReader.H:74
Foam::ensightSurfaceReader::geometry
virtual const meshedSurface & geometry(const label timeIndex)
Return a reference to the surface geometry.
Definition: ensightSurfaceReader.C:364
Foam::ensightSurfaceReader::readGeometryHeader
Pair< idTypes > readGeometryHeader(ensightReadFile &is) const
Read (and discard) geometry file header.
Definition: ensightSurfaceReader.C:155
Foam::ensightSurfaceReader
Ensight format surface reader.
Definition: ensightSurfaceReader.H:54
Foam::ensightSurfaceReader::streamFormat_
IOstreamOption::streamFormat streamFormat_
Format flag.
Definition: ensightSurfaceReader.H:71
Foam::ensightSurfaceReader::GIVEN
Use "given" values (not supported)
Definition: ensightSurfaceReader.H:67
Foam::ensightSurfaceReader::debugSection
void debugSection(const word &expected, IFstream &is) const
Read and check a section header.
Definition: ensightSurfaceReader.C:106
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam::IStringStream
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
Definition: StringStream.H:108
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SphericalTensor< scalar >
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::ensightSurfaceReader::readFromLine
void readFromLine(const label nSkip, IStringStream &is, Type &value) const
Helper function to return Type after skipping n tokens.
Definition: ensightSurfaceReaderTemplates.C:35
Foam::ensightSurfaceReader::IGNORE
Read but "ignore".
Definition: ensightSurfaceReader.H:66
Foam::ensightSurfaceReader::NONE
"off", "assign"
Definition: ensightSurfaceReader.H:65
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:54
Foam::ensightSurfaceReader::surfPtr_
autoPtr< meshedSurface > surfPtr_
Pointer to the surface.
Definition: ensightSurfaceReader.H:98
Foam::Vector< scalar >
Foam::List< word >
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::ensightSurfaceReader::readField
tmp< Field< Type > > readField(const label timeIndex, const label fieldIndex) const
Helper function to return a field.
timeIndex
label timeIndex
Definition: getTimeIndex.H:30
ensightReadFile.H
Foam::ensightSurfaceReader::fieldFileNames_
List< string > fieldFileNames_
Field file names.
Definition: ensightSurfaceReader.H:83
Foam::ensightSurfaceReader::timeValues_
instantList timeValues_
Times.
Definition: ensightSurfaceReader.H:95
Foam::ensightSurfaceReader::field
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.
Definition: ensightSurfaceReader.C:638
Foam::MeshedSurface< face >
Foam::ensightSurfaceReader::nTimeSteps_
label nTimeSteps_
Number of time steps.
Definition: ensightSurfaceReader.H:86
Foam::ensightSurfaceReader::fieldNames_
List< word > fieldNames_
Field names.
Definition: ensightSurfaceReader.H:80
Foam::ensightSurfaceReader::TypeName
TypeName("ensight")
Runtime type information.
Foam::ensightSurfaceReader::timeIncrement_
label timeIncrement_
Time increment.
Definition: ensightSurfaceReader.H:92