ensightFile.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) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2016-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::ensightFile
29
30Description
31 Ensight output with specialized write() for strings, integers and floats.
32 Correctly handles binary write as well.
33
34\*---------------------------------------------------------------------------*/
35
36#ifndef Foam_ensightFile_H
37#define Foam_ensightFile_H
38
39#include "OFstream.H"
40#include "ensightFileName.H"
41#include "ensightVarName.H"
42#include "IndirectListBase.H"
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
46namespace Foam
47{
48
49/*---------------------------------------------------------------------------*\
50 Class ensightFile Declaration
51\*---------------------------------------------------------------------------*/
53class ensightFile
54:
55 public OFstream
56{
57 // Private Data
58
59 //- Allow undef in results
60 static bool allowUndef_;
61
62 //- Value to represent undef in results (default: 1e+37, floatVGREAT)
63 static scalar undefValue_;
64
65 //- The '*' mask appropriate for subDir
66 static string mask_;
67
68 //- The printf format for zero-padded subdirectory numbers
69 static string dirFmt_;
70
71
72 // Private Member Functions
73
74 //- Initialize by setting the ASCII output formatting
75 void initialize();
76
77 //- No copy construct
78 ensightFile(const ensightFile&) = delete;
79
80 //- No copy assignment
81 void operator=(const ensightFile&) = delete;
82
83
84public:
85
86 // Static Data Members
87
88 //- The keyword "coordinates"
89 static const char* const coordinates;
90
91
92 // Static Functions
93
94 //- Return a null ensightFile
95 inline static const ensightFile& null()
96 {
97 return NullObjectRef<ensightFile>();
98 }
99
100
101 // Constructors
102
103 //- Construct from pathName.
104 // The entire pathName is checked for valid ensight naming.
105 explicit ensightFile
106 (
107 const fileName& pathname,
109 );
110
111 //- Construct from path and name.
112 // Only the name portion is checked for valid ensight naming.
114 (
115 const fileName& path,
116 const fileName& name,
118 );
119
120
121 //- Destructor
122 ~ensightFile() = default;
123
124
125 // Member Functions
126
127 // Access
128
129 //- Return setting for whether 'undef' values are allowed in results
130 static bool allowUndef();
131
132 //- The '*' mask appropriate for subDir
133 static string mask();
134
135 //- Consistent zero-padded numbers for subdirectories
136 static string subDir(const label);
137
138 //- Set width of subDir and mask. Default width is 8 digits.
139 // Max width is 31 digits.
140 static void subDirWidth(const label);
141
142 //- Return current width of subDir and mask.
143 static label subDirWidth();
144
145
146 // Edit
147
148 //- Enable/disable use of \c undef keyword and value
149 static bool allowUndef(bool enabled);
150
151 //- Assign the value to represent undef in the results
152 // Returns the previous value
153 // NB: do not use values larger than floatScalarVGREAT
154 static scalar undefValue(const scalar value);
155
156
157 // Output
158
159 //- Write element keyword with trailing newline,
160 //- optionally with undef and the value for undefined
161 virtual Ostream& writeKeyword(const keyType& key);
162
163 //- Write "C Binary" string for binary files (eg, geometry/measured)
165
166 //- Write C-string as "%79s" or as binary (max 80 chars)
167 Ostream& writeString(const char* str);
168
169 //- Write string as "%79s" or as binary (max 80 chars)
170 Ostream& writeString(const std::string& str);
171
172 //- Write undef value
174
175
176 //- Writing token does not make sense
177 virtual bool write(const token&)
178 {
180 return false;
181 }
182
183 //- Writing single character does not make sense
184 virtual Ostream& write(const char)
185 {
187 return *this;
188 }
189
190 //- Binary write
191 virtual Ostream& write(const char* buf, std::streamsize count);
192
193 //- Write C-string, uses writeString()
194 virtual Ostream& write(const char* str);
195
196 //- Write word, uses writeString()
197 virtual Ostream& write(const word& str);
198
199 //- Write string, uses writeString()
200 virtual Ostream& write(const string& str);
201
202 //- Write integer as "%10d" or as binary
203 virtual Ostream& write(const int32_t val);
204
205 //- Write integer as "%10d" or as binary
206 virtual Ostream& write(const int64_t val);
207
208 //- Write integer with specified width or as binary
209 Ostream& write(const label value, const label fieldWidth);
210
211 //- Write floating-point as "%12.5e" or as binary
212 virtual Ostream& write(const floatScalar val);
213
214 //- Write floating-point as "%12.5e" or as binary
215 virtual Ostream& write(const doubleScalar val);
216
217 //- Add carriage return to ascii stream
218 void newline();
219
220
221 // Convenience Output Methods
222
223 //- Begin a part (0-based index internally).
224 void beginPart(const label index);
225
226 //- Begin a "particle coordinates" block (measured data)
227 void beginParticleCoordinates(const label nparticles);
228
229 //- Write a list of integers
230 // With carriage return after each value (ascii stream)
231 void writeLabels(const UList<label>& list);
232
233 //- Write a list of integers
234 // With carriage return after each value (ascii stream)
235 template<class Addr>
237
238 //- Write a list of integers as float values
239 // With carriage return after each value (ascii stream)
240 void writeList(const UList<label>& field);
241
242 //- Write a list of floats as "%12.5e" or as binary
243 // With carriage return after each value (ascii stream)
244 void writeList(const UList<scalar>& field);
245
246 //- Write an indirect list of scalars as "%12.5e" or as binary
247 // With carriage return after each value (ascii stream)
248 template<class Addr>
250
251
252 // Other Methods
253
254 //- Check for any NaN in the field
255 static bool isUndef(const UList<scalar>& field);
256
257 //- Check for any NaN in the field
258 template<class Addr>
259 static bool isUndef(const IndirectListBase<scalar, Addr>& field);
260};
261
262
263// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264
265} // End namespace Foam
266
267// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268
269#ifdef NoRepository
270 #include "ensightFileTemplates.C"
271#endif
272
273// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274
275#endif
276
277// ************************************************************************* //
streamFormat format() const noexcept
Get the current stream format.
streamFormat
Data format (ascii | binary)
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
Output to file stream, using an OSstream.
Definition: OFstream.H:57
virtual const fileName & name() const
Read/write access to the name of the stream.
Definition: OSstream.H:107
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:55
Ostream & writeBinaryHeader()
Write "C Binary" string for binary files (eg, geometry/measured)
Definition: ensightFile.C:339
static const char *const coordinates
The keyword "coordinates".
Definition: ensightFile.H:88
static bool isUndef(const UList< scalar > &field)
Check for any NaN in the field.
Definition: ensightFile.C:89
virtual Ostream & writeKeyword(const keyType &key)
Definition: ensightFile.C:320
virtual Ostream & write(const char)
Writing single character does not make sense.
Definition: ensightFile.H:183
void beginPart(const label index)
Begin a part (0-based index internally).
Definition: ensightFile.C:354
static bool allowUndef()
Return setting for whether 'undef' values are allowed in results.
Definition: ensightFile.C:146
static label subDirWidth()
Return current width of subDir and mask.
Definition: ensightFile.C:83
void writeList(const UList< label > &field)
Write a list of integers as float values.
Definition: ensightFile.C:382
void writeLabels(const UList< label > &list)
Write a list of integers.
Definition: ensightFile.C:372
Ostream & writeUndef()
Write undef value.
Definition: ensightFile.C:313
static const ensightFile & null()
Return a null ensightFile.
Definition: ensightFile.H:94
static scalar undefValue(const scalar value)
Assign the value to represent undef in the results.
Definition: ensightFile.C:160
static string subDir(const label)
Consistent zero-padded numbers for subdirectories.
Definition: ensightFile.C:56
virtual bool write(const token &)
Writing token does not make sense.
Definition: ensightFile.H:176
void beginParticleCoordinates(const label nparticles)
Begin a "particle coordinates" block (measured data)
Definition: ensightFile.C:363
Ostream & writeString(const char *str)
Write C-string as "%79s" or as binary (max 80 chars)
Definition: ensightFile.C:171
void newline()
Add carriage return to ascii stream.
Definition: ensightFile.C:304
static string mask()
The '*' mask appropriate for subDir.
Definition: ensightFile.C:50
~ensightFile()=default
Destructor.
A class for handling file names.
Definition: fileName.H:76
A class for handling keywords in dictionaries.
Definition: keyType.H:71
A token holds an item read from Istream.
Definition: token.H:69
A class for handling words, derived from Foam::string.
Definition: word.H:68
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
rDeltaTY field()
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
Namespace for OpenFOAM.
double doubleScalar
A typedef for double.
Definition: scalarFwd.H:48
float floatScalar
A typedef for float.
Definition: scalarFwd.H:45
runTime write()