Added ScheduleEnums file - with CompletionStateEnum

This commit is contained in:
Joakim Hove
2013-11-06 16:19:48 +01:00
parent cf0b1235a4
commit bc6e2ee2c6
4 changed files with 146 additions and 1 deletions

View File

@@ -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})

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include <string>
#include <stdexcept>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
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 );
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef SCHEDULE_ENUMS_H
#define SCHEDULE_ENUMS_H
#include <string>
#include <stdexcept>
namespace Opm {
enum CompletionStateEnum {
OPEN = 1,
SHUT = 2,
AUTO = 3
};
const std::string CompletionStateEnum2String( CompletionStateEnum enumValue );
CompletionStateEnum CompletionStateEnumFromString( const std::string& stringValue );
}
#endif

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#define BOOST_TEST_MODULE ParserEnumTests
#include <boost/test/unit_test.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
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" ) ));
}