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-2022 OpenCFD Ltd.
10  Copyright (C) 2026 Keysight Technologies
11 -------------------------------------------------------------------------------
12 License
13  This file is part of OpenFOAM.
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 Class
29  Foam::surfaceWriters::vtkWriter
30 
31 Description
32  A surfaceWriter for VTK legacy (.vtk) or XML (.vtp) format.
33 
34  The formatOptions for vtk:
35  \table
36  Property | Description | Required | Default
37  format | ascii or binary format | no | binary
38  legacy | Legacy VTK output | no | false
39  precision | Write precision in ascii | no | same as IOstream
40  scale | Output geometry scaling | no | 1
41  transform | Output coordinate transform | no |
42  fieldLevel | Subtract field level before scaling | no | empty dict
43  fieldScale | Output field scaling | no | empty dict
44  normal | Write face area-normal in output | no | false
45  \endtable
46 
47  For example,
48  \verbatim
49  formatOptions
50  {
51  vtk
52  {
53  format binary;
54  legacy false;
55  precision 10;
56  fieldLevel
57  {
58  p 1e5; // Absolute -> gauge [Pa]
59  }
60  fieldScale
61  {
62  "p.*" 0.01; // [Pa] -> [mbar]
63  }
64  }
65  }
66  \endverbatim
67 
68  \section Output file locations
69 
70  The \c rootdir normally corresponds to something like
71  \c postProcessing/<name>
72 
73  \subsection Geometry and Fields
74  \verbatim
75  rootdir
76  `-- timeName
77  `-- surfaceName.{vtk,vtp}
78  \endverbatim
79 
80 SourceFiles
81  vtkSurfaceWriter.cxx
82 
83 \*---------------------------------------------------------------------------*/
84 
85 #ifndef Foam_surfaceWriters_vtkWriter_H
86 #define Foam_surfaceWriters_vtkWriter_H
87 
88 #include "surfaceWriter.H"
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
92 namespace Foam
93 {
94 
95 namespace vtk
96 {
97 // Forward Declarations
98 class outputOptions;
99 class surfaceWriter;
100 }
101 
102 namespace surfaceWriters
103 {
104 
105 /*---------------------------------------------------------------------------*\
106  Class vtkWriter Declaration
107 \*---------------------------------------------------------------------------*/
108 
109 class vtkWriter
110 :
111  public surfaceWriter
112 {
113  // Private Data
114 
115  //- The VTK output format type.
116  // Stored as a raw value to avoid a header dependency on fileFormats
117  unsigned fmtType_;
118 
119  //- ASCII write precision
120  unsigned precision_;
121 
122  //- Output face area normal
123  const bool writeNormal_;
124 
125  //- Backend writer - master only
126  autoPtr<Foam::vtk::surfaceWriter> writer_;
127 
128 
129  // Private Member Functions
130 
131  //- Templated write field operation
132  template<class Type>
133  fileName writeTemplate
134  (
135  const word& fieldName,
136  const Field<Type>& localValues
137  );
138 
139 
140 public:
141 
142  //- Declare type-name, virtual type (without debug switch)
143  TypeNameNoDebug("vtk");
144 
145 
146  // Constructors
147 
148  //- Default construct
150 
151  //- Construct with VTK output options
152  explicit vtkWriter(vtk::outputOptions opts);
153 
154  //- Construct with some output options
155  explicit vtkWriter(const dictionary& options);
156 
157  //- Construct from components
158  // The file name is with/without an extension.
159  vtkWriter
160  (
161  const meshedSurf& surf,
162  const fileName& outputPath,
163  bool parallel = UPstream::parRun(),
164  const dictionary& options = dictionary()
165  );
166 
167  //- Construct from components with specified output path.
168  // The file name is with/without an extension.
169  vtkWriter
170  (
171  const pointField& points,
172  const faceList& faces,
173  const fileName& outputPath,
174  bool parallel = UPstream::parRun(),
175  const dictionary& options = dictionary()
176  );
177 
178 
179  //- Destructor. Calls close()
180  virtual ~vtkWriter();
181 
182 
183  // Member Functions
184 
185  //- Finish output, clears backend.
186  virtual void close(); // override
187 
188  //- Begin time step. Clears existing backend.
189  virtual void beginTime(const Time& t); // override
190 
191  //- Begin time step. Clears existing backend.
192  virtual void beginTime(const instant& inst); // override
193 
194  //- End time step. Clears existing backend.
195  virtual void endTime(); // override
196 
197 
198  // Write
199 
200  //- Write surface geometry to file.
201  virtual fileName write(); // override
202 
209 };
210 
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 } // End namespace surfaceWriters
215 } // End namespace Foam
216 
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 
219 #endif
220 
221 // ************************************************************************* //
virtual void endTime()
End time step. Clears existing backend.
A class for handling file names.
Definition: fileName.H:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:130
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1774
TypeNameNoDebug("vtk")
Declare type-name, virtual type (without debug switch)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:43
Encapsulated combinations of output format options. This is primarily useful when defining the output...
const pointField & points
virtual fileName write()
Write surface geometry to file.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
Definition: instant.H:53
vtkWriter()
Default construct.
Tensor of scalars, i.e. Tensor<scalar>.
virtual void close()
Finish output, clears backend.
virtual void beginTime(const Time &t)
Begin time step. Clears existing backend.
Namespace for OpenFOAM.
virtual ~vtkWriter()
Destructor. Calls close()