From: Wolfgang Bangerth Date: Thu, 17 Nov 2016 20:46:57 +0000 (-0700) Subject: More cleanups of GridIn::read_vtk(). X-Git-Tag: v8.5.0-rc1~383^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7125ec17aeb8b9ec5bdfa24ce51cc9ba85d8fd0;p=dealii.git More cleanups of GridIn::read_vtk(). Specifically, get rid of a pointless array. Make the assumption that underlies it explicit by adding assertions. --- diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index da43e25891..29801b640f 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -126,9 +126,6 @@ void GridIn::read_vtk(std::istream &in) std::vector< Point > vertices; std::vector< CellData > cells; SubCellData subcelldata; - std::map cell_indices; // # cell in unv (key) ---> # cell in deal.II (value) - - unsigned int n_vertices; std::string keyword; @@ -138,7 +135,9 @@ void GridIn::read_vtk(std::istream &in) if (keyword == "POINTS") { + unsigned int n_vertices; in >> n_vertices; + in.ignore(256, '\n');//ignoring the number beside the total no. of points. for (unsigned int vertex = 0; vertex < n_vertices; ++vertex) @@ -188,14 +187,19 @@ void GridIn::read_vtk(std::istream &in) if (type == 8) { + // we assume that the file contains first all cells, + // and only then any faces or lines + AssertThrow (subcelldata.boundary_quads.size() == 0 + && + subcelldata.boundary_lines.size() == 0, + ExcNotImplemented()); + cells.push_back(CellData()); for (unsigned int j = 0; j < type; j++) //loop to feed data in >> cells.back().vertices[j]; cells.back().material_id = 0; - - cell_indices[count] = count; } else if ( type == 4) @@ -223,14 +227,17 @@ void GridIn::read_vtk(std::istream &in) if (type == 4) { + // we assume that the file contains first all cells, + // and only then any faces + AssertThrow (subcelldata.boundary_lines.size() == 0, + ExcNotImplemented()); + cells.push_back(CellData()); for (unsigned int j = 0; j < type; j++) //loop to feed data in >> cells.back().vertices[j]; cells.back().material_id = 0; - - cell_indices[count] = count; } else if (type == 2) @@ -319,16 +326,20 @@ void GridIn::read_vtk(std::istream &in) textnew[i] + "> section")); } - for (unsigned int i = 0; i < cells.size(); i++) //assigning IDs to cells. + // read material ids first for all cells, then for all + // faces. the assumption that cells come before all faces + // has been verified above via an assertion, so the order + // used in the following blocks makes sense + for (unsigned int i = 0; i < cells.size(); i++) { double id; in >> id; - cells[cell_indices[i]].material_id = id; + cells[i].material_id = id; } if (dim == 3) { - for (unsigned int i = 0; i < subcelldata.boundary_quads.size(); i++) //assigning IDs to bounds. + for (unsigned int i = 0; i < subcelldata.boundary_quads.size(); i++) { double id; in >> id; @@ -337,7 +348,7 @@ void GridIn::read_vtk(std::istream &in) } else if (dim == 2) { - for (unsigned int i = 0; i < subcelldata.boundary_lines.size(); i++) //assigning IDs to bounds. + for (unsigned int i = 0; i < subcelldata.boundary_lines.size(); i++) { double id; in >> id;