Added GridProrpties to EclipseState.

This commit is contained in:
Joakim Hove
2014-05-16 15:58:04 +02:00
parent ce0dc92822
commit e72a0da8b1
3 changed files with 92 additions and 1 deletions

View File

@@ -19,18 +19,22 @@
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <iostream>
#include <boost/algorithm/string/join.hpp>
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<GridProperty<int> > 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<std::pair<std::string , int> > supportedKeywords = {{ "SATNUM" , 0 }};
m_intGridProperties = std::make_shared<GridProperties<int> >(volume , supportedKeywords);
if (Section::hasREGIONS(deck)) {
std::shared_ptr<Opm::REGIONSSection> regionsSection(new Opm::REGIONSSection(deck) );
for (auto iter = regionsSection->begin(); iter != regionsSection->end(); ++iter) {
DeckKeywordConstPtr deckKeyword = *iter;
if (supportsGridProperty( deckKeyword->name()))
loadGridPropertyFromDeckKeyword( deckKeyword );
}
}
}
}

View File

@@ -23,6 +23,7 @@
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
#include <set>
@@ -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<GridProperty<int> > 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<enum Phase::PhaseEnum> phases;
std::string m_title;
std::shared_ptr<GridProperties<int> > m_intGridProperties;
};
typedef std::shared_ptr<EclipseState> EclipseStatePtr;

View File

@@ -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<GridProperty<int> > 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);
}