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