ensightSurfaceWriter.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 OpenFOAM Foundation
9  Copyright (C) 2015-2019 OpenCFD Ltd.
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::surfaceWriters::ensightWriter
29 
30 Description
31  A surfaceWriter for Ensight format.
32 
33  \verbatim
34  formatOptions
35  {
36  ensight
37  {
38  format ascii;
39  collateTimes true;
40  }
41  }
42  \endverbatim
43 
44  Format options:
45  \table
46  Property | Description | Required | Default
47  format | ascii/binary | no | ascii
48  collateTimes | use common geometry for times | no | true
49  \endtable
50 
51  The collated format maintains an internal list of the known times
52  as well as a file-cached version with the field information.
53  The information is used for restarts.
54 
55 SourceFiles
56  ensightSurfaceWriter.C
57 
58 \*---------------------------------------------------------------------------*/
59 
60 #ifndef ensightSurfaceWriter_H
61 #define ensightSurfaceWriter_H
62 
63 #include "surfaceWriter.H"
64 #include "bitSet.H"
65 #include "DynamicList.H"
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 namespace Foam
70 {
71 namespace surfaceWriters
72 {
73 
74 /*---------------------------------------------------------------------------*\
75  Class ensightWriter Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 class ensightWriter
79 :
80  public surfaceWriter
81 {
82  // Private Data
83 
84  //- Output format option (default: IOstream::ASCII)
85  IOstream::streamFormat writeFormat_;
86 
87  //- Collate times (default: true)
88  bool collateTimes_;
89 
90  //- The collated output times
91  DynamicList<scalar> times_;
92 
93  //- Indices in times_ when geometry (mesh) has been written (collated)
94  bitSet meshes_;
95 
96  //- Cached information for times, geometry, fields (collated)
97  dictionary cache_;
98 
99 
100  // Private Member Functions
101 
102  //- Read time information from baseDir / dictName.
103  // Returns timeIndex corresponding to timeValue
104  label readPreviousTimes
105  (
106  const fileName& baseDir,
107  const word& dictName,
108  const scalar& timeValue
109  );
110 
111  //- The geometry can be any of the following:
112  //
113  // 0: constant/static
114  // 1: moving, with the same frequency as the data
115  // 2: moving, with different frequency as the data
116  int geometryTimeset() const;
117 
118  //- Print time-set for ensight case file with a single time
119  static void printTimeset
120  (
121  OSstream& os,
122  const label ts,
123  const scalar& timeValue
124  );
125 
126  //- Print time-set for ensight case file, with N times and 0-based
127  //- file numbering
128  //
129  // \verbatim
130  // TIME
131  // time set: ts
132  // number of steps: ns
133  // filename start number: 0
134  // filename increment: 1
135  // time values: time_1 time_2 ... time_ns
136  // \endverbatim
137  static void printTimeset
138  (
139  OSstream& os,
140  const label ts,
141  const UList<scalar>& times
142  );
143 
144 
145  //- Print time-set for ensight case file, with N times, 0-based
146  //- file numbering but perhaps non-contiguous
147  //
148  // \verbatim
149  // TIME
150  // time set: ts
151  // number of steps: ns
152  // filename numbers: idx_1 idx_2 ... idx_ns
153  // time values: time_1 time_2 ... time_ns
154  // \endverbatim
155  static void printTimeset
156  (
157  OSstream& os,
158  const label ts,
159  const UList<scalar>& times,
160  const bitSet& indices
161  );
162 
163 
164  //- Write geometry
165  fileName writeCollated();
166 
167  //- Write geometry
168  fileName writeUncollated();
169 
170  //- Templated write operation - one file per timestep
171  template<class Type>
172  fileName writeCollated
173  (
174  const word& fieldName,
175  const Field<Type>& localValues
176  );
177 
178  //- Templated write operation - all time steps in single file
179  template<class Type>
180  fileName writeUncollated
181  (
182  const word& fieldName,
183  const Field<Type>& localValues
184  );
185 
186  //- Templated write operation
187  template<class Type>
188  fileName writeTemplate
189  (
190  const word& fieldName,
191  const Field<Type>& localValues
192  );
193 
194 public:
195 
196  //- Declare type-name, virtual type (without debug switch)
197  TypeNameNoDebug("ensight");
198 
199 
200  // Constructors
201 
202  //- Default construct
203  ensightWriter();
204 
205  //- Construct with some output options
206  explicit ensightWriter(const dictionary& options);
207 
208  //- Construct from components
210  (
211  const meshedSurf& surf,
212  const fileName& outputPath,
213  bool parallel = Pstream::parRun(),
214  const dictionary& options = dictionary()
215  );
216 
217  //- Construct from components
219  (
220  const pointField& points,
221  const faceList& faces,
222  const fileName& outputPath,
223  bool parallel = Pstream::parRun(),
224  const dictionary& options = dictionary()
225  );
226 
227 
228  //- Destructor
229  virtual ~ensightWriter() = default;
230 
231 
232  // Member Functions
233 
234  //- Finish output, clears output times.
235  // Later reuse will rebuild times from fieldsDict file cache.
236  virtual void close(); // override
237 
238  //- True if the surface format supports geometry in a separate file.
239  // False if geometry and field must be in a single file
240  virtual bool separateGeometry() const;
241 
242  //- Write surface geometry to file.
243  virtual fileName write(); // override
244 
251 };
252 
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 } // End namespace surfaceWriters
257 } // End namespace Foam
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 #endif
262 
263 // ************************************************************************* //
Foam::surfaceWriters::ensightWriter::declareSurfaceWriterWriteMethod
declareSurfaceWriterWriteMethod(label)
Foam::surfaceWriters::ensightWriter::ensightWriter
ensightWriter()
Default construct.
Definition: ensightSurfaceWriter.C:175
Foam::Tensor< scalar >
Foam::SymmTensor< scalar >
Foam::surfaceWriter::timeValue
scalar timeValue() const
The current time value/name.
Definition: surfaceWriterI.H:102
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:111
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::surfaceWriters::ensightWriter
A surfaceWriter for Ensight format.
Definition: ensightSurfaceWriter.H:92
Foam::DynamicList< scalar >
Foam::surfaceWriters::ensightWriter::~ensightWriter
virtual ~ensightWriter()=default
Destructor.
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:415
Foam::meshedSurf
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:49
dictName
const word dictName("blockMeshDict")
surfaceWriter.H
bitSet.H
Foam::surfaceWriters::ensightWriter::write
virtual fileName write()
Write surface geometry to file.
Definition: ensightSurfaceWriter.C:248
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::OSstream
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:54
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SphericalTensor< scalar >
Foam::surfaceWriters::ensightWriter::separateGeometry
virtual bool separateGeometry() const
True if the surface format supports geometry in a separate file.
Definition: ensightSurfaceWriter.C:242
Foam::surfaceWriters::ensightWriter::TypeNameNoDebug
TypeNameNoDebug("ensight")
Declare type-name, virtual type (without debug switch)
Foam::Vector< scalar >
Foam::List< face >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
points
const pointField & points
Definition: gmvOutputHeader.H:1
DynamicList.H
Foam::surfaceWriters::ensightWriter::close
virtual void close()
Finish output, clears output times.
Definition: ensightSurfaceWriter.C:228