From 05ad2b9a9c7fe9e63bcf2c23757e42fe37c3f01a Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 20 Oct 2016 17:53:56 -0500 Subject: [PATCH] Fix GridIn::read_vtk(). The function reads a section of VTK files of the form CELL_DATA 4 SCALARS MaterialID double 1 LOOKUP_TABLE default 1.000000 2.000000 3.000000 4.000000 but internally (despite the fact that the field is declared as 'double' above) reads them as integers. This leads to wrong results if they are given as floating point numbers, as in the case above. While there also add an assertion an clean things up slightly. --- source/grid/grid_in.cc | 33 +++++++-- tests/grid/grid_in_vtk_3d_03.output | 108 ++++++++++++++-------------- 2 files changed, 80 insertions(+), 61 deletions(-) diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index 97de9881dd..b101d32742 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -307,8 +307,27 @@ void GridIn::read_vtk(std::istream &in) if (keyword == "CELL_DATA") { - int no_ids; - in>>no_ids; + unsigned int no_ids; + in >> no_ids; + + AssertThrow (no_ids == no_cells + (dim == 3 ? + no_quads : + (dim == 2 ? + no_lines + : + 0)), + ExcMessage ("The VTK reader found a CELL_DATA statement " + "that lists a total of " + + Utilities::int_to_string (no_ids) + + " cell data objects, but this needs to " + "equal the number of cells (which is " + + Utilities::int_to_string (no_cells) + + ") plus the number of quads (" + + Utilities::int_to_string (no_quads) + + " in 3d or the number of lines (" + + Utilities::int_to_string (no_lines) + + ") in 2d.")); + std::string linenew; std::string textnew[2]; @@ -331,7 +350,7 @@ void GridIn::read_vtk(std::istream &in) for (unsigned int i = 0; i < no_cells; i++) //assigning IDs to cells. { - int id; + double id; in>>id; cells[cell_indices[i]].material_id = id; } @@ -340,8 +359,8 @@ void GridIn::read_vtk(std::istream &in) { for (unsigned int i = 0; i < no_quads; i++) //assigning IDs to bounds. { - int id; - in>>id; + double id; + in >> id; subcelldata.boundary_quads[quad_indices[i]].material_id = id; } } @@ -349,8 +368,8 @@ void GridIn::read_vtk(std::istream &in) { for (unsigned int i = 0; i < no_lines; i++) //assigning IDs to bounds. { - int id; - in>>id; + double id; + in >> id; subcelldata.boundary_lines[line_indices[i]].material_id = id; } } diff --git a/tests/grid/grid_in_vtk_3d_03.output b/tests/grid/grid_in_vtk_3d_03.output index 2293dc9500..80c3135d2d 100644 --- a/tests/grid/grid_in_vtk_3d_03.output +++ b/tests/grid/grid_in_vtk_3d_03.output @@ -24,75 +24,75 @@ DEAL:: 20 4 0.0 10. 10. 0 1 0.0 10. 0.0 0 1 -10. 0.0 10. 0 0 -20. 0.0 10. 0 0 -20. 10. 10. 0 0 -10. 10. 10. 0 0 -10. 0.0 10. 0 0 +10. 0.0 10. 0 2 +20. 0.0 10. 0 2 +20. 10. 10. 0 2 +10. 10. 10. 0 2 +10. 0.0 10. 0 2 -10. 0.0 0.0 0 0 -20. 0.0 0.0 0 0 -20. 10. 0.0 0 0 -10. 10. 0.0 0 0 -10. 0.0 0.0 0 0 +10. 0.0 0.0 0 2 +20. 0.0 0.0 0 2 +20. 10. 0.0 0 2 +10. 10. 0.0 0 2 +10. 0.0 0.0 0 2 -10. 0.0 10. 0 0 -10. 0.0 0.0 0 0 +10. 0.0 10. 0 2 +10. 0.0 0.0 0 2 -20. 0.0 10. 0 0 -20. 0.0 0.0 0 0 +20. 0.0 10. 0 2 +20. 0.0 0.0 0 2 -20. 10. 10. 0 0 -20. 10. 0.0 0 0 +20. 10. 10. 0 2 +20. 10. 0.0 0 2 -10. 10. 10. 0 0 -10. 10. 0.0 0 0 +10. 10. 10. 0 2 +10. 10. 0.0 0 2 -10. 10. 10. 0 0 -20. 10. 10. 0 0 -20. 20. 10. 0 0 -10. 20. 10. 0 0 -10. 10. 10. 0 0 +10. 10. 10. 0 3 +20. 10. 10. 0 3 +20. 20. 10. 0 3 +10. 20. 10. 0 3 +10. 10. 10. 0 3 -10. 10. 0.0 0 0 -20. 10. 0.0 0 0 -20. 20. 0.0 0 0 -10. 20. 0.0 0 0 -10. 10. 0.0 0 0 +10. 10. 0.0 0 3 +20. 10. 0.0 0 3 +20. 20. 0.0 0 3 +10. 20. 0.0 0 3 +10. 10. 0.0 0 3 -10. 10. 10. 0 0 -10. 10. 0.0 0 0 +10. 10. 10. 0 3 +10. 10. 0.0 0 3 -20. 10. 10. 0 0 -20. 10. 0.0 0 0 +20. 10. 10. 0 3 +20. 10. 0.0 0 3 -20. 20. 10. 0 0 -20. 20. 0.0 0 0 +20. 20. 10. 0 3 +20. 20. 0.0 0 3 -10. 20. 10. 0 0 -10. 20. 0.0 0 0 +10. 20. 10. 0 3 +10. 20. 0.0 0 3 -20. 10. 10. 0 0 -30. 10. 10. 0 0 -30. 20. 10. 0 0 -20. 20. 10. 0 0 -20. 10. 10. 0 0 +20. 10. 10. 0 4 +30. 10. 10. 0 4 +30. 20. 10. 0 4 +20. 20. 10. 0 4 +20. 10. 10. 0 4 -20. 10. 0.0 0 0 -30. 10. 0.0 0 0 -30. 20. 0.0 0 0 -20. 20. 0.0 0 0 -20. 10. 0.0 0 0 +20. 10. 0.0 0 4 +30. 10. 0.0 0 4 +30. 20. 0.0 0 4 +20. 20. 0.0 0 4 +20. 10. 0.0 0 4 -20. 10. 10. 0 0 -20. 10. 0.0 0 0 +20. 10. 10. 0 4 +20. 10. 0.0 0 4 -30. 10. 10. 0 0 -30. 10. 0.0 0 0 +30. 10. 10. 0 4 +30. 10. 0.0 0 4 -30. 20. 10. 0 0 -30. 20. 0.0 0 0 +30. 20. 10. 0 4 +30. 20. 0.0 0 4 -20. 20. 10. 0 0 -20. 20. 0.0 0 0 +20. 20. 10. 0 4 +20. 20. 0.0 0 4 -- 2.39.5