Flow123d  JS_before_hm-1623-gd361259
msh_vtkreader.cc
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 msh_vtkreader.cc
15  * @brief
16  * @author dalibor
17  */
18 
19 
20 #include <iostream>
21 #include <vector>
22 #include <pugixml.hpp>
23 #include "boost/lexical_cast.hpp"
24 
25 #include "msh_vtkreader.hh"
26 #include "system/system.hh"
27 #include "system/index_types.hh"
28 #include "mesh/bih_tree.hh"
29 #include "mesh/mesh.h"
30 #include "mesh/accessors.hh"
31 
32 #include "config.h"
33 #include <zlib.h>
34 
35 
36 /*******************************************************************
37  * Helper methods
38  */
39 template<typename T>
40 T read_binary_value(std::istream &data_stream)
41 {
42  T val;
43  data_stream.read(reinterpret_cast<char *>(&val), sizeof(val));
44  return val;
45 }
46 
47 
48 uint64_t read_header_type(DataType data_header_type, std::istream &data_stream)
49 {
50  if (data_header_type == DataType::uint64)
51  return read_binary_value<uint64_t>(data_stream);
52  else if (data_header_type == DataType::uint32)
53  return (uint64_t)read_binary_value<unsigned int>(data_stream);
54  else {
55  ASSERT(false).error("Unsupported header_type!\n"); //should not happen
56  return 0;
57  }
58 }
59 
60 
61 /*******************************************************************
62  * implementation of VtkMeshReader
63  */
64 const double VtkMeshReader::point_tolerance = 1E-10;
65 
66 
68 : BaseMeshReader(file_name),
69  time_step_(0.0)
70 {
71  data_section_name_ = "DataArray";
72  has_compatible_mesh_ = false;
74 }
75 
76 
77 
78 VtkMeshReader::VtkMeshReader(const FilePath &file_name, std::shared_ptr<ElementDataFieldMap> element_data_values, double time_step)
79 : BaseMeshReader(file_name, element_data_values),
80  time_step_(time_step)
81 {
82  data_section_name_ = "DataArray";
83  has_compatible_mesh_ = false;
85 }
86 
87 
88 
90 {
91  delete data_stream_;
92 }
93 
94 
95 
96 void VtkMeshReader::read_base_vtk_attributes(pugi::xml_node vtk_node, unsigned int &n_nodes, unsigned int &n_elements)
97 {
98  try {
99  // header type of appended data
100  header_type_ = this->get_data_type( vtk_node.attribute("header_type").as_string() );
101  } catch(ExcWrongType &e) {
102  e << EI_SectionTypeName("base parameter header_type");
103  }
104  // data format
106  data_format_ = DataFormat::ascii;
107  } else {
109  // Allowable values of header type are only 'UInt64' or 'UInt32'
110  THROW( ExcWrongType() << EI_ErrMessage("Forbidden") << EI_SectionTypeName("base parameter header_type")
111  << EI_VTKFile(tok_.f_name()));
112  }
113  std::string compressor = vtk_node.attribute("compressor").as_string();
114  if (compressor == "vtkZLibDataCompressor")
115  data_format_ = DataFormat::binary_zlib;
116  else
117  data_format_ = DataFormat::binary_uncompressed;
118  }
119  // size of node and element vectors
120  pugi::xml_node piece_node = vtk_node.child("UnstructuredGrid").child("Piece");
121  n_nodes = piece_node.attribute("NumberOfPoints").as_uint();
122  n_elements = piece_node.attribute("NumberOfCells").as_uint();
123 }
124 
125 
126 
128  Tokenizer::Position appended_pos;
129 
130  {
131  // find line by tokenizer
132  tok_.set_position( Tokenizer::Position() );
133  if (! tok_.skip_to("AppendedData"))
134  THROW(ExcMissingTag() << EI_TagType("tag") << EI_TagName("AppendedData") << EI_VTKFile(tok_.f_name()) );
135  else {
136  appended_pos = tok_.get_position();
137  }
138  }
139 
140  // find exact position of appended data (starts with '_')
141  char c;
142  data_stream_->seekg(appended_pos.file_position_);
143  do {
144  data_stream_->get(c);
145  } while (c!='_');
146  appended_pos.file_position_ = data_stream_->tellg();
147  appended_pos.line_counter_++;
148  delete data_stream_; // close stream
149 
150  // reopen stream in binary mode
151  data_stream_ = new std::ifstream( tok_.f_name(), std::ios_base::in | std::ios_base::binary );
152 
153  return appended_pos;
154 }
155 
156 
157 BaseMeshReader::MeshDataHeader VtkMeshReader::create_header(pugi::xml_node node, unsigned int n_entities, Tokenizer::Position pos,
159 {
160  MeshDataHeader header;
161  header.field_name = node.attribute("Name").as_string();
162  header.time = this->time_step_;
163  try {
164  header.type = this->get_data_type( node.attribute("type").as_string() );
165  } catch(ExcWrongType &e) {
166  e << EI_SectionTypeName("DataArray " + header.field_name);
167  }
168  header.discretization = disc;
169  if (disc == OutputTime::DiscreteSpace::NATIVE_DATA) {
170  header.n_components = node.attribute("n_dofs_per_element").as_uint();
171  header.dof_handler_hash = node.attribute("dof_handler_hash").as_uint();
172  } else {
173  header.n_components = node.attribute("NumberOfComponents").as_uint(1);
174  }
175  header.n_entities = n_entities;
176  std::string format = node.attribute("format").as_string();
177  if (format=="appended") {
178  if (data_format_ == DataFormat::ascii)
179  THROW(ExcInvalidFormat() << EI_FieldName(header.field_name) << EI_ExpectedFormat("ascii") << EI_VTKFile(tok_.f_name()) );
180  std::streampos file_pos = pos.file_position_;
181  file_pos += node.attribute("offset").as_uint();
182  header.position = Tokenizer::Position( file_pos, pos.line_counter_, pos.line_position_ );
183  } else if (format=="ascii") {
184  if (data_format_ != DataFormat::ascii)
185  THROW(ExcInvalidFormat() << EI_FieldName(header.field_name) << EI_ExpectedFormat("appended") << EI_VTKFile(tok_.f_name()) );
186 
187  tok_.set_position( Tokenizer::Position() );
188  bool is_point = (header.field_name=="");
189  std::string found_str = (is_point) ? "<Points>" : "Name=\"" + header.field_name + "\"";
190  if (! tok_.skip_to(found_str))
191  THROW(ExcMissingTag() << EI_TagType("DataArray tag") << EI_TagName(header.field_name) << EI_VTKFile(tok_.f_name()) );
192  else {
193  if (is_point) tok_.skip_to("DataArray");
194  header.position = tok_.get_position();
195  }
196  } else {
197  THROW(ExcUnknownFormat() << EI_FieldName(header.field_name) << EI_VTKFile(tok_.f_name()) );
198  }
199 
200  return header;
201 }
202 
203 
205 {
206  pugi::xml_document doc;
207  doc.load_file( tok_.f_name().c_str() );
208  unsigned int n_nodes, n_elements;
209  this->read_base_vtk_attributes( doc.child("VTKFile"), n_nodes, n_elements );
210 
211  // open ifstream for find position
212  data_stream_ = new std::ifstream( tok_.f_name() );
213 
214  // data of appended tag
215  Tokenizer::Position appended_pos;
217  // no AppendedData tag
218  } else {
219  appended_pos = get_appended_position();
220  }
221 
222  pugi::xml_node node = doc.child("VTKFile").child("UnstructuredGrid").child("Piece");
223 
224  header_table_.clear();
225 
226  // create headers of Points and Cells DataArrays
227  auto points_header = create_header( node.child("Points").child("DataArray"), n_nodes, appended_pos,
228  OutputTime::DiscreteSpace::MESH_DEFINITION );
229  points_header.field_name = "Points";
230  header_table_.insert( std::pair<std::string, MeshDataHeader>("Points", points_header) );
231  auto con_header = create_header( node.child("Cells").find_child_by_attribute("DataArray", "Name", "connectivity"),
232  n_elements, appended_pos, OutputTime::DiscreteSpace::MESH_DEFINITION );
233  header_table_.insert( std::pair<std::string, MeshDataHeader>("connectivity", con_header) );
234  auto offsets_header = create_header( node.child("Cells").find_child_by_attribute("DataArray", "Name", "offsets"),
235  n_elements, appended_pos, OutputTime::DiscreteSpace::MESH_DEFINITION );
236  header_table_.insert( std::pair<std::string, MeshDataHeader>("offsets", offsets_header) );
237  auto types_header = create_header( node.child("Cells").find_child_by_attribute("DataArray", "Name", "types"), n_elements,
238  appended_pos, OutputTime::DiscreteSpace::MESH_DEFINITION );
239  header_table_.insert( std::pair<std::string, MeshDataHeader>("types", types_header) );
240 
241  pugi::xml_node point_node = node.child("PointData");
242  for (pugi::xml_node subnode = point_node.child("DataArray"); subnode; subnode = subnode.next_sibling("DataArray")) {
243  auto header = create_header( subnode, n_nodes, appended_pos, OutputTime::DiscreteSpace::NODE_DATA );
244  header_table_.insert( std::pair<std::string, MeshDataHeader>(header.field_name, header) );
245  }
246 
247  pugi::xml_node cell_node = node.child("CellData");
248  for (pugi::xml_node subnode = cell_node.child("DataArray"); subnode; subnode = subnode.next_sibling("DataArray")) {
249  auto header = create_header( subnode, n_elements, appended_pos, OutputTime::DiscreteSpace::ELEM_DATA );
250  header_table_.insert( std::pair<std::string, MeshDataHeader>(header.field_name, header) );
251  }
252 
253  pugi::xml_node native_node = node.child("Flow123dData");
254  for (pugi::xml_node subnode = native_node.child("DataArray"); subnode; subnode = subnode.next_sibling("DataArray")) {
255  auto header = create_header( subnode, n_elements, appended_pos, OutputTime::DiscreteSpace::NATIVE_DATA );
256  header_table_.insert( std::pair<std::string, MeshDataHeader>(header.field_name, header) );
257  }
258 }
259 
260 
262 {
263  unsigned int count = header_table_.count(header_query.field_name);
264 
265  if (count == 0) {
266  // no data found
267  THROW( ExcFieldNameNotFound() << EI_FieldName(header_query.field_name) << EI_MeshFile(tok_.f_name()));
268  } else if (count == 1) {
269  HeaderTable::iterator table_it = header_table_.find(header_query.field_name);
270 
271  // check discretization
272  if (header_query.discretization != table_it->second.discretization) {
273  if (header_query.discretization != OutputTime::DiscreteSpace::UNDEFINED) {
274  WarningOut().fmt(
275  "Invalid value of 'input_discretization' for field '{}', time: {}.\nCorrect discretization type will be used.\n",
276  header_query.field_name, header_query.time);
277  }
278  header_query.discretization = table_it->second.discretization;
279  }
280 
281  if (header_query.discretization == OutputTime::DiscreteSpace::NATIVE_DATA)
282  if (header_query.dof_handler_hash != table_it->second.dof_handler_hash) {
283  THROW(ExcInvalidDofHandler() << EI_FieldName(header_query.field_name) << EI_VTKFile(tok_.f_name()) );
284  }
285  actual_header_ = table_it->second;
286  } else {
287  /*HeaderTable::iterator table_it;
288  for (table_it=header_table_.equal_range(header_query.field_name).first; table_it!=header_table_.equal_range(header_query.field_name).second; ++table_it) {
289  if (header_query.discretization != table_it->second.discretization) {
290  header_query.dof_handler_hash = table_it->second.dof_handler_hash;
291  actual_header_ = table_it->second;
292  }
293  }*/
294  THROW( ExcMissingFieldDiscretization() << EI_FieldName(header_query.field_name) << EI_Time(header_query.time) << EI_MeshFile(tok_.f_name()));
295  }
296 
297  return actual_header_;
298 }
299 
300 
301 
302 DataType VtkMeshReader::get_data_type(std::string type_str) {
303  // names of types in DataArray section
304  static const std::map<std::string, DataType> types = {
305  {"Int8", DataType::int8},
306  {"UInt8", DataType::uint8},
307  {"Int16", DataType::int16},
308  {"UInt16", DataType::uint16},
309  {"Int32", DataType::int32},
310  {"UInt32", DataType::uint32},
311  {"Int64", DataType::int64},
312  {"UInt64", DataType::uint64},
313  {"Float32", DataType::float32},
314  {"Float64", DataType::float64},
315  {"", DataType::undefined}
316  };
317 
319  if (it != types.end()) {
320  return it->second;
321  } else {
322  THROW( ExcWrongType() << EI_ErrMessage("Unknown") << EI_VTKFile(tok_.f_name()));
323  return DataType::uint32;
324  }
325 
326 }
327 
328 
329 
331 {
332  static const std::vector<unsigned int> sizes = { 1, 1, 2, 2, 4, 4, 8, 8, 4, 8, 0 };
333 
334  return sizes[data_type];
335 }
336 
337 
338 
339 void VtkMeshReader::read_element_data(ElementDataCacheBase &data_cache, MeshDataHeader actual_header, unsigned int n_components,
340  bool boundary_domain) {
341 
342  ASSERT(!boundary_domain).error("Reading VTK data of boundary elements is not supported yet!\n");
343 
344  switch (data_format_) {
345  case DataFormat::ascii: {
346  parse_ascii_data( data_cache, n_components, actual_header.n_entities, actual_header.position );
347  break;
348  }
349  case DataFormat::binary_uncompressed: {
350  ASSERT_PTR(data_stream_).error();
351  parse_binary_data( data_cache, n_components, actual_header.n_entities, actual_header.position);
352  break;
353  }
354  case DataFormat::binary_zlib: {
355  ASSERT_PTR(data_stream_).error();
356  parse_compressed_data( data_cache, n_components, actual_header.n_entities, actual_header.position);
357  break;
358  }
359  default: {
360  ASSERT(false).error(); // should not happen
361  break;
362  }
363  }
364 
365  LogOut().fmt("time: {}; {} entities of field {} read.\n",
366  actual_header.time, n_read_, actual_header.field_name);
367 }
368 
369 
370 void VtkMeshReader::parse_ascii_data(ElementDataCacheBase &data_cache, unsigned int n_components, unsigned int n_entities,
371  Tokenizer::Position pos)
372 {
373  n_read_ = 0;
374 
375  tok_.set_position( pos );
376  try {
377  tok_.next_line();
378  for (unsigned int i_row = 0; i_row < n_entities; ++i_row) {
379  data_cache.read_ascii_data(tok_, n_components, i_row);
380  n_read_++;
381  }
382  } catch (boost::bad_lexical_cast &) {
383  THROW(ExcWrongFormat() << EI_Type("DataArray tag") << EI_TokenizerMsg(tok_.position_msg())
384  << EI_MeshFile(tok_.f_name()) );
385  }
386 }
387 
388 
389 void VtkMeshReader::parse_binary_data(ElementDataCacheBase &data_cache, unsigned int n_components, unsigned int n_entities,
390  Tokenizer::Position pos)
391 {
392  n_read_ = 0;
393 
394  data_stream_->seekg(pos.file_position_);
396 
397  for (unsigned int i_row = 0; i_row < n_entities; ++i_row) {
398  data_cache.read_binary_data(*data_stream_, n_components, i_row);
399  n_read_++;
400  }
401 }
402 
403 
404 void VtkMeshReader::parse_compressed_data(ElementDataCacheBase &data_cache, unsigned int n_components, unsigned int n_entities,
405  Tokenizer::Position pos)
406 {
407  data_stream_->seekg(pos.file_position_);
408  uint64_t n_blocks = read_header_type(header_type_, *data_stream_);
409  uint64_t u_size = read_header_type(header_type_, *data_stream_);
410  uint64_t p_size = read_header_type(header_type_, *data_stream_);
411 
412  std::vector<uint64_t> block_sizes;
413  block_sizes.reserve(n_blocks);
414  for (uint64_t i = 0; i < n_blocks; ++i) {
415  block_sizes.push_back( read_header_type(header_type_, *data_stream_) );
416  }
417 
418  stringstream decompressed_data;
419  uint64_t decompressed_data_size = 0;
420  for (uint64_t i = 0; i < n_blocks; ++i) {
421  uint64_t decompressed_block_size = (i==n_blocks-1 && p_size>0) ? p_size : u_size;
422  uint64_t compressed_block_size = block_sizes[i];
423 
424  std::vector<char> data_block(compressed_block_size);
425  data_stream_->read(&data_block[0], compressed_block_size);
426 
427  std::vector<char> buffer(decompressed_block_size);
428 
429  // set zlib object
430  z_stream strm;
431  strm.zalloc = 0;
432  strm.zfree = 0;
433  strm.next_in = (Bytef *)(&data_block[0]);
434  strm.avail_in = compressed_block_size;
435  strm.next_out = (Bytef *)(&buffer[0]);
436  strm.avail_out = decompressed_block_size;
437 
438  // decompression of data
439  inflateInit(&strm);
440  inflate(&strm, Z_NO_FLUSH);
441  inflateEnd(&strm);
442 
443  // store decompressed data to stream
444  decompressed_data << std::string(buffer.begin(), buffer.end());
445  decompressed_data_size += decompressed_block_size;
446  }
447 
448  n_read_ = 0;
449 
450  for (unsigned int i_row = 0; i_row < n_entities; ++i_row) {
451  data_cache.read_binary_data(decompressed_data, n_components, i_row);
452  n_read_++;
453  }
454 }
455 
456 
458  // will be implemented later
459  // ASSERT(0).error("Not implemented!");
460 }
461 
462 
465 
466  ElementDataFieldMap::iterator it=element_data_values_->find("Points");
467  ASSERT(it != element_data_values_->end()).error("Missing cache of Points section. Did you call create_node_element_caches()?\n");
468 
469  // create nodes of mesh
470  std::vector<double> &vect = *( dynamic_cast<ElementDataCache<double> &>(*(it->second)).get_component_data(0).get() );
471  unsigned int n_nodes = vect.size()/3;
472  mesh->init_node_vector( n_nodes );
473  arma::vec3 point;
474  for (unsigned int i=0, ivec=0; i<n_nodes; ++i) {
475  point(0)=vect[ivec]; ++ivec;
476  point(1)=vect[ivec]; ++ivec;
477  point(2)=vect[ivec]; ++ivec;
478  mesh->add_node(i, point);
479  }
480 
481  bulk_elements_id_.clear();
482 }
483 
484 
486  // read offset section in VTK file
487  ElementDataFieldMap::iterator offset_it=element_data_values_->find("offsets");
488  ASSERT(offset_it != element_data_values_->end()).error("Missing cache of offsets section. Did you call create_node_element_caches()?\n");
489  std::vector<unsigned int> &offsets_vec = *( dynamic_cast<ElementDataCache<unsigned int> &>(*(offset_it->second)).get_component_data(0).get() );
490 
491  // read connectivity data section
492  ElementDataFieldMap::iterator conn_it=element_data_values_->find("connectivity");
493  ASSERT(conn_it != element_data_values_->end()).error("Missing cache of offsets section. Did you call create_node_element_caches()?\n");
494  std::vector<unsigned int> &connectivity_vec = *( dynamic_cast<ElementDataCache<unsigned int> &>(*(conn_it->second)).get_component_data(0).get() );
495 
496  // iterate trough connectivity data, create bulk elements
497  // fill bulk_elements_id_ vector
498  bulk_elements_id_.clear();
499  bulk_elements_id_.resize(offsets_vec.size());
500  mesh->init_element_vector(offsets_vec.size());
501  unsigned int i_con = 0, last_offset=0, dim;
502  vector<unsigned int> node_list;
503  for (unsigned int i=0; i<offsets_vec.size(); ++i) { // iterate trough offset - one value for every element
504  dim = offsets_vec[i] - last_offset - 1; // dimension of vtk element
505  for ( ; i_con<offsets_vec[i]; ++i_con ) { // iterate trough all nodes of any element
506  node_list.push_back( connectivity_vec[i_con] );
507  }
508  mesh->add_element(i, dim, dim, 0, node_list); // TODO need to set region_id (3rd parameter, now is created from dim)
509  bulk_elements_id_[i] = (LongIdx)i;
510  node_list.clear();
511  last_offset = offsets_vec[i];
512  }
513 
514  mesh->create_boundary_elements();
515 }
516 
517 
519  ElementDataFieldMap::iterator it=element_data_values_->find("Points");
520  if ( it != element_data_values_->end() ) {
521  // prevents repeat call of read_nodes
522  return;
523  }
524 
525  ASSERT( !has_compatible_mesh_ ).error();
526 
527  has_compatible_mesh_ = true;
528 
529  // read Points data section
530  HeaderQuery header_params("Points", 0.0, OutputTime::DiscreteSpace::MESH_DEFINITION);
531  auto point_header = this->find_header(header_params);
532  bulk_elements_id_.resize(point_header.n_entities);
533  for (unsigned int i=0; i<bulk_elements_id_.size(); ++i) bulk_elements_id_[i]=i;
534  this->get_element_data<double>(point_header.n_entities, point_header.n_components, false, 0 );
535 
536  // read offset data section
537  HeaderQuery offsets_params("offsets", 0.0, OutputTime::DiscreteSpace::MESH_DEFINITION);
538  auto offset_header = this->find_header(offsets_params);
539  for (unsigned int i=bulk_elements_id_.size(); i<offset_header.n_entities; ++i) bulk_elements_id_.push_back(i);
540  std::vector<unsigned int> &offsets_vec = *( this->get_element_data<unsigned int>(offset_header.n_entities, offset_header.n_components, false, 0 ) );
541 
542  // read connectivity data section
543  HeaderQuery con_params("connectivity", 0.0, OutputTime::DiscreteSpace::MESH_DEFINITION);
544  auto & con_header = this->find_header(con_params);
545  con_header.n_entities = offsets_vec[offsets_vec.size()-1];
546  for (unsigned int i=bulk_elements_id_.size(); i<con_header.n_entities; ++i) bulk_elements_id_.push_back(i);
547  this->get_element_data<unsigned int>(con_header.n_entities, con_header.n_components, false, 0 );
548 
549  has_compatible_mesh_ = false;
550  bulk_elements_id_.clear();
551 }
552 
553 
554 
555 // explicit instantiation of template methods
556 template unsigned int read_binary_value<unsigned int>(std::istream &data_stream);
557 template uint64_t read_binary_value<uint64_t>(std::istream &data_stream);
MeshDataHeader create_header(pugi::xml_node node, unsigned int n_entities, Tokenizer::Position pos, OutputTime::DiscreteSpace disc)
Helper method that create DataArray header of given xml node (used from make_header_table) ...
void make_header_table() override
Reads table of DataArray headers through pugixml interface.
void parse_binary_data(ElementDataCacheBase &data_cache, unsigned int n_components, unsigned int n_entities, Tokenizer::Position pos)
Parse binary data to data cache.
double time_step_
time of VTK file (getting only during initialization from PVD reader)
DataType type
Type of data (used only for VTK reader)
HeaderTable header_table_
Table with data of DataArray headers.
void read_nodes(Mesh *mesh)
void init_element_vector(unsigned int size)
Initialize element_vec_, set size and reset counters of boundary and bulk elements.
Definition: mesh.cc:1210
static const double point_tolerance
Tolerance during comparison point data with GMSH nodes.
DataFormat data_format_
variants of data format (ascii, appended, compressed appended)
template unsigned int read_binary_value< unsigned int >(std::istream &data_stream)
void add_node(unsigned int node_id, arma::vec3 coords)
Add new node of given id and coordinates to mesh.
Definition: mesh.cc:1150
VtkMeshReader(const FilePath &file_name)
template uint64_t read_binary_value< uint64_t >(std::istream &data_stream)
std::shared_ptr< ElementDataFieldMap > element_data_values_
Cache with last read element data.
unsigned int create_boundary_elements()
Create boundary elements from data of temporary structure, this method MUST be call after read mesh f...
Definition: mesh.cc:1349
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3141
std::string field_name
Name of field.
void read_base_vtk_attributes(pugi::xml_node vtk_node, unsigned int &n_nodes, unsigned int &n_elements)
Set base attributes of VTK and get count of nodes and elements.
Definition: mesh.h:77
DataType get_data_type(std::string type_str)
Get DataType by value of string.
std::string data_section_name_
Store name of field data section specify for type of mesh file.
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:347
#define LogOut()
Macro defining &#39;log&#39; record of log.
Definition: logger.hh:273
std::size_t dof_handler_hash
Hash of DOF handler object.
unsigned int n_entities
Number of rows.
uint64_t read_header_type(DataType data_header_type, std::istream &data_stream)
MeshDataHeader & find_header(HeaderQuery &header_query) override
void read_physical_names(Mesh *mesh) override
std::istream * data_stream_
input stream allow read appended data, used only if this tag exists
virtual void read_ascii_data(Tokenizer &tok, unsigned int n_components, unsigned int i_row)=0
virtual ~VtkMeshReader()
Destructor.
OutputTime::DiscreteSpace discretization
Flag marks input discretization of data of VTK file.
DataType header_type_
header type of VTK file (only for appended data)
void parse_compressed_data(ElementDataCacheBase &data_cache, unsigned int n_components, unsigned int n_entities, Tokenizer::Position pos)
Uncompress and parse binary compressed data to data cache.
std::string field_name
Name of field.
unsigned int n_read_
store count of read entities
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
void read_elements(Mesh *mesh)
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Definition: index_types.hh:24
Tokenizer::Position position
Position of data in mesh file.
OutputTime::DiscreteSpace discretization
Flag determinate type of discrete of Field (typically is used for native data of VTK) ...
double time
Time of field data (used only for GMSH reader)
void create_node_element_caches()
void parse_ascii_data(ElementDataCacheBase &data_cache, unsigned int n_components, unsigned int n_entities, Tokenizer::Position pos)
Parse ascii data to data cache.
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
Definition: asserts.hh:336
T read_binary_value(std::istream &data_stream)
void read_element_data(ElementDataCacheBase &data_cache, MeshDataHeader actual_header, unsigned int n_components, bool boundary_domain) override
unsigned int n_components
Number of values on one row.
double time
Time of field data (used only for GMSH and PVD reader)
ComponentDataPtr get_component_data(unsigned int component_idx)
Return vector of element data for get component.
MeshDataHeader actual_header_
Header of actual loaded data.
#define WarningOut()
Macro defining &#39;warning&#39; record of log.
Definition: logger.hh:270
void add_element(unsigned int elm_id, unsigned int dim, unsigned int region_id, unsigned int partition_id, std::vector< unsigned int > node_ids)
Add new element of given id to mesh.
Definition: mesh.cc:1158
DataType
Types of VTK data (value &#39;undefined&#39; for empty value)
Tokenizer tok_
Tokenizer used for reading ASCII file format.
virtual void read_binary_data(std::istream &data_stream, unsigned int n_components, unsigned int i_row)=0
unsigned int type_value_size(DataType data_type)
Return size of value of data_type.
std::size_t dof_handler_hash
Hash of DOF handler object (only for native data of VTK file)
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:53
Tokenizer::Position get_appended_position()
Get position of AppendedData tag in VTK file.
void init_node_vector(unsigned int size)
Initialize node_vec_, set size.
Definition: mesh.cc:1224
vector< LongIdx > bulk_elements_id_