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