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  Copyright (C) 2026 Keysight Technologies
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::ensightSurfaceReader
29 
30 Description
31  Ensight format surface reader
32 
33  \verbatim
34  readOptions
35  {
36  ensight
37  {
38  debug false;
39  masterOnly true;
40  vertexOnly false;
41  }
42  }
43  \endverbatim
44 
45  Format options for ensight:
46  \table
47  Property | Description | Required | Default
48  debug | Add debug flag | no | false
49  masterOnly | Read files on master and broadcast values | no | true
50  vertexOnly | Retain 1D vertex/point elements, no faces | no | false
51  \endtable
52 
53 SourceFiles
54  ensightSurfaceReader.cxx
55  ensightSurfaceReader.txx
56 
57 \*---------------------------------------------------------------------------*/
58 
59 #ifndef Foam_ensightSurfaceReader_H
60 #define Foam_ensightSurfaceReader_H
61 
62 #include "surfaceReader.H"
63 #include "ensightCase.H"
64 #include "ensightFaces.H"
65 #include "ensightReadFile.H"
66 #include "Pair.H"
67 
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 
70 namespace Foam
71 {
72 
73 /*---------------------------------------------------------------------------*\
74  Class ensightSurfaceReader Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 class ensightSurfaceReader
78 :
79  public surfaceReader
80 {
81 protected:
82 
83  // Data Types
84 
85  //- Handling of node/element id types (off, assign, ignore, given)
86  enum idTypes : unsigned char
87  {
88  NONE = 0,
89  IGNORE = 1,
90  GIVEN = 2
91  };
92 
93 
94  // Protected Data
95 
96  //- Read on master and broadcast (in parallel)
97  bool masterOnly_;
98 
99  //- Retain 1D vertex/point elements, no faces
100  bool vertexOnly_;
101 
102  //- Format flag
104 
105  //- Base directory
108  //- The timeset/fileset (if any) associated with the mesh
110 
111  //- Name of mesh file, including any subdirectory
113 
114  //- The timeset/fileset (if any) associated with fields
117  //- Field names
119 
120  //- Field file names
122 
123  //- Start time index
124  label timeStartIndex_;
125 
126  //- Time increment
127  label timeIncrement_;
128 
129  //- Numbers for files
132  //- Times
134 
135  //- Pointer to the surface
137 
138  //- Has these 1D vertex/point elements
140 
141  //- List of (element-type, count) tuples.
142  // Element-type is typically (tria3, quad4, nsided).
143  // A negative count means a discarded (ignored) element type.
145 
147  // Static Member Functions
148 
149  //- Helper function to read an ascii line from file,
150  //- skipping blank lines and comments.
151  // \return True if reading was successful
152  static bool readLine(ISstream& is, std::string& line);
153 
154  //- Check a section header
155  static void checkSection
156  (
157  const word& expected,
158  const string& buffer,
159  const ISstream& is // For errors
160  );
162  //- Read and check a section header
163  static void debugSection(const word& expected, ISstream& is);
164 
165 
166  // Protected Member Functions
167 
168  //- Read (and discard) geometry file header.
169  // \return information about node/element id handling
172  //- Read the case file
173  void readCase(ISstream& is);
174 
175  //- Read and return surface geometry.
176  // Updates elemTypeInfo_ and vertexElements_
178  (
179  const fileName& geometryFile,
181  const label timeIndex = 0
182  );
183 
184  //- Helper function to return a field
185  template<class Type>
187  (
188  const fileName& dataFile,
189  const word& fieldName,
190  const label timeIndex = 0
191  ) const;
192 
193  //- Helper function to return a field
194  template<class Type>
196  (
197  const label timeIndex,
198  const label fieldIndex
199  ) const;
200 
201 
202 public:
203 
204  // Generated Methods
205 
206  //- No copy construct
208 
209  //- No copy assignment
210  void operator=(const ensightSurfaceReader&) = delete;
211 
212 
213  //- Runtime type information
214  TypeName("ensight");
215 
216 
217  // Constructors
218 
219  //- Construct from fileName, with reader options
220  explicit ensightSurfaceReader
221  (
222  const fileName& fName,
223  const dictionary& options = dictionary()
224  );
225 
226 
227  //- Destructor
228  virtual ~ensightSurfaceReader() = default;
229 
230 
231  // Member Functions
232 
233  //- Return a reference to the surface geometry
234  virtual const meshedSurface& geometry(const label timeIndex);
235 
236  //- The number of 1D vertex/point elements for the last geometry read.
237  //- Non-zero when the surface reader is used/misused to read
238  //- vertex/point elements instead of faces (advanced option)
239  virtual label nVertexElements() const;
240 
241  //- Return a list of the available times
242  virtual instantList times() const;
243 
244  //- Return a list of the available fields at a given time
245  virtual wordList fieldNames(const label timeIndex) const;
246 
247  //- Return a scalar field at a given time
248  virtual tmp<Field<scalar>> field
249  (
250  const label timeIndex,
251  const label fieldIndex,
252  const scalar& refValue = pTraits<scalar>::zero
253  ) const;
254 
255  //- Return a vector field at a given time
256  virtual tmp<Field<vector>> field
257  (
258  const label timeIndex,
259  const label fieldIndex,
260  const vector& refValue = pTraits<vector>::zero
261  ) const;
262 
263  //- Return a sphericalTensor field at a given time
265  (
266  const label timeIndex,
267  const label fieldIndex,
269  ) const;
270 
271  //- Return a symmTensor field at a given time
273  (
274  const label timeIndex,
275  const label fieldIndex,
276  const symmTensor& refValue = pTraits<symmTensor>::zero
277  ) const;
278 
279  //- Return a tensor field at a given time
280  virtual tmp<Field<tensor>> field
281  (
282  const label timeIndex,
283  const label fieldIndex,
284  const tensor& refValue = pTraits<tensor>::zero
285  ) const;
286 };
287 
288 
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 
291 } // End namespace Foam
292 
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 
295 #ifdef NoRepository
296  #include "ensightSurfaceReader.txx"
297 #endif
298 
299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
300 
301 
302 #endif
303 
304 // ************************************************************************* //
Use "given" values (not supported)
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:130
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
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:63
bool masterOnly_
Read on master and broadcast (in parallel)
List< word > fieldNames_
Field names.
virtual const meshedSurface & geometry(const label timeIndex)
Return a reference to the surface geometry.
static void checkSection(const word &expected, const string &buffer, const ISstream &is)
Check a section header.
static bool readLine(ISstream &is, std::string &line)
Helper function to read an ascii line from file, skipping blank lines and comments.
fileName meshFileName_
Name of mesh file, including any subdirectory.
TypeName("ensight")
Runtime type information.
autoPtr< meshedSurface > surfPtr_
Pointer to the surface.
A class for handling words, derived from Foam::string.
Definition: word.H:63
bool vertexOnly_
Retain 1D vertex/point elements, no faces.
labelList vertexElements_
Has these 1D vertex/point elements.
A variant of IFstream with specialised handling for Ensight reading of strings, integers and floats (...
Ensight format surface reader.
Pair< idTypes > readGeometryHeader(ensightReadFile &is) const
Read (and discard) geometry file header.
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.
tmp< Field< Type > > readField(const fileName &dataFile, const word &fieldName, const label timeIndex=0) const
Helper function to return a field.
virtual instantList times() const
Return a list of the available times.
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:51
virtual wordList fieldNames(const label timeIndex) const
Return a list of the available fields at a given time.
labelList fileNumbers_
Numbers for files.
void readCase(ISstream &is)
Read the case file.
streamFormat
Data format (ascii | binary | coherent)
labelPair meshTimeset_
The timeset/fileset (if any) associated with the mesh.
static void debugSection(const word &expected, ISstream &is)
Read and check a section header.
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>.
List< labelPair > elemTypeInfo_
List of (element-type, count) tuples.
meshedSurface readGeometry(const fileName &geometryFile, const label timeIndex=0)
Read and return surface geometry.
virtual label nVertexElements() const
The number of 1D vertex/point elements for the last geometry read. Non-zero when the surface reader i...
void operator=(const ensightSurfaceReader &)=delete
No copy assignment.
Namespace for OpenFOAM.
label timeIndex
Definition: getTimeIndex.H:24
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.