Flow123d  JS_before_hm-995-g9546b8d
output_vtk.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file output_vtk.h
15  * @brief Header: The functions for VTK outputs.
16  */
17 
18 #ifndef OUTPUT_VTK_HH_
19 #define OUTPUT_VTK_HH_
20 
21 #include <memory> // for shared_ptr
22 #include <ostream> // for ofstream, stringstream, ostringstream
23 #include <string> // for string
24 #include "output_time.hh" // for OutputTime, OutputTime::OutputDataFieldVec
25 #include <zlib.h>
26 
27 class Mesh;
28 namespace Input {
29  class Record;
30  namespace Type {
31  class Record;
32  class Selection;
33  }
34 }
35 template <typename T> class ElementDataCache;
36 
37 using namespace std;
38 
39 
40 /**
41  * \brief This class is used for output data to VTK file format
42  */
43 class OutputVTK : public OutputTime {
44 
45 public:
47  typedef uLong zlib_ulong;
48 
49 
50  /**
51  * \brief The constructor of this class. The head of file is written, when
52  * constructor is called
53  */
54  OutputVTK();
55 
56  /**
57  * \brief The destructor of this class. It writes tail of the file too.
58  */
59  ~OutputVTK();
60 
61  /**
62  * \brief The definition of input record for vtk file format
63  */
64  static const Input::Type::Record & get_input_type();
65 
66  /**
67  * \brief The definition of input record for selection of variant of file format
68  */
69  static const Input::Type::Selection & get_input_type_variant();
70 
71 
72 
73  /**
74  * \brief This function write data to VTK (.pvd) file format
75  * for curent time
76  */
77  int write_data(void);
78 
79  /**
80  * \brief This function writes header of VTK (.pvd) file format
81  */
82  int write_head(void);
83 
84  /**
85  * \brief This function writes tail of VTK (.pvd) file format
86  */
87  int write_tail(void);
88 
89  /// Override @p OutputTime::init_from_input.
90  void init_from_input(const std::string &equation_name, const Input::Record &in_rec, std::string unit_str) override;
91 
92 protected:
93 
94  /**
95  * \brief The declaration enumeration used for variant of file VTK format
96  */
97  typedef enum {
98  VARIANT_ASCII = 0,
99  VARIANT_BINARY_UNCOMPRESSED = 1,
100  VARIANT_BINARY_ZLIB = 2
101  } VTKVariant;
102 
103  // VTK Element types
104  typedef enum {
105  VTK_VERTEX = 1,
106  VTK_POLY_VERTEX = 2,
107  VTK_LINE = 3,
108  VTK_POLY_LINE = 4,
109  VTK_TRIANGLE = 5,
110  VTK_TRIANGLE_STRIP = 6,
111  VTK_POLYGON = 7,
112  VTK_PIXEL = 8,
113  VTK_QUAD = 9,
114  VTK_TETRA = 10,
115  VTK_VOXEL = 11,
116  VTK_HEXAHEDRON = 12,
117  VTK_WEDGE = 13,
118  VTK_PYRAMID = 14,
119  VTK_QUADRIC_EDGE = 21,
120  VTK_QUADRIC_TRIANGLE = 22,
121  VTK_QUADRIC_QUAD = 23,
122  VTK_QUADRIC_TETRA = 24,
123  VTK_QUADRIC_HEXAHEDRON = 25
124  } VTKElemType;
125 
126  // VTK Element size (number of nodes)
127  typedef enum {
128  VTK_LINE_SIZE = 2,
129  VTK_TRIANGLE_SIZE = 3,
130  VTK_TETRA_SIZE = 4
131  } VTKElemSize;
132 
133  /// Registrar of class to factory
134  static const int registrar;
135 
136  /// Formats of DataArray section
138 
139  /**
140  * Used internally by write_data.
141  */
142  string form_vtu_filename_(string basename, int i_step, int rank);
143 
144  /**
145  * \brief Write header of VTK file (.vtu)
146  */
147  void write_vtk_vtu_head(void);
148 
149  /**
150  * \brief Fills the data cache with VTK element types indicators.
151  */
152  std::shared_ptr<ElementDataCache<unsigned int>> fill_element_types_data();
153 
154  /**
155  * Write registered data of all components of given Field to output stream
156  */
157  void write_vtk_field_data(OutputDataFieldVec &output_data_map);
158 
159  /**
160  * Write output data stored in OutputData vector to output stream
161  */
162  void write_vtk_data(OutputDataPtr output_data);
163 
164  /**
165  * \brief Write names of data sets in @p output_data vector that have value type equal to @p type.
166  * Output is done into stream @p file.
167  */
168  void write_vtk_data_names(ofstream &file,
169  OutputDataFieldVec &output_data_map);
170 
171  /**
172  * \brief Write data on nodes to the VTK file (.vtu)
173  */
174  void write_vtk_node_data(void);
175 
176  /**
177  * \brief Write data on elements to the VTK file (.vtu)
178  */
179  void write_vtk_element_data(void);
180 
181  /**
182  * \brief Write native data (part of our own data skipped by Paraview) to the VTK file (.vtu)
183  *
184  * Tags of native data are subtags of 'Flow123dData' tag, that is subtag of 'Piece' tag
185  */
186  void write_vtk_native_data(void);
187 
188  /**
189  * \brief Write tail of VTK file (.vtu)
190  */
191  void write_vtk_vtu_tail(void);
192 
193  /**
194  * \brief This function write all scalar and vector data on nodes and elements
195  * to the VTK file (.vtu)
196  */
197  void write_vtk_vtu(void);
198 
199  /**
200  * Set appropriate file path substrings.
201  * Make subdirectory for VTU time frames.
202  */
203  void make_subdirectory();
204 
205  /**
206  * Compress data stored in @p uncompressed_stream to @p compressed_stream.
207  *
208  * Use ZLib compression.
209  */
210  void compress_data(stringstream &uncompressed_stream, stringstream &compressed_stream);
211 
212 
213  /**
214  * Data output stream (could be same as base_file)
215  */
216  ofstream _data_file;
217 
218  /**
219  * Stream of appended data (used only for binary appended output)
220  */
221  ostringstream appended_data_;
222 
223  /**
224  * Path to time frame VTU data subdirectory
225  */
226  string subdir_name_;
227 
228  /// Basename of main output file (without extension)
230 
231  /// Main output file directory
233 
234  /// Output format (ascii, binary or binary compressed)
236 };
237 
238 #endif /* OUTPUT_VTK_HH_ */
uLong zlib_ulong
Definition: output_vtk.hh:47
static const std::vector< std::string > formats
Formats of DataArray section.
Definition: output_vtk.hh:137
string subdir_name_
Definition: output_vtk.hh:226
Abstract linear system class.
Definition: balance.hh:40
static const int registrar
Registrar of class to factory.
Definition: output_vtk.hh:134
Definition: mesh.h:78
std::shared_ptr< ElementDataCacheBase > OutputDataPtr
Definition: output_time.hh:122
string main_output_basename_
Basename of main output file (without extension)
Definition: output_vtk.hh:229
string main_output_dir_
Main output file directory.
Definition: output_vtk.hh:232
OutputTime FactoryBaseType
Definition: output_vtk.hh:46
VTKVariant
The declaration enumeration used for variant of file VTK format.
Definition: output_vtk.hh:97
ofstream _data_file
Definition: output_vtk.hh:216
ostringstream appended_data_
Definition: output_vtk.hh:221
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
This class is used for output data to VTK file format.
Definition: output_vtk.hh:43
The class for outputting data during time.
Definition: output_time.hh:50
VTKVariant variant_type_
Output format (ascii, binary or binary compressed)
Definition: output_vtk.hh:235
Record type proxy class.
Definition: type_record.hh:182
Template for classes storing finite set of named values.