Flow123d  release_3.0.0-968-gc87a28e79
msh_pvdreader.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_pvdreader.cc
15  * @brief
16  * @author dalibor
17  */
18 
19 
20 #include <iostream>
21 #include <vector>
22 #include <pugixml.hpp>
23 
24 #include "msh_pvdreader.hh"
25 #include "msh_vtkreader.hh"
26 
27 
28 
30 : BaseMeshReader(file_name)
31 {
32  data_section_name_ = "DataArray";
33  has_compatible_mesh_ = false;
34  pvd_path_dir_ = file_name.parent_path();
36 }
37 
38 
40 {
41  for (auto file_data : file_list_) {
42  if (file_data.reader != nullptr) delete file_data.reader;
43  }
44 }
45 
46 
48  // will be implemented later
49 }
50 
51 
53  file_list_[0].reader = new VtkMeshReader(file_list_[0].file_name, this->element_data_values_, file_list_[0].time);
54  file_list_[0].reader->read_nodes(mesh);
55 }
56 
57 
59  file_list_[0].reader->read_elements(mesh);
60 }
61 
62 
63 void PvdMeshReader::read_element_data(ElementDataCacheBase &data_cache, MeshDataHeader actual_header, unsigned int n_components,
64  bool boundary_domain) {
65 
66  ASSERT(!boundary_domain).error("Reading PVD data of boundary elements is not supported yet!\n");
67  list_it_->reader->read_element_data(data_cache, actual_header, n_components, boundary_domain);
68 }
69 
70 
72  ASSERT(file_list_.size()).error("Empty PVD file, no DataSet tag found.\n");
73  ASSERT(file_list_[0].reader == nullptr).error("Method check_compatible_mesh must be called as first, before reading element data.\n");
74 
75  file_list_[0].reader = new VtkMeshReader(file_list_[0].file_name, this->element_data_values_, file_list_[0].time);
76  file_list_[0].reader->check_compatible_mesh(mesh);
77 
78  this->bulk_elements_id_ = file_list_[0].reader->bulk_elements_id_;
79  this->boundary_elements_id_ = file_list_[0].reader->boundary_elements_id_;
80  this->has_compatible_mesh_ = true;
81 }
82 
83 
85  pugi::xml_document doc;;
86  doc.load_file( tok_.f_name().c_str() );
87  pugi::xml_node node = doc.child("VTKFile").child("Collection");
88 
89  double last_time = -numeric_limits<double>::infinity(); // check ascending order of times
90  std::vector<std::string> sub_paths; //allow construct paths of VTK files
91  sub_paths.resize(2);
92  sub_paths[0] = pvd_path_dir_;
93 
94  // read PVD data
95  for (pugi::xml_node subnode = node.child("DataSet"); subnode; subnode = subnode.next_sibling("DataSet")) {
96  double time = subnode.attribute("timestep").as_double();
97  if (time <= last_time) {
98  WarningOut().fmt("Wrong time order in PVD file '{}', time '{}'. Skipping this time step.\n", tok_.f_name(), time );
99  } else {
100  sub_paths[1] = subnode.attribute("file").as_string();
101  FilePath vtk_path(sub_paths, FilePath::input_file);
102  last_time = time;
103  file_list_.push_back( VtkFileData(time, vtk_path) );
104  }
105  }
106 }
107 
108 
110  auto comp = [](double t, const VtkFileData &a) {
111  return t * (1.0 + 2.0*numeric_limits<double>::epsilon()) < a.time;
112  };
113 
114  // find iterator to data of VTK file
115  list_it_ = std::upper_bound(file_list_.begin(),
116  file_list_.end(),
117  header_query.time,
118  comp);
119  --list_it_;
120 
121  // check if VTK reader exists and eventually creates its
122  if (!list_it_->reader) {
123  list_it_->reader = new VtkMeshReader(list_it_->file_name, this->element_data_values_, list_it_->time);
124  list_it_->reader->bulk_elements_id_ = this->bulk_elements_id_;
125  list_it_->reader->boundary_elements_id_ = this->boundary_elements_id_;
126  list_it_->reader->has_compatible_mesh_ = true;
127  }
128 
129  actual_header_ = list_it_->reader->find_header(header_query);
130  return actual_header_;
131 }
132 
PvdMeshReader::find_header
MeshDataHeader & find_header(HeaderQuery &header_query) override
Definition: msh_pvdreader.cc:109
BaseMeshReader::actual_header_
MeshDataHeader actual_header_
Header of actual loaded data.
Definition: msh_basereader.hh:263
BaseMeshReader::tok_
Tokenizer tok_
Tokenizer used for reading ASCII file format.
Definition: msh_basereader.hh:256
BaseMeshReader::boundary_elements_id_
vector< LongIdx > boundary_elements_id_
Definition: msh_basereader.hh:260
PvdMeshReader::check_compatible_mesh
void check_compatible_mesh(Mesh &mesh) override
Definition: msh_pvdreader.cc:71
ASSERT
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:346
PvdMeshReader::read_physical_names
void read_physical_names(Mesh *mesh) override
Definition: msh_pvdreader.cc:47
FilePath
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
PvdMeshReader::make_header_table
void make_header_table() override
Definition: msh_pvdreader.cc:84
VtkMeshReader
Definition: msh_vtkreader.hh:40
std::vector< std::string >
PvdMeshReader::VtkFileData
Represents data of one VTK file defined in PVD file.
Definition: msh_pvdreader.hh:70
PvdMeshReader::pvd_path_dir_
std::string pvd_path_dir_
Path to PVD file allows construct FilePath objects of VTK files.
Definition: msh_pvdreader.hh:106
PvdMeshReader::file_list_
std::vector< VtkFileData > file_list_
Store list of VTK files and time steps declared in PVD file.
Definition: msh_pvdreader.hh:103
FilePath::parent_path
string parent_path() const
Definition: file_path.cc:183
PvdMeshReader::read_nodes
void read_nodes(Mesh *mesh) override
Definition: msh_pvdreader.cc:52
PvdMeshReader::read_elements
void read_elements(Mesh *mesh) override
Definition: msh_pvdreader.cc:58
BaseMeshReader::element_data_values_
std::shared_ptr< ElementDataFieldMap > element_data_values_
Cache with last read element data.
Definition: msh_basereader.hh:253
PvdMeshReader::PvdMeshReader
PvdMeshReader(const FilePath &file_name)
Definition: msh_pvdreader.cc:29
BaseMeshReader
Definition: msh_basereader.hh:58
PvdMeshReader::~PvdMeshReader
~PvdMeshReader()
Destructor.
Definition: msh_pvdreader.cc:39
ElementDataCacheBase
Definition: element_data_cache_base.hh:33
msh_pvdreader.hh
PvdMeshReader::list_it_
std::vector< VtkFileData >::iterator list_it_
Iterator to items of file_list_.
Definition: msh_pvdreader.hh:109
BaseMeshReader::MeshDataHeader
Definition: msh_basereader.hh:100
Mesh
Definition: mesh.h:80
WarningOut
#define WarningOut()
Macro defining 'warning' record of log.
Definition: logger.hh:246
FilePath::input_file
@ input_file
Definition: file_path.hh:68
msh_vtkreader.hh
PvdMeshReader::read_element_data
void read_element_data(ElementDataCacheBase &data_cache, MeshDataHeader actual_header, unsigned int n_components, bool boundary_domain) override
Definition: msh_pvdreader.cc:63
BaseMeshReader::data_section_name_
std::string data_section_name_
Store name of field data section specify for type of mesh file.
Definition: msh_basereader.hh:250
BaseMeshReader::MeshDataHeader::time
double time
Time of field data (used only for GMSH reader)
Definition: msh_basereader.hh:125
BaseMeshReader::HeaderQuery::time
double time
Time of field data (used only for GMSH and PVD reader)
Definition: msh_basereader.hh:138
BaseMeshReader::has_compatible_mesh_
bool has_compatible_mesh_
Definition: msh_basereader.hh:247
BaseMeshReader::HeaderQuery
Definition: msh_basereader.hh:132
BaseMeshReader::bulk_elements_id_
vector< LongIdx > bulk_elements_id_
Definition: msh_basereader.hh:260