diff --git a/opm/parser/eclipse/EclipseState/EclipseState.cpp b/opm/parser/eclipse/EclipseState/EclipseState.cpp index 00a7488a0..d279a6a85 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -18,12 +18,14 @@ */ #include +#include #include #include namespace Opm { EclipseState::EclipseState(DeckConstPtr deck) { + initPhases(deck); initSchedule(deck); } @@ -38,4 +40,20 @@ namespace Opm { } + void EclipseState::initPhases(DeckConstPtr deck) { + if (deck->hasKeyword("OIL")) + phases.insert(PhaseEnum::OIL); + + if (deck->hasKeyword("GAS")) + phases.insert(PhaseEnum::GAS); + + if (deck->hasKeyword("WATER")) + phases.insert(PhaseEnum::WATER); + } + + + bool EclipseState::hasPhase(enum PhaseEnum phase) const { + return (phases.count(phase) == 1); + } + } diff --git a/opm/parser/eclipse/EclipseState/EclipseState.hpp b/opm/parser/eclipse/EclipseState/EclipseState.hpp index 6eeca2c7f..1a9ea8ee4 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.hpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.hpp @@ -22,6 +22,7 @@ #include +#include #include namespace Opm { @@ -30,11 +31,14 @@ namespace Opm { public: EclipseState(DeckConstPtr deck); ScheduleConstPtr getSchedule() const; - + bool hasPhase(enum PhaseEnum phase) const; private: void initSchedule(DeckConstPtr deck); + void initPhases(DeckConstPtr deck); + ScheduleConstPtr schedule; + std::set phases; }; typedef std::shared_ptr EclipseStatePtr; diff --git a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp index 2ea59362f..e8c04db62 100644 --- a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp +++ b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -35,6 +36,10 @@ using namespace Opm; DeckPtr createDeck() { DeckPtr deck(new Deck()); + DeckKeywordPtr oilKeyword(new DeckKeyword("OIL")); + DeckKeywordPtr gasKeyword(new DeckKeyword("GAS")); + + DeckKeywordPtr scheduleKeyword(new DeckKeyword("SCHEDULE")); DeckKeywordPtr startKeyword(new DeckKeyword("START")); DeckRecordPtr startRecord(new DeckRecord()); @@ -52,6 +57,8 @@ DeckPtr createDeck() { startRecord->addItem( yearItem ); startKeyword->addRecord( startRecord ); + deck->addKeyword( oilKeyword ); + deck->addKeyword( gasKeyword ); deck->addKeyword( startKeyword ); deck->addKeyword( scheduleKeyword ); @@ -68,3 +75,13 @@ BOOST_AUTO_TEST_CASE(CreatSchedule) { BOOST_CHECK_EQUAL( schedule->getStartDate() , boost::gregorian::date(1998 , 3 , 8 )); } + + +BOOST_AUTO_TEST_CASE(PhasesCorrect) { + DeckPtr deck = createDeck(); + EclipseState state(deck); + + BOOST_CHECK( state.hasPhase( PhaseEnum::OIL )); + BOOST_CHECK( state.hasPhase( PhaseEnum::GAS )); + BOOST_CHECK( !state.hasPhase( PhaseEnum::WATER )); +}