Added std::set<enum PhaseEnum> to keep track of phases present to the EclipseState.

This commit is contained in:
Joakim Hove
2014-01-07 17:52:20 +01:00
parent b90830ea79
commit 09f70a2205
3 changed files with 40 additions and 1 deletions

View File

@@ -18,12 +18,14 @@
*/
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <iostream>
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);
}
}

View File

@@ -22,6 +22,7 @@
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <set>
#include <memory>
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<enum PhaseEnum> phases;
};
typedef std::shared_ptr<EclipseState> EclipseStatePtr;

View File

@@ -26,6 +26,7 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/Deck/DeckIntItem.hpp>
#include <opm/parser/eclipse/Deck/DeckStringItem.hpp>
@@ -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 ));
}