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-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::ensightSurfaceReader
28
29Description
30 Ensight format surface reader
31
32SourceFiles
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
48namespace Foam
49{
50
51/*---------------------------------------------------------------------------*\
52 Class ensightSurfaceReader Declaration
53\*---------------------------------------------------------------------------*/
56:
57 public surfaceReader
58{
59protected:
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
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
156public:
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// ************************************************************************* //
Input/output from string buffers.
label n
Input from file stream, using an ISstream.
Definition: IFstream.H:57
streamFormat
Data format (ascii | binary)
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
Definition: StringStream.H:112
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:69
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Ensight output with specialized read() for strings, integers and floats. Correctly handles binary rea...
Ensight format surface reader.
void debugSection(const word &expected, IFstream &is) const
Read and check a section header.
void skip(const label n, Istream &is) const
Helper function to skip forward n steps in stream.
static fileName replaceMask(const fileName &fName, const label timeIndex)
Replace the '*' mask chars with a 0 padded string.
virtual instantList times() const
Return a list of the available times.
Pair< idTypes > readGeometryHeader(ensightReadFile &is) const
Read (and discard) geometry file header.
label timeIncrement_
Time increment.
IOstreamOption::streamFormat streamFormat_
Format flag.
idTypes
Handling of node/element id types (off, assign, ignore, given)
@ GIVEN
Use "given" values (not supported)
label nTimeSteps_
Number of time steps.
void readCase(IFstream &is)
Read the case file.
fileName baseDir_
Base directory.
List< word > fieldNames_
Field names.
autoPtr< meshedSurface > surfPtr_
Pointer to the surface.
TypeName("ensight")
Runtime type information.
void readFromLine(const label nSkip, IStringStream &is, Type &value) const
Helper function to return Type after skipping n tokens.
tmp< Field< Type > > readField(const label timeIndex, const label fieldIndex) const
Helper function to return a field.
void readLine(IFstream &is, string &buffer) const
Helper function to read an ascii line from file.
virtual const meshedSurface & geometry(const label timeIndex)
Return a reference to the surface geometry.
label timeStartIndex_
Start time index.
List< Tuple2< string, label > > schema_
virtual ~ensightSurfaceReader()=default
Destructor.
List< string > fieldFileNames_
Field file names.
fileName meshFileName_
Name of mesh file, including any subdirectory.
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:76
Base class for surface readers.
Definition: surfaceReader.H:54
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
rDeltaTY field()
Namespace for OpenFOAM.
label timeIndex
Definition: getTimeIndex.H:30
A non-counting (dummy) refCount.
Definition: refCount.H:59
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73