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