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