]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix GridIn::read_vtk 9795/head
authorPeter Munch <peterrmuench@gmail.com>
Thu, 2 Apr 2020 10:58:18 +0000 (12:58 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Sun, 5 Apr 2020 08:45:25 +0000 (10:45 +0200)
source/grid/grid_in.cc
tests/grid/grid_in_vtk_2d/mesh
tests/grid/grid_in_vtk_3d/mesh
tests/grid/grid_in_vtk_3d_03.vtk
tests/grid/grid_in_vtk_3d_04.vtk

index 11a3881fde80b15a8ec4393ffc27fbecac3cf9af..38df964fad0acc7562707045b498f4af43724470 100644 (file)
@@ -381,11 +381,19 @@ GridIn<dim, spacedim>::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<std::size_t>(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<dim, spacedim>::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<dim, spacedim>::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<dim, spacedim>::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<dim, spacedim>::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 =
index 71ed09807b86511e776c3d3e17c4e587c7833a0e..4ac38d72db512c7a6a3f24541713031962785913 100644 (file)
@@ -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
index fe3cfab2625a578faa4dd964a10901fc38249e9d..bbc46db27197f2cbfe0030136a3cbc439ab31ad6 100644 (file)
@@ -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 
index eda6a1af1e96efb4f52cee134f92f003e9585d71..e5aeea1e5fdf64860d2314732c2d0718c51045a2 100644 (file)
@@ -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
index 7cc98ea1e692dbdc52f7463e373575e1f0ee831c..996c8ddfc408dd143d83f202bc7720be1c9113bf 100644 (file)
@@ -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 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.