22#include <vtkAbstractArray.h>
23#include <vtkCellArray.h>
24#include <vtkCellData.h>
25#include <vtkDoubleArray.h>
27#include <vtkIntArray.h>
28#include <vtkPointData.h>
30#include <vtkUnsignedCharArray.h>
31#include <vtkUnsignedIntArray.h>
37 d_reader_p = vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
38 d_reader_p->SetFileName(
const_cast<char *
>(f.c_str()));
45 if (model->
d_x.size() == 0)
55 d_grid_p = d_reader_p->GetOutput();
56 vtkIdType num_nodes = d_grid_p->GetNumberOfPoints();
58 if (num_nodes != model->
d_x.size()) {
59 throw std::runtime_error(
61 <<
"Error: Number of points data = " << num_nodes <<
62 " in file does not match the number of points = "
63 << model->
d_x.size() <<
". Aborting reading.\n");
67 for (
size_t i = 0; i < num_nodes; i++) {
71 d_grid_p->GetPoint(
id, x);
74 model->
setX(i, i_node);
78 vtkPointData *p_field = d_grid_p->GetPointData();
80 std::vector<std::string> tags = {
"Displacement",
"Velocity"};
81 for (
auto tag: tags) {
83 if (p_field->HasArray(tag.c_str())) {
84 vtkDataArray *array = p_field->GetArray(tag.c_str());
86 auto data_a = vtkSmartPointer<vtkDoubleArray>::New();
87 data_a->SetNumberOfComponents(3);
88 data_a->Allocate(3, 1);
90 for (
size_t i = 0; i < array->GetNumberOfTuples(); i++) {
91 array->GetTuples(i, i, data_a);
92 auto xi =
util::Point(data_a->GetValue(0), data_a->GetValue(1),
94 if (tag ==
"Displacement")
96 else if (tag ==
"Velocity")
101 if (tag ==
"Velocity") {
102 throw std::runtime_error(
104 <<
"Error: Restart file does not have <Velocity> data. "
105 "Aborting reading.\n");
106 }
else if (tag ==
"Displacement") {
108 for (
size_t i=0; i<model->
d_x.size(); i++)
A class to store model data.
std::vector< util::Point > d_x
Current positions of the nodes.
void setU(size_t i, const util::Point &u)
Set displacement of the node.
util::Point & getX(size_t i)
Get current coordinate of the node.
util::Point & getXRef(size_t i)
Get reference coordinate of the node.
void setV(size_t i, const util::Point &v)
Set velocity of the node.
void setX(size_t i, const util::Point &x)
Set current coordinate of the node.
void readNodes(data::ModelData *model)
Writes the nodes to the file.
VtkParticleReader(const std::string &filename)
Constructor.
void close()
Closes the file and store it to the hard disk.
vtkSmartPointer< vtkXMLUnstructuredGridReader > d_reader_p
XML unstructured grid writer.
Collects a message with stream syntax for use in an exception.
std::string checkAndCreateNewFilename(std::string const &filename, std::string filename_ext)
Check for extension and if possible create new filename from a given filename and a given extension.
A structure to represent 3d vectors.