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-2020 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 
50  selection
51  {
52  box
53  {
54  action use;
55  source box;
56  box (-0.1 -0.01 -0.1) (0.1 0.30 0.1);
57  }
58  dome
59  {
60  action add;
61  source sphere;
62  origin (-0.1 -0.01 -0.1);
63  radius 0.25;
64  }
65  centre
66  {
67  action subtract;
68  source sphere;
69  origin (-0.1 -0.01 -0.1);
70  radius 0.1;
71  }
72  blob
73  {
74  action add;
75  source surface;
76  surface triSurfaceMesh;
77  name blob.stl;
78  }
79  }
80  }
81  \endverbatim
82 
83  \heading Basic Usage
84  \table
85  Property | Description | Required | Default
86  type | Type name: vtkWrite | yes |
87  fields | Fields to output (wordRe list) | yes |
88  boundary | Convert boundary fields | no | true
89  internal | Convert internal fields | no | true
90  single | Combine patches into a single boundary | no | false
91  interpolate | Interpolate for point values | no | false
92  \endtable
93 
94  \heading Output Options
95  \table
96  Property | Description | Required | Default
97  format | ascii or binary format | no | binary
98  legacy | Legacy VTK output | no | false
99  precision | Write precision in ascii | no | same as IOstream
100  directory | The output directory name | no | postProcessing/NAME
101  width | Padding width for file name | no | 8
102  decompose | Decompose polyhedral cells | no | false
103  writeIds | Write cell,patch,proc id fields | no | false
104  \endtable
105 
106  \heading Output Selection
107  \table
108  Property | Description | Required | Default
109  region | Name for a single region | no | region0
110  regions | List of regions (wordRe list) | no |
111  patches | Limit to listed patches (wordRe list) | no |
112  selection | Cell selection (topoSet actions) | no | empty dict
113  \endtable
114 
115 Note
116  The region of interest is defined by the selection dictionary
117  as a set of actions (use,add,subtract,subset,invert).
118  Omitting the selection dictionary is the same as specifying the
119  conversion of all cells (in the selected regions).
120  Omitting the patches entry is the same as specifying the conversion of all
121  patches.
122 
123 See also
124  Foam::functionObjects::ensightWrite
125  Foam::functionObjects::fvMeshFunctionObject
126  Foam::functionObjects::timeControl
127 
128 SourceFiles
129  vtkWrite.C
130  vtkWriteTemplates.C
131 
132 \*---------------------------------------------------------------------------*/
133 
134 #ifndef functionObjects_vtkWrite_H
135 #define functionObjects_vtkWrite_H
136 
137 #include "timeFunctionObject.H"
138 #include "foamVtkInternalWriter.H"
139 #include "foamVtkPatchWriter.H"
140 #include "foamVtkSeriesWriter.H"
141 #include "fvMeshSubsetProxy.H"
142 #include "searchableSurfaces.H"
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 namespace Foam
147 {
148 namespace functionObjects
149 {
150 
151 /*---------------------------------------------------------------------------*\
152  Class vtkWrite Declaration
153 \*---------------------------------------------------------------------------*/
154 
155 class vtkWrite
156 :
157  public functionObjects::timeFunctionObject
158 {
159  // Private Data
160 
161  //- The output directory
162  fileName outputDir_;
163 
164  //- The printf format for zero-padding names
165  string printf_;
166 
167  //- VTK output options
168  vtk::outputOptions writeOpts_;
169 
170  //- Verbose output
171  bool verbose_;
172 
173  //- Convert internal mesh
174  bool doInternal_;
175 
176  //- Convert boundary mesh
177  bool doBoundary_;
178 
179  //- Combine patches into a single file
180  bool oneBoundary_;
181 
182  //- Interpolate cell to point values
183  bool interpolate_;
184 
185  //- Decompose polyhedra
186  bool decompose_;
187 
188  //- Write cell ids field
189  bool writeIds_;
190 
191  //- Track changes in mesh geometry
192  enum polyMesh::readUpdateState meshState_;
193 
194  //- Requested names of regions to process
195  wordRes selectRegions_;
196 
197  //- Requested names of patches to process
198  wordRes selectPatches_;
199 
200  //- Requested names of fields to process
201  wordRes selectFields_;
202 
203  //- Dictionary of volume selections
204  dictionary selection_;
205 
206  //- Pointers to the requested mesh regions
207  HashTable<const fvMesh*> meshes_;
208 
209  //- Subsetting for meshes.
210  // Access index according to sorted mesh names.
211  PtrList<fvMeshSubset> meshSubsets_;
212 
213  //- Storage for VTU cells, sizing.
214  // Access index according to sorted mesh names.
215  PtrList<vtk::vtuCells> vtuMappings_;
216 
217  //- VTK file series
218  HashTable<vtk::seriesWriter, fileName> series_;
219 
220 
221  // Private Member Functions
222 
223  //- Update mesh subset according to zones, geometry, bounds
224  bool updateSubset(fvMeshSubset& subsetter) const;
225 
226  //- Get patchIds selected in list
227  labelList getSelectedPatches(const polyBoundaryMesh& patches) const;
228 
229  //- Read information for selections
230  bool readSelection(const dictionary& dict);
231 
232  //- Update meshes, subMeshes etc.
233  bool update();
234 
235 
236  // Write
237 
238  //- Write all volume fields
239  label writeAllVolFields
240  (
241  autoPtr<vtk::internalWriter>& internalWriter,
242  UPtrList<vtk::patchWriter>& patchWriters,
243  const fvMeshSubset& proxy,
244  const wordHashSet& acceptField
245  ) const;
246 
247  //- Write all volume fields with point interpolation
248  label writeAllVolFields
249  (
250  autoPtr<vtk::internalWriter>& internalWriter,
251  const autoPtr<volPointInterpolation>& pInterp,
252  UPtrList<vtk::patchWriter>& patchWriters,
253  const UPtrList
254  <
256  >& patchInterps,
257  const fvMeshSubset& proxy,
258  const wordHashSet& acceptField
259  ) const;
260 
261  //- Write selected GeoField fields.
262  template<class GeoField>
263  label writeVolFields
264  (
267  const fvMeshSubset& proxy,
268  const wordHashSet& acceptField
269  ) const;
270 
271  //- Write selected GeoField fields with point interpolation
272  template<class GeoField>
273  label writeVolFields
274  (
278  const UPtrList
279  <
281  >& patchInterps,
282  const fvMeshSubset& proxy,
283  const wordHashSet& acceptField
284  ) const;
285 
286 
287  //- No copy construct
288  vtkWrite(const vtkWrite&) = delete;
289 
290  //- No copy assignment
291  void operator=(const vtkWrite&) = delete;
292 
293 
294 public:
295 
296  //- Runtime type information
297  TypeName("vtkWrite");
298 
299 
300  // Constructors
301 
302  //- Construct from Time and dictionary
303  vtkWrite
304  (
305  const word& name,
306  const Time& runTime,
307  const dictionary& dict
308  );
309 
310 
311  //- Destructor
312  virtual ~vtkWrite() = default;
313 
314 
315  // Member Functions
316 
317  //- Read the vtkWrite specification
318  virtual bool read(const dictionary& dict);
319 
320  //- Execute - does nothing
321  virtual bool execute();
322 
323  //- Write fields
324  virtual bool write();
325 
326  //- On end - cleanup internal allocations
327  virtual bool end();
328 
329  //- Update for changes of mesh
330  virtual void updateMesh(const mapPolyMesh& mpm);
331 
332  //- Update for mesh point-motion
333  virtual void movePoints(const polyMesh& mesh);
334 };
335 
336 
337 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 
339 } // End namespace functionObjects
340 } // End namespace Foam
341 
342 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
343 
344 #ifdef NoRepository
345  #include "vtkWriteTemplates.C"
346 #endif
347 
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
349 
350 #endif
351 
352 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjects::vtkWrite::end
virtual bool end()
On end - cleanup internal allocations.
Definition: vtkWrite.C:756
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::functionObjects::vtkWrite::execute
virtual bool execute()
Execute - does nothing.
Definition: vtkWrite.C:245
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
Foam::functionObjects::vtkWrite::movePoints
virtual void movePoints(const polyMesh &mesh)
Update for mesh point-motion.
Definition: vtkWriteUpdate.C:277
Foam::fvMeshSubset
Given the original mesh and the list of selected cells, it creates the mesh consisting only of the de...
Definition: fvMeshSubset.H:73
Foam::functionObjects::vtkWrite::read
virtual bool read(const dictionary &dict)
Read the vtkWrite specification.
Definition: vtkWrite.C:164
Foam::functionObjects::vtkWrite::TypeName
TypeName("vtkWrite")
Runtime type information.
internalWriter
autoPtr< vtk::internalWriter > internalWriter
Definition: convertProcessorPatches.H:60
Foam::functionObjects::timeFunctionObject
Virtual base class for function objects with a reference to Time.
Definition: timeFunctionObject.H:56
patchWriters
PtrList< vtk::patchWriter > patchWriters
Definition: convertProcessorPatches.H:63
Foam::functionObjects::vtkWrite::write
virtual bool write()
Write fields.
Definition: vtkWrite.C:251
Foam::HashSet< word, Hash< word > >
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
timeFunctionObject.H
searchableSurfaces.H
Foam::writeAllVolFields
label writeAllVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
Definition: writeVolFields.H:126
Foam::functionObjects::vtkWrite::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Definition: vtkWriteUpdate.C:271
Foam::UPtrList
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:62
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
foamVtkSeriesWriter.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
fvMeshSubsetProxy.H
Foam::writeVolFields
label writeVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
Definition: writeVolFields.H:90
foamVtkPatchWriter.H
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:90
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
vtkWriteTemplates.C
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::PrimitivePatchInterpolation
Interpolation class within a primitive patch. Allows interpolation from points to faces and vice vers...
Definition: PrimitivePatchInterpolation.H:53
Foam::functionObjects::vtkWrite::~vtkWrite
virtual ~vtkWrite()=default
Destructor.
Foam::List< label >
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::wordHashSet
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:77
foamVtkInternalWriter.H
patchInterps
PtrList< PrimitivePatchInterpolation< primitivePatch > > patchInterps
Definition: convertVolumeFields.H:130
pInterp
autoPtr< volPointInterpolation > pInterp
Definition: convertVolumeFields.H:81
Foam::functionObjects::vtkWrite
Writes fields in VTK (xml or legacy) format. Writes cell-values or point-interpolated values for volF...
Definition: vtkWrite.H:254