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