From 1d06e4f946ac3593dc69fc97915eb94a36639fb4 Mon Sep 17 00:00:00 2001 From: kanschat Date: Mon, 12 May 2008 19:07:23 +0000 Subject: [PATCH] Previous version of GridIn::read_msh() could not handle files produced on a different computer with different newlines: fixed now GridIn::read_msh() now does not complain about types 15 (points) anymore. They are simply ignored git-svn-id: https://svn.dealii.org/trunk@16078 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/grid_in.h | 39 ++++++++++++++++++++++++-- deal.II/deal.II/source/grid/grid_in.cc | 28 ++++++++++-------- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/deal.II/deal.II/include/grid/grid_in.h b/deal.II/deal.II/include/grid/grid_in.h index fbd616001b..b8af5d563f 100644 --- a/deal.II/deal.II/include/grid/grid_in.h +++ b/deal.II/deal.II/include/grid/grid_in.h @@ -278,7 +278,41 @@ class GridIn void read_xda (std::istream &in); /** - * Read grid data from an msh file. + * Read grid data from an msh + * file. + * + * The text file read consists of + * two blocks. The first lists + * the positions of the mesh + * nodes and has the format + * + * @pre + * $NOD + * + * 1 + * 2 + * ... + * n + * $ENDNOD + * + * The second block lists the + * connectivity and material id's + * of the cells and faces. It is + * enclosed by $ELM and + * $ENDELM + * keywords. deal.II can handle + * elements which are lines, + * quadrilaterals or hexahedra + * only. For convenience, element + * type 15 (points) are ignored. + * + * @note The input function of + * deal.II does not distinguish + * between newline and other + * whitespace. Therefore, deal.II + * will be able to read files in + * a slightly more general format + * than Gmsh. */ void read_msh (std::istream &in); @@ -377,7 +411,8 @@ class GridIn << "ELM-TYPE\n" << "1 Line (2 nodes, 1 edge).\n" << "3 Quadrilateral (4 nodes, 4 edges).\n" - << "5 Hexahedron (8 nodes, 12 edges, 6 faces)."); + << "5 Hexahedron (8 nodes, 12 edges, 6 faces)." + << "15 Point (1 node, ignored when read)"); protected: /** * Store address of the triangulation to diff --git a/deal.II/deal.II/source/grid/grid_in.cc b/deal.II/deal.II/source/grid/grid_in.cc index 5a43966ab3..885d597f1c 100644 --- a/deal.II/deal.II/source/grid/grid_in.cc +++ b/deal.II/deal.II/source/grid/grid_in.cc @@ -556,7 +556,7 @@ void GridIn::read_msh (std::istream &in) unsigned int dummy; std::string line; - getline(in, line); + in >> line; AssertThrow (line=="$NOD", ExcInvalidGMSHInput(line)); @@ -583,18 +583,15 @@ void GridIn::read_msh (std::istream &in) // store mapping; vertex_indices[vertex_number] = vertex; }; - - // This is needed to flush the last - // new line - getline (in, line); - - // Now read in next bit - getline (in, line); + + // Assert we reached the end of the block + in >> line; AssertThrow (line=="$ENDNOD", ExcInvalidGMSHInput(line)); - getline (in, line); + // Now read in next bit + in >> line; AssertThrow (line=="$ELM", ExcInvalidGMSHInput(line)); @@ -729,10 +726,19 @@ void GridIn::read_msh (std::istream &in) } else - // cannot read this - AssertThrow (false, ExcGmshUnsupportedGeometry(cell_type)); + if (cell_type == 15) + { + // Ignore vertices + } + else + // cannot read this + AssertThrow (false, ExcGmshUnsupportedGeometry(cell_type)); }; + // Assert we reached the end of the block + in >> line; + AssertThrow (line=="$ENDELM", + ExcInvalidGMSHInput(line)); // check that no forbidden arrays are used Assert (subcelldata.check_consistency(dim), ExcInternalError()); -- 2.39.5