From: Wolfgang Bangerth Date: Thu, 8 May 2014 23:41:35 +0000 (+0000) Subject: Patch by Giorgos Kourakos: Make GridIn::read_vtk less rigid. X-Git-Tag: v8.2.0-rc1~511 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49d74747db47da5155c63670a8263f84a1be07b3;p=dealii.git Patch by Giorgos Kourakos: Make GridIn::read_vtk less rigid. git-svn-id: https://svn.dealii.org/trunk@32894 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index e52d5cf9ad..92d4fcfcd6 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -148,7 +148,14 @@ inconvenience this causes.

Specific improvements

    -
  1. New: There is now a QSorted quadrature which takes an +
  2. New: The GridIn::read_vtk() function places fewer restrictions + on the VTK files it wants to read and should, consequently, be able + to read more correctly formatted VTK files than before. +
    + (Giorgos Kourakos, 2014/05/08) +
  3. + +
  4. New: There is now a QSorted quadrature which takes an arbitrary quadrature at construction time and reorders the quadrature points according to the weigths, from smaller to bigger. This should improve stability of higher order polynomial integration. diff --git a/deal.II/source/grid/grid_in.cc b/deal.II/source/grid/grid_in.cc index 52ae8a5187..024a708b2e 100644 --- a/deal.II/source/grid/grid_in.cc +++ b/deal.II/source/grid/grid_in.cc @@ -57,20 +57,27 @@ void GridIn::read_vtk(std::istream &in) { Assert((dim == 2)||(dim == 3), ExcNotImplemented()); std::string line; - std::string text[4]; - text[0] = "# vtk DataFile Version 3.0"; - text[1] = "vtk output"; - text[2] = "ASCII"; - text[3] = "DATASET UNSTRUCTURED_GRID"; - for (unsigned int i = 0; i < 4; i++) //Checking for the match between initial strings/text in the file. + // verify that the first, third and fourth lines match + // expectations. the second line of the file may essentially be + // anything the author of the file chose to identify what's in + // there, so we just ensure that we can read it + { + std::string text[4]; + text[0] = "# vtk DataFile Version 3.0"; + text[1] = "****"; + text[2] = "ASCII"; + text[3] = "DATASET UNSTRUCTURED_GRID"; + + for (unsigned int i = 0; i < 4; ++i) { getline(in,line); - - AssertThrow (line.compare(text[i]) == 0, - ExcMessage(std::string("While reading VTK file, failed to find <") + - text[i] + ">")); + if (i != 1) + AssertThrow (line.compare(text[i]) == 0, + ExcMessage(std::string("While reading VTK file, failed to find a header line with text <") + + text[i] + ">")); } + } ///////////////////Declaring storage and mappings////////////////// @@ -150,6 +157,7 @@ void GridIn::read_vtk(std::istream &in) for (unsigned int j = 0; j < type; j++) //loop to feed data in >> cells.back().vertices[j]; + cells.back().material_id = 0; for (unsigned int j = 0; j < type; j++) //loop to feed the data of the vertices to the cell @@ -269,14 +277,14 @@ void GridIn::read_vtk(std::istream &in) for (unsigned int i = 0; i < 2; i++) { - getline(in,linenew); - - if (linenew.compare(textnew[i]) == 0) - {} - else - AssertThrow (false, - ExcMessage (std::string("While reading VTK file, failed to find <") + - textnew[i] + "> section")); + getline(in, linenew); + if (i == 0) + if (linenew.size() > textnew[0].size()) + linenew.resize(textnew[0].size()); + + AssertThrow (linenew.compare(textnew[i]) == 0, + ExcMessage (std::string("While reading VTK file, failed to find <") + + textnew[i] + "> section")); } for (unsigned int i = 0; i < no_cells; i++) //assigning IDs to cells. @@ -305,10 +313,6 @@ void GridIn::read_vtk(std::istream &in) } } } - else - AssertThrow (false, - ExcMessage ("While reading VTK file, failed to find CELL_DATA section")); - Assert(subcelldata.check_consistency(dim), ExcInternalError());