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