diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 6bb3134b2..1e7433491 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -107,7 +107,6 @@ if(ENABLE_ECL_INPUT) src/opm/parser/eclipse/EclipseState/Tables/Tables.cpp src/opm/parser/eclipse/EclipseState/Tables/VFPInjTable.cpp src/opm/parser/eclipse/EclipseState/Tables/VFPProdTable.cpp - src/opm/parser/eclipse/Parser/MessageContainer.cpp src/opm/parser/eclipse/Parser/ParseContext.cpp src/opm/parser/eclipse/Parser/Parser.cpp src/opm/parser/eclipse/Parser/ParserEnums.cpp @@ -181,7 +180,6 @@ if(ENABLE_ECL_INPUT) tests/parser/GroupTests.cpp tests/parser/InitConfigTest.cpp tests/parser/IOConfigTests.cpp - tests/parser/MessageContainerTest.cpp tests/parser/MessageLimitTests.cpp tests/parser/MultiRegTests.cpp tests/parser/MultisegmentWellTests.cpp @@ -325,7 +323,6 @@ if(ENABLE_ECL_INPUT) opm/parser/eclipse/Parser/ParserItem.hpp opm/parser/eclipse/Parser/Parser.hpp opm/parser/eclipse/Parser/ParserRecord.hpp - opm/parser/eclipse/Parser/MessageContainer.hpp opm/parser/eclipse/Parser/ParserKeyword.hpp opm/parser/eclipse/Parser/InputErrorAction.hpp opm/parser/eclipse/Parser/ParserEnums.hpp diff --git a/GenerateKeywords.cmake b/GenerateKeywords.cmake index f232b7fa4..67e6fc229 100644 --- a/GenerateKeywords.cmake +++ b/GenerateKeywords.cmake @@ -7,7 +7,6 @@ set(genkw_SOURCES src/opm/json/JsonObject.cpp src/opm/parser/eclipse/Deck/DeckOutput.cpp src/opm/parser/eclipse/Generator/KeywordGenerator.cpp src/opm/parser/eclipse/Generator/KeywordLoader.cpp - src/opm/parser/eclipse/Parser/MessageContainer.cpp src/opm/parser/eclipse/Parser/ParseContext.cpp src/opm/parser/eclipse/Parser/ParserEnums.cpp src/opm/parser/eclipse/Parser/ParserItem.cpp @@ -19,6 +18,11 @@ set(genkw_SOURCES src/opm/json/JsonObject.cpp src/opm/parser/eclipse/Units/Dimension.cpp src/opm/parser/eclipse/Units/UnitSystem.cpp src/opm/parser/eclipse/Utility/Stringview.cpp + src/opm/common/OpmLog/OpmLog.cpp + src/opm/common/OpmLog/Logger.cpp + src/opm/common/OpmLog/StreamLog.cpp + src/opm/common/OpmLog/LogBackend.cpp + src/opm/common/OpmLog/LogUtil.cpp ) if(NOT cjson_FOUND) list(APPEND genkw_SOURCES external/cjson/cJSON.c) diff --git a/examples/opmi.cpp b/examples/opmi.cpp index 49f67b1b5..6d78fddb3 100644 --- a/examples/opmi.cpp +++ b/examples/opmi.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -28,20 +27,6 @@ #include #include -inline void dumpMessages( const Opm::MessageContainer& messageContainer) { - auto extractMessage = [](const Opm::Message& msg) { - const auto& location = msg.location; - if (location) - return location.filename + ":" + std::to_string( location.lineno ) + " " + msg.message; - else - return msg.message; - }; - - - for(const auto& msg : messageContainer) - std::cout << extractMessage(msg) << std::endl; -} - inline void loadDeck( const char * deck_file) { Opm::ParseContext parseContext; @@ -55,7 +40,6 @@ inline void loadDeck( const char * deck_file) { Opm::SummaryConfig summary( deck, schedule, state.getTableManager( ), parseContext ); std::cout << "complete." << std::endl; - dumpMessages( deck.getMessageContainer() ); } diff --git a/opm/parser/eclipse/Deck/Deck.hpp b/opm/parser/eclipse/Deck/Deck.hpp index b535c4f23..43818cd2d 100644 --- a/opm/parser/eclipse/Deck/Deck.hpp +++ b/opm/parser/eclipse/Deck/Deck.hpp @@ -30,7 +30,6 @@ #include #include -#include #ifdef OPM_PARSER_DECK_API_WARNING #ifndef OPM_PARSER_DECK_API @@ -136,7 +135,6 @@ namespace Opm { void addKeyword( const DeckKeyword& keyword ); DeckKeyword& getKeyword( size_t ); - MessageContainer& getMessageContainer() const; const UnitSystem& getDefaultUnitSystem() const; const UnitSystem& getActiveUnitSystem() const; @@ -154,7 +152,6 @@ namespace Opm { Deck( std::vector< DeckKeyword >&& ); std::vector< DeckKeyword > keywordList; - mutable MessageContainer m_messageContainer; UnitSystem defaultUnits; UnitSystem activeUnits; diff --git a/opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp b/opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp index 94d03479f..df88ab4fc 100644 --- a/opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp +++ b/opm/parser/eclipse/EclipseState/Eclipse3DProperties.hpp @@ -66,7 +66,6 @@ namespace Opm { bool hasDeckIntGridProperty(const std::string& keyword) const; bool hasDeckDoubleGridProperty(const std::string& keyword) const; bool supportsGridProperty(const std::string& keyword) const; - MessageContainer getMessageContainer(); private: const GridProperty& getRegion(const DeckItem& regionItem) const; diff --git a/opm/parser/eclipse/EclipseState/EclipseState.hpp b/opm/parser/eclipse/EclipseState/EclipseState.hpp index 90cc50b3d..da4db1792 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.hpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.hpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -97,9 +96,6 @@ namespace Opm { const UnitSystem& getDeckUnitSystem() const; const UnitSystem& getUnits() const; - const MessageContainer& getMessageContainer() const; - MessageContainer& getMessageContainer(); - std::string getTitle() const; void applyModifierDeck(const Deck& deck); @@ -130,8 +126,6 @@ namespace Opm { FaultCollection m_faults; std::string m_title; - MessageContainer m_messageContainer; - }; } diff --git a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp index 9c0af979e..14f973904 100644 --- a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -27,8 +27,6 @@ #include #include -#include - #include #include @@ -176,11 +174,8 @@ namespace Opm { void resetACTNUM( const int * actnum); bool equal(const EclipseGrid& other) const; const ecl_grid_type * c_ptr() const; - const MessageContainer& getMessageContainer() const; - MessageContainer& getMessageContainer(); - private: - MessageContainer m_messages; + private: double m_minpvValue; MinpvMode::ModeEnum m_minpvMode; Value m_pinch; diff --git a/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp b/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp index 3d3d6f69b..4f54c1daa 100644 --- a/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -113,10 +112,6 @@ namespace Opm { const Box& inputBox); - const MessageContainer& getMessageContainer() const; - MessageContainer& getMessageContainer(); - - template bool hasKeyword() const { return hasKeyword( Keyword::keywordName ); @@ -199,7 +194,6 @@ namespace Opm { size_t ny = 0; size_t nz = 0; const UnitSystem * m_deckUnitSystem = nullptr; - MessageContainer m_messages; mutable std::unordered_map m_supportedKeywords; mutable storage m_properties; diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index 9bfa1de3d..71ce7814d 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -36,7 +36,6 @@ #include #include #include -#include #include namespace Opm @@ -108,8 +107,6 @@ namespace Opm const Events& getEvents() const; const Deck& getModifierDeck(size_t timeStep) const; bool hasOilVaporizationProperties() const; - const MessageContainer& getMessageContainer() const; - MessageContainer& getMessageContainer(); /* Will remove all completions which are connected to cell which is not @@ -129,7 +126,6 @@ namespace Opm MessageLimits m_messageLimits; Phases m_phases; - MessageContainer m_messages; WellProducer::ControlModeEnum m_controlModeWHISTCTL; std::vector< Well* > getWells(const std::string& wellNamePattern); diff --git a/opm/parser/eclipse/EclipseState/Schedule/Well.hpp b/opm/parser/eclipse/EclipseState/Schedule/Well.hpp index 4dcb5c845..3bb559e38 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Well.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Well.hpp @@ -35,7 +35,6 @@ #include #include #include -#include namespace Opm { @@ -161,7 +160,6 @@ namespace Opm { void addSegmentSet(size_t time_step, SegmentSet new_segmentset); - const MessageContainer& getMessageContainer() const; const Events& getEvents() const; void addEvent(ScheduleEvents::Events event, size_t reportStep); bool hasEvent(uint64_t eventMask, size_t reportStep) const; @@ -202,7 +200,6 @@ namespace Opm { WellCompletion::CompletionOrderEnum m_comporder; bool m_allowCrossFlow; bool m_automaticShutIn; - MessageContainer m_messages; // WELSEGS DATA - for mutli-segment wells // flag indicating if the well is a multi-segment well DynamicState< SegmentSet > m_segmentset; diff --git a/opm/parser/eclipse/EclipseState/Tables/TableManager.hpp b/opm/parser/eclipse/EclipseState/Tables/TableManager.hpp index 211d582ac..cc417e38a 100644 --- a/opm/parser/eclipse/EclipseState/Tables/TableManager.hpp +++ b/opm/parser/eclipse/EclipseState/Tables/TableManager.hpp @@ -23,6 +23,9 @@ #include +#include +#include + #include #include #include @@ -46,7 +49,6 @@ #include #include #include -#include namespace Opm { @@ -137,9 +139,6 @@ namespace Opm { /// deck has keyword "JFUNC" --- Use Leverett's J Function for capillary pressure bool useJFunc() const; - const MessageContainer& getMessageContainer() const; - MessageContainer& getMessageContainer(); - double rtemp() const; private: TableContainer& forceGetTables( const std::string& tableName , size_t numTables); @@ -259,7 +258,7 @@ namespace Opm { // should be copied... if (tableIdx == 0) { std::string msg = "The first table for keyword "+keywordName+" must be explicitly defined! Ignoring keyword"; - m_messages.warning(tableKeyword.getFileName() + std::to_string(tableKeyword.getLineNumber()) + msg); + OpmLog::warning(Log::fileMessage(tableKeyword.getFileName(), tableKeyword.getLineNumber(), msg)); return; } tableVector.push_back(tableVector.back()); @@ -315,7 +314,6 @@ namespace Opm { const JFunc m_jfunc; - MessageContainer m_messages; double m_rtemp; }; } diff --git a/opm/parser/eclipse/EclipseState/Tables/VFPProdTable.hpp b/opm/parser/eclipse/EclipseState/Tables/VFPProdTable.hpp index cb45815e7..3631fd4f9 100644 --- a/opm/parser/eclipse/EclipseState/Tables/VFPProdTable.hpp +++ b/opm/parser/eclipse/EclipseState/Tables/VFPProdTable.hpp @@ -23,8 +23,6 @@ #include -#include - namespace Opm { class DeckItem; @@ -230,8 +228,6 @@ public: return m_data; } - const MessageContainer& getMessageContainer() const; - private: //"Header" variables @@ -252,7 +248,6 @@ private: //The data itself, using the data ordering m_data[thp][wfr][gfr][alq][flo] array_type m_data; - MessageContainer m_messages; /** * Debug function that runs a series of asserts to check for sanity of inputs. * Called after init to check that everything looks ok. diff --git a/opm/parser/eclipse/Parser/MessageContainer.hpp b/opm/parser/eclipse/Parser/MessageContainer.hpp deleted file mode 100644 index dde8c6dfb..000000000 --- a/opm/parser/eclipse/Parser/MessageContainer.hpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - Copyright 2016 Statoil ASA. - - This file is part of the Open Porous Media project (OPM). - - OPM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OPM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OPM. If not, see . -*/ - -#ifndef MESSAGECONTAINER_H -#define MESSAGECONTAINER_H - -#include -#include -#include - -namespace Opm { - - struct Location { - Location() = default; - Location( const std::string&, size_t ); - - std::string filename; - size_t lineno = 0; - - explicit operator bool() const { - return lineno != 0; - } - }; - - struct Message { - enum type { - Debug = 1, - Note = 2, - Info = 3, - Warning = 4, - Error = 5, - Problem = 6, - Bug = 7 - }; - - Message( type mt, const std::string& msg, Location&& loc ) : - mtype( mt ), message( msg ), location( std::move( loc ) ) {} - - Message( type mt, const std::string& msg ) : - mtype( mt ), message( msg ) {} - - - type mtype; - std::string message; - Location location; - }; - - - ///Message container is used to replace OpmLog functionalities. - class MessageContainer { - public: - - using const_iterator = std::vector< Message >::const_iterator; - - void error(const std::string& msg, const std::string& filename, const size_t lineno); - void error(const std::string& msg); - - void bug(const std::string& msg, const std::string& filename, const size_t lineno); - void bug(const std::string& msg); - - void warning(const std::string& msg, const std::string& filename, const size_t lineno); - void warning(const std::string& msg); - - void info(const std::string& msg, const std::string& filename, const size_t lineno); - void info(const std::string& msg); - - void debug(const std::string& msg, const std::string& filename, const size_t lineno); - void debug(const std::string& msg); - - void problem(const std::string& msg, const std::string& filename, const size_t lineno); - void problem(const std::string& msg); - - void note(const std::string& msg, const std::string& filename, const size_t lineno); - void note(const std::string& msg); - - void add( const Message& ); - void add( Message&& ); - - void appendMessages(const MessageContainer& other); - - const_iterator begin() const; - const_iterator end() const; - - std::size_t size() const; - - private: - std::vector m_messages; - }; - -} // namespace Opm - -#endif // OPM_MESSAGECONTAINER_HEADER_INCLUDED diff --git a/opm/parser/eclipse/Parser/ParseContext.hpp b/opm/parser/eclipse/Parser/ParseContext.hpp index 1d60c7ef8..a8034a6a8 100644 --- a/opm/parser/eclipse/Parser/ParseContext.hpp +++ b/opm/parser/eclipse/Parser/ParseContext.hpp @@ -25,8 +25,9 @@ #include #include +#include + #include -#include namespace Opm { @@ -82,7 +83,7 @@ namespace Opm { explicit ParseContext(InputError::Action default_action); explicit ParseContext(const std::vector>& initial); - Message::type handleError( const std::string& errorKey, MessageContainer& msgContainer, const std::string& msg ) const; + void handleError( const std::string& errorKey, const std::string& msg ) const; bool hasKey(const std::string& key) const; ParseContext withKey(const std::string& key, InputError::Action action = InputError::WARN) const; ParseContext& withKey(const std::string& key, InputError::Action action = InputError::WARN); diff --git a/opm/parser/eclipse/Parser/ParserKeyword.hpp b/opm/parser/eclipse/Parser/ParserKeyword.hpp index e3aefa897..5ba156bbb 100644 --- a/opm/parser/eclipse/Parser/ParserKeyword.hpp +++ b/opm/parser/eclipse/Parser/ParserKeyword.hpp @@ -40,7 +40,6 @@ namespace Opm { class ParserDoubleItem; class RawKeyword; class string_view; - class MessageContainer; /* Small helper struct to assemble the information needed to infer the size @@ -123,7 +122,7 @@ namespace Opm { SectionNameSet::const_iterator validSectionNamesBegin() const; SectionNameSet::const_iterator validSectionNamesEnd() const; - DeckKeyword parse(const ParseContext& parseContext , MessageContainer& msgContainer, std::shared_ptr< RawKeyword > rawKeyword) const; + DeckKeyword parse(const ParseContext& parseContext , std::shared_ptr< RawKeyword > rawKeyword) const; enum ParserKeywordSizeEnum getSizeType() const; const KeywordSize& getKeywordSize() const; bool isDataKeyword() const; diff --git a/opm/parser/eclipse/Parser/ParserRecord.hpp b/opm/parser/eclipse/Parser/ParserRecord.hpp index 018458af4..94a160651 100644 --- a/opm/parser/eclipse/Parser/ParserRecord.hpp +++ b/opm/parser/eclipse/Parser/ParserRecord.hpp @@ -33,7 +33,6 @@ namespace Opm { class ParseContext; class ParserItem; class RawRecord; - class MessageContainer; class ParserRecord { public: @@ -43,7 +42,7 @@ namespace Opm { void addDataItem( ParserItem item ); const ParserItem& get(size_t index) const; const ParserItem& get(const std::string& itemName) const; - DeckRecord parse( const ParseContext&, MessageContainer&, RawRecord& ) const; + DeckRecord parse( const ParseContext&, RawRecord& ) const; bool isDataRecord() const; bool equal(const ParserRecord& other) const; bool hasDimension() const; diff --git a/src/opm/parser/eclipse/Deck/Deck.cpp b/src/opm/parser/eclipse/Deck/Deck.cpp index a1ea38b55..0577f761f 100644 --- a/src/opm/parser/eclipse/Deck/Deck.cpp +++ b/src/opm/parser/eclipse/Deck/Deck.cpp @@ -167,7 +167,6 @@ namespace Opm { Deck::Deck( const Deck& d ) : DeckView( d.begin(), d.begin() ), keywordList( d.keywordList ), - m_messageContainer( d.m_messageContainer ), defaultUnits( d.defaultUnits ), activeUnits( d.activeUnits ), m_dataFile( d.m_dataFile ) { @@ -194,10 +193,6 @@ namespace Opm { return this->keywordList.at( index ); } - MessageContainer& Deck::getMessageContainer() const { - return this->m_messageContainer; - } - UnitSystem& Deck::getDefaultUnitSystem() { return this->defaultUnits; } diff --git a/src/opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp b/src/opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp index c05e8aec2..4d2ccc322 100644 --- a/src/opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp +++ b/src/opm/parser/eclipse/EclipseState/Eclipse3DProperties.cpp @@ -969,13 +969,4 @@ namespace Opm { } } - - - MessageContainer Eclipse3DProperties::getMessageContainer() { - MessageContainer messages; - messages.appendMessages(m_intGridProperties.getMessageContainer()); - messages.appendMessages(m_doubleGridProperties.getMessageContainer()); - return messages; - } - } diff --git a/src/opm/parser/eclipse/EclipseState/EclipseState.cpp b/src/opm/parser/eclipse/EclipseState/EclipseState.cpp index 72c47e377..d59fba091 100644 --- a/src/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/src/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -21,6 +21,8 @@ #include +#include + #include #include #include @@ -43,7 +45,6 @@ #include #include #include -#include namespace Opm { @@ -63,8 +64,8 @@ namespace Opm { m_inputGrid.resetACTNUM(m_eclipseProperties.getIntGridProperty("ACTNUM").getData().data()); if( this->runspec().phases().size() < 3 ) - m_messageContainer.info("Only " + std::to_string( this->runspec().phases().size() ) - + " fluid phases are enabled" ); + OpmLog::info("Only " + std::to_string( this->runspec().phases().size() ) + + " fluid phases are enabled" ); if (deck.hasKeyword( "TITLE" )) { const auto& titleKeyword = deck.getKeyword( "TITLE" ); @@ -75,10 +76,6 @@ namespace Opm { initTransMult(); initFaults(deck); - - m_messageContainer.appendMessages(m_tables.getMessageContainer()); - m_messageContainer.appendMessages(m_inputGrid.getMessageContainer()); - m_messageContainer.appendMessages(m_eclipseProperties.getMessageContainer()); } const UnitSystem& EclipseState::getDeckUnitSystem() const { @@ -110,15 +107,6 @@ namespace Opm { return m_eclipseProperties; } - const MessageContainer& EclipseState::getMessageContainer() const { - return m_messageContainer; - } - - - MessageContainer& EclipseState::getMessageContainer() { - return m_messageContainer; - } - const TableManager& EclipseState::getTableManager() const { return m_tables; @@ -224,11 +212,11 @@ namespace Opm { } void EclipseState::complainAboutAmbiguousKeyword(const Deck& deck, const std::string& keywordName) { - m_messageContainer.error("The " + keywordName + " keyword must be unique in the deck. Ignoring all!"); + OpmLog::error("The " + keywordName + " keyword must be unique in the deck. Ignoring all!"); auto keywords = deck.getKeywordList(keywordName); for (size_t i = 0; i < keywords.size(); ++i) { std::string msg = "Ambiguous keyword "+keywordName+" defined here"; - m_messageContainer.error(keywords[i]->getFileName(), msg, keywords[i]->getLineNumber()); + OpmLog::error(Log::fileMessage(keywords[i]->getFileName(), keywords[i]->getLineNumber(), msg)); } } diff --git a/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp b/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp index ed56a7baf..29f5bb747 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -24,6 +24,8 @@ #include #include +#include + #include #include #include @@ -104,7 +106,6 @@ namespace Opm { EclipseGrid::EclipseGrid(const EclipseGrid& src, const double* zcorn , const std::vector& actnum) : GridDims(src.getNX(), src.getNY(), src.getNZ()), - m_messages( src.m_messages ), m_minpvValue( src.m_minpvValue ), m_minpvMode( src.m_minpvMode ), m_pinch( src.m_pinch ), @@ -177,7 +178,7 @@ namespace Opm { resetACTNUM( actnumData.data()); else { const std::string msg = "The ACTNUM keyword has " + std::to_string( actnumData.size() ) + " elements - expected : " + std::to_string( getCartesianSize()) + " - ignored."; - m_messages.warning(msg); + OpmLog::warning(msg); } } } @@ -512,7 +513,7 @@ namespace Opm { "Wrong size of the ZCORN keyword: Expected 8*x*ny*nz = " + std::to_string(static_cast(8*nx*ny*nz)) + " is " + std::to_string(static_cast(ZCORNKeyWord.getDataSize())); - m_messages.error(msg); + OpmLog::error(msg); throw std::invalid_argument(msg); } } @@ -524,7 +525,7 @@ namespace Opm { "Wrong size of the COORD keyword: Expected 6*(nx + 1)*(ny + 1) = " + std::to_string(static_cast(6*(nx + 1)*(ny + 1))) + " is " + std::to_string(static_cast(COORDKeyWord.getDataSize())); - m_messages.error(msg); + OpmLog::error(msg); throw std::invalid_argument(msg); } } @@ -699,16 +700,6 @@ namespace Opm { } - const MessageContainer& EclipseGrid::getMessageContainer() const { - return m_messages; - } - - - MessageContainer& EclipseGrid::getMessageContainer() { - return m_messages; - } - - bool EclipseGrid::equal(const EclipseGrid& other) const { bool status = (m_pinch.equal( other.m_pinch ) && (ecl_grid_compare( c_ptr() , other.c_ptr() , true , false , false )) && (m_minpvMode == other.getMinpvMode())); if(m_minpvMode!=MinpvMode::ModeEnum::Inactive){ diff --git a/src/opm/parser/eclipse/EclipseState/Grid/GridProperties.cpp b/src/opm/parser/eclipse/EclipseState/Grid/GridProperties.cpp index 0e6a2f141..0b1f06094 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/GridProperties.cpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/GridProperties.cpp @@ -19,6 +19,8 @@ #include +#include + #include #include #include @@ -111,17 +113,6 @@ namespace Opm { } - - template< typename T > - const MessageContainer& GridProperties::getMessageContainer() const { - return m_messages; - } - - template< typename T > - MessageContainer& GridProperties::getMessageContainer() { - return m_messages; - } - template< typename T > bool GridProperties::supportsKeyword(const std::string& keyword) const { const std::string kw = normalize(keyword); @@ -215,7 +206,7 @@ namespace Opm { // if the property was already added auto generated, we just need to make it // non-auto generated if (m_autoGeneratedProperties.count(kw)) { - m_messages.warning("The keyword "+kw+" has been used to calculate the " + OpmLog::warning("The keyword "+kw+" has been used to calculate the " "defaults of another keyword before the first time it was " "explicitly mentioned in the deck. Maybe you need to change " "the ordering of your keywords (move "+kw+" to the front?)."); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index 68b52e6c8..ac7f68f78 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -24,6 +24,8 @@ #include #include +#include + #include #include #include @@ -259,7 +261,7 @@ namespace Opm { m_events.addEvent( ScheduleEvents::GEO_MODIFIER , currentStep); } else { std::string msg = "OPM does not support grid property modifier " + keyword.name() + " in the Schedule section. Error at report: " + std::to_string( currentStep ); - parseContext.handleError( ParseContext::UNSUPPORTED_SCHEDULE_GEO_MODIFIER , m_messages, msg ); + parseContext.handleError( ParseContext::UNSUPPORTED_SCHEDULE_GEO_MODIFIER , msg ); } } } @@ -301,8 +303,8 @@ namespace Opm { const std::string bhp_terminate = record.getItem("BPH_TERMINATE").getTrimmedString(0); if (bhp_terminate == "YES") { std::string msg = "The WHISTCTL keyword does not handle 'YES'. i.e. to terminate the run"; - m_messages.error(msg); - parseContext.handleError( ParseContext::UNSUPPORTED_TERMINATE_IF_BHP , m_messages, msg ); + OpmLog::error(msg); + parseContext.handleError( ParseContext::UNSUPPORTED_TERMINATE_IF_BHP , msg ); } } @@ -314,8 +316,8 @@ namespace Opm { const auto& methodItem = record.getItem(); if ((methodItem.get< std::string >(0) != "TRACK") && (methodItem.get< std::string >(0) != "INPUT")) { std::string msg = "The COMPORD keyword only handles 'TRACK' or 'INPUT' order."; - m_messages.error(msg); - parseContext.handleError( ParseContext::UNSUPPORTED_COMPORD_TYPE , m_messages, msg ); + OpmLog::error(msg); + parseContext.handleError( ParseContext::UNSUPPORTED_COMPORD_TYPE , msg ); } } } @@ -377,13 +379,13 @@ namespace Opm { if( currentWell.getHeadI() != headI ) { std::string msg = "HEAD_I changed for well " + currentWell.name(); - this->m_messages.info(keyword.getFileName(), msg, keyword.getLineNumber()); + OpmLog::info(Log::fileMessage(keyword.getFileName(), keyword.getLineNumber(), msg)); currentWell.setHeadI( currentStep, headI ); } if( currentWell.getHeadJ() != headJ ) { std::string msg = "HEAD_J changed for well " + currentWell.name(); - this->m_messages.info( keyword.getFileName(), msg, keyword.getLineNumber() ); + OpmLog::info(Log::fileMessage(keyword.getFileName(), keyword.getLineNumber(), msg)); currentWell.setHeadJ( currentStep, headJ ); } @@ -397,8 +399,6 @@ namespace Opm { if (handleGroupFromWELSPECS(groupName, newTree)) needNewTree = true; - //Collect messages from wells. - m_messages.appendMessages(currentWell.getMessageContainer()); } if (needNewTree) { @@ -476,7 +476,7 @@ namespace Opm { std::string msg = "Well " + well->name() + " is a history matched well with zero rate where crossflow is banned. " + "This well will be closed at " + std::to_string ( m_timeMap.getTimePassedUntil(currentStep) / (60*60*24) ) + " days"; - m_messages.note(msg); + OpmLog::note(msg); updateWellStatus( *well, currentStep, WellCommon::StatusEnum::SHUT ); } } @@ -642,7 +642,7 @@ namespace Opm { std::string msg = "Well " + well->name() + " is an injector with zero rate where crossflow is banned. " + "This well will be closed at " + std::to_string ( m_timeMap.getTimePassedUntil(currentStep) / (60*60*24) ) + " days"; - m_messages.note(msg); + OpmLog::note(msg); updateWellStatus( *well, currentStep, WellCommon::StatusEnum::SHUT ); } } @@ -775,7 +775,7 @@ namespace Opm { std::string msg = "Well " + well.name() + " is an injector with zero rate where crossflow is banned. " + "This well will be closed at " + std::to_string ( m_timeMap.getTimePassedUntil(currentStep) / (60*60*24) ) + " days"; - m_messages.note(msg); + OpmLog::note(msg); updateWellStatus( well, currentStep, WellCommon::StatusEnum::SHUT ); } } @@ -853,7 +853,7 @@ namespace Opm { + " where crossflow is banned has zero total rate." + " This well is prevented from opening at " + std::to_string( days ) + " days"; - m_messages.note(msg); + OpmLog::note(msg); } else { this->updateWellStatus( *well, currentStep, status ); } @@ -1275,7 +1275,7 @@ namespace Opm { std::string msg = "All completions in well " + well.name() + " is shut at " + std::to_string ( m_timeMap.getTimePassedUntil(currentStep) / (60*60*24) ) + " days. \n" + "The well is therefore also shut."; - m_messages.note(msg); + OpmLog::note(msg); updateWellStatus( well, currentStep, WellCommon::StatusEnum::SHUT); } } @@ -1653,14 +1653,7 @@ namespace Opm { return m_messageLimits; } - const MessageContainer& Schedule::getMessageContainer() const { - return m_messages; - } - - - MessageContainer& Schedule::getMessageContainer() { - return m_messages; - } + const Events& Schedule::getEvents() const { diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp index adb41f358..2835bb6af 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well.cpp @@ -19,6 +19,8 @@ #include +#include + #include #include #include @@ -230,7 +232,7 @@ namespace Opm { bool Well::setStatus(size_t timeStep, WellCommon::StatusEnum status) { if ((WellCommon::StatusEnum::OPEN == status) && getCompletions(timeStep).allCompletionsShut()) { - m_messages.note("When handling keyword for well " + name() + ": Cannot open a well where all completions are shut"); + OpmLog::note("When handling keyword for well " + name() + ": Cannot open a well where all completions are shut" ); return false; } else { bool update = m_status.update( timeStep , status ); @@ -241,10 +243,6 @@ namespace Opm { } } - const MessageContainer& Well::getMessageContainer() const { - return m_messages; - } - bool Well::isProducer(size_t timeStep) const { return bool( m_isProducer.get(timeStep) ); } diff --git a/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp b/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp index 746f4d535..86470b449 100644 --- a/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp +++ b/src/opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.cpp @@ -19,7 +19,6 @@ #include -#include #include #include #include @@ -124,44 +123,22 @@ namespace { }; -/* - When the error handling config says that the error should be - logged, the handleMissingWell and handleMissingGroup routines - cheat. Ideally we should have a MessageContainer instance around - and pass that to the parseContext::handlError() routine. Instead - we: - - 1. We instantiate new MessageContainer() which is just - immediately dropped to floor, leaving the messages behind. - - 2. Print a message on stderr. - - The case of incorrectly/missing well/group names in the SUMMARY - section did just not seem important enough to warrant the - refactoring required to pass a mutable proper MessageContainer - all the way down here. -*/ - - - void handleMissingWell( const ParseContext& parseContext , const std::string& keyword, const std::string& well) { std::string msg = std::string("Error in keyword:") + keyword + std::string(" No such well: ") + well; - MessageContainer msgContainer; if (parseContext.get( ParseContext::SUMMARY_UNKNOWN_WELL) == InputError::WARN) std::cerr << "ERROR: " << msg << std::endl; - parseContext.handleError( ParseContext::SUMMARY_UNKNOWN_WELL , msgContainer , msg ); + parseContext.handleError( ParseContext::SUMMARY_UNKNOWN_WELL , msg ); } void handleMissingGroup( const ParseContext& parseContext , const std::string& keyword, const std::string& group) { std::string msg = std::string("Error in keyword:") + keyword + std::string(" No such group: ") + group; - MessageContainer msgContainer; if (parseContext.get( ParseContext::SUMMARY_UNKNOWN_GROUP) == InputError::WARN) std::cerr << "ERROR: " << msg << std::endl; - parseContext.handleError( ParseContext::SUMMARY_UNKNOWN_GROUP , msgContainer , msg ); + parseContext.handleError( ParseContext::SUMMARY_UNKNOWN_GROUP , msg ); } inline void keywordW( std::vector< ERT::smspec_node >& list, diff --git a/src/opm/parser/eclipse/EclipseState/Tables/TableManager.cpp b/src/opm/parser/eclipse/EclipseState/Tables/TableManager.cpp index 3cea3ea36..0b3f15f48 100644 --- a/src/opm/parser/eclipse/EclipseState/Tables/TableManager.cpp +++ b/src/opm/parser/eclipse/EclipseState/Tables/TableManager.cpp @@ -18,6 +18,8 @@ along with OPM. If not, see . */ +#include + #include #include #include @@ -507,7 +509,6 @@ namespace Opm { VFPProdTable table; table.init(keyword, unit_system); - m_messages.appendMessages(table.getMessageContainer()); //Check that the table in question has a unique ID int table_id = table.getTableNum(); @@ -792,22 +793,13 @@ namespace Opm { return m_jfunc; } - const MessageContainer& TableManager::getMessageContainer() const { - return m_messages; - } - - - MessageContainer& TableManager::getMessageContainer() { - return m_messages; - } - void TableManager::complainAboutAmbiguousKeyword(const Deck& deck, const std::string& keywordName) { - m_messages.error("The " + keywordName + " keyword must be unique in the deck. Ignoring all!"); + OpmLog::error("The " + keywordName + " keyword must be unique in the deck. Ignoring all!"); const auto& keywords = deck.getKeywordList(keywordName); for (size_t i = 0; i < keywords.size(); ++i) { std::string msg = "Ambiguous keyword "+keywordName+" defined here"; - m_messages.error(keywords[i]->getFileName(), msg, keywords[i]->getLineNumber()); + OpmLog::error(Log::fileMessage(keywords[i]->getFileName(), keywords[i]->getLineNumber(), msg)); } } diff --git a/src/opm/parser/eclipse/EclipseState/Tables/VFPProdTable.cpp b/src/opm/parser/eclipse/EclipseState/Tables/VFPProdTable.cpp index d420f4014..b07e94fca 100644 --- a/src/opm/parser/eclipse/EclipseState/Tables/VFPProdTable.cpp +++ b/src/opm/parser/eclipse/EclipseState/Tables/VFPProdTable.cpp @@ -20,6 +20,8 @@ #include #include +#include + #include #include #include @@ -394,7 +396,7 @@ void VFPProdTable::check(const DeckKeyword& keyword, const double table_scaling_ } if (!points.empty()) { - m_messages.warning("VFP table for production wells has BHP versus THP not " + OpmLog::warning("VFP table for production wells has BHP versus THP not " + std::string("monotonically increasing.\nThis may cause convergence ") + "issues due to switching between BHP and THP control mode." + std::string("\nIn keyword VFPPROD table number ") @@ -402,7 +404,7 @@ void VFPProdTable::check(const DeckKeyword& keyword, const double table_scaling_ + ", file " + keyword.getFileName() + ", line " + std::to_string(keyword.getLineNumber()) + "\n"); - m_messages.note(points); + OpmLog::note(points); } } @@ -539,11 +541,4 @@ void VFPProdTable::convertALQToSI(const ALQ_TYPE& type, } - -const MessageContainer& VFPProdTable::getMessageContainer() const -{ - return m_messages; -} - - } //Namespace opm diff --git a/src/opm/parser/eclipse/EclipseState/checkDeck.cpp b/src/opm/parser/eclipse/EclipseState/checkDeck.cpp index 17e5cf3ff..253b87403 100644 --- a/src/opm/parser/eclipse/EclipseState/checkDeck.cpp +++ b/src/opm/parser/eclipse/EclipseState/checkDeck.cpp @@ -18,6 +18,9 @@ */ #include +#include +#include + #include #include #include @@ -33,7 +36,7 @@ bool checkDeck( Deck& deck, const Parser& parser, size_t enabledChecks) { const auto& keyword = deck.getKeyword(keywordIdx); if (!parser.isRecognizedKeyword( keyword.name() ) ) { std::string msg("Keyword '" + keyword.name() + "' is unknown."); - deck.getMessageContainer().warning(msg, keyword.getFileName(), keyword.getLineNumber()); + OpmLog::warning( Log::fileMessage(keyword.getFileName(), keyword.getLineNumber(), msg) ); deckValid = false; } } diff --git a/src/opm/parser/eclipse/Parser/MessageContainer.cpp b/src/opm/parser/eclipse/Parser/MessageContainer.cpp deleted file mode 100644 index c284e4a56..000000000 --- a/src/opm/parser/eclipse/Parser/MessageContainer.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - Copyright 2016 Statoil ASA. - - This file is part of the Open Porous Media project (OPM). - - OPM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OPM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OPM. If not, see . -*/ - -#include - -#include - - -namespace Opm { - - Location::Location( const std::string& fn, size_t ln ) : - filename( fn ), lineno( ln ) - { - if( ln == 0 ) - throw std::invalid_argument( "Invalid line number 0 for file '" - + fn + "'" ); - } - - void MessageContainer::error( const std::string& msg, - const std::string& filename, - const size_t lineno ) { - m_messages.emplace_back( - Message { Message::Error, msg, Location { filename, lineno } } - ); - } - - - void MessageContainer::error( const std::string& msg ) { - m_messages.emplace_back( Message { Message::Error, msg, {} } ); - } - - - void MessageContainer::bug( const std::string& msg, - const std::string& filename, - const size_t lineno ) { - m_messages.emplace_back( - Message { Message::Bug, msg, { filename, lineno } } - ); - } - - - void MessageContainer::bug( const std::string& msg ) { - m_messages.emplace_back( Message { Message::Bug, msg, {} } ); - } - - - void MessageContainer::warning( const std::string& msg, - const std::string& filename, - const size_t lineno ) { - m_messages.emplace_back( Message { - Message::Warning, msg, { filename, lineno } - } - ); - } - - - void MessageContainer::warning( const std::string& msg ) { - m_messages.emplace_back( - Message { Message::Warning, msg,{} } - ); - } - - - - void MessageContainer::info( const std::string& msg, - const std::string& filename, - const size_t lineno ) { - m_messages.emplace_back( - Message { Message::Info, msg, { filename, lineno } } - ); - } - - - void MessageContainer::info( const std::string& msg ) { - m_messages.emplace_back( Message { Message::Info, msg, {} } ); - } - - - void MessageContainer::debug( const std::string& msg, - const std::string& filename, - const size_t lineno ) { - m_messages.emplace_back( - Message { Message::Debug, msg, { filename, lineno } } - ); - } - - - void MessageContainer::debug( const std::string& msg ) { - m_messages.emplace_back( Message { Message::Debug, msg, {} } ); - } - - - void MessageContainer::problem( const std::string& msg, - const std::string& filename, - const size_t lineno ) { - m_messages.emplace_back( - Message { Message::Problem, msg, { filename, lineno } } - ); - } - - - void MessageContainer::problem( const std::string& msg ) { - m_messages.emplace_back( Message { Message::Problem, msg, {} } ); - } - - - void MessageContainer::note( const std::string& msg, - const std::string& filename, - const size_t lineno ) { - m_messages.emplace_back( - Message { Message::Note, msg, { filename, lineno } } - ); - } - - - void MessageContainer::note( const std::string& msg ) { - m_messages.emplace_back( Message { Message::Note, msg, {} } ); - } - - - void MessageContainer::add( const Message& msg ) { - this->m_messages.push_back( msg ); - } - - void MessageContainer::add( Message&& msg ) { - this->m_messages.push_back( std::move( msg ) ); - } - - - void MessageContainer::appendMessages(const MessageContainer& other) - { - for(const auto& msg : other) { - this->add(msg); - } - } - - - MessageContainer::const_iterator MessageContainer::begin() const { - return m_messages.begin(); - } - - MessageContainer::const_iterator MessageContainer::end() const { - return m_messages.end(); - } - - std::size_t MessageContainer::size() const { - return m_messages.size(); - } - - -} // namespace Opm diff --git a/src/opm/parser/eclipse/Parser/ParseContext.cpp b/src/opm/parser/eclipse/Parser/ParseContext.cpp index 6b37a0f7a..0ab88ee45 100644 --- a/src/opm/parser/eclipse/Parser/ParseContext.cpp +++ b/src/opm/parser/eclipse/Parser/ParseContext.cpp @@ -94,25 +94,21 @@ namespace Opm { } - Message::type ParseContext::handleError( + void ParseContext::handleError( const std::string& errorKey, - MessageContainer& msgContainer, const std::string& msg ) const { InputError::Action action = get( errorKey ); if (action == InputError::WARN) { - msgContainer.warning(msg); - return Message::Warning; + OpmLog::warning(msg); + return; } else if (action == InputError::THROW_EXCEPTION) { - msgContainer.error(msg); + OpmLog::error(msg); throw std::invalid_argument(errorKey + ": " + msg); } - - return Message::Debug; - } std::map::const_iterator ParseContext::begin() const { diff --git a/src/opm/parser/eclipse/Parser/Parser.cpp b/src/opm/parser/eclipse/Parser/Parser.cpp index 8b306fb94..4a96a62e6 100644 --- a/src/opm/parser/eclipse/Parser/Parser.cpp +++ b/src/opm/parser/eclipse/Parser/Parser.cpp @@ -24,6 +24,9 @@ #include #include +#include +#include + #include #include @@ -292,7 +295,7 @@ void ParserState::loadFile(const boost::filesystem::path& inputFile) { inputFileCanonical = boost::filesystem::canonical(inputFile); } catch (boost::filesystem::filesystem_error fs_error) { std::string msg = "Could not open file: " + inputFile.string(); - parseContext.handleError( ParseContext::PARSE_MISSING_INCLUDE , deck.getMessageContainer() , msg); + parseContext.handleError( ParseContext::PARSE_MISSING_INCLUDE , msg); return; } @@ -305,7 +308,7 @@ void ParserState::loadFile(const boost::filesystem::path& inputFile) { // make sure the file we'd like to parse is readable if( !ufp ) { std::string msg = "Could not read from file: " + inputFile.string(); - parseContext.handleError( ParseContext::PARSE_MISSING_INCLUDE , deck.getMessageContainer() , msg); + parseContext.handleError( ParseContext::PARSE_MISSING_INCLUDE , msg); return; } @@ -365,7 +368,7 @@ void ParserState::handleRandomText(const string_view& keywordString ) const { << this->current_path() << ":" << this->line(); } - parseContext.handleError( errorKey , deck.getMessageContainer() , msg.str() ); + parseContext.handleError( errorKey , msg.str() ); } void ParserState::openRootFile( const boost::filesystem::path& inputFile) { @@ -393,7 +396,7 @@ boost::filesystem::path ParserState::getIncludeFilePath( std::string path ) cons if (path.find('\\') != std::string::npos) { // ... if so, replace with slashes and create a warning. std::replace(path.begin(), path.end(), '\\', '/'); - deck.getMessageContainer().warning("Replaced one or more backslash with a slash in an INCLUDE path."); + OpmLog::warning("Replaced one or more backslash with a slash in an INCLUDE path."); } boost::filesystem::path includeFilePath(path); @@ -414,8 +417,7 @@ std::shared_ptr< RawKeyword > createRawKeyword( const string_view& kw, ParserSta if( !parser.isRecognizedKeyword( keywordString ) ) { if( ParserKeyword::validDeckName( keywordString ) ) { std::string msg = "Keyword " + keywordString + " not recognized."; - auto& msgContainer = parserState.deck.getMessageContainer(); - parserState.parseContext.handleError( ParseContext::PARSE_UNKNOWN_KEYWORD, msgContainer, msg ); + parserState.parseContext.handleError( ParseContext::PARSE_UNKNOWN_KEYWORD, msg ); parserState.unknown_keyword = true; return {}; } @@ -465,8 +467,7 @@ std::shared_ptr< RawKeyword > createRawKeyword( const string_view& kw, ParserSta std::string msg = "Expected the kewyord: " +keyword_size.keyword + " to infer the number of records in: " + keywordString; - auto& msgContainer = parserState.deck.getMessageContainer(); - parserState.parseContext.handleError(ParseContext::PARSE_MISSING_DIMS_KEYWORD , msgContainer, msg ); + parserState.parseContext.handleError(ParseContext::PARSE_MISSING_DIMS_KEYWORD , msg ); const auto* keyword = parser.getKeyword( keyword_size.keyword ); const auto& record = keyword->getRecord(0); @@ -580,15 +581,14 @@ bool parseState( ParserState& parserState, const Parser& parser ) { if( parser.isRecognizedKeyword( parserState.rawKeyword->getKeywordName() ) ) { const auto& kwname = parserState.rawKeyword->getKeywordName(); const auto* parserKeyword = parser.getParserKeywordFromDeckName( kwname ); - parserState.deck.addKeyword( parserKeyword->parse( parserState.parseContext, parserState.deck.getMessageContainer(), parserState.rawKeyword ) ); + parserState.deck.addKeyword( parserKeyword->parse( parserState.parseContext, parserState.rawKeyword ) ); } else { DeckKeyword deckKeyword( parserState.rawKeyword->getKeywordName(), false ); const std::string msg = "The keyword " + parserState.rawKeyword->getKeywordName() + " is not recognized"; deckKeyword.setLocation( parserState.rawKeyword->getFilename(), parserState.rawKeyword->getLineNR()); parserState.deck.addKeyword( std::move( deckKeyword ) ); - parserState.deck.getMessageContainer().warning( - parserState.current_path().string(), msg, parserState.line() ); + OpmLog::warning(Log::fileMessage(parserState.current_path().string(), parserState.line(), msg)); } } @@ -865,7 +865,7 @@ std::vector Parser::getAllDeckNames () const { { if( deck.size() == 0 ) { std::string msg = "empty decks are invalid\n"; - deck.getMessageContainer().warning(msg); + OpmLog::warning(msg); return false; } @@ -874,7 +874,7 @@ std::vector Parser::getAllDeckNames () const { if( deck.getKeyword(0).name() != "RUNSPEC" ) { std::string msg = "The first keyword of a valid deck must be RUNSPEC\n"; auto curKeyword = deck.getKeyword(0); - deck.getMessageContainer().warning(msg, curKeyword.getFileName(), curKeyword.getLineNumber()); + OpmLog::warning(Log::fileMessage(curKeyword.getFileName(), curKeyword.getLineNumber(), msg) ); deckValid = false; } @@ -894,7 +894,7 @@ std::vector Parser::getAllDeckNames () const { std::string msg = "The keyword '"+curKeywordName+"' is located in the '"+curSectionName +"' section where it is invalid"; - deck.getMessageContainer().warning(msg, curKeyword.getFileName(), curKeyword.getLineNumber()); + OpmLog::warning(Log::fileMessage(curKeyword.getFileName(), curKeyword.getLineNumber(), msg) ); deckValid = false; } @@ -905,7 +905,7 @@ std::vector Parser::getAllDeckNames () const { if (curKeywordName != "GRID") { std::string msg = "The RUNSPEC section must be followed by GRID instead of "+curKeywordName; - deck.getMessageContainer().warning(msg, curKeyword.getFileName(), curKeyword.getLineNumber()); + OpmLog::warning(Log::fileMessage(curKeyword.getFileName(), curKeyword.getLineNumber(), msg) ); deckValid = false; } @@ -915,7 +915,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; - deck.getMessageContainer().warning(msg, curKeyword.getFileName(), curKeyword.getLineNumber()); + OpmLog::warning(Log::fileMessage(curKeyword.getFileName(), curKeyword.getLineNumber(), msg) ); deckValid = false; } @@ -925,7 +925,7 @@ std::vector Parser::getAllDeckNames () const { if (curKeywordName != "PROPS") { std::string msg = "The EDIT section must be followed by PROPS instead of "+curKeywordName; - deck.getMessageContainer().warning(msg, curKeyword.getFileName(), curKeyword.getLineNumber()); + OpmLog::warning(Log::fileMessage(curKeyword.getFileName(), curKeyword.getLineNumber(), msg) ); deckValid = false; } @@ -935,7 +935,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; - deck.getMessageContainer().warning(msg, curKeyword.getFileName(), curKeyword.getLineNumber()); + OpmLog::warning(Log::fileMessage(curKeyword.getFileName(), curKeyword.getLineNumber(), msg) ); deckValid = false; } @@ -945,7 +945,7 @@ std::vector Parser::getAllDeckNames () const { if (curKeywordName != "SOLUTION") { std::string msg = "The REGIONS section must be followed by SOLUTION instead of "+curKeywordName; - deck.getMessageContainer().warning(msg, curKeyword.getFileName(), curKeyword.getLineNumber()); + OpmLog::warning(Log::fileMessage(curKeyword.getFileName(), curKeyword.getLineNumber(), msg) ); deckValid = false; } @@ -955,7 +955,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; - deck.getMessageContainer().warning(msg, curKeyword.getFileName(), curKeyword.getLineNumber()); + OpmLog::warning(Log::fileMessage(curKeyword.getFileName(), curKeyword.getLineNumber(), msg) ); deckValid = false; } @@ -965,7 +965,7 @@ std::vector Parser::getAllDeckNames () const { if (curKeywordName != "SCHEDULE") { std::string msg = "The SUMMARY section must be followed by SCHEDULE instead of "+curKeywordName; - deck.getMessageContainer().warning(msg, curKeyword.getFileName(), curKeyword.getLineNumber()); + OpmLog::warning(Log::fileMessage(curKeyword.getFileName(), curKeyword.getLineNumber(), msg) ); deckValid = false; } @@ -976,7 +976,7 @@ std::vector Parser::getAllDeckNames () const { std::string msg = "The SCHEDULE section must be the last one (" +curKeywordName+" specified after SCHEDULE)"; - deck.getMessageContainer().warning(msg, curKeyword.getFileName(), curKeyword.getLineNumber()); + OpmLog::warning(Log::fileMessage(curKeyword.getFileName(), curKeyword.getLineNumber(), msg) ); deckValid = false; } } @@ -986,7 +986,7 @@ std::vector Parser::getAllDeckNames () const { const auto& curKeyword = deck.getKeyword(deck.size() - 1); std::string msg = "The last section of a valid deck must be SCHEDULE (is "+curSectionName+")"; - deck.getMessageContainer().warning(msg, curKeyword.getFileName(), curKeyword.getLineNumber()); + OpmLog::warning(Log::fileMessage(curKeyword.getFileName(), curKeyword.getLineNumber(), msg) ); deckValid = false; } diff --git a/src/opm/parser/eclipse/Parser/ParserKeyword.cpp b/src/opm/parser/eclipse/Parser/ParserKeyword.cpp index fa69d7c85..60d0a791f 100644 --- a/src/opm/parser/eclipse/Parser/ParserKeyword.cpp +++ b/src/opm/parser/eclipse/Parser/ParserKeyword.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -476,7 +475,6 @@ void set_dimensions( ParserItem& item, } DeckKeyword ParserKeyword::parse(const ParseContext& parseContext, - MessageContainer& msgContainer, std::shared_ptr< RawKeyword > rawKeyword) const { if( !rawKeyword->isFinished() ) throw std::invalid_argument("Tried to create a deck keyword from an incomplete raw keyword " + rawKeyword->getKeywordName()); @@ -490,7 +488,7 @@ void set_dimensions( ParserItem& item, if( m_records.size() == 0 && rawRecord.size() > 0 ) throw std::invalid_argument("Missing item information " + rawKeyword->getKeywordName()); - keyword.addRecord( getRecord( record_nr ).parse( parseContext, msgContainer, rawRecord ) ); + keyword.addRecord( getRecord( record_nr ).parse( parseContext, rawRecord ) ); record_nr++; } diff --git a/src/opm/parser/eclipse/Parser/ParserRecord.cpp b/src/opm/parser/eclipse/Parser/ParserRecord.cpp index a27b39a0c..560f2550f 100644 --- a/src/opm/parser/eclipse/Parser/ParserRecord.cpp +++ b/src/opm/parser/eclipse/Parser/ParserRecord.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -124,7 +123,7 @@ namespace { return *itr; } - DeckRecord ParserRecord::parse(const ParseContext& parseContext , MessageContainer& msgContainer, RawRecord& rawRecord ) const { + DeckRecord ParserRecord::parse(const ParseContext& parseContext , RawRecord& rawRecord ) const { std::vector< DeckItem > items; items.reserve( this->size() + 20 ); for( const auto& parserItem : *this ) @@ -134,7 +133,7 @@ namespace { std::string msg = "The RawRecord for keyword \"" + rawRecord.getKeywordName() + "\" in file\"" + rawRecord.getFileName() + "\" contained " + std::to_string(rawRecord.size()) + " too many items according to the spec. RawRecord was: " + rawRecord.getRecordString(); - parseContext.handleError(ParseContext::PARSE_EXTRA_DATA , msgContainer, msg); + parseContext.handleError(ParseContext::PARSE_EXTRA_DATA , msg); } return { std::move( items ) }; diff --git a/tests/parser/DeckTests.cpp b/tests/parser/DeckTests.cpp index 76705e3cc..8d4fb6b37 100644 --- a/tests/parser/DeckTests.cpp +++ b/tests/parser/DeckTests.cpp @@ -509,11 +509,10 @@ BOOST_AUTO_TEST_CASE(StringsWithSpaceOK) { ParserRecord record1; RawRecord rawRecord( " ' VALUE ' " ); ParseContext parseContext; - MessageContainer msgContainer; record1.addItem( itemString ); - const auto deckRecord = record1.parse( parseContext , msgContainer, rawRecord ); + const auto deckRecord = record1.parse( parseContext , rawRecord ); BOOST_CHECK_EQUAL(" VALUE " , deckRecord.getItem(0).get< std::string >(0)); } diff --git a/tests/parser/MessageContainerTest.cpp b/tests/parser/MessageContainerTest.cpp deleted file mode 100644 index 6811f6bc2..000000000 --- a/tests/parser/MessageContainerTest.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - Copyright 2016 Statoil ASA. - - This file is part of the Open Porous Media project (OPM). - - OPM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OPM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OPM. If not, see . -*/ - - -#define BOOST_TEST_MODULE MessageContainerTest - -#include - -#include - - -using namespace Opm; - -BOOST_AUTO_TEST_CASE(TestIterator) { - - MessageContainer msgContainer; - msgContainer.error("This is an error."); - msgContainer.bug("This is a bug.", "dummy.log", 20); - { - BOOST_CHECK_EQUAL("This is an error.", msgContainer.begin()->message); - BOOST_CHECK_EQUAL("dummy.log", (msgContainer.end()-1)->location.filename); - BOOST_CHECK_EQUAL(20U , (msgContainer.end()-1)->location.lineno); - } - - MessageContainer msgList; - msgList.debug("Debug"); - msgList.info("Info"); - msgList.warning("Warning"); - msgList.error("Error"); - msgList.problem("Problem"); - msgList.bug("Bug"); - msgList.note("Note"); - std::vector msgString = {"Debug", "Info", "Warning", "Error", "Problem", "Bug", "Note"}; - int i = 0; - for (const auto& msg : msgList) { - BOOST_CHECK_EQUAL(msg.message, msgString[i]); - i++; - } -} - -BOOST_AUTO_TEST_CASE(LocationImplicitConversion) { - MessageContainer mc; - mc.warning( "Warning" ); - mc.info( "Info", "filename", 10 ); - - BOOST_CHECK( !mc.begin()->location ); - BOOST_CHECK( (mc.begin() + 1)->location ); - BOOST_CHECK_THROW( mc.info( "msg", "filename", 0 ), std::invalid_argument ); -} - - -BOOST_AUTO_TEST_CASE(appendMessages) { - MessageContainer msgContainer; - MessageContainer msgList; - - msgContainer.error("Error: msgContainer."); - BOOST_CHECK_EQUAL(1U, msgContainer.size()); - - msgList.warning("Warning: msgList."); - msgContainer.appendMessages(msgList); - BOOST_CHECK_EQUAL(2U, msgContainer.size()); - - BOOST_CHECK_EQUAL("Error: msgContainer.", msgContainer.begin()->message); - BOOST_CHECK_EQUAL("Warning: msgList.", (msgContainer.end()-1)->message); -} diff --git a/tests/parser/ParserTests.cpp b/tests/parser/ParserTests.cpp index 8802853bf..cdcdf1edb 100644 --- a/tests/parser/ParserTests.cpp +++ b/tests/parser/ParserTests.cpp @@ -1030,16 +1030,14 @@ BOOST_AUTO_TEST_CASE(parse_validRecord_noThrow) { auto record = createSimpleParserRecord(); ParseContext parseContext; RawRecord raw( string_view( "100 443" ) ); - MessageContainer msgContainer; - BOOST_CHECK_NO_THROW(record.parse(parseContext, msgContainer, raw ) ); + BOOST_CHECK_NO_THROW(record.parse(parseContext, raw ) ); } BOOST_AUTO_TEST_CASE(parse_validRecord_deckRecordCreated) { auto record = createSimpleParserRecord(); RawRecord rawRecord( string_view( "100 443" ) ); ParseContext parseContext; - MessageContainer msgContainer; - const auto deckRecord = record.parse(parseContext , msgContainer, rawRecord); + const auto deckRecord = record.parse(parseContext , rawRecord); BOOST_CHECK_EQUAL(2U, deckRecord.size()); } @@ -1071,8 +1069,7 @@ BOOST_AUTO_TEST_CASE(parse_validMixedRecord_noThrow) { auto record = createMixedParserRecord(); RawRecord rawRecord( string_view( "1 2 10.0 20.0 4 90.0") ); ParseContext parseContext; - MessageContainer msgContainer; - BOOST_CHECK_NO_THROW(record.parse(parseContext , msgContainer, rawRecord)); + BOOST_CHECK_NO_THROW(record.parse(parseContext , rawRecord)); } BOOST_AUTO_TEST_CASE(Equal_Equal_ReturnsTrue) { @@ -1212,15 +1209,14 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooManyItems_Throws) { RawRecord rawRecord( "3 3 3 " ); - MessageContainer msgContainer; - BOOST_CHECK_NO_THROW(parserRecord.parse(parseContext , msgContainer, rawRecord)); + BOOST_CHECK_NO_THROW(parserRecord.parse(parseContext , rawRecord)); RawRecord rawRecordOneExtra( "3 3 3 4 " ); - BOOST_CHECK_THROW(parserRecord.parse(parseContext , msgContainer, rawRecordOneExtra), std::invalid_argument); + BOOST_CHECK_THROW(parserRecord.parse(parseContext , rawRecordOneExtra), std::invalid_argument); RawRecord rawRecordForgotRecordTerminator( "3 3 3 \n 4 4 4 " ); - BOOST_CHECK_THROW(parserRecord.parse(parseContext , msgContainer, rawRecordForgotRecordTerminator), std::invalid_argument); + BOOST_CHECK_THROW(parserRecord.parse(parseContext , rawRecordForgotRecordTerminator), std::invalid_argument); } @@ -1241,10 +1237,9 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooFewItems) { ParseContext parseContext; RawRecord rawRecord( "3 3 " ); // no default specified for the third item, record can be parsed just fine but trying - // to access the data will raise an exception... - MessageContainer msgContainer; - BOOST_CHECK_NO_THROW(parserRecord.parse(parseContext , msgContainer, rawRecord)); - auto record = parserRecord.parse(parseContext , msgContainer, rawRecord); + // to access the data will raise an exception...; + BOOST_CHECK_NO_THROW(parserRecord.parse(parseContext , rawRecord)); + auto record = parserRecord.parse(parseContext , rawRecord); BOOST_CHECK_NO_THROW(record.getItem(2)); BOOST_CHECK_THROW(record.getItem(2).get< int >(0), std::out_of_range); } @@ -1623,14 +1618,13 @@ BOOST_AUTO_TEST_CASE(ParseEmptyRecord) { item.setType( int() ); auto rawkeyword = std::make_shared< RawKeyword >( tabdimsKeyword->getName() , "FILE" , 10U , 1 ); ParseContext parseContext; - MessageContainer msgContainer; BOOST_CHECK_EQUAL( Raw::FIXED , rawkeyword->getSizeType()); rawkeyword->addRawRecordString("/"); record.addItem(item); tabdimsKeyword->addRecord( record ); - const auto deckKeyword = tabdimsKeyword->parse( parseContext , msgContainer, rawkeyword ); + const auto deckKeyword = tabdimsKeyword->parse( parseContext , rawkeyword ); BOOST_REQUIRE_EQUAL( 1U , deckKeyword.size()); const auto& deckRecord = deckKeyword.getRecord(0); diff --git a/tests/parser/integration/parse_write.cpp b/tests/parser/integration/parse_write.cpp index 6547fb949..69d521134 100644 --- a/tests/parser/integration/parse_write.cpp +++ b/tests/parser/integration/parse_write.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include #include