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-2020 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 "surfaceWriterCaching.H"
65 
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 
68 namespace Foam
69 {
70 namespace surfaceWriters
71 {
72 
73 /*---------------------------------------------------------------------------*\
74  Class ensightWriter Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 class ensightWriter
78 :
79  public surfaceWriter
80 {
81  // Private Data
82 
83  //- Output format option (default: IOstream::ASCII)
84  IOstream::streamFormat writeFormat_;
85 
86  //- Collate times (default: true)
87  bool collateTimes_;
88 
89  //- Cached information for times, geometry, fields (collated)
90  writerCaching caching_;
91 
92 
93  // Private Member Functions
94 
95  //- The geometry can be any of the following:
96  //
97  // 0: constant/static
98  // 1: moving, with the same frequency as the data
99  // 2: moving, with different frequency as the data
100  int geometryTimeset() const;
101 
102  //- Print time-set for ensight case file with a single time
103  static void printTimeset
104  (
105  OSstream& os,
106  const label ts,
107  const scalar timeValue
108  );
109 
110  //- Print time-set for ensight case file, with N times and 0-based
111  //- file numbering
112  //
113  // \verbatim
114  // TIME
115  // time set: ts
116  // number of steps: ns
117  // filename start number: 0
118  // filename increment: 1
119  // time values: time_1 time_2 ... time_ns
120  // \endverbatim
121  static void printTimeset
122  (
123  OSstream& os,
124  const label ts,
125  const UList<scalar>& times
126  );
127 
128 
129  //- Print time-set for ensight case file, with N times, 0-based
130  //- file numbering but perhaps non-contiguous
131  //
132  // \verbatim
133  // TIME
134  // time set: ts
135  // number of steps: ns
136  // filename numbers: idx_1 idx_2 ... idx_ns
137  // time values: time_1 time_2 ... time_ns
138  // \endverbatim
139  static void printTimeset
140  (
141  OSstream& os,
142  const label ts,
143  const UList<scalar>& times,
144  const bitSet& indices
145  );
146 
147 
148  //- Write geometry
149  fileName writeCollated();
150 
151  //- Write geometry
152  fileName writeUncollated();
153 
154  //- Templated write operation - one file per timestep
155  template<class Type>
156  fileName writeCollated
157  (
158  const word& fieldName,
159  const Field<Type>& localValues
160  );
161 
162  //- Templated write operation - all time steps in single file
163  template<class Type>
164  fileName writeUncollated
165  (
166  const word& fieldName,
167  const Field<Type>& localValues
168  );
169 
170  //- Templated write operation
171  template<class Type>
172  fileName writeTemplate
173  (
174  const word& fieldName,
175  const Field<Type>& localValues
176  );
177 
178 public:
179 
180  //- Declare type-name, virtual type (without debug switch)
181  TypeNameNoDebug("ensight");
182 
183 
184  // Constructors
185 
186  //- Default construct
187  ensightWriter();
188 
189  //- Construct with some output options
190  explicit ensightWriter(const dictionary& options);
191 
192  //- Construct from components
194  (
195  const meshedSurf& surf,
196  const fileName& outputPath,
197  bool parallel = Pstream::parRun(),
198  const dictionary& options = dictionary()
199  );
200 
201  //- Construct from components
203  (
204  const pointField& points,
205  const faceList& faces,
206  const fileName& outputPath,
207  bool parallel = Pstream::parRun(),
208  const dictionary& options = dictionary()
209  );
210 
211 
212  //- Destructor
213  virtual ~ensightWriter() = default;
214 
215 
216  // Member Functions
217 
218  //- Finish output, clears output times.
219  // Later reuse will rebuild times from fieldsDict file cache.
220  virtual void close(); // override
221 
222  //- True if the surface format supports geometry in a separate file.
223  // False if geometry and field must be in a single file
224  virtual bool separateGeometry() const;
225 
226  //- Write surface geometry to file.
227  virtual fileName write(); // override
228 
235 };
236 
237 
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 
240 } // End namespace surfaceWriters
241 } // End namespace Foam
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 #endif
246 
247 // ************************************************************************* //
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:112
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:114
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::surfaceWriters::ensightWriter
A surfaceWriter for Ensight format.
Definition: ensightSurfaceWriter.H:91
Foam::surfaceWriters::ensightWriter::~ensightWriter
virtual ~ensightWriter()=default
Destructor.
Foam::meshedSurf
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:49
surfaceWriter.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:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SphericalTensor< scalar >
surfaceWriterCaching.H
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::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
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
Foam::surfaceWriters::ensightWriter::close
virtual void close()
Finish output, clears output times.
Definition: ensightSurfaceWriter.C:230
Foam::surfaceWriters::writerCaching
Information for surface writers with collated times.
Definition: surfaceWriterCaching.H:59