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