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