From de5e3d90cd8c8a27c435f16040159ecea6745f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Wed, 7 Oct 2020 00:25:24 +0200 Subject: [PATCH] Miscellaneous Cleanup Changes In particular, include standard library headers as needed, fix function declarations (operator<<() for Well::WellProductionProperties), and make a few helper functions 'static' to avoid warnings of the form "no previous declaration for". For the Schedule's keyword handlers, also switch to storing member function pointers directly instead of std::function objects. This saves space and does not incur function pointer conversions. Use std::invoke to call those handlers to avoid having to spell out the '->*' operator. --- .../EclipseState/Schedule/Well/Well.hpp | 11 ++++-- .../Schedule/Well/WellConnections.hpp | 2 + .../EclipseState/Schedule/KeywordHandlers.cpp | 38 +++++++++---------- .../Schedule/Well/WellConnections.cpp | 7 +++- tests/parser/ConnectionTests.cpp | 32 +++++++++------- tests/parser/ScheduleTests.cpp | 12 +++--- tests/parser/WellTests.cpp | 2 - 7 files changed, 57 insertions(+), 47 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp b/opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp index be7b17dbf..268883b04 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp @@ -21,8 +21,15 @@ #ifndef WELL2_HPP #define WELL2_HPP +#include #include +#include +#include #include +#include +#include + +#include #include #include @@ -45,8 +52,6 @@ namespace Opm { class DeckRecord; class EclipseGrid; class DeckKeyword; -struct WellInjectionProperties; -class WellProductionProperties; class UDQActive; class UDQConfig; class SICD; @@ -638,7 +643,7 @@ private: }; std::ostream& operator<<( std::ostream&, const Well::WellInjectionProperties& ); -std::ostream& operator<<( std::ostream&, const WellProductionProperties& ); +std::ostream& operator<<( std::ostream&, const Well::WellProductionProperties& ); int eclipseControlMode(const Well::InjectorCMode imode, const InjectorType itype); diff --git a/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.hpp b/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.hpp index bc6406077..51f816722 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.hpp @@ -25,6 +25,8 @@ #include +#include + namespace Opm { class EclipseGrid; class FieldPropsManager; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp index 244f70f48..fa263b309 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/KeywordHandlers.cpp @@ -17,6 +17,7 @@ along with OPM. If not, see . */ +#include #include #include #include @@ -1680,7 +1681,7 @@ namespace { bool Schedule::handleNormalKeyword(const HandlerContext& handlerContext, const ParseContext& parseContext, ErrorGuard& errors) { - using handler_function = std::function; + using handler_function = void (Schedule::*)(const HandlerContext&, const ParseContext&, ErrorGuard&); static const std::unordered_map handler_functions = { { "BRANPROP", &Schedule::handleBRANPROP }, { "COMPDAT" , &Schedule::handleCOMPDAT }, @@ -1757,27 +1758,24 @@ namespace { { "WTRACER" , &Schedule::handleWTRACER }, }; - const auto function_iterator = handler_functions.find(handlerContext.keyword.name()); - - if (function_iterator != handler_functions.end()) { - const auto& handler = function_iterator->second; - - try { - handler(this, handlerContext, parseContext, errors); - } catch (const OpmInputError&) { - throw; - } catch (const std::exception& e) { - const OpmInputError opm_error { e, handlerContext.keyword.location() } ; - - OpmLog::error(opm_error.what()); - - std::throw_with_nested(opm_error); - } - - return true; - } else { + auto function_iterator = handler_functions.find(handlerContext.keyword.name()); + if (function_iterator == handler_functions.end()) { return false; } + + try { + std::invoke(function_iterator->second, this, handlerContext, parseContext, errors); + } catch (const OpmInputError&) { + throw; + } catch (const std::exception& e) { + const OpmInputError opm_error { e, handlerContext.keyword.location() } ; + + OpmLog::error(opm_error.what()); + + std::throw_with_nested(opm_error); + } + + return true; } } diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.cpp index d4c8f97f8..3b831f334 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.cpp @@ -17,10 +17,15 @@ along with OPM. If not, see . */ +#include #include #include -#include +#include #include +#include +#include +#include +#include #include #include diff --git a/tests/parser/ConnectionTests.cpp b/tests/parser/ConnectionTests.cpp index 1494c0aa8..fb3c09e35 100644 --- a/tests/parser/ConnectionTests.cpp +++ b/tests/parser/ConnectionTests.cpp @@ -17,6 +17,7 @@ along with OPM. If not, see . */ +#include #include #include #include @@ -28,6 +29,7 @@ #include #include +#include #include #include #include @@ -41,6 +43,22 @@ #include #include +namespace { +Opm::WellConnections loadCOMPDAT(const std::string& compdat_keyword) { + Opm::EclipseGrid grid(10,10,10); + Opm::TableManager tables; + Opm::Parser parser; + const auto deck = parser.parseString(compdat_keyword); + Opm::FieldPropsManager field_props(deck, Opm::Phases{true, true, true}, grid, Opm::TableManager()); + const auto& keyword = deck.getKeyword("COMPDAT", 0); + Opm::WellConnections connections(Opm::Connection::Order::TRACK, 10,10); + for (const auto& rec : keyword) + connections.loadCOMPDAT(rec, grid, field_props); + + return connections; +} +} + namespace Opm { inline std::ostream& operator<<( std::ostream& stream, const Connection& c ) { @@ -150,20 +168,6 @@ BOOST_AUTO_TEST_CASE(ActiveCompletions) { BOOST_CHECK_EQUAL( completion3, active_completions.get(1)); } -Opm::WellConnections loadCOMPDAT(const std::string& compdat_keyword) { - Opm::EclipseGrid grid(10,10,10); - Opm::TableManager tables; - Opm::Parser parser; - const auto deck = parser.parseString(compdat_keyword); - Opm::FieldPropsManager field_props(deck, Opm::Phases{true, true, true}, grid, Opm::TableManager()); - const auto& keyword = deck.getKeyword("COMPDAT", 0); - Opm::WellConnections connections(Opm::Connection::Order::TRACK, 10,10); - for (const auto& rec : keyword) - connections.loadCOMPDAT(rec, grid, field_props); - - return connections; -} - BOOST_AUTO_TEST_CASE(loadCOMPDATTEST) { Opm::UnitSystem units(Opm::UnitSystem::UnitType::UNIT_TYPE_METRIC); // Unit system used in deck FIRST_SIM.DATA. { diff --git a/tests/parser/ScheduleTests.cpp b/tests/parser/ScheduleTests.cpp index c1ea2d02c..605e549c5 100644 --- a/tests/parser/ScheduleTests.cpp +++ b/tests/parser/ScheduleTests.cpp @@ -17,19 +17,17 @@ along with OPM. If not, see . */ -#include +#include #include -#include +#include #define BOOST_TEST_MODULE ScheduleTests #include -#include #include #include - #include #include #include @@ -61,7 +59,7 @@ using namespace Opm; -Schedule make_schedule(const std::string& deck_string) { +static Schedule make_schedule(const std::string& deck_string) { const auto& deck = Parser{}.parseString(deck_string); auto python = std::make_shared(); EclipseGrid grid(10,10,10); @@ -408,7 +406,7 @@ BOOST_AUTO_TEST_CASE(CreateScheduleDeckWellsOrdered) { } -bool has_well( const std::vector& wells, const std::string& well_name) { +static bool has_well( const std::vector& wells, const std::string& well_name) { for (const auto& well : wells ) if (well.name( ) == well_name) return true; @@ -3159,7 +3157,7 @@ BOOST_AUTO_TEST_CASE(WTEST_CONFIG) { } -bool has(const std::vector& l, const std::string& s) { +static bool has(const std::vector& l, const std::string& s) { auto f = std::find(l.begin(), l.end(), s); return (f != l.end()); } diff --git a/tests/parser/WellTests.cpp b/tests/parser/WellTests.cpp index 38ffbf075..467230155 100644 --- a/tests/parser/WellTests.cpp +++ b/tests/parser/WellTests.cpp @@ -59,8 +59,6 @@ inline std::ostream& operator<<( std::ostream& stream, const Well& well ) { } } - - BOOST_AUTO_TEST_CASE(WellCOMPDATtestTRACK) { Opm::Parser parser; std::string input =