]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Patch by Giorgos Kourakos: Make GridIn::read_vtk less rigid.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 May 2014 23:41:35 +0000 (23:41 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 May 2014 23:41:35 +0000 (23:41 +0000)
git-svn-id: https://svn.dealii.org/trunk@32894 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/source/grid/grid_in.cc

index e52d5cf9ad4dd3ef53cdb3bb756b69ce26a3efbf..92d4fcfcd68719ac3c7214323150c9210ec45979 100644 (file)
@@ -148,7 +148,14 @@ inconvenience this causes.
 <h3>Specific improvements</h3>
 
 <ol>
-  <li> New: There is now a QSorted<dim> quadrature which takes an 
+  <li> 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.
+  <br>
+  (Giorgos Kourakos, 2014/05/08)
+  </li>  
+
+  <li> 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.
index 52ae8a51873aba3d074b7d940627a4bd7a413fec..024a708b2e0fc97cdb4012a4d4968d963f4bef43 100644 (file)
@@ -57,20 +57,27 @@ void GridIn<dim, spacedim>::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<dim, spacedim>::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<dim, spacedim>::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<dim, spacedim>::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());
 

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.