ensightCase.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) 2016-2022 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::ensightCase
28
29Description
30 Supports writing of ensight cases as well as providing common factory
31 methods to open new files.
32
33SourceFiles
34 ensightCase.C
35 ensightCaseI.H
36 ensightCaseOptions.C
37 ensightCaseTemplates.C
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef Foam_ensightCase_H
42#define Foam_ensightCase_H
43
44#include "autoPtr.H"
45#include "HashSet.H"
46#include "InfoProxy.H"
47#include "Map.H"
48#include "HashSet.H"
49#include "Pstream.H"
50#include "ensightGeoFile.H"
51#include <memory>
52
53// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54
55namespace Foam
56{
57
58// Forward Declarations
59class bitSet;
60class ensightCase;
61class instant;
62class OSstream;
63class Time;
64
65/*---------------------------------------------------------------------------*\
66 Class ensightCase Declaration
67\*---------------------------------------------------------------------------*/
69class ensightCase
70{
71public:
72
73 // Forward Declarations
74 class options;
75
76 // Public Data
77
78 //- The name for data subdirectory: "data"
79 static const char* dataDirName;
80
81 //- The name for geometry files: "geometry"
82 static const char* geometryName;
83
84
85private:
86
87 // Private Data
88
89 //- Case writing options
90 const std::unique_ptr<options> options_;
91
92 //- Output stream (master only)
93 mutable std::unique_ptr<OFstream> os_;
94
95 //- Output path (absolute)
96 fileName ensightDir_;
97
98 //- Case name (with ".case" ending)
99 word caseName_;
100
101 //- Track state changes since last write
102 mutable bool changed_;
103
104 //- Time index (timeset 1)
105 label timeIndex_;
106
107 //- Time value (timeset 1)
108 scalar timeValue_;
109
110 //- Record of time index/value used (eg, field values).
111 // These values will be used for timeset 1.
112 Map<scalar> timesUsed_;
113
114 //- Record time indices when geometry is written.
115 // These values will be used to decide if timeset 1
116 // or a separate timeset are used.
117 // The special index '-1' is used for static geometry.
118 mutable labelHashSet geomTimes_;
119
120 //- Record time indices when clouds are written.
121 // These values will be used to decide if timeset 1
122 // or a separate timeset are used.
123 mutable labelHashSet cloudTimes_;
124
125 //- Fields/Variables with the ensight type
126 mutable HashTable<string> variables_;
127
128 //- Remember fields that are to be treated as point data
129 mutable HashSet<string> nodeVariables_;
130
131 //- Cloud names and variables
132 mutable HashTable<HashTable<string>> cloudVars_;
133
134
135 // Private Member Functions
136
137 //- The data directory
138 fileName dataDir() const;
139
140 //- Initial file management (master only)
141 void initialize();
142
143 //- Check if timeset uses different times than from time-set 1
144 label checkTimeset(const labelHashSet& lookup) const;
145
146 //- Write the header into the case file.
147 void writeHeader() const;
148
149 //- Write the timeset 1 into the case file.
150 // Return the time correction in effect
151 scalar writeTimeset() const;
152
153 //- Write the timeset into the case file.
154 void writeTimeset
155 (
156 const label ts,
157 const labelHashSet& lookup,
158 const scalar timeCorrection = 0
159 ) const;
160
161
162 //- Note the geometry being used
163 void noteGeometry(const bool moving) const;
164
165 //- Note the cloud being used
166 void noteCloud(const word& cloudName) const;
167
168 //- Note the cloud/variable being used
169 void noteCloud
170 (
171 const word& cloudName,
172 const word& varName,
173 const char* ensightType
174 ) const;
175
176 //- Note the field variable being used
177 void noteVariable
178 (
179 const word& varName,
180 const char* ensightType
181 ) const;
182
183
184 //- Open stream for new data file (on master), using the current index.
185 // File is without initial description lines.
186 autoPtr<ensightFile> createDataFile(const word& name) const;
187
188 //- Open stream for new cloud file (on master).
189 // File is without initial description lines.
190 autoPtr<ensightFile> createCloudFile
191 (
192 const word& cloudName,
193 const word& name
194 ) const;
195
196
197 //- No copy construct
198 ensightCase(const ensightCase&) = delete;
199
200 //- No copy assignment
201 void operator=(const ensightCase&) = delete;
202
203
204public:
205
206 // Constructors
207
208 //- Construct from components
210 (
211 const fileName& ensightDir,
212 const word& caseName,
213 const options& opts
214 );
215
216 //- Construct from components with all default options
218 (
219 const fileName& ensightDir,
220 const word& caseName,
222 );
223
224
225 //- Destructor
226 ~ensightCase() = default;
227
228
229 // Member Functions
230
231 // Access
232
233 //- Reference to the case options
234 inline const ensightCase::options& option() const;
235
236 //- The output file format (ascii/binary)
238
239 //- The nominal path to the case file
240 inline const fileName& path() const noexcept;
241
242 //- The output '*' mask
243 inline const word& mask() const;
244
245 //- Consistent zero-padded integer value
246 inline word padded(const label i) const;
247
248 //- Force use of values per node instead of per element
249 inline bool nodeValues() const;
250
251 //- Write clouds into their own directory instead in "data" directory
252 inline bool separateCloud() const;
253
254
255 // Edit
256
257 //- Set time for time-set 1, using next available index.
258 // Create corresponding sub-directory.
259 // Do not mix between nextTime and setTime in an application.
260 void nextTime(const scalar t);
261
262 //- Set time for time-set 1, using next available index.
263 // Create corresponding sub-directory.
264 // Do not mix between nextTime and setTime in an application.
265 void nextTime(const instant& t);
266
267 //- Set current index and time for time-set 1.
268 // Create corresponding sub-directory
269 // \note do not mix between nextTime and setTime in an application.
270 void setTime(const scalar t, const label index);
271
272 //- Set current index and time for time-set 1.
273 // Create corresponding sub-directory
274 // \note do not mix between nextTime and setTime in an application.
275 void setTime(const instant& t, const label index);
276
277
278 // Addition of entries to case file
279
280 //- Open stream for new geometry file (on master).
281 autoPtr<ensightGeoFile> newGeometry(bool moving = false) const;
282
283 //- Open stream for new cloud positions (on master).
284 // Note the use of ensightFile, not ensightGeoFile.
286 (
287 const word& cloudName
288 ) const;
289
290 //- Open stream for new data file (on master), with current index.
291 // Optionally marking as containing POINT_DATA
292 template<class Type>
294 (
295 const word& varName,
296 const bool isPointData = false
297 ) const;
298
299 //- Open stream for new data file (on master), with current index
300 //- and marking as containing POINT_DATA
301 template<class Type>
302 autoPtr<ensightFile> newPointData(const word& varName) const;
303
304 //- Open stream for new cloud data file (on master), with current index.
305 template<class Type>
307 (
308 const word& cloudName,
309 const word& varName
310 ) const;
311
312
313 // Output
314
315 //- Rewind the output stream (master only).
316 void rewind() const;
317
318 //- Write the case file
319 void write() const;
320
321 //- Output stream (master only).
322 inline Ostream& operator()() const;
323
324 //- Print some general information.
325 Ostream& printInfo(Ostream& os) const;
326
327
328 // Output Helpers
329
330 //- Print time-set for ensight case file with a single time
331 static void printTimeset
332 (
333 OSstream& os,
334 const label ts,
335 const scalar timeValue
336 );
337
338 //- Print time-set for ensight case file, with N times and 0-based
339 //- file numbering
340 //
341 // \verbatim
342 // TIME
343 // time set: ts
344 // number of steps: ns
345 // filename start number: 0
346 // filename increment: 1
347 // time values: time_1 time_2 ... time_ns
348 // \endverbatim
349 static void printTimeset
350 (
351 OSstream& os,
352 const label ts,
353 const UList<scalar>& times
354 );
355
356 //- Print time-set for ensight case file, with N times, 0-based
357 //- file numbering but perhaps non-contiguous
358 //
359 // \verbatim
360 // TIME
361 // time set: ts
362 // number of steps: ns
363 // filename numbers: idx_1 idx_2 ... idx_ns
364 // time values: time_1 time_2 ... time_ns
365 // \endverbatim
366 static void printTimeset
367 (
368 OSstream& os,
369 const label ts,
370 const UList<scalar>& times,
371 const bitSet& indices
372 );
373};
374
375
376/*---------------------------------------------------------------------------*\
377 Class ensightCase::options Declaration
378\*---------------------------------------------------------------------------*/
379
380//- Configuration options for the ensightCase
381class ensightCase::options
382{
383 // Private Data
384
385 //- Ascii/Binary file output
387
388 //- Remove existing directory and sub-directories on creation
389 bool overwrite_;
390
391 //- Force use of values per node instead of per element
392 bool nodeValues_;
393
394 //- Write clouds into their own directory
395 bool separateCloud_;
396
397 //- Width of mask for subdirectories
398 label width_;
399
400 //- The '*' mask appropriate for subdirectories
401 word mask_;
402
403 //- The printf format for zero-padded subdirectory numbers
404 string printf_;
405
406
407public:
408
409 // Constructors
410
411 //- Construct with the specified format (default is binary)
413
414
415 // Member Functions
416
417 // Access
418
419 //- Ascii/Binary file output
420 IOstreamOption::streamFormat format() const noexcept { return format_; }
421
422 //- The '*' mask appropriate for sub-directories
423 const word& mask() const noexcept { return mask_; }
424
425 //- Consistent zero-padded integer value
426 word padded(const label i) const;
427
428 //- Return current width of mask and padded.
429 label width() const noexcept { return width_; }
430
431 //- Remove existing directory and sub-directories on creation
432 bool overwrite() const noexcept { return overwrite_; }
433
434 //- Write clouds into their own directory instead in "data" directory
435 bool separateCloud() const noexcept { return separateCloud_; }
436
437
438 // Edit
439
440 //- Set width of mask and padded.
441 // Default width is 8 digits, max width is 31 digits.
442 void width(const label i);
443
444 //- Remove existing directory and sub-directories on creation
445 void overwrite(bool on) noexcept { overwrite_ = on; }
446
447 //- Write clouds into their own directory instead in "data" directory
448 void separateCloud(bool on) noexcept { separateCloud_ = on; }
449
450
451 // Housekeeping
452
453 //- Forced use of values per node instead of per element
454 bool nodeValues() const noexcept { return nodeValues_; }
455
456 //- Force use of values per node instead of per element
457 // Deprecated(2020-02) - The newData() method with a second parameter
458 // is more flexible.
459 // \deprecated(2020-02) - newData() with second parameter
460 void nodeValues(bool on) noexcept { nodeValues_ = on; }
461};
462
463
464// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
465
466} // End namespace Foam
467
468// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
469
470#include "ensightCaseI.H"
471
472#ifdef NoRepository
473 #include "ensightCaseTemplates.C"
474#endif
475
476#endif
477
478// ************************************************************************* //
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
streamFormat
Data format (ascii | binary)
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:57
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
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
Configuration options for the ensightCase.
Definition: ensightCase.H:381
bool nodeValues() const noexcept
Forced use of values per node instead of per element.
Definition: ensightCase.H:453
label width() const noexcept
Return current width of mask and padded.
Definition: ensightCase.H:428
void separateCloud(bool on) noexcept
Write clouds into their own directory instead in "data" directory.
Definition: ensightCase.H:447
bool overwrite() const noexcept
Remove existing directory and sub-directories on creation.
Definition: ensightCase.H:431
bool separateCloud() const noexcept
Write clouds into their own directory instead in "data" directory.
Definition: ensightCase.H:434
const word & mask() const noexcept
The '*' mask appropriate for sub-directories.
Definition: ensightCase.H:422
void overwrite(bool on) noexcept
Remove existing directory and sub-directories on creation.
Definition: ensightCase.H:444
IOstreamOption::streamFormat format() const noexcept
Ascii/Binary file output.
Definition: ensightCase.H:419
Supports writing of ensight cases as well as providing common factory methods to open new files.
Definition: ensightCase.H:69
const word & mask() const
The output '*' mask.
Definition: ensightCaseI.H:48
autoPtr< ensightFile > newCloud(const word &cloudName) const
Open stream for new cloud positions (on master).
Definition: ensightCase.C:824
static const char * dataDirName
The name for data subdirectory: "data".
Definition: ensightCase.H:78
autoPtr< ensightFile > newData(const word &varName, const bool isPointData=false) const
Open stream for new data file (on master), with current index.
void write() const
Write the case file.
Definition: ensightCase.C:596
autoPtr< ensightFile > newPointData(const word &varName) const
Ostream & printInfo(Ostream &os) const
Print some general information.
Definition: ensightCase.C:857
const fileName & path() const noexcept
The nominal path to the case file.
Definition: ensightCaseI.H:42
word padded(const label i) const
Consistent zero-padded integer value.
Definition: ensightCaseI.H:54
bool nodeValues() const
Force use of values per node instead of per element.
Definition: ensightCaseI.H:60
autoPtr< ensightGeoFile > newGeometry(bool moving=false) const
Open stream for new geometry file (on master).
Definition: ensightCase.C:790
void setTime(const scalar t, const label index)
Set current index and time for time-set 1.
Definition: ensightCase.C:565
~ensightCase()=default
Destructor.
autoPtr< ensightFile > newCloudData(const word &cloudName, const word &varName) const
Open stream for new cloud data file (on master), with current index.
static const char * geometryName
The name for geometry files: "geometry".
Definition: ensightCase.H:81
void rewind() const
Rewind the output stream (master only).
Definition: ensightCase.C:848
bool separateCloud() const
Write clouds into their own directory instead in "data" directory.
Definition: ensightCaseI.H:66
void nextTime(const scalar t)
Set time for time-set 1, using next available index.
Definition: ensightCase.C:552
const ensightCase::options & option() const
Reference to the case options.
Definition: ensightCaseI.H:30
IOstreamOption::streamFormat format() const
The output file format (ascii/binary)
Definition: ensightCaseI.H:36
static void printTimeset(OSstream &os, const label ts, const scalar timeValue)
Print time-set for ensight case file with a single time.
Definition: ensightCase.C:44
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:55
Specialized Ensight output with extra geometry file header.
A class for handling file names.
Definition: fileName.H:76
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
Definition: instant.H:56
Lookup type of boundary radiation properties.
Definition: lookup.H:66
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
const direction noexcept
Definition: Scalar.H:223
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
const word cloudName(propsDict.get< word >("cloud"))