vtkSurfaceWriter.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::vtkWriter
29 
30 Description
31  A surfaceWriter for VTK legacy (.vtk) or XML (.vtp) format.
32 
33  The formatOptions for vtk:
34  \table
35  Property | Description | Required | Default
36  format | ascii or binary format | no | binary
37  legacy | Legacy VTK output | no | false
38  precision | Write precision in ascii | no | same as IOstream
39  fieldScale | output field scaling (dictionary) | no | empty
40  \endtable
41 
42  For example,
43  \verbatim
44  formatOptions
45  {
46  vtk
47  {
48  format binary;
49  legacy false;
50  precision 10;
51  fieldScale
52  {
53  "p.*" 0.01; // [Pa] -> [mbar]
54  }
55  }
56  }
57  \endverbatim
58 
59  \heading Output file locations
60 
61  The \c rootdir normally corresponds to something like
62  \c postProcessing/<name>
63 
64  \subheading Geometry and Fields
65  \verbatim
66  rootdir
67  `-- timeName
68  `-- surfaceName.{vtk,vtp}
69  \endverbatim
70 
71 SourceFiles
72  vtkSurfaceWriter.C
73 
74 \*---------------------------------------------------------------------------*/
75 
76 #ifndef vtkSurfaceWriter_H
77 #define vtkSurfaceWriter_H
78 
79 #include "surfaceWriter.H"
80 
81 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82 
83 namespace Foam
84 {
85 
86 namespace vtk
87 {
88 // Forward Declarations
89 class outputOptions;
90 class surfaceWriter;
91 }
92 
93 namespace surfaceWriters
94 {
95 
96 /*---------------------------------------------------------------------------*\
97  Class vtkWriter Declaration
98 \*---------------------------------------------------------------------------*/
99 
100 class vtkWriter
101 :
102  public surfaceWriter
103 {
104  // Private Data
105 
106  //- The VTK output format type.
107  // Stored as a raw value to avoid a header dependency on fileFormats
108  unsigned fmtType_;
109 
110  //- ASCII write precision
111  unsigned precision_;
112 
113  //- Output field scaling
114  const dictionary fieldScale_;
115 
116  //- Backend writer - master only
117  autoPtr<Foam::vtk::surfaceWriter> writer_;
118 
119 
120  // Private Member Functions
121 
122  //- Templated write field operation
123  template<class Type>
124  fileName writeTemplate
125  (
126  const word& fieldName,
127  const Field<Type>& localValues
128  );
129 
130 
131 public:
132 
133  //- Declare type-name, virtual type (without debug switch)
134  TypeNameNoDebug("vtk");
135 
136 
137  // Constructors
138 
139  //- Default construct
140  vtkWriter();
141 
142  //- Construct with some output options
143  explicit vtkWriter(const vtk::outputOptions& opts);
144 
145  //- Construct with some output options
146  explicit vtkWriter(const dictionary& options);
147 
148  //- Construct from components
149  // The file name is with/without an extension.
150  vtkWriter
151  (
152  const meshedSurf& surf,
153  const fileName& outputPath,
154  bool parallel = Pstream::parRun(),
155  const dictionary& options = dictionary()
156  );
157 
158  //- Construct from components with specified output path.
159  // The file name is with/without an extension.
160  vtkWriter
161  (
162  const pointField& points,
163  const faceList& faces,
164  const fileName& outputPath,
165  bool parallel = Pstream::parRun(),
166  const dictionary& options = dictionary()
167  );
168 
169 
170  //- Destructor. Calls close()
171  virtual ~vtkWriter();
172 
173 
174  // Member Functions
175 
176  //- Finish output, clears backend.
177  virtual void close(); // override
178 
179  //- Begin time step. Clears existing backend.
180  virtual void beginTime(const Time& t); // override
181 
182  //- Begin time step. Clears existing backend.
183  virtual void beginTime(const instant& inst); // override
184 
185  //- End time step. Clears existing backend.
186  virtual void endTime(); // override
187 
188 
189  // Write
190 
191  //- Write surface geometry to file.
192  virtual fileName write(); // override
193 
200 };
201 
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 } // End namespace surfaceWriters
206 } // End namespace Foam
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 #endif
211 
212 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
Foam::Tensor< scalar >
Foam::surfaceWriters::vtkWriter::declareSurfaceWriterWriteMethod
declareSurfaceWriterWriteMethod(label)
Foam::SymmTensor< scalar >
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
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::surfaceWriters::vtkWriter::write
virtual fileName write()
Write surface geometry to file.
Definition: vtkSurfaceWriter.C:186
Foam::UPstream::parRun
static bool & parRun()
Test if this a parallel run, or allow modify access.
Definition: UPstream.H:434
Foam::surfaceWriters::vtkWriter::close
virtual void close()
Finish output, clears backend.
Definition: vtkSurfaceWriter.C:158
Foam::meshedSurf
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:49
Foam::surfaceWriters::vtkWriter::beginTime
virtual void beginTime(const Time &t)
Begin time step. Clears existing backend.
Definition: vtkSurfaceWriter.C:165
surfaceWriter.H
Foam::surfaceWriters::vtkWriter
A surfaceWriter for VTK legacy (.vtk) or XML (.vtp) format.
Definition: vtkSurfaceWriter.H:124
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::surfaceWriters::vtkWriter::endTime
virtual void endTime()
End time step. Clears existing backend.
Definition: vtkSurfaceWriter.C:179
Foam::surfaceWriters::vtkWriter::TypeNameNoDebug
TypeNameNoDebug("vtk")
Declare type-name, virtual type (without debug switch)
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::surfaceWriters::vtkWriter::~vtkWriter
virtual ~vtkWriter()
Destructor. Calls close()
Definition: vtkSurfaceWriter.C:150
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SphericalTensor< scalar >
Foam::autoPtr< Foam::vtk::surfaceWriter >
Foam::Vector< scalar >
Foam::List< face >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:52
Foam::surfaceWriters::vtkWriter::vtkWriter
vtkWriter()
Default construct.
Definition: vtkSurfaceWriter.C:64