Made Schedule handle the GRUPTREE keyword, Added testing to GroupTreeTests.cpp

This commit is contained in:
Kristian Flikka 2013-11-14 16:08:10 +01:00
parent d3e5b198af
commit a8e3128ef8
7 changed files with 225 additions and 47 deletions

View File

@ -19,7 +19,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
#include <iostream>
namespace Opm {
@ -30,6 +30,16 @@ namespace Opm {
throw std::invalid_argument("Deck does not contain SCHEDULE section.\n");
}
void Schedule::initFromDeck(DeckConstPtr deck) {
createTimeMap(deck);
initRootGroupTreeNode(getTimeMap());
iterateScheduleSection(deck);
}
void Schedule::initRootGroupTreeNode(TimeMapConstPtr timeMap) {
m_rootGroupTree.reset(new DynamicState<GroupTreePtr>(timeMap, GroupTreePtr(new GroupTree())));
}
void Schedule::createTimeMap(DeckConstPtr deck) {
boost::gregorian::date startDate(defaultStartDate);
if (deck->hasKeyword("START")) {
@ -40,11 +50,6 @@ namespace Opm {
m_timeMap = TimeMapPtr(new TimeMap(startDate));
}
void Schedule::initFromDeck(DeckConstPtr deck) {
createTimeMap(deck);
iterateScheduleSection(deck);
}
void Schedule::iterateScheduleSection(DeckConstPtr deck) {
DeckKeywordConstPtr scheduleKeyword = deck->getKeyword("SCHEDULE");
size_t deckIndex = scheduleKeyword->getDeckIndex() + 1;
@ -73,8 +78,12 @@ namespace Opm {
handleWCONPROD(keyword, currentStep);
if (keyword->name() == "COMPDAT")
handleCOMPDAT( keyword , currentStep );
if (keyword->name() == "COMPDAT")
handleCOMPDAT(keyword, currentStep);
if (keyword->name() == "GRUPTREE")
handleGRUPTREE(keyword, currentStep);
deckIndex++;
}
@ -121,18 +130,30 @@ namespace Opm {
handleWCON(keyword, currentStep, true);
}
void Schedule::handleCOMPDAT(DeckKeywordConstPtr keyword , size_t currentStep) {
std::map<std::string , std::vector< CompletionConstPtr> > completionMapList = Completion::completionsFromCOMPDATKeyword( keyword );
std::map<std::string , std::vector< CompletionConstPtr> >::iterator iter;
for( iter= completionMapList.begin(); iter != completionMapList.end(); iter++) {
const std::string wellName = iter->first;
WellPtr well = getWell( wellName );
void Schedule::handleCOMPDAT(DeckKeywordConstPtr keyword, size_t currentStep) {
std::map<std::string, std::vector< CompletionConstPtr> > completionMapList = Completion::completionsFromCOMPDATKeyword(keyword);
std::map<std::string, std::vector< CompletionConstPtr> >::iterator iter;
well->addCompletions( currentStep , iter->second );
for (iter = completionMapList.begin(); iter != completionMapList.end(); iter++) {
const std::string wellName = iter->first;
WellPtr well = getWell(wellName);
well->addCompletions(currentStep, iter->second);
}
}
void Schedule::handleGRUPTREE(DeckKeywordConstPtr keyword, size_t currentStep) {
GroupTreePtr currentTree = m_rootGroupTree->get(currentStep);
GroupTreePtr newTree = currentTree->deepCopy();
for (size_t recordNr = 0; recordNr < keyword->size(); recordNr++) {
DeckRecordConstPtr record = keyword->getRecord(recordNr);
const std::string& childName = record->getItem("CHILD_GROUP")->getString(0);
const std::string& parentName = record->getItem("PARENT_GROUP")->getString(0);
GroupTreeNodePtr theNewNode = newTree->updateTree(childName, parentName);
}
m_rootGroupTree->add(currentStep, newTree);
}
boost::gregorian::date Schedule::getStartDate() const {
return m_timeMap->getStartDate();
}
@ -141,6 +162,10 @@ namespace Opm {
return m_timeMap;
}
GroupTreePtr Schedule::getGroupTree(size_t timeStep) const {
return m_rootGroupTree->get(timeStep);
}
void Schedule::addWell(const std::string& wellName) {
WellPtr well(new Well(wellName, m_timeMap));
m_wells[ wellName ] = well;

View File

@ -22,6 +22,10 @@
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/GroupTree.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/DynamicState.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <boost/shared_ptr.hpp>
@ -43,14 +47,16 @@ namespace Opm
size_t numWells() const;
bool hasWell(const std::string& wellName) const;
WellPtr getWell(const std::string& wellName) const;
GroupTreePtr getGroupTree(size_t t) const;
private:
TimeMapPtr m_timeMap;
std::map<std::string , WellPtr> m_wells;
boost::shared_ptr<DynamicState<GroupTreePtr> > m_rootGroupTree;
void initFromDeck(DeckConstPtr deck);
void createTimeMap(DeckConstPtr deck);
void initRootGroupTreeNode(TimeMapConstPtr timeMap);
void iterateScheduleSection(DeckConstPtr deck);
void addWell(const std::string& wellName);
@ -61,6 +67,8 @@ namespace Opm
void handleCOMPDAT(DeckKeywordConstPtr keyword , size_t currentStep);
void handleDATES(DeckKeywordConstPtr keyword);
void handleTSTEP(DeckKeywordConstPtr keyword);
void handleGRUPTREE(DeckKeywordConstPtr keyword, size_t currentStep);
};
typedef boost::shared_ptr<Schedule> SchedulePtr;
typedef boost::shared_ptr<const Schedule> ScheduleConstPtr;

View File

@ -36,3 +36,8 @@ add_test(NAME runDynamicStateTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMA
add_executable(runGroupTreeNodeTests GroupTreeNodeTests.cpp)
target_link_libraries(runGroupTreeNodeTests Parser ${Boost_LIBRARIES})
add_test(NAME runGroupTreeNodeTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runGroupTreeNodeTests )
add_executable(runGroupTreeTests GroupTreeTests.cpp)
target_link_libraries(runGroupTreeTests Parser ${Boost_LIBRARIES})
add_test(NAME runGroupTreeTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runGroupTreeTests )

View File

@ -24,6 +24,8 @@
#include <boost/test/unit_test.hpp>
#include <stdexcept>
#include <iostream>
using namespace Opm;
@ -54,7 +56,6 @@ BOOST_AUTO_TEST_CASE(AddNode_ParentIsField_AddedUnderField) {
BOOST_CHECK(rootNode->hasChildGroup("CHILD_OF_FIELD"));
}
BOOST_AUTO_TEST_CASE(AddNode_ParentNotAdded_ChildAndParentAdded) {
GroupTree tree;
tree.updateTree("CHILD", "NEWPARENT");
@ -65,3 +66,42 @@ BOOST_AUTO_TEST_CASE(AddNode_ParentNotAdded_ChildAndParentAdded) {
BOOST_CHECK(newParent->hasChildGroup("CHILD"));
}
BOOST_AUTO_TEST_CASE(DeepCopy_TreeWithChildren_ObjectsDifferContentMatch) {
GroupTreePtr tree(new GroupTree());
tree->updateTree("L1CHILD1", "FIELD");
tree->updateTree("L1CHILD2", "FIELD");
tree->updateTree("L2CHILD1", "L1CHILD1");
tree->updateTree("L2CHILD2", "L1CHILD1");
tree->updateTree("L3CHILD1", "L2CHILD1");
GroupTreePtr copiedTree = tree->deepCopy();
GroupTreeNodePtr fieldNodeCopy = copiedTree->getNode("FIELD");
GroupTreeNodePtr fieldNodeOriginal = tree->getNode("FIELD");
BOOST_CHECK(!(fieldNodeCopy == fieldNodeOriginal));
BOOST_CHECK_EQUAL(fieldNodeCopy->name(), fieldNodeOriginal->name());
GroupTreeNodePtr L1CHILD1NodeCopy = fieldNodeCopy->getChildGroup("L1CHILD1");
GroupTreeNodePtr L1CHILD1NodeOriginal = fieldNodeOriginal->getChildGroup("L1CHILD1");
BOOST_CHECK(!(L1CHILD1NodeCopy == L1CHILD1NodeOriginal));
BOOST_CHECK_EQUAL(L1CHILD1NodeCopy->name(), L1CHILD1NodeOriginal->name());
GroupTreeNodePtr L1CHILD2NodeCopy = fieldNodeCopy->getChildGroup("L1CHILD2");
GroupTreeNodePtr L1CHILD2NodeOriginal = fieldNodeOriginal->getChildGroup("L1CHILD2");
BOOST_CHECK(!(L1CHILD2NodeCopy == L1CHILD2NodeOriginal));
BOOST_CHECK_EQUAL(L1CHILD2NodeCopy->name(), L1CHILD2NodeOriginal->name());
GroupTreeNodePtr L2CHILD1NodeCopy = L1CHILD1NodeCopy->getChildGroup("L2CHILD1");
GroupTreeNodePtr L2CHILD1NodeOriginal = L1CHILD1NodeOriginal->getChildGroup("L2CHILD1");
BOOST_CHECK(!(L2CHILD1NodeCopy == L2CHILD1NodeOriginal));
BOOST_CHECK_EQUAL(L2CHILD1NodeCopy->name(), L2CHILD1NodeOriginal->name());
GroupTreeNodePtr L2CHILD2NodeCopy = L1CHILD1NodeCopy->getChildGroup("L2CHILD2");
GroupTreeNodePtr L2CHILD2NodeOriginal = L1CHILD1NodeOriginal->getChildGroup("L2CHILD2");
BOOST_CHECK(!(L2CHILD2NodeCopy == L2CHILD2NodeOriginal));
BOOST_CHECK_EQUAL(L2CHILD2NodeCopy->name(), L2CHILD2NodeOriginal->name());
GroupTreeNodePtr L3CHILD1NodeCopy = L2CHILD1NodeCopy->getChildGroup("L3CHILD1");
GroupTreeNodePtr L3CHILD1NodeOriginal = L2CHILD1NodeOriginal->getChildGroup("L3CHILD1");
BOOST_CHECK(!(L3CHILD1NodeCopy == L3CHILD1NodeOriginal));
BOOST_CHECK_EQUAL(L3CHILD1NodeCopy->name(), L3CHILD1NodeOriginal->name());
}

View File

@ -64,8 +64,6 @@ BOOST_AUTO_TEST_CASE(CreateScheduleDeckMissingSCHEDULE_Throws) {
}
BOOST_AUTO_TEST_CASE(CreateScheduleDeckMissingReturnsDefaults) {
DeckPtr deck(new Deck());
DeckKeywordPtr keyword(new DeckKeyword("SCHEDULE"));
@ -100,4 +98,30 @@ BOOST_AUTO_TEST_CASE(EmptyScheduleHasNoWells) {
}
BOOST_AUTO_TEST_CASE(CreateSchedule_DeckWithoutGRUPTREE_HasRootGroupTreeNodeForTimeStepZero) {
DeckPtr deck = createDeck();
Schedule schedule(deck);
BOOST_CHECK_EQUAL("FIELD", schedule.getGroupTree(0)->getNode("FIELD")->name());
}
//BOOST_AUTO_TEST_CASE(CreateSchedule_DeckWithoutGRUPTREE_HasRootGroupTreeNodeForTimeStepZero) {
// DeckPtr deck = createDeck();
// DeckKeywordPtr gruptreeKeyword(new DeckKeyword("GRUPTREE"));
//
// DeckRecordPtr recordChildOfField(new DeckRecord());
// DeckStringItemPtr itemChild1(new DeckStringItem("CHILD_GROUP"));
// itemChild1->push_back("BARNET");
// DeckStringItemPtr itemParent1(new DeckStringItem("PARENT_GROUP"));
// itemParent1->push_back("FAREN");
//
// recordChildOfField->addItem()
// gruptreeKeyword->addRecord(DeckRecordConstPtr()
//
// Schedule schedule(deck);
// BOOST_CHECK_EQUAL("FIELD", schedule.getGroupTreeNode(0)->name());
//}

View File

@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(WellTesting) {
boost::filesystem::path scheduleFile("testdata/integration_tests/SCHEDULE/SCHEDULE_WELLS2");
DeckPtr deck = parser->parse(scheduleFile.string());
ScheduleConstPtr sched(new Schedule(deck));
BOOST_CHECK_EQUAL(3U, sched->numWells());
BOOST_CHECK(sched->hasWell("W_1"));
BOOST_CHECK(sched->hasWell("W_2"));
@ -63,7 +63,7 @@ BOOST_AUTO_TEST_CASE(WellTesting) {
BOOST_CHECK_EQUAL(0, well1->getOilRate(1));
BOOST_CHECK_EQUAL(0, well1->getOilRate(2));
BOOST_CHECK(!well1->isInPredictionMode(3));
BOOST_CHECK_EQUAL(4000, well1->getOilRate(3));
BOOST_CHECK_EQUAL(4000, well1->getOilRate(4));
@ -71,50 +71,112 @@ BOOST_AUTO_TEST_CASE(WellTesting) {
BOOST_CHECK(!well1->isInPredictionMode(6));
BOOST_CHECK_EQUAL(14000, well1->getOilRate(6));
BOOST_CHECK(well1->isInPredictionMode(7));
BOOST_CHECK_EQUAL(11000, well1->getOilRate(7));
BOOST_CHECK(!well1->isInPredictionMode(8));
BOOST_CHECK_EQUAL(13000, well1->getOilRate(8));
BOOST_CHECK_EQUAL(13000, well1->getOilRate(9));
BOOST_CHECK_EQUAL(13000, well1->getOilRate(10));
BOOST_CHECK_EQUAL( 3U , sched->numWells());
BOOST_CHECK( sched->hasWell("W_1"));
BOOST_CHECK( sched->hasWell("W_2"));
BOOST_CHECK( sched->hasWell("W_3"));
BOOST_CHECK_EQUAL(3U, sched->numWells());
BOOST_CHECK(sched->hasWell("W_1"));
BOOST_CHECK(sched->hasWell("W_2"));
BOOST_CHECK(sched->hasWell("W_3"));
{
WellPtr well1 = sched->getWell("W_1");
BOOST_CHECK_EQUAL( 13000 , well1->getOilRate( 8 ));
WellPtr well1 = sched->getWell("W_1");
BOOST_CHECK_EQUAL(13000, well1->getOilRate(8));
}
}
}
BOOST_AUTO_TEST_CASE( WellTestCOMPDAT ) {
BOOST_AUTO_TEST_CASE(WellTestCOMPDAT) {
ParserPtr parser(new Parser());
boost::filesystem::path scheduleFile("testdata/integration_tests/SCHEDULE/SCHEDULE_WELLS2");
DeckPtr deck = parser->parse(scheduleFile.string());
ScheduleConstPtr sched( new Schedule(deck));
ScheduleConstPtr sched(new Schedule(deck));
BOOST_CHECK_EQUAL( 3U , sched->numWells());
BOOST_CHECK( sched->hasWell("W_1"));
BOOST_CHECK( sched->hasWell("W_2"));
BOOST_CHECK( sched->hasWell("W_3"));
BOOST_CHECK_EQUAL(3U, sched->numWells());
BOOST_CHECK(sched->hasWell("W_1"));
BOOST_CHECK(sched->hasWell("W_2"));
BOOST_CHECK(sched->hasWell("W_3"));
{
WellPtr well1 = sched->getWell("W_1");
BOOST_CHECK_EQUAL( 13000 , well1->getOilRate( 8 ));
CompletionSetConstPtr completions = well1->getCompletions( 0 );
BOOST_CHECK_EQUAL( 0U , completions->size() );
BOOST_CHECK_EQUAL(13000, well1->getOilRate(8));
CompletionSetConstPtr completions = well1->getCompletions(0);
BOOST_CHECK_EQUAL(0U, completions->size());
completions = well1->getCompletions( 3 );
BOOST_CHECK_EQUAL( 4U , completions->size() );
BOOST_CHECK_EQUAL( OPEN , completions->get(3)->getState() );
completions = well1->getCompletions( 7 );
BOOST_CHECK_EQUAL( 4U , completions->size() );
BOOST_CHECK_EQUAL( SHUT , completions->get(3)->getState() );
completions = well1->getCompletions(3);
BOOST_CHECK_EQUAL(4U, completions->size());
BOOST_CHECK_EQUAL(OPEN, completions->get(3)->getState());
completions = well1->getCompletions(7);
BOOST_CHECK_EQUAL(4U, completions->size());
BOOST_CHECK_EQUAL(SHUT, completions->get(3)->getState());
}
}
BOOST_AUTO_TEST_CASE(GroupTreeTest_GRUPTREE_with_explicit_L0_parenting) {
ParserPtr parser(new Parser());
boost::filesystem::path scheduleFile("testdata/integration_tests/SCHEDULE/SCHEDULE_GRUPTREE_EXPLICIT_PARENTING");
DeckPtr deck = parser->parse(scheduleFile.string());
ScheduleConstPtr sched(new Schedule(deck));
GroupTreeNodePtr rootNode = sched->getGroupTree(0)->getNode("FIELD");
sched->getGroupTree(0)->printTree();
BOOST_REQUIRE_EQUAL("FIELD", rootNode->name());
BOOST_CHECK(rootNode->hasChildGroup("FIRST_LEVEL1"));
GroupTreeNodePtr FIRST_LEVEL1 = rootNode->getChildGroup("FIRST_LEVEL1");
BOOST_CHECK(rootNode->hasChildGroup("FIRST_LEVEL2"));
GroupTreeNodePtr FIRST_LEVEL2 = rootNode->getChildGroup("FIRST_LEVEL2");
BOOST_CHECK(FIRST_LEVEL1->hasChildGroup("SECOND_LEVEL1"));
GroupTreeNodePtr SECOND_LEVEL1 = FIRST_LEVEL1->getChildGroup("SECOND_LEVEL1");
BOOST_CHECK(FIRST_LEVEL2->hasChildGroup("SECOND_LEVEL2"));
GroupTreeNodePtr SECOND_LEVEL2 = FIRST_LEVEL2->getChildGroup("SECOND_LEVEL2");
BOOST_CHECK(SECOND_LEVEL1->hasChildGroup("THIRD_LEVEL1"));
GroupTreeNodePtr THIRD_LEVEL1 = SECOND_LEVEL1->getChildGroup("THIRD_LEVEL1");
}
BOOST_AUTO_TEST_CASE(GroupTreeTest_PrintGrouptree) {
ParserPtr parser(new Parser());
boost::filesystem::path scheduleFile("testdata/integration_tests/SCHEDULE/SCHEDULE_GRUPTREE_EXPLICIT_PARENTING");
DeckPtr deck = parser->parse(scheduleFile.string());
ScheduleConstPtr sched(new Schedule(deck));
GroupTreePtr rootNode = sched->getGroupTree(0);
rootNode->printTree();
}
BOOST_AUTO_TEST_CASE(GroupTreeTest_GRUPTREE_with_implicit_L0_parenting) {
};
BOOST_AUTO_TEST_CASE(GroupTreeTest_GRUPTREE_with_explicit_then_implicit_LO_parenting) {
};
BOOST_AUTO_TEST_CASE(GroupTreeTest_GRUPTREE_with_moving_of_node) {
};
BOOST_AUTO_TEST_CASE(GroupTreeTest_GRUPTREE_with_adding_of_node) {
};
BOOST_AUTO_TEST_CASE(GroupTreeTest_only_WELSPECS_grouping) {
};
BOOST_AUTO_TEST_CASE(GroupTreeTest_WELSPECS_TSTEPS_and_then_more_WELSPECS_grouping) {
};
BOOST_AUTO_TEST_CASE(GroupTreeTest_WELSPECS_someTSTEPS_and_then_GRUPTREE_grouping) {
};

View File

@ -0,0 +1,14 @@
START
10 MAI 2007 /
SCHEDULE
GRUPTREE
'FIRST_LEVEL1' 'FIELD' /
'FIRST_LEVEL2' 'FIELD' /
'SECOND_LEVEL1' 'FIRST_LEVEL1' /
'SECOND_LEVEL2' 'FIRST_LEVEL2' /
'THIRD_LEVEL1' 'SECOND_LEVEL1' /
/