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