From 639597a46bf20805c4be5b7099c5985f46107e3f Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Thu, 2 Apr 2020 12:58:18 +0200 Subject: [PATCH] Fix GridIn::read_vtk --- source/grid/grid_in.cc | 24 ++++++++++++++++-------- tests/grid/grid_in_vtk_2d/mesh | 4 ++-- tests/grid/grid_in_vtk_3d/mesh | 2 +- tests/grid/grid_in_vtk_3d_03.vtk | 10 +++++----- tests/grid/grid_in_vtk_3d_04.vtk | 2 +- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index 11a3881fde..38df964fad 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -381,11 +381,19 @@ GridIn::read_vtk(std::istream &in) // keyword. continue; - // Now we got somewhere. Proceed from here. - // Ignore everything till the end of the line. - // SCALARS MaterialID 1 + // Now we got somewhere. Proceed from here, assert + // that the type of the table is int, and ignore the + // rest of the line. + // SCALARS MaterialID int 1 // (the last number is optional) - in.ignore(256, '\n'); + std::string line; + std::getline(in, line); + AssertThrow( + line.substr(1, + std::min(static_cast(3), + line.size() - 1)) == "int", + ExcMessage( + "While reading VTK file, material- and manifold IDs can only have type 'int'.")); in >> keyword; AssertThrow( @@ -406,7 +414,7 @@ GridIn::read_vtk(std::istream &in) // the order used in the following blocks makes sense for (unsigned int i = 0; i < cells.size(); i++) { - double id; + int id; in >> id; if (field_name == "MaterialID") cells[i].material_id = @@ -422,7 +430,7 @@ GridIn::read_vtk(std::istream &in) { for (auto &boundary_quad : subcelldata.boundary_quads) { - double id; + int id; in >> id; if (field_name == "MaterialID") boundary_quad.material_id = @@ -435,7 +443,7 @@ GridIn::read_vtk(std::istream &in) } for (auto &boundary_line : subcelldata.boundary_lines) { - double id; + int id; in >> id; if (field_name == "MaterialID") boundary_line.material_id = @@ -451,7 +459,7 @@ GridIn::read_vtk(std::istream &in) { for (auto &boundary_line : subcelldata.boundary_lines) { - double id; + int id; in >> id; if (field_name == "MaterialID") boundary_line.material_id = diff --git a/tests/grid/grid_in_vtk_2d/mesh b/tests/grid/grid_in_vtk_2d/mesh index 71ed09807b..4ac38d72db 100644 --- a/tests/grid/grid_in_vtk_2d/mesh +++ b/tests/grid/grid_in_vtk_2d/mesh @@ -10,6 +10,6 @@ CELLS 1 5 CELL_TYPES 1 9 CELL_DATA 1 -SCALARS MaterialID double +SCALARS MaterialID int LOOKUP_TABLE default -1 \ No newline at end of file +1 diff --git a/tests/grid/grid_in_vtk_3d/mesh b/tests/grid/grid_in_vtk_3d/mesh index fe3cfab262..bbc46db271 100644 --- a/tests/grid/grid_in_vtk_3d/mesh +++ b/tests/grid/grid_in_vtk_3d/mesh @@ -631,7 +631,7 @@ CELL_TYPES 275 9 CELL_DATA 275 -SCALARS MaterialID double +SCALARS MaterialID int LOOKUP_TABLE default 0 0 20 20 0 0 20 20 20 0 20 0 20 0 20 20 0 20 diff --git a/tests/grid/grid_in_vtk_3d_03.vtk b/tests/grid/grid_in_vtk_3d_03.vtk index eda6a1af1e..e5aeea1e5f 100644 --- a/tests/grid/grid_in_vtk_3d_03.vtk +++ b/tests/grid/grid_in_vtk_3d_03.vtk @@ -34,9 +34,9 @@ CELL_TYPES 4 12 12 CELL_DATA 4 -SCALARS MaterialID double 1 +SCALARS MaterialID int 1 LOOKUP_TABLE default -1.000000 -2.000000 -3.000000 -4.000000 +1 +2 +3 +4 diff --git a/tests/grid/grid_in_vtk_3d_04.vtk b/tests/grid/grid_in_vtk_3d_04.vtk index 7cc98ea1e6..996c8ddfc4 100644 --- a/tests/grid/grid_in_vtk_3d_04.vtk +++ b/tests/grid/grid_in_vtk_3d_04.vtk @@ -1847,7 +1847,7 @@ CELL_TYPES 771 9 CELL_DATA 771 -SCALARS MaterialID double +SCALARS MaterialID int LOOKUP_TABLE default 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -- 2.39.5