From e56e2f4d26dea76e3f6e55f82fa90750e8b9fe35 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Wed, 19 Jul 2023 17:44:59 +0200 Subject: [PATCH] Register errors concerning section topology in ErrorGuard. That will make those (e.g. EDITNNC in the GRiD section) fatal. --- opm/input/eclipse/Deck/DeckSection.hpp | 2 ++ .../input/eclipse/EclipseState/checkDeck.cpp | 2 +- src/opm/input/eclipse/Parser/Parser.cpp | 24 ++++++++++--------- tests/parser/SectionTests.cpp | 22 ++++++++--------- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/opm/input/eclipse/Deck/DeckSection.hpp b/opm/input/eclipse/Deck/DeckSection.hpp index 84b574db2..75c373db1 100644 --- a/opm/input/eclipse/Deck/DeckSection.hpp +++ b/opm/input/eclipse/Deck/DeckSection.hpp @@ -27,6 +27,7 @@ namespace Opm { class Deck; +class ErrorGuard; enum class Section { RUNSPEC, @@ -63,6 +64,7 @@ class DeckSection : public DeckView { // the right order static bool checkSectionTopology(const Deck& deck, const Parser&, + ErrorGuard& errorGuard, bool ensureKeywordSectionAffiliation = false); diff --git a/src/opm/input/eclipse/EclipseState/checkDeck.cpp b/src/opm/input/eclipse/EclipseState/checkDeck.cpp index a3999cc7b..a971caabb 100644 --- a/src/opm/input/eclipse/EclipseState/checkDeck.cpp +++ b/src/opm/input/eclipse/EclipseState/checkDeck.cpp @@ -50,7 +50,7 @@ bool checkDeck( const Deck& deck, const Parser& parser, const ParseContext& pars // make sure all mandatory sections are present and that their order is correct if (enabledChecks & SectionTopology) { bool ensureKeywordSection = enabledChecks & KeywordSection; - deckValid = deckValid && DeckSection::checkSectionTopology(deck, parser, ensureKeywordSection); + deckValid = deckValid && DeckSection::checkSectionTopology(deck, parser, errorGuard, ensureKeywordSection); } const std::string& deckUnitSystem = uppercase(deck.getActiveUnitSystem().getName()); diff --git a/src/opm/input/eclipse/Parser/Parser.cpp b/src/opm/input/eclipse/Parser/Parser.cpp index 6ac2076de..a87d018aa 100644 --- a/src/opm/input/eclipse/Parser/Parser.cpp +++ b/src/opm/input/eclipse/Parser/Parser.cpp @@ -1554,6 +1554,7 @@ std::vector Parser::getAllDeckNames () const { bool DeckSection::checkSectionTopology(const Deck& deck, const Parser& parser, + Opm::ErrorGuard& errorGuard, bool ensureKeywordSectionAffiliation) { if( deck.size() == 0 ) { @@ -1563,11 +1564,12 @@ std::vector Parser::getAllDeckNames () const { } bool deckValid = true; + const std::string errorKey = "SECTION_TOPOLOGY_ERROR"; if( deck[0].name() != "RUNSPEC" ) { std::string msg = "The first keyword of a valid deck must be RUNSPEC\n"; auto curKeyword = deck[0]; - OpmLog::warning(Log::fileMessage(curKeyword.location(), msg) ); + errorGuard.addError(errorKey, Log::fileMessage(curKeyword.location(), msg) ); deckValid = false; } @@ -1587,7 +1589,7 @@ std::vector Parser::getAllDeckNames () const { std::string msg = "The keyword '"+curKeywordName+"' is located in the '"+curSectionName +"' section where it is invalid"; - OpmLog::warning(Log::fileMessage(curKeyword.location(), msg) ); + errorGuard.addError(errorKey, Log::fileMessage(curKeyword.location(), msg) ); deckValid = false; } @@ -1598,7 +1600,7 @@ std::vector Parser::getAllDeckNames () const { if (curKeywordName != "GRID") { std::string msg = "The RUNSPEC section must be followed by GRID instead of "+curKeywordName; - OpmLog::warning(Log::fileMessage(curKeyword.location(), msg) ); + errorGuard.addError(errorKey, Log::fileMessage(curKeyword.location(), msg) ); deckValid = false; } @@ -1608,7 +1610,7 @@ std::vector Parser::getAllDeckNames () const { if (curKeywordName != "EDIT" && curKeywordName != "PROPS") { std::string msg = "The GRID section must be followed by EDIT or PROPS instead of "+curKeywordName; - OpmLog::warning(Log::fileMessage(curKeyword.location(), msg) ); + errorGuard.addError(errorKey, Log::fileMessage(curKeyword.location(), msg) ); deckValid = false; } @@ -1618,7 +1620,7 @@ std::vector Parser::getAllDeckNames () const { if (curKeywordName != "PROPS") { std::string msg = "The EDIT section must be followed by PROPS instead of "+curKeywordName; - OpmLog::warning(Log::fileMessage(curKeyword.location(), msg) ); + errorGuard.addError(errorKey, Log::fileMessage(curKeyword.location(), msg) ); deckValid = false; } @@ -1628,7 +1630,7 @@ std::vector Parser::getAllDeckNames () const { if (curKeywordName != "REGIONS" && curKeywordName != "SOLUTION") { std::string msg = "The PROPS section must be followed by REGIONS or SOLUTION instead of "+curKeywordName; - OpmLog::warning(Log::fileMessage(curKeyword.location(), msg) ); + errorGuard.addError(errorKey, Log::fileMessage(curKeyword.location(), msg) ); deckValid = false; } @@ -1638,7 +1640,7 @@ std::vector Parser::getAllDeckNames () const { if (curKeywordName != "SOLUTION") { std::string msg = "The REGIONS section must be followed by SOLUTION instead of "+curKeywordName; - OpmLog::warning(Log::fileMessage(curKeyword.location(), msg) ); + errorGuard.addError(errorKey, Log::fileMessage(curKeyword.location(), msg) ); deckValid = false; } @@ -1648,7 +1650,7 @@ std::vector Parser::getAllDeckNames () const { if (curKeywordName != "SUMMARY" && curKeywordName != "SCHEDULE") { std::string msg = "The SOLUTION section must be followed by SUMMARY or SCHEDULE instead of "+curKeywordName; - OpmLog::warning(Log::fileMessage(curKeyword.location(), msg) ); + errorGuard.addError(errorKey, Log::fileMessage(curKeyword.location(), msg) ); deckValid = false; } @@ -1658,7 +1660,7 @@ std::vector Parser::getAllDeckNames () const { if (curKeywordName != "SCHEDULE") { std::string msg = "The SUMMARY section must be followed by SCHEDULE instead of "+curKeywordName; - OpmLog::warning(Log::fileMessage(curKeyword.location(), msg) ); + errorGuard.addError(errorKey, Log::fileMessage(curKeyword.location(), msg) ); deckValid = false; } @@ -1669,7 +1671,7 @@ std::vector Parser::getAllDeckNames () const { std::string msg = "The SCHEDULE section must be the last one (" +curKeywordName+" specified after SCHEDULE)"; - OpmLog::warning(Log::fileMessage(curKeyword.location(), msg) ); + errorGuard.addError(errorKey, Log::fileMessage(curKeyword.location(), msg) ); deckValid = false; } } @@ -1679,7 +1681,7 @@ std::vector Parser::getAllDeckNames () const { const auto& curKeyword = deck[deck.size() - 1]; std::string msg = "The last section of a valid deck must be SCHEDULE (is "+curSectionName+")"; - OpmLog::warning(Log::fileMessage(curKeyword.location(), msg) ); + errorGuard.addError(errorKey, Log::fileMessage(curKeyword.location(), msg) ); deckValid = false; } diff --git a/tests/parser/SectionTests.cpp b/tests/parser/SectionTests.cpp index 92d58603d..a5f82c291 100644 --- a/tests/parser/SectionTests.cpp +++ b/tests/parser/SectionTests.cpp @@ -233,7 +233,7 @@ BOOST_AUTO_TEST_CASE(Section_ValidDecks) { "SCHEDULE\n" "TEST5\n"; - BOOST_CHECK( Opm::DeckSection::checkSectionTopology( parser.parseString( minimal, mode, errors ), parser) ); + BOOST_CHECK( Opm::DeckSection::checkSectionTopology( parser.parseString( minimal, mode, errors ), parser, errors) ); const std::string with_opt = "RUNSPEC\n" "TEST1\n" @@ -252,7 +252,7 @@ BOOST_AUTO_TEST_CASE(Section_ValidDecks) { "SCHEDULE\n" "TEST8\n"; - BOOST_CHECK(Opm::DeckSection::checkSectionTopology( parser.parseString( with_opt, mode, errors ), parser)); + BOOST_CHECK(Opm::DeckSection::checkSectionTopology( parser.parseString( with_opt, mode, errors ), parser, errors)); } BOOST_AUTO_TEST_CASE(Section_InvalidDecks) { @@ -274,7 +274,7 @@ BOOST_AUTO_TEST_CASE(Section_InvalidDecks) { "SCHEDULE\n" "TEST5\n"; - BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( keyword_before_RUNSPEC, mode, errors ), parser)); + BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( keyword_before_RUNSPEC, mode, errors ), parser, errors)); const std::string wrong_order = "RUNSPEC\n" "TEST1\n" @@ -293,7 +293,7 @@ BOOST_AUTO_TEST_CASE(Section_InvalidDecks) { "SCHEDULE\n" "TEST8\n"; - BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( wrong_order, mode, errors ), parser)); + BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( wrong_order, mode, errors ), parser, errors)); const std::string duplicate = "RUNSPEC\n" "TEST1\n" @@ -314,7 +314,7 @@ BOOST_AUTO_TEST_CASE(Section_InvalidDecks) { "SCHEDULE\n" "TEST8\n"; - BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( duplicate, mode, errors ), parser)); + BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( duplicate, mode, errors ), parser, errors)); const std::string section_after_SCHEDULE = "RUNSPEC\n" "TEST1\n" @@ -333,7 +333,7 @@ BOOST_AUTO_TEST_CASE(Section_InvalidDecks) { "EDIT\n" "TEST3\n"; - BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( section_after_SCHEDULE, mode, errors ), parser)); + BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( section_after_SCHEDULE, mode, errors ), parser, errors)); const std::string missing_runspec = "GRID\n" "TEST2\n" @@ -344,7 +344,7 @@ BOOST_AUTO_TEST_CASE(Section_InvalidDecks) { "SCHEDULE\n" "TEST5\n"; - BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( missing_runspec, mode, errors ), parser)); + BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( missing_runspec, mode, errors ), parser, errors)); const std::string missing_GRID = "RUNSPEC\n" @@ -356,7 +356,7 @@ BOOST_AUTO_TEST_CASE(Section_InvalidDecks) { "SCHEDULE\n" "TEST5\n"; - BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( missing_GRID, mode, errors ), parser)); + BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( missing_GRID, mode, errors ), parser, errors)); const std::string missing_PROPS = "RUNSPEC\n" "TEST1\n" @@ -367,7 +367,7 @@ BOOST_AUTO_TEST_CASE(Section_InvalidDecks) { "SCHEDULE\n" "TEST5\n"; - BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( missing_PROPS, mode, errors ), parser)); + BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( missing_PROPS, mode, errors ), parser, errors)); const std::string missing_SOLUTION = "RUNSPEC\n" "TEST1\n" @@ -378,7 +378,7 @@ BOOST_AUTO_TEST_CASE(Section_InvalidDecks) { "SCHEDULE\n" "TEST5\n"; - BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( missing_SOLUTION, mode, errors ), parser)); + BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( missing_SOLUTION, mode, errors ), parser, errors)); const std::string missing_SCHEDULE = "RUNSPEC\n" "TEST1\n" @@ -389,5 +389,5 @@ BOOST_AUTO_TEST_CASE(Section_InvalidDecks) { "SOLUTION\n" "TEST4\n"; - BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( missing_SCHEDULE, mode, errors ), parser)); + BOOST_CHECK(!Opm::DeckSection::checkSectionTopology( parser.parseString( missing_SCHEDULE, mode, errors ), parser, errors)); }