vtkWrite.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) 2017-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::functionObjects::vtkWrite
28 
29 Group
30  grpUtilitiesFunctionObjects
31 
32 Description
33  Writes fields in VTK (xml or legacy) format.
34  Writes cell-values or point-interpolated values for volFields.
35 
36  Example of function object specification:
37  \verbatim
38  vtkWrite1
39  {
40  type vtkWrite;
41  libs (utilityFunctionObjects);
42  writeControl writeTime;
43  writeInterval 1;
44  format binary;
45  legacy false;
46  decompose false;
47  ...
48  fields (U p);
49  // excludeFields ("force.*");
50 
51  selection
52  {
53  box
54  {
55  action use;
56  source box;
57  box (-0.1 -0.01 -0.1) (0.1 0.30 0.1);
58  }
59  dome
60  {
61  action add;
62  source sphere;
63  origin (-0.1 -0.01 -0.1);
64  radius 0.25;
65  }
66  centre
67  {
68  action subtract;
69  source sphere;
70  origin (-0.1 -0.01 -0.1);
71  radius 0.1;
72  }
73  blob
74  {
75  action add;
76  source surface;
77  surface triSurfaceMesh;
78  name blob.stl;
79  }
80  }
81  }
82  \endverbatim
83 
84  \heading Basic Usage
85  \table
86  Property | Description | Required | Default
87  type | Type name: vtkWrite | yes |
88  fields | Select fields to output (wordRe list) | yes |
89  excludeFields | Exclude fields from output (wordRe list) | no |
90  boundary | Convert boundary fields | no | true
91  internal | Convert internal fields | no | true
92  single | Combine patches into a single boundary | no | false
93  interpolate | Interpolate for point values | no | false
94  \endtable
95 
96  \heading Output Options
97  \table
98  Property | Description | Required | Default
99  format | ascii or binary format | no | binary
100  legacy | Legacy VTK output | no | false
101  precision | Write precision in ascii | no | same as IOstream
102  directory | The output directory name | no | postProcessing/NAME
103  width | Padding width for file name | no | 8
104  decompose | Decompose polyhedral cells | no | false
105  writeIds | Write cell,patch,proc id fields | no | false
106  \endtable
107 
108  \heading Output Selection
109  \table
110  Property | Description | Required | Default
111  region | Name for a single region | no | region0
112  regions | List of regions (wordRe list) | no |
113  patches | Limit to listed patches (wordRe list) | no |
114  excludePatches | Exclude specified patches | no |
115  selection | Cell selection (topoSet actions) | no | empty dict
116  \endtable
117 
118 Note
119  The region of interest is defined by the selection dictionary
120  as a set of actions (use,add,subtract,subset,invert).
121  Omitting the selection dictionary is the same as specifying the
122  conversion of all cells (in the selected regions).
123  Omitting the patches entry is the same as specifying the conversion of all
124  patches.
125 
126 See also
127  Foam::functionObjects::ensightWrite
128  Foam::functionObjects::fvMeshFunctionObject
129  Foam::functionObjects::timeControl
130  Foam::cellBitSet::select
131 
132 SourceFiles
133  vtkWrite.C
134  vtkWriteImpl.C
135 
136 \*---------------------------------------------------------------------------*/
137 
138 #ifndef Foam_functionObjects_vtkWrite_H
139 #define Foam_functionObjects_vtkWrite_H
140 
141 #include "timeFunctionObject.H"
142 #include "foamVtkInternalWriter.H"
143 #include "foamVtkPatchWriter.H"
144 #include "foamVtkSeriesWriter.H"
145 #include "fvMeshSubsetProxy.H"
146 #include "searchableSurfaces.H"
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 namespace Foam
151 {
152 namespace functionObjects
153 {
154 
155 /*---------------------------------------------------------------------------*\
156  Class vtkWrite Declaration
157 \*---------------------------------------------------------------------------*/
158 
159 class vtkWrite
160 :
161  public functionObjects::timeFunctionObject
162 {
163  // Private Data
164 
165  //- The output directory
166  fileName outputDir_;
167 
168  //- The printf format for zero-padding names
169  string printf_;
170 
171  //- VTK output options
172  vtk::outputOptions writeOpts_;
173 
174  //- Verbose output
175  bool verbose_;
176 
177  //- Convert internal mesh
178  bool doInternal_;
179 
180  //- Convert boundary mesh
181  bool doBoundary_;
182 
183  //- Combine patches into a single file
184  bool oneBoundary_;
185 
186  //- Interpolate cell to point values
187  bool interpolate_;
188 
189  //- Decompose polyhedra
190  bool decompose_;
191 
192  //- Write cell ids field
193  bool writeIds_;
194 
195  //- Track changes in mesh geometry
196  enum polyMesh::readUpdateState meshState_;
197 
198  //- Requested names of regions to process
199  wordRes selectRegions_;
200 
201  //- Requested names of patches to process
202  wordRes selectPatches_;
203 
204  //- Selection of patches to block
205  wordRes blockPatches_;
206 
207  //- Requested selection of fields to process
208  wordRes selectFields_;
209 
210  //- Selection of fields to block
211  wordRes blockFields_;
212 
213  //- Dictionary of volume selections
214  dictionary selection_;
215 
216  //- Pointers to the requested mesh regions
217  HashTable<const fvMesh*> meshes_;
218 
219  //- Subsetting for meshes.
220  // Access index according to sorted mesh names.
221  PtrList<fvMeshSubset> meshSubsets_;
222 
223  //- Storage for VTU cells, sizing.
224  // Access index according to sorted mesh names.
225  PtrList<vtk::vtuCells> vtuMappings_;
226 
227  //- VTK file series
228  HashTable<vtk::seriesWriter, fileName> series_;
229 
230 
231  // Private Member Functions
232 
233  //- Update mesh subset according to zones, geometry, bounds
234  bool updateSubset(fvMeshSubset& subsetter) const;
235 
236  //- Get patchIds selected in list
237  labelList getSelectedPatches(const polyBoundaryMesh& patches) const;
238 
239  //- Read information for selections
240  bool readSelection(const dictionary& dict);
241 
242  //- Update meshes, subMeshes etc.
243  bool update();
244 
245 
246  // Write
247 
248  //- Write all volume fields
249  label writeAllVolFields
250  (
251  autoPtr<vtk::internalWriter>& internalWriter,
252  UPtrList<vtk::patchWriter>& patchWriters,
253  const fvMeshSubset& proxy,
254  const wordHashSet& candidateNames
255  ) const;
256 
257  //- Write all volume fields with point interpolation
258  label writeAllVolFields
259  (
260  autoPtr<vtk::internalWriter>& internalWriter,
261  const autoPtr<volPointInterpolation>& pInterp,
262  UPtrList<vtk::patchWriter>& patchWriters,
263  const UPtrList
264  <
266  >& patchInterps,
267  const fvMeshSubset& proxy,
268  const wordHashSet& candidateNames
269  ) const;
270 
271  //- Write selected GeoField fields.
272  template<class GeoField>
273  label writeVolFieldsImpl
274  (
277  const fvMeshSubset& proxy,
278  const wordHashSet& candidateNames
279  ) const;
280 
281  //- Write selected GeoField fields with point interpolation
282  template<class GeoField>
283  label writeVolFieldsImpl
284  (
288  const UPtrList
289  <
291  >& patchInterps,
292  const fvMeshSubset& proxy,
293  const wordHashSet& candidateNames
294  ) const;
295 
296 
297  //- No copy construct
298  vtkWrite(const vtkWrite&) = delete;
299 
300  //- No copy assignment
301  void operator=(const vtkWrite&) = delete;
302 
303 
304 public:
305 
306  //- Runtime type information
307  TypeName("vtkWrite");
308 
309 
310  // Constructors
311 
312  //- Construct from Time and dictionary
313  vtkWrite
314  (
315  const word& name,
316  const Time& runTime,
317  const dictionary& dict
318  );
319 
320 
321  //- Destructor
322  virtual ~vtkWrite() = default;
323 
324 
325  // Member Functions
326 
327  //- Read the vtkWrite specification
328  virtual bool read(const dictionary& dict);
329 
330  //- Execute - does nothing
331  virtual bool execute();
332 
333  //- Write fields
334  virtual bool write();
335 
336  //- On end - cleanup internal allocations
337  virtual bool end();
338 
339  //- Update for changes of mesh
340  virtual void updateMesh(const mapPolyMesh& mpm);
341 
342  //- Update for mesh point-motion
343  virtual void movePoints(const polyMesh& mesh);
344 };
345 
346 
347 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348 
349 } // End namespace functionObjects
350 } // End namespace Foam
351 
352 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
353 
354 #endif
355 
356 // ************************************************************************* //
TypeName("vtkWrite")
Runtime type information.
dictionary dict
Interpolation class within a primitive patch. Allows interpolation from points to faces and vice vers...
virtual bool write()
Write fields.
Definition: vtkWrite.C:255
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
engineTime & runTime
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
const word & name() const noexcept
Return the name of this functionObject.
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual ~vtkWrite()=default
Destructor.
autoPtr< vtk::internalWriter > internalWriter
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:73
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:100
Holds a reference to the original mesh (the baseMesh) and optionally to a subset of that mesh (the su...
Definition: fvMeshSubset.H:75
PtrList< PrimitivePatchInterpolation< primitivePatch > > patchInterps
Writes fields in VTK (xml or legacy) format. Writes cell-values or point-interpolated values for volF...
Definition: vtkWrite.H:264
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
const polyBoundaryMesh & patches
virtual bool execute()
Execute - does nothing.
Definition: vtkWrite.C:249
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:89
List< label > labelList
A List of labels.
Definition: List.H:62
virtual bool read(const dictionary &dict)
Read the vtkWrite specification.
Definition: vtkWrite.C:168
virtual bool end()
On end - cleanup internal allocations.
Definition: vtkWrite.C:785
PtrList< vtk::patchWriter > patchWriters
virtual void movePoints(const polyMesh &mesh)
Update for mesh point-motion.
Namespace for OpenFOAM.
autoPtr< volPointInterpolation > pInterp