diff --git a/src/mesh/GmshReader.cpp b/src/mesh/GmshReader.cpp index ee6d46fe791325c01364410f94fb0cc50d8494b0..25c1a4b7be013091143fdab3034f5dc8efbe2073 100644 --- a/src/mesh/GmshReader.cpp +++ b/src/mesh/GmshReader.cpp @@ -139,12 +139,14 @@ GmshReader::GmshReader(const std::string& filename) } // gmsh 2.2 format keywords - __keywordList["$MeshFormat"] = MESHFORMAT; - __keywordList["$EndMeshFormat"] = ENDMESHFORMAT; - __keywordList["$Nodes"] = NODES; - __keywordList["$EndNodes"] = ENDNODES; - __keywordList["$Elements"] = ELEMENTS; - __keywordList["$EndElements"] = ENDELEMENTS; + __keywordList["$MeshFormat"] = MESHFORMAT; + __keywordList["$EndMeshFormat"] = ENDMESHFORMAT; + __keywordList["$Nodes"] = NODES; + __keywordList["$EndNodes"] = ENDNODES; + __keywordList["$Elements"] = ELEMENTS; + __keywordList["$EndElements"] = ENDELEMENTS; + __keywordList["$PhysicalNames"] = PHYSICALNAMES; + __keywordList["$EndPhysicalNames"] = ENDPHYSICALNAMES; __numberOfPrimitiveNodes.resize(16); __numberOfPrimitiveNodes[ 0] = 2; // edge @@ -489,6 +491,14 @@ GmshReader::__readElements2_2() } } +void +GmshReader:: +__readPhysicalNames2_2() +{ + std::cerr << __FILE__ << ':' << __LINE__ << ": NIY\n"; + std::exit(0); +} + void GmshReader::__proceedData() { @@ -869,16 +879,11 @@ GmshReader::__nextKeyword() { GmshReader::Keyword kw; - std::cerr << "warning: " << rang::fg::red << __PRETTY_FUNCTION__ << rang::fg::reset << " keyword validity not checked!\n"; - int retval = 1; std::string aKeyword; m_fin >> aKeyword; - if (retval < 0) { + if (not m_fin) { kw.second = EndOfFile; return kw; - } else if (retval == 0) { - kw.second = Unknown; - return kw; } KeywordList::iterator i = __keywordList.find(aKeyword.c_str()); @@ -889,10 +894,10 @@ GmshReader::__nextKeyword() return kw; } - // throw ErrorHandler(__FILE__,__LINE__, - // "reading file '"+m_filename - // +"': unknown keyword '"+aKeyword+"'", - // ErrorHandler::normal); + throw ErrorHandler(__FILE__,__LINE__, + "reading file '"+m_filename + +"': unknown keyword '"+aKeyword+"'", + ErrorHandler::normal); kw.first = aKeyword; kw.second = Unknown; @@ -903,41 +908,51 @@ void GmshReader:: __readGmshFormat2_2() { std::cout << "- Reading Gmsh format 2.2\n"; - GmshReader::Keyword kw; - kw = this->__nextKeyword(); - if (kw.second != NODES) { - // throw ErrorHandler(__FILE__,__LINE__, - // "reading file '"+m_filename - // +"': expecting $Nodes, '"+kw.first+"' was found", - // ErrorHandler::normal); - } - - this->__readVertices(); - - kw = this->__nextKeyword(); - if (kw.second != ENDNODES) { - // throw ErrorHandler(__FILE__,__LINE__, - // "reading file '"+m_filename - // +"': expecting $EndNodes, '"+kw.first+"' was found", - // ErrorHandler::normal); - } - - // Getting elements list - kw = this->__nextKeyword(); - if (kw.second != ELEMENTS) { - // throw ErrorHandler(__FILE__,__LINE__, - // "reading file '"+m_filename - // +"': expecting $Elements, '"+kw.first+"' was found", - // ErrorHandler::normal); - } - - this->__readElements2_2(); + GmshReader::Keyword kw = std::make_pair("", Unknown); + while (kw.second != EndOfFile) { + kw = this->__nextKeyword(); + switch (kw.second) { + case NODES: { + this->__readVertices(); + if (this->__nextKeyword().second != ENDNODES) { + throw ErrorHandler(__FILE__,__LINE__, + "reading file '"+m_filename + +"': expecting $EndNodes, '"+kw.first+"' was found", + ErrorHandler::normal); + } + break; + } + case ELEMENTS: { + this->__readElements2_2(); + kw = this->__nextKeyword(); + if (kw.second != ENDELEMENTS) { + throw ErrorHandler(__FILE__,__LINE__, + "reading file '"+m_filename + +"': expecting $EndElements, '"+kw.first+"' was found", + ErrorHandler::normal); + } + break; + } + case PHYSICALNAMES: { + this->__readPhysicalNames2_2(); + if (this->__nextKeyword().second != ENDPHYSICALNAMES) { + throw ErrorHandler(__FILE__,__LINE__, + "reading file '"+m_filename + +"': expecting $EndNodes, '"+kw.first+"' was found", + ErrorHandler::normal); + } + break; + } - kw = this->__nextKeyword(); - if (kw.second != ENDELEMENTS) { - // throw ErrorHandler(__FILE__,__LINE__, - // "reading file '"+m_filename - // +"': expecting $EndElements, '"+kw.first+"' was found", - // ErrorHandler::normal); + case EndOfFile: { + break; + } + default: { + throw ErrorHandler(__FILE__,__LINE__, + "reading file '"+m_filename + +"': unexpected '"+kw.first+"'", + ErrorHandler::normal); + } + } } } diff --git a/src/mesh/GmshReader.hpp b/src/mesh/GmshReader.hpp index 5aec14118d6f7d08466e091f2c66201c375f480b..5cb7e9e7b6c76d9d1a9615eb122bab673def1050 100644 --- a/src/mesh/GmshReader.hpp +++ b/src/mesh/GmshReader.hpp @@ -126,6 +126,8 @@ private: ENDNODES, ELEMENTS, ENDELEMENTS, + PHYSICALNAMES, + ENDPHYSICALNAMES, Unknown, EndOfFile @@ -176,16 +178,11 @@ private: */ void __readElements2_2(); - // /** - // * Common interface for writing references - // * - // * @param references the set of computed references - // * @param objectName the type of refernces - // */ - // void __writeReferences(const std::set<size_t>& references, - // std::string objectName); - - + /** + * Reads physical names + * + */ + void __readPhysicalNames2_2(); Connectivity2D* m_connectivity; Mesh<Connectivity2D>* m_mesh;