From eae4cbb889d3cf3af162181f6c26a30e2bd284aa Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 28 Jan 2014 08:35:12 +0100 Subject: [PATCH] Added InjectorType enum. --- .../EclipseState/Schedule/ScheduleEnums.cpp | 32 +++++++++++++++++++ .../EclipseState/Schedule/ScheduleEnums.hpp | 7 ++-- .../Schedule/tests/ScheduleEnumTests.cpp | 32 +++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.cpp b/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.cpp index c18c443fb..9d9bc1772 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.cpp +++ b/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.cpp @@ -211,5 +211,37 @@ namespace Opm { throw std::invalid_argument("Unknown enum state string: " + stringValue ); } } + + /*****************************************************************/ + + namespace InjectorType { + const std::string InjectorEnum2String( InjectorEnum enumValue ) { + switch( enumValue ) { + case OIL: + return "OIL"; + case GAS: + return "GAS"; + case WATER: + return "WATER"; + case MULTI: + return "MULTI"; + default: + throw std::invalid_argument("unhandled enum value"); + } + } + + InjectorEnum InjectorEnumFromString( const std::string& stringValue ) { + if (stringValue == "OIL") + return OIL; + else if (stringValue == "WATER") + return WATER; + else if (stringValue == "GAS") + return GAS; + else if (stringValue == "MULTI") + return MULTI; + else + throw std::invalid_argument("Unknown enum state string: " + stringValue ); + } + } } diff --git a/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp b/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp index cbcdb3335..14b8201a0 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp @@ -44,13 +44,16 @@ namespace Opm { - namespace Injector { - enum InjectorType { + namespace InjectorType { + enum InjectorEnum { WATER = 1, GAS = 2, OIL = 3, MULTI = 4 }; + + const std::string InjectorEnum2String( InjectorEnum enumValue ); + InjectorEnum InjectorEnumFromString( const std::string& stringValue ); }; diff --git a/opm/parser/eclipse/EclipseState/Schedule/tests/ScheduleEnumTests.cpp b/opm/parser/eclipse/EclipseState/Schedule/tests/ScheduleEnumTests.cpp index 4bf2e5476..c14a62259 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/tests/ScheduleEnumTests.cpp +++ b/opm/parser/eclipse/EclipseState/Schedule/tests/ScheduleEnumTests.cpp @@ -219,3 +219,35 @@ BOOST_AUTO_TEST_CASE(TestPhaseEnumMask) { +/*****************************************************************/ + +BOOST_AUTO_TEST_CASE(TestInjectorEnum2String) { + BOOST_CHECK_EQUAL( "OIL" , InjectorType::InjectorEnum2String(InjectorType::OIL)); + BOOST_CHECK_EQUAL( "GAS" , InjectorType::InjectorEnum2String(InjectorType::GAS)); + BOOST_CHECK_EQUAL( "WATER" , InjectorType::InjectorEnum2String(InjectorType::WATER)); + BOOST_CHECK_EQUAL( "MULTI" , InjectorType::InjectorEnum2String(InjectorType::MULTI)); +} + + +BOOST_AUTO_TEST_CASE(TestInjectorEnumFromString) { + BOOST_CHECK_THROW( InjectorType::InjectorEnumFromString("XXX") , std::invalid_argument ); + BOOST_CHECK_EQUAL( InjectorType::OIL , InjectorType::InjectorEnumFromString("OIL")); + BOOST_CHECK_EQUAL( InjectorType::WATER , InjectorType::InjectorEnumFromString("WATER")); + BOOST_CHECK_EQUAL( InjectorType::GAS , InjectorType::InjectorEnumFromString("GAS")); + BOOST_CHECK_EQUAL( InjectorType::MULTI , InjectorType::InjectorEnumFromString("MULTI")); +} + + + +BOOST_AUTO_TEST_CASE(TestInjectorEnumLoop) { + BOOST_CHECK_EQUAL( InjectorType::OIL , InjectorType::InjectorEnumFromString( InjectorType::InjectorEnum2String( InjectorType::OIL ) )); + BOOST_CHECK_EQUAL( InjectorType::WATER , InjectorType::InjectorEnumFromString( InjectorType::InjectorEnum2String( InjectorType::WATER ) )); + BOOST_CHECK_EQUAL( InjectorType::GAS , InjectorType::InjectorEnumFromString( InjectorType::InjectorEnum2String( InjectorType::GAS ) )); + BOOST_CHECK_EQUAL( InjectorType::MULTI , InjectorType::InjectorEnumFromString( InjectorType::InjectorEnum2String( InjectorType::MULTI ) )); + + BOOST_CHECK_EQUAL( "MULTI" , InjectorType::InjectorEnum2String(InjectorType::InjectorEnumFromString( "MULTI" ) )); + BOOST_CHECK_EQUAL( "OIL" , InjectorType::InjectorEnum2String(InjectorType::InjectorEnumFromString( "OIL" ) )); + BOOST_CHECK_EQUAL( "GAS" , InjectorType::InjectorEnum2String(InjectorType::InjectorEnumFromString( "GAS" ) )); + BOOST_CHECK_EQUAL( "WATER" , InjectorType::InjectorEnum2String(InjectorType::InjectorEnumFromString( "WATER" ) )); +} +