From bc6e2ee2c642ccfb9f74e825c438ad55749ca91c Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 6 Nov 2013 16:19:48 +0100 Subject: [PATCH] Added ScheduleEnums file - with CompletionStateEnum --- opm/parser/eclipse/CMakeLists.txt | 4 +- .../EclipseState/Schedule/ScheduleEnums.cpp | 52 ++++++++++++++++++ .../EclipseState/Schedule/ScheduleEnums.hpp | 38 +++++++++++++ .../Schedule/tests/ScheduleEnumTests.cpp | 53 +++++++++++++++++++ 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.cpp create mode 100644 opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp create mode 100644 opm/parser/eclipse/EclipseState/Schedule/tests/ScheduleEnumTests.cpp diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt index 3358a1c27..60f0fbc83 100644 --- a/opm/parser/eclipse/CMakeLists.txt +++ b/opm/parser/eclipse/CMakeLists.txt @@ -49,7 +49,8 @@ Parser/ParserStringItem.cpp set (state_source EclipseState/Schedule/TimeMap.cpp EclipseState/Schedule/Schedule.cpp -EclipseState/Schedule/Well.cpp ) +EclipseState/Schedule/Well.cpp +EclipseState/Schedule/ScheduleEnums.cpp ) set( HEADER_FILES RawDeck/RawConsts.hpp @@ -80,6 +81,7 @@ EclipseState/Schedule/TimeMap.hpp EclipseState/Schedule/Schedule.hpp EclipseState/Schedule/Well.hpp EclipseState/Schedule/DynamicState.hpp +EclipseState/Schedule/ScheduleEnums.hpp ) add_library(buildParser ${rawdeck_source} ${build_parser_source} ${deck_source}) diff --git a/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.cpp b/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.cpp new file mode 100644 index 000000000..4912a0e23 --- /dev/null +++ b/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.cpp @@ -0,0 +1,52 @@ +/* + Copyright 2013 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 + +#include + +namespace Opm { + + const std::string CompletionStateEnum2String( CompletionStateEnum enumValue ) { + switch( enumValue ) { + case OPEN: + return "OPEN"; + case AUTO: + return "AUTO"; + case SHUT: + return "SHUT"; + } + } + + + CompletionStateEnum CompletionStateEnumFromString( const std::string& stringValue ) { + if (stringValue == "OPEN") + return OPEN; + else if (stringValue == "SHUT") + return SHUT; + else if (stringValue == "AUTO") + return AUTO; + 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 new file mode 100644 index 000000000..bb716806b --- /dev/null +++ b/opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp @@ -0,0 +1,38 @@ +/* + Copyright 2013 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 SCHEDULE_ENUMS_H +#define SCHEDULE_ENUMS_H + +#include +#include + +namespace Opm { + enum CompletionStateEnum { + OPEN = 1, + SHUT = 2, + AUTO = 3 + }; + + const std::string CompletionStateEnum2String( CompletionStateEnum enumValue ); + CompletionStateEnum CompletionStateEnumFromString( const std::string& stringValue ); + +} + +#endif diff --git a/opm/parser/eclipse/EclipseState/Schedule/tests/ScheduleEnumTests.cpp b/opm/parser/eclipse/EclipseState/Schedule/tests/ScheduleEnumTests.cpp new file mode 100644 index 000000000..8e3c6828f --- /dev/null +++ b/opm/parser/eclipse/EclipseState/Schedule/tests/ScheduleEnumTests.cpp @@ -0,0 +1,53 @@ +/* + Copyright 2013 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 ParserEnumTests +#include + +#include + +using namespace Opm; + +BOOST_AUTO_TEST_CASE(TestCompletionStateEnum2String) { + BOOST_CHECK_EQUAL( "AUTO" , CompletionStateEnum2String(AUTO)); + BOOST_CHECK_EQUAL( "OPEN" , CompletionStateEnum2String(OPEN)); + BOOST_CHECK_EQUAL( "SHUT" , CompletionStateEnum2String(SHUT)); +} + + +BOOST_AUTO_TEST_CASE(TestCompletionStateEnumFromString) { + BOOST_CHECK_THROW( CompletionStateEnumFromString("XXX") , std::invalid_argument ); + BOOST_CHECK_EQUAL( AUTO , CompletionStateEnumFromString("AUTO")); + BOOST_CHECK_EQUAL( SHUT , CompletionStateEnumFromString("SHUT")); + BOOST_CHECK_EQUAL( OPEN , CompletionStateEnumFromString("OPEN")); +} + + + +BOOST_AUTO_TEST_CASE(TestCompletionStateEnumLoop) { + BOOST_CHECK_EQUAL( AUTO , CompletionStateEnumFromString( CompletionStateEnum2String( AUTO ) )); + BOOST_CHECK_EQUAL( SHUT , CompletionStateEnumFromString( CompletionStateEnum2String( SHUT ) )); + BOOST_CHECK_EQUAL( OPEN , CompletionStateEnumFromString( CompletionStateEnum2String( OPEN ) )); + + BOOST_CHECK_EQUAL( "AUTO" , CompletionStateEnum2String(CompletionStateEnumFromString( "AUTO" ) )); + BOOST_CHECK_EQUAL( "OPEN" , CompletionStateEnum2String(CompletionStateEnumFromString( "OPEN" ) )); + BOOST_CHECK_EQUAL( "SHUT" , CompletionStateEnum2String(CompletionStateEnumFromString( "SHUT" ) )); +} +