diff --git a/opm/parser/eclipse/EclipseState/EclipseState.cpp b/opm/parser/eclipse/EclipseState/EclipseState.cpp index 1ecf86b79..c42896977 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -19,18 +19,22 @@ #include #include +#include #include #include + #include #include namespace Opm { - EclipseState::EclipseState(DeckConstPtr deck) { + EclipseState::EclipseState(DeckConstPtr deck) + { initPhases(deck); initEclipseGrid(deck); initSchedule(deck); initTitle(deck); + initProperties(deck); } @@ -85,4 +89,45 @@ namespace Opm { m_title = boost::algorithm::join(itemValue, " "); } } + + bool EclipseState::supportsGridProperty(const std::string& keyword) const { + return m_intGridProperties->supportsKeyword( keyword ); + } + + bool EclipseState::hasIntGridProperty(const std::string& keyword) const { + return m_intGridProperties->hasKeyword( keyword ); + } + + /* + Observe that this will autocreate a property if it has not been explicitly added. + */ + std::shared_ptr > EclipseState::getIntProperty( const std::string& keyword ) { + return m_intGridProperties->getKeyword( keyword ); + } + + + void EclipseState::loadGridPropertyFromDeckKeyword(DeckKeywordConstPtr deckKeyword) { + const std::string& keyword = deckKeyword->name(); + auto gridProperty = m_intGridProperties->getKeyword( keyword ); + gridProperty->loadFromDeckKeyword( deckKeyword ); + } + + + void EclipseState::initProperties(DeckConstPtr deck) { + size_t volume = m_eclipseGrid->getCartesianSize(); + std::vector > supportedKeywords = {{ "SATNUM" , 0 }}; + m_intGridProperties = std::make_shared >(volume , supportedKeywords); + + if (Section::hasREGIONS(deck)) { + std::shared_ptr regionsSection(new Opm::REGIONSSection(deck) ); + + for (auto iter = regionsSection->begin(); iter != regionsSection->end(); ++iter) { + DeckKeywordConstPtr deckKeyword = *iter; + + if (supportsGridProperty( deckKeyword->name())) + loadGridPropertyFromDeckKeyword( deckKeyword ); + + } + } + } } diff --git a/opm/parser/eclipse/EclipseState/EclipseState.hpp b/opm/parser/eclipse/EclipseState/EclipseState.hpp index a0113c0a9..593f39726 100644 --- a/opm/parser/eclipse/EclipseState/EclipseState.hpp +++ b/opm/parser/eclipse/EclipseState/EclipseState.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -37,17 +38,24 @@ namespace Opm { EclipseGridConstPtr getEclipseGrid() const; bool hasPhase(enum Phase::PhaseEnum phase) const; std::string getTitle() const; + bool supportsGridProperty(const std::string& keyword) const; + std::shared_ptr > getIntProperty( const std::string& keyword ); + bool hasIntGridProperty(const std::string& keyword) const; + void loadGridPropertyFromDeckKeyword(DeckKeywordConstPtr deckKeyword); private: void initSchedule(DeckConstPtr deck); void initEclipseGrid(DeckConstPtr deck); void initPhases(DeckConstPtr deck); void initTitle(DeckConstPtr deck); + void initProperties(DeckConstPtr deck); + EclipseGridConstPtr m_eclipseGrid; ScheduleConstPtr schedule; std::set phases; std::string m_title; + std::shared_ptr > m_intGridProperties; }; typedef std::shared_ptr EclipseStatePtr; diff --git a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp index 7db6e0a70..fbad4bfa8 100644 --- a/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp +++ b/opm/parser/eclipse/EclipseState/tests/EclipseStateTests.cpp @@ -62,6 +62,11 @@ static DeckPtr createDeck() { "START\n" "8 MAR 1998 /\n" "\n" + "REGIONS\n" + "FLUXNUM\n" + "1000*1 /\n" + "SATNUM\n" + "1000*2 /\n" "SCHEDULE\n" "\n"; @@ -98,3 +103,36 @@ BOOST_AUTO_TEST_CASE(TitleCorrect) { BOOST_CHECK_EQUAL( state.getTitle(), "The title"); } + + +BOOST_AUTO_TEST_CASE(IntProperties) { + DeckPtr deck = createDeck(); + EclipseState state(deck); + + BOOST_CHECK_EQUAL( false , state.supportsGridProperty("PVTNUM")); + BOOST_CHECK_EQUAL( true , state.supportsGridProperty("SATNUM")); + BOOST_CHECK_EQUAL( true , state.hasIntGridProperty("SATNUM")); +} + + + +BOOST_AUTO_TEST_CASE(PropertiesNotSupportedThrows) { + DeckPtr deck = createDeck(); + EclipseState state(deck); + DeckKeywordConstPtr fluxNUM = deck->getKeyword("FLUXNUM"); + BOOST_CHECK_THROW( state.loadGridPropertyFromDeckKeyword( fluxNUM ) , std::invalid_argument) +} + + +BOOST_AUTO_TEST_CASE(GetProperty) { + DeckPtr deck = createDeck(); + EclipseState state(deck); + + std::shared_ptr > satNUM = state.getIntProperty( "SATNUM" ); + + BOOST_CHECK_EQUAL(1000U , satNUM->size() ); + for (size_t i=0; i < satNUM->size(); i++) + BOOST_CHECK_EQUAL( 2 , satNUM->iget(i) ); + + BOOST_CHECK_THROW( satNUM->iget(100000) , std::invalid_argument); +}