36 using namespace
Input::Type;
39 return Record(
"vtk",
"Parameters of vtk output format.")
43 "Variant of output stream file format.")
46 "Parallel or serial version of file format.")
52 return Selection(
"VTK variant (ascii or binary)")
54 "ASCII variant of VTK file format")
56 "Uncompressed appended binary XML VTK format without usage of base64 encoding of appended data.")
57 #ifdef FLOW123D_HAVE_ZLIB 59 "Appended binary XML VTK format without usage of base64 encoding of appended data. Compressed with ZLib.")
60 #endif // FLOW123D_HAVE_ZLIB 92 const std::shared_ptr<TimeUnitConversion>& time_unit_conv)
98 this->
parallel_ = format_rec.val<
bool>(
"parallel");
101 if(this->
rank_ == 0) {
119 ss << basename <<
"/" << basename <<
"-" 120 << std::setw(6) << std::setfill(
'0') << i_step <<
"." << rank <<
".vtu";
123 ss << basename <<
"/" << basename <<
"-" 124 << std::setw(6) << std::setfill(
'0') << i_step <<
".vtu";
132 <<
"<DataSet timestep=\"" << step
133 <<
"\" group=\"\" part=\"" << rank
134 <<
"\" file=\"" << file
156 if (this->
rank_ == 0) {
167 for (
int i_rank=0; i_rank<
n_proc_; ++i_rank) {
188 <<
", rank: " << this->
rank_ 189 <<
") file: " << frame_file_name <<
" ... ";
214 if(this->
rank_ == 0) {
228 file <<
"<?xml version=\"1.0\"?>" << endl;
231 file <<
"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\"";
233 file <<
" header_type=\"UInt64\"";
235 if ( this->
variant_type_ == VTKVariant::VARIANT_BINARY_ZLIB ) {
236 file <<
" compressor=\"vtkZLibDataCompressor\"";
239 file <<
"<UnstructuredGrid>" << endl;
246 auto &offsets = *( this->
offsets_->get_component_data(0).get() );
247 unsigned int n_elements = offsets.size()-1;
253 for(
unsigned int i=0; i < n_elements; i++)
255 n_nodes = offsets[i+1]-offsets[i];
278 "Int8",
"UInt8",
"Int16",
"UInt16",
"Int32",
"UInt32",
"Float32",
"Float64" };
282 file <<
"<DataArray type=\"" << types[output_data->vtk_type()] <<
"\" ";
284 if( ! output_data->field_input_name().empty())
285 file <<
"Name=\"" << output_data->field_input_name() <<
"\" ";
287 if (output_data->n_comp() > 1)
290 <<
"NumberOfComponents=\"" << output_data->n_comp() <<
"\" ";
298 output_data->print_ascii_all(file, start);
299 file <<
"\n</DataArray>" << endl;
302 double range_min, range_max;
303 output_data->get_min_max_range(range_min, range_max);
305 file <<
"RangeMin=\"" << range_min <<
"\" RangeMax=\"" << range_max <<
"\"/>" << endl;
306 if ( this->
variant_type_ == VTKVariant::VARIANT_BINARY_UNCOMPRESSED ) {
309 stringstream uncompressed_data, compressed_data;
310 output_data->print_binary_all( uncompressed_data,
false, start );
321 static const size_t BUF_SIZE = 32 * 1024;
323 string uncompressed_string = uncompressed_stream.str();
324 zlib_ulong uncompressed_size = uncompressed_string.size();
325 stringstream compressed_data;
327 zlib_ulong count_of_blocks = (uncompressed_size + BUF_SIZE - 1) / BUF_SIZE;
328 zlib_ulong last_block_size = (uncompressed_size % BUF_SIZE);
329 compressed_stream.write(reinterpret_cast<const char*>(&count_of_blocks),
sizeof(
unsigned long long int));
330 compressed_stream.write(reinterpret_cast<const char*>(&BUF_SIZE),
sizeof(
unsigned long long int));
331 compressed_stream.write(reinterpret_cast<const char*>(&last_block_size),
sizeof(
unsigned long long int));
333 for (
zlib_ulong i=0; i<count_of_blocks; ++i) {
335 std::string data_block = uncompressed_string.substr(i*BUF_SIZE, BUF_SIZE);
336 zlib_ulong data_block_size = data_block.size();
339 uint8_t temp_buffer[BUF_SIZE];
345 strm.next_in =
reinterpret_cast<uint8_t *
>(&data_block[0]);
346 strm.avail_in = data_block_size;
347 strm.next_out = temp_buffer;
348 strm.avail_out = BUF_SIZE;
351 deflateInit(&strm, Z_BEST_COMPRESSION);
352 while (strm.avail_in != 0) {
353 int res = deflate(&strm, Z_NO_FLUSH);
355 if (strm.avail_out == 0) {
356 buffer.insert(buffer.end(), temp_buffer, temp_buffer + BUF_SIZE);
357 strm.next_out = temp_buffer;
358 strm.avail_out = BUF_SIZE;
361 int deflate_res = Z_OK;
362 while (deflate_res == Z_OK) {
363 if (strm.avail_out == 0) {
364 buffer.insert(buffer.end(), temp_buffer, temp_buffer + BUF_SIZE);
365 strm.next_out = temp_buffer;
366 strm.avail_out = BUF_SIZE;
368 deflate_res = deflate(&strm, Z_FINISH);
370 ASSERT_EQ(deflate_res, Z_STREAM_END).error();
371 buffer.insert(buffer.end(), temp_buffer, temp_buffer + BUF_SIZE - strm.avail_out);
375 std::string str(buffer.begin(), buffer.end());
377 compressed_stream.write(reinterpret_cast<const char*>(&compressed_data_size),
sizeof(
unsigned long long int));
378 compressed_data << str;
381 compressed_stream << compressed_data.str();
388 if( ! data->is_dummy())
398 if (output_data_vec.empty())
return;
400 file <<
"Scalars=\"";
403 && ! data->is_dummy())
404 file << data->field_input_name() <<
",";
407 file <<
"Vectors=\"";
410 && ! data->is_dummy())
411 file << data->field_input_name() <<
",";
414 file <<
"Tensors=\"";
417 && ! data->is_dummy())
418 file << data->field_input_name() <<
",";
429 node_corner_data.insert(node_corner_data.end(),
432 if( ! node_corner_data.empty() ) {
434 file <<
"<PointData ";
445 file <<
"</PointData>" << endl;
455 if (data_map.empty())
return;
458 file <<
"<CellData ";
466 file <<
"</CellData>" << endl;
475 if (data_map.empty())
return;
478 file <<
"<Flow123dData ";
484 file <<
"<DataArray type=\"Float64\" ";
485 file <<
"Name=\"" << output_data->field_input_name() <<
"\" ";
487 file <<
"dof_handler_hash=\"" << output_data->dof_handler_hash() <<
"\" ";
488 file <<
"n_dofs_per_element=\"" << output_data->n_comp() <<
"\"";
493 file << std::fixed << std::setprecision(10);
494 output_data->print_ascii_all(file);
495 file <<
"\n</DataArray>" << endl;
498 double range_min, range_max;
499 output_data->get_min_max_range(range_min, range_max);
501 file <<
"RangeMin=\"" << range_min <<
"\" RangeMax=\"" << range_max <<
"\"/>" << endl;
502 if ( this->
variant_type_ == VTKVariant::VARIANT_BINARY_UNCOMPRESSED ) {
505 stringstream uncompressed_data, compressed_data;
506 output_data->print_binary_all( uncompressed_data,
false );
514 file <<
"</Flow123dData>" << endl;
522 file <<
"</UnstructuredGrid>" << endl;
525 file <<
"<AppendedData encoding=\"raw\">" << endl;
528 file <<
"</AppendedData>" << endl;
530 file <<
"</VTKFile>" << endl;
542 file <<
"<Piece NumberOfPoints=\"" << this->
nodes_->n_values()
543 <<
"\" NumberOfCells=\"" << this->
offsets_->n_values()-1 <<
"\">" << endl;
546 file <<
"<Points>" << endl;
548 file <<
"</Points>" << endl;
551 file <<
"<Cells>" << endl;
556 file <<
"</Cells>" << endl;
568 file <<
"</Piece>" << endl;
579 if(this->
rank_ != 0) {
585 this->
_base_file <<
"<?xml version=\"1.0\"?>" << endl;
586 this->
_base_file <<
"<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">" << endl;
598 if(this->
rank_ != 0) {
Classes for auxiliary output mesh.
Input::Record input_record_
void fix_main_file_extension(std::string extension)
static const std::vector< std::string > formats
Formats of DataArray section.
std::shared_ptr< ElementDataCache< unsigned int > > connectivity_
Vector maps the nodes to their coordinates in vector nodes_.
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)
std::shared_ptr< ElementDataCache< unsigned int > > fill_element_types_data()
Fills the data cache with VTK element types indicators.
void write_vtk_vtu(void)
This function write all scalar and vector data on nodes and elements to the VTK file (...
std::shared_ptr< ElementDataCache< unsigned int > > offsets_
Vector of offsets of node indices of elements. Maps elements to their nodes in connectivity_.
static const int registrar
Registrar of class to factory.
static Input::Type::Abstract & get_input_format_type()
The specification of output file format.
void write_vtk_data(OutputDataPtr output_data, unsigned int start=0)
std::shared_ptr< ElementDataCacheBase > OutputDataPtr
std::shared_ptr< ElementDataCache< double > > nodes_
Vector of node coordinates. [spacedim x n_nodes].
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.
Basic time management class.
VTKVariant
The declaration enumeration used for variant of file VTK format.
bool parallel_
Parallel or serial version of file format (parallel has effect only for VTK)
void open_stream(Stream &stream) const
int write_data(void)
This function write data to VTK (.pvd) file format for curent time.
virtual void init_from_input(const std::string &equation_name, const Input::Record &in_rec, const std::shared_ptr< TimeUnitConversion > &time_unit_conv)
Constructor of OutputTime object. It opens base file for writing.
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.
void init_from_input(const std::string &equation_name, const Input::Record &in_rec, const std::shared_ptr< TimeUnitConversion > &time_unit_conv) override
Override OutputTime::init_from_input.
string parent_path() const
int write_tail(void)
This function writes tail of VTK (.pvd) file format.
void set_stream_precision(std::ofstream &stream)
~OutputVTK()
The destructor of this class. It writes tail of the file too.
std::shared_ptr< TimeUnitConversion > time_unit_converter
Time unit conversion object from the equation time governor.
void write_vtk_native_data(void)
Write native data (part of our own data skipped by Paraview) to the VTK file (.vtu) ...
Dedicated class for storing path to input and output files.
Support classes for parallel programing.
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)
string form_vtu_filename_(string basename, int i_step, int rank)
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)
string pvd_dataset_line(double step, int rank, string file)
OutputDataFieldVec output_data_vec_[N_DISCRETE_SPACES]
void compress_data(stringstream &uncompressed_stream, stringstream &compressed_stream)
bool enable_refinement_
Auxiliary flag for refinement enabling, due to gmsh format.
void write_vtk_vtu_head(void)
Write header of VTK file (.vtu)
#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.