34 using namespace
Input::Type;
37 return Record(
"vtk",
"Parameters of vtk output format.")
41 "Variant of output stream file format.")
50 return Selection(
"VTK variant (ascii or binary)")
52 "ASCII variant of VTK file format")
54 "Uncompressed appended binary XML VTK format without usage of base64 encoding of appended data.")
55 #ifdef FLOW123D_HAVE_ZLIB 57 "Appended binary XML VTK format without usage of base64 encoding of appended data. Compressed with ZLib.")
58 #endif // FLOW123D_HAVE_ZLIB 110 if(this->
rank != 0) {
119 << std::setw(6) << std::setfill(
'0') << this->
current_step 123 std::string frame_file_name = ss.str();
135 this->
_base_file.precision(std::numeric_limits<double>::digits10);
139 this->
_base_file << scientific <<
"<DataSet timestep=\"" << (isfinite(this->
time)?this->
time:0)
140 <<
"\" group=\"\" part=\"0\" file=\"" << relative_frame_file <<
"\"/>" << endl;
144 LogOut() << __func__ <<
": Writing output (frame " << this->current_step <<
") file " << relative_frame_file <<
" ... ";
179 file <<
"<?xml version=\"1.0\"?>" << endl;
182 file <<
"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\"";
184 file <<
" header_type=\"UInt64\"";
186 if ( this->
variant_type_ == VTKVariant::VARIANT_BINARY_ZLIB ) {
187 file <<
" compressor=\"vtkZLibDataCompressor\"";
190 file <<
"<UnstructuredGrid>" << endl;
198 unsigned int n_elements = offsets.size();
200 data.resize(n_elements);
203 n_nodes = offsets[0];
216 for(
unsigned int i=1; i < n_elements; i++)
218 n_nodes = offsets[i]-offsets[i-1];
239 "Int8",
"UInt8",
"Int16",
"UInt16",
"Int32",
"UInt32",
"Float32",
"Float64" };
245 file <<
"<DataArray type=\"" << types[output_data->vtk_type_] <<
"\" ";
247 if( ! output_data->output_field_name.empty())
248 file <<
"Name=\"" << output_data->output_field_name <<
"\" ";
250 if (output_data->n_elem_ > 1)
253 <<
"NumberOfComponents=\"" << output_data->n_elem_ <<
"\" ";
260 file << std::fixed << std::setprecision(10);
261 output_data->print_ascii_all(file);
262 file <<
"\n</DataArray>" << endl;
265 double range_min, range_max;
266 output_data->get_min_max_range(range_min, range_max);
268 file <<
"RangeMin=\"" << range_min <<
"\" RangeMax=\"" << range_max <<
"\"/>" << endl;
269 if ( this->
variant_type_ == VTKVariant::VARIANT_BINARY_UNCOMPRESSED ) {
272 stringstream uncompressed_data, compressed_data;
273 output_data->print_binary_all( uncompressed_data,
false );
284 static const size_t BUF_SIZE = 32 * 1024;
286 string uncompressed_string = uncompressed_stream.str();
287 uLong uncompressed_size = uncompressed_string.size();
288 stringstream compressed_data;
290 uLong count_of_blocks = (uncompressed_size + BUF_SIZE - 1) / BUF_SIZE;
291 uLong last_block_size = (uncompressed_size % BUF_SIZE);
292 compressed_stream.write(reinterpret_cast<const char*>(&count_of_blocks),
sizeof(
unsigned long long int));
293 compressed_stream.write(reinterpret_cast<const char*>(&BUF_SIZE),
sizeof(
unsigned long long int));
294 compressed_stream.write(reinterpret_cast<const char*>(&last_block_size),
sizeof(
unsigned long long int));
296 for (uLong i=0; i<count_of_blocks; ++i) {
298 std::string data_block = uncompressed_string.substr(i*BUF_SIZE, BUF_SIZE);
299 uLong data_block_size = data_block.size();
302 uint8_t temp_buffer[BUF_SIZE];
308 strm.next_in =
reinterpret_cast<uint8_t *
>(&data_block[0]);
309 strm.avail_in = data_block_size;
310 strm.next_out = temp_buffer;
311 strm.avail_out = BUF_SIZE;
314 deflateInit(&strm, Z_BEST_COMPRESSION);
315 while (strm.avail_in != 0) {
316 int res = deflate(&strm, Z_NO_FLUSH);
318 if (strm.avail_out == 0) {
319 buffer.insert(buffer.end(), temp_buffer, temp_buffer + BUF_SIZE);
320 strm.next_out = temp_buffer;
321 strm.avail_out = BUF_SIZE;
324 int deflate_res = Z_OK;
325 while (deflate_res == Z_OK) {
326 if (strm.avail_out == 0) {
327 buffer.insert(buffer.end(), temp_buffer, temp_buffer + BUF_SIZE);
328 strm.next_out = temp_buffer;
329 strm.avail_out = BUF_SIZE;
331 deflate_res = deflate(&strm, Z_FINISH);
333 ASSERT_EQ(deflate_res, Z_STREAM_END).error();
334 buffer.insert(buffer.end(), temp_buffer, temp_buffer + BUF_SIZE - strm.avail_out);
338 std::string str(buffer.begin(), buffer.end());
339 uLong compressed_data_size = str.size();
340 compressed_stream.write(reinterpret_cast<const char*>(&compressed_data_size),
sizeof(
unsigned long long int));
341 compressed_data << str;
344 compressed_stream << compressed_data.str();
360 if (output_data_vec.empty())
return;
362 file <<
"Scalars=\"";
367 file <<
"Vectors=\"";
372 file <<
"Tensors=\"";
385 node_corner_data.insert(node_corner_data.end(),
388 if( ! node_corner_data.empty() ) {
390 file <<
"<PointData ";
401 file <<
"</PointData>" << endl;
411 if (data_map.empty())
return;
414 file <<
"<CellData ";
422 file <<
"</CellData>" << endl;
430 file <<
"</UnstructuredGrid>" << endl;
433 file <<
"<AppendedData encoding=\"raw\">" << endl;
436 file <<
"</AppendedData>" << endl;
438 file <<
"</VTKFile>" << endl;
453 file <<
"<Piece NumberOfPoints=\"" <<
output_mesh_->n_nodes()
454 <<
"\" NumberOfCells=\"" <<
output_mesh_->n_elements() <<
"\">" << endl;
457 file <<
"<Points>" << endl;
459 file <<
"</Points>" << endl;
463 file <<
"<Cells>" << endl;
466 auto types = std::make_shared<MeshData<unsigned int>>(
"types");
469 file <<
"</Cells>" << endl;
478 file <<
"</Piece>" << endl;
483 <<
"\" NumberOfCells=\"" <<
output_mesh_->n_elements() <<
"\">" << endl;
486 file <<
"<Points>" << endl;
488 file <<
"</Points>" << endl;
491 file <<
"<Cells>" << endl;
494 auto types = std::make_shared<MeshData<unsigned int>>(
"types");
497 file <<
"</Cells>" << endl;
506 file <<
"</Piece>" << endl;
518 if(this->
rank != 0) {
525 this->
_base_file <<
"<?xml version=\"1.0\"?>" << endl;
526 this->
_base_file <<
"<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">" << endl;
538 if(this->
rank != 0) {
Classes for auxiliary output mesh.
std::shared_ptr< OutputMesh > output_mesh_
Output mesh.
virtual void init_from_input(const std::string &equation_name, Mesh &mesh, const Input::Record &in_rec)
Constructor of OutputTime object. It opens base file for writing.
Input::Record input_record_
std::shared_ptr< OutputMeshDiscontinuous > output_mesh_discont_
Discontinuous (non-conforming) mesh. Used for CORNER_DATA.
void fix_main_file_extension(std::string extension)
static const Input::Type::Record & get_input_type()
The definition of input record for vtk file format.
void write_vtk_field_data(OutputDataFieldVec &output_data_map)
void write_vtk_vtu(void)
This function write all scalar and vector data on nodes and elements to the VTK file (...
void write_vtk_data(OutputDataPtr output_data)
static const int registrar
Registrar of class to factory.
static Input::Type::Abstract & get_input_format_type()
The specification of output file format.
void fill_element_types_vector(std::vector< unsigned int > &data)
Fills the given vector with VTK element types indicators.
string main_output_basename_
Basename of main output file (without extension)
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
int write_head(void)
This function writes header of VTK (.pvd) file format.
string main_output_dir_
Main output file directory.
void write_vtk_element_data(void)
Write data on elements to the VTK file (.vtu)
#define LogOut()
Macro defining 'log' record of log.
VTKVariant
The declaration enumeration used for variant of file VTK format.
void open_stream(Stream &stream) const
int write_data(void)
This function write data to VTK (.pvd) file format for curent time.
ostringstream appended_data_
void write_vtk_vtu_tail(void)
Write tail of VTK file (.vtu)
This class is used for output data to VTK file format.
string parent_path() const
int write_tail(void)
This function writes tail of VTK (.pvd) file format.
~OutputVTK()
The destructor of this class. It writes tail of the file too.
Dedicated class for storing path to input and output files.
OutputVTK()
The constructor of this class. The head of file is written, when constructor is called.
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
VTKVariant variant_type_
Output format (ascii, binary or binary compressed)
void write_vtk_node_data(void)
Write data on nodes to the VTK file (.vtu)
OutputDataFieldVec output_data_vec_[N_DISCRETE_SPACES]
void compress_data(stringstream &uncompressed_stream, stringstream &compressed_stream)
std::shared_ptr< OutputDataBase > OutputDataPtr
bool enable_refinement_
Auxliary flag for refinement enabling, due to gmsh format.
void write_vtk_vtu_head(void)
Write header of VTK file (.vtu)
void init_from_input(const std::string &equation_name, Mesh &mesh, const Input::Record &in_rec) override
Override OutputTime::init_from_input.
#define FLOW123D_FORCE_LINK_IN_CHILD(x)
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
static const Input::Type::Selection & get_input_type_variant()
The definition of input record for selection of variant of file format.
void write_vtk_data_names(ofstream &file, OutputDataFieldVec &output_data_map)
Write names of data sets in output_data vector that have value type equal to type. Output is done into stream file.