32 #include <boost/any.hpp>
44 using namespace Input::Type;
47 =
Record(
"vtk",
"Parameters of vtk output format.")
51 "Variant of output stream file format.")
54 "Parallel or serial version of file format.")
56 "Compression used in output stream file format.");
60 =
Selection(
"VTK variant (ascii or binary)")
62 "ASCII variant of VTK file format")
64 "Binary variant of VTK file format (not supported yet)");
68 =
Selection(
"Type of compression of VTK file format")
70 "Data in VTK file format are not compressed")
72 "Data in VTK file format are compressed using zlib (not supported yet)");
78 ofstream &file = this->get_data_file();
80 file <<
"<?xml version=\"1.0\"?>" << endl;
83 file <<
"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">" << endl;
84 file <<
"<UnstructuredGrid>" << endl;
89 Mesh *mesh = this->get_mesh();
90 ofstream &file = this->get_data_file();
96 file <<
"<Points>" << endl;
98 file <<
"<DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">" << endl;
102 this->get_data_file().precision(std::numeric_limits<double>::digits10);
106 file << scientific << node->getX() <<
" ";
107 file << scientific << node->getY() <<
" ";
108 file << scientific << node->getZ() <<
" ";
113 file << endl <<
"</DataArray>" << endl;
115 file <<
"</Points>" << endl;
120 Mesh *mesh = this->get_mesh();
121 ofstream &file = this->get_data_file();
129 file <<
"<Cells>" << endl;
131 file <<
"<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << endl;
135 node = ele->node[li];
136 file << node->
aux <<
" ";
140 file << endl <<
"</DataArray>" << endl;
143 file <<
"<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << endl;
149 tmp += VTK_LINE_SIZE;
152 tmp += VTK_TRIANGLE_SIZE;
155 tmp += VTK_TETRA_SIZE;
161 file << endl <<
"</DataArray>" << endl;
164 file <<
"<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">" << endl;
169 file << (int)VTK_LINE <<
" ";
172 file << (int)VTK_TRIANGLE <<
" ";
175 file << (int)VTK_TETRA <<
" ";
180 file << endl <<
"</DataArray>" << endl;
183 file <<
"</Cells>" << endl;
188 Mesh *mesh = this->get_mesh();
189 ofstream &file = this->get_data_file();
195 file <<
"<Points>" << endl;
197 file <<
"<DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">" << endl;
199 this->get_data_file().precision(std::numeric_limits<double>::digits10);
202 node = ele->node[li];
204 file << scientific << node->
getX() <<
" ";
205 file << scientific << node->
getY() <<
" ";
206 file << scientific << node->
getZ() <<
" ";
210 file << endl <<
"</DataArray>" << endl;
212 file <<
"</Points>" << endl;
217 Mesh *mesh = this->get_mesh();
218 ofstream &file = this->get_data_file();
222 unsigned int li, tmp;
225 file <<
"<Cells>" << endl;
227 file <<
"<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << endl;
237 file << endl <<
"</DataArray>" << endl;
240 file <<
"<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << endl;
246 tmp += VTK_LINE_SIZE;
249 tmp += VTK_TRIANGLE_SIZE;
252 tmp += VTK_TETRA_SIZE;
258 file << endl <<
"</DataArray>" << endl;
261 file <<
"<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">" << endl;
266 file << (int)VTK_LINE <<
" ";
269 file << (int)VTK_TRIANGLE <<
" ";
272 file << (int)VTK_TETRA <<
" ";
277 file << endl <<
"</DataArray>" << endl;
280 file <<
"</Cells>" << endl;
288 ofstream &file = this->get_data_file();
292 file <<
"<DataArray type=\"Float64\" "
293 <<
"Name=\"" << data->output_field_name <<
"\" ";
294 if (data->n_elem_ > 1)
297 <<
"NumberOfComponents=\"" << data->n_elem_ <<
"\" ";
299 file <<
"format=\"ascii\">"
304 file.precision(std::numeric_limits<double>::digits10);
306 for(
unsigned int i=0; i < data->n_values; i ++) {
307 data->print(file, i);
310 file <<
"\n</DataArray>" << endl;
319 file <<
"Scalars=\"";
320 for(
auto &data : vec_output_data)
324 file <<
"Vectors=\"";
325 for(
auto &data : vec_output_data)
329 file <<
"Tensors=\"";
330 for(
auto &data : vec_output_data)
338 ofstream &file = this->get_data_file();
342 node_corner_data.insert(node_corner_data.end(), this->corner_data.begin(), this->corner_data.end());
344 if( ! node_corner_data.empty() ) {
346 file <<
"<PointData ";
347 write_vtk_data_names(file, node_corner_data);
351 if( ! this->node_data.empty() ) {
352 this->write_vtk_data_ascii(this->node_data);
356 if( ! this->corner_data.empty() ) {
357 this->write_vtk_data_ascii(this->corner_data);
361 file <<
"</PointData>" << endl;
368 ofstream &file = this->get_data_file();
370 if(this->elem_data.empty() !=
true) {
372 file <<
"<CellData ";
373 write_vtk_data_names(file, this->elem_data);
377 this->write_vtk_data_ascii(this->elem_data);
380 file <<
"</CellData>" << endl;
387 ofstream &file = this->get_data_file();
389 file <<
"</UnstructuredGrid>" << endl;
390 file <<
"</VTKFile>" << endl;
396 ofstream &file = this->get_data_file();
397 Mesh *mesh = this->get_mesh();
400 this->write_vtk_vtu_head();
403 if(this->corner_data.empty() ==
true)
406 file <<
"<Piece NumberOfPoints=\"" << mesh->
n_nodes() <<
"\" NumberOfCells=\"" << mesh->
n_elements() <<
"\">" << endl;
409 this->write_vtk_geometry();
412 this->write_vtk_topology();
415 this->write_vtk_node_data();
418 this->write_vtk_element_data();
421 file <<
"</Piece>" << endl;
425 file <<
"<Piece NumberOfPoints=\"" << this->get_corner_count() <<
"\" NumberOfCells=\"" << mesh->
n_elements() <<
"\">" << endl;
428 this->write_vtk_discont_geometry();
431 this->write_vtk_discont_topology();
434 this->write_vtk_node_data();
437 this->write_vtk_element_data();
440 file <<
"</Piece>" << endl;
444 this->write_vtk_vtu_tail();
451 char base_dir_name[PATH_MAX];
452 char new_dir_name[PATH_MAX];
453 char base_file_name[PATH_MAX];
455 char frame_file_name[PATH_MAX];
456 ofstream *data_file =
new ofstream;
469 if(this->header_written ==
false) {
471 this->header_written =
true;
474 strncpy(base_dir_name, this->base_filename()->c_str(), PATH_MAX);
478 for(j=strlen(base_dir_name)-1; j>0; j--) {
479 if(base_dir_name[j]==
'/') {
480 base_dir_name[j]=
'\0';
485 strncpy(base_file_name, this->base_filename()->c_str(), PATH_MAX);
488 for(i=strlen(base_file_name)-1; i>=0; i--) {
489 if(base_file_name[i]==
'.') {
495 strncpy(base, &base_file_name[j+1], i-j-1);
499 sprintf(new_dir_name,
"%s/%s", base_dir_name, base);
502 dir = opendir(new_dir_name);
505 ret = mkdir(new_dir_name, 0777);
508 xprintf(
Err,
"Couldn't create directory: %s, error: %s\n", new_dir_name, strerror(errno));
514 sprintf(frame_file_name,
"%s/%s-%06d.vtu", new_dir_name, base, this->current_step);
516 data_file->open(frame_file_name);
517 if(data_file->is_open() ==
false) {
518 xprintf(
Err,
"Could not write output to the file: %s\n", frame_file_name);
522 this->set_data_file(data_file);
524 xprintf(
MsgLog,
"%s: Writing output file %s ... ", __func__, this->base_filename()->c_str());
527 for(i=strlen(frame_file_name); i>=0; i--) {
534 this->get_base_file().precision(std::numeric_limits<double>::digits10);
537 this->get_base_file() << scientific <<
"<DataSet timestep=\"" << (isfinite(this->time)?this->time:0) <<
"\" group=\"\" part=\"0\" file=\"" << base <<
"/" << &frame_file_name[i+1] <<
"\"/>" << endl;
541 xprintf(
MsgLog,
"%s: Writing output (frame %d) file %s ... ", __func__,
542 this->current_step, frame_file_name);
544 this->write_vtk_vtu();
549 this->set_data_file(NULL);
569 xprintf(
MsgLog,
"%s: Writing output file (head) %s ... ", __func__,
570 this->base_filename()->c_str() );
572 this->get_base_file() <<
"<?xml version=\"1.0\"?>" << endl;
573 this->get_base_file() <<
"<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">" << endl;
574 this->get_base_file() <<
"<Collection>" << endl;
593 xprintf(
MsgLog,
"%s: Writing output file (tail) %s ... ", __func__,
594 this->base_filename()->c_str() );
596 this->get_base_file() <<
"</Collection>" << endl;
597 this->get_base_file() <<
"</VTKFile>" << endl;
Common parent class for templated OutputData.
static Input::Type::AbstractRecord input_format_type
The specification of output file format.
void write_vtk_discont_topology(void)
Write topology (connection of nodes) to the VTK file (.vtu)
#define FOR_ELEMENT_NODES(i, j)
Header: The functions for all outputs.
static Input::Type::Selection input_type_variant
The definition of input record for selection of variant of file format.
void write_vtk_vtu(void)
This function write all scalar and vector data on nodes and elements to the VTK file (...
#define FOR_ELEMENTS(_mesh_, __i)
void write_vtk_geometry(void)
Write geometry (position of nodes) to the VTK file (.vtu)
int write_head(void)
This function writes header of VTK (.pvd) file format.
I/O functions with filename storing, able to track current line in opened file. All standard stdio fu...
void write_vtk_element_data(void)
Write data on elements to the VTK file (.vtu)
void write_vtk_data_names(ofstream &file, vector< OutputDataBase * > &output_data)
Write names of data sets in output_data vector that have value type equal to type. Output is done into stream file.
void write_vtk_discont_geometry(void)
Write geometry (position of nodes) to the VTK file (.vtu)
static Input::Type::Record input_type
The definition of input record for vtk file format.
void write_vtk_data_ascii(vector< OutputDataBase * > &output_data)
int write_data(void)
This function write data to VTK (.pvd) file format for curent time.
unsigned int n_elements() const
static Input::Type::Selection input_type_compression
The definition of input record for selection of compression type.
void write_vtk_vtu_tail(void)
Write tail of VTK file (.vtu)
int write_tail(void)
This function writes tail of VTK (.pvd) file format.
The class for outputing data during time.
~OutputVTK()
The destructor of this class. It writes tail of the file too.
#define FOR_NODES(_mesh_, i)
OutFileFormat file_format
Header: The functions for VTK outputs.
OutputVTK()
The constructor of this class. The head of file is written, when constructor is called.
void write_vtk_node_data(void)
Write data on nodes to the VTK file (.vtu)
unsigned int n_nodes() const
void write_vtk_vtu_head(void)
Write header of VTK file (.vtu)
void write_vtk_topology(void)
Write topology (connection of nodes) to the VTK file (.vtu)