From 5b8b94bdf2169ef6c273dfdfd46ab47f37394387 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 16 Nov 2016 20:10:00 -0700 Subject: [PATCH] More GridIn::write_vtk() cleanups. --- source/grid/grid_in.cc | 51 +++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index e86ac7e54c..da43e25891 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -123,14 +123,12 @@ void GridIn::read_vtk(std::istream &in) ///////////////////Declaring storage and mappings////////////////// - std::vector< Point > vertices;//vector of vertices - std::vector< CellData > cells;//vector of cells - SubCellData subcelldata;//subcell data that includes bounds and material IDs. + 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; - unsigned int n_quads=0; - unsigned int n_lines=0; std::string keyword; @@ -173,8 +171,6 @@ void GridIn::read_vtk(std::istream &in) in >> keyword; - unsigned int n_cells = 0; - ///////////////////Processing the CELLS section that contains cells(cells) and bound_quads(subcelldata)/////////////////////// if (keyword == "CELLS") @@ -200,7 +196,6 @@ void GridIn::read_vtk(std::istream &in) cells.back().material_id = 0; cell_indices[count] = count; - ++n_cells; } else if ( type == 4) @@ -209,9 +204,8 @@ void GridIn::read_vtk(std::istream &in) for (unsigned int j = 0; j < type; j++) //loop to feed the data to the boundary in >> subcelldata.boundary_quads.back().vertices[j]; - subcelldata.boundary_quads.back().material_id = 0; - ++n_quads; + subcelldata.boundary_quads.back().material_id = 0; } else @@ -237,7 +231,6 @@ void GridIn::read_vtk(std::istream &in) cells.back().material_id = 0; cell_indices[count] = count; - ++n_cells; } else if (type == 2) @@ -252,8 +245,6 @@ void GridIn::read_vtk(std::istream &in) } subcelldata.boundary_lines.back().material_id = 0; - - ++n_lines; } else @@ -287,25 +278,25 @@ void GridIn::read_vtk(std::istream &in) if (keyword == "CELL_DATA") { - unsigned int no_ids; - in >> no_ids; - - AssertThrow (no_ids == n_cells + (dim == 3 ? - n_quads : - (dim == 2 ? - n_lines - : - 0)), + unsigned int n_ids; + in >> n_ids; + + AssertThrow (n_ids == cells.size() + (dim == 3 ? + subcelldata.boundary_quads.size() : + (dim == 2 ? + subcelldata.boundary_lines.size() + : + 0)), ExcMessage ("The VTK reader found a CELL_DATA statement " "that lists a total of " - + Utilities::int_to_string (no_ids) + + + Utilities::int_to_string (n_ids) + " cell data objects, but this needs to " "equal the number of cells (which is " - + Utilities::int_to_string (n_cells) + + + Utilities::int_to_string (cells.size()) + ") plus the number of quads (" - + Utilities::int_to_string (n_quads) + + + Utilities::int_to_string (subcelldata.boundary_quads.size()) + " in 3d or the number of lines (" - + Utilities::int_to_string (n_lines) + + + Utilities::int_to_string (subcelldata.boundary_lines.size()) + ") in 2d.")); @@ -328,16 +319,16 @@ void GridIn::read_vtk(std::istream &in) textnew[i] + "> section")); } - for (unsigned int i = 0; i < n_cells; i++) //assigning IDs to cells. + for (unsigned int i = 0; i < cells.size(); i++) //assigning IDs to cells. { double id; - in>>id; + in >> id; cells[cell_indices[i]].material_id = id; } if (dim == 3) { - for (unsigned int i = 0; i < n_quads; i++) //assigning IDs to bounds. + for (unsigned int i = 0; i < subcelldata.boundary_quads.size(); i++) //assigning IDs to bounds. { double id; in >> id; @@ -346,7 +337,7 @@ void GridIn::read_vtk(std::istream &in) } else if (dim == 2) { - for (unsigned int i = 0; i < n_lines; i++) //assigning IDs to bounds. + for (unsigned int i = 0; i < subcelldata.boundary_lines.size(); i++) //assigning IDs to bounds. { double id; in >> id; -- 2.39.5