Changed Schedule::init() to load both time related and other keywords in the same main loop

This commit is contained in:
Joakim Hove
2013-11-05 17:58:57 +01:00
parent ddc24927e4
commit df741dfc89
3 changed files with 54 additions and 32 deletions

View File

@@ -24,23 +24,14 @@
namespace Opm
{
Schedule::Schedule(DeckConstPtr deck) {
if (deck->hasKeyword("SCHEDULE")) {
initTimeMap( deck );
initWells( deck );
} else
if (deck->hasKeyword("SCHEDULE"))
initFromDeck( deck );
else
throw std::invalid_argument("Deck does not contain SCHEDULE section.\n");
}
void Schedule::initTimeMap(DeckConstPtr deck) {
boost::gregorian::date startDate( defaultStartDate );
if (deck->hasKeyword("START")) {
DeckKeywordConstPtr startKeyword = deck->getKeyword("START");
startDate = TimeMap::dateFromEclipse( startKeyword->getRecord(0));
}
m_timeMap = TimeMapPtr(new TimeMap(startDate));
/*void Schedule::initTimeMap(DeckConstPtr deck) {
DeckKeywordConstPtr scheduleKeyword = deck->getKeyword( "SCHEDULE" );
size_t deckIndex = scheduleKeyword->getDeckIndex() + 1;
while (deckIndex < deck->size()) {
@@ -54,22 +45,45 @@ namespace Opm
deckIndex++;
}
}
*/
void Schedule::createTimeMap(DeckConstPtr deck) {
boost::gregorian::date startDate( defaultStartDate );
if (deck->hasKeyword("START")) {
DeckKeywordConstPtr startKeyword = deck->getKeyword("START");
startDate = TimeMap::dateFromEclipse( startKeyword->getRecord(0));
}
m_timeMap = TimeMapPtr(new TimeMap(startDate));
}
void Schedule::initWells(DeckConstPtr deck) {
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;
size_t currentStep = 0;
while (deckIndex < deck->size()) {
DeckKeywordConstPtr keyword = deck->getKeyword( deckIndex );
if (keyword->name() == "TSTEP")
if (keyword->name() == "DATES") {
handleDATES( keyword );
currentStep += keyword->size();
}
if (keyword->name() == "DATES")
if (keyword->name() == "TSTEP") {
handleTSTEP( keyword );
currentStep += keyword->size();
}
if (keyword->name() == "WELSPECS")
handleWELSPECS( keyword );
@@ -81,12 +95,13 @@ namespace Opm
}
void Schedule::addWell(const std::string& wellName) {
WellPtr well(new Well(wellName , m_timeMap));
m_wells[ wellName ] = well;
void Schedule::handleDATES(DeckKeywordConstPtr keyword) {
m_timeMap->addFromDATESKeyword( keyword );
}
void Schedule::handleTSTEP(DeckKeywordConstPtr keyword) {
m_timeMap->addFromTSTEPKeyword( keyword );
}
void Schedule::handleWELSPECS(DeckKeywordConstPtr keyword) {
for (size_t recordNr = 0; recordNr < keyword->size(); recordNr++) {
@@ -115,8 +130,8 @@ namespace Opm
}
}
boost::gregorian::date Schedule::getStartDate() const {
return m_timeMap->getStartDate();
}
@@ -127,6 +142,11 @@ namespace Opm
}
void Schedule::addWell(const std::string& wellName) {
WellPtr well(new Well(wellName , m_timeMap));
m_wells[ wellName ] = well;
}
size_t Schedule::numWells() const {
return m_wells.size();
}

View File

@@ -43,17 +43,21 @@ namespace Opm
size_t numWells() const;
bool hasWell(const std::string& wellName) const;
WellPtr getWell(const std::string& wellName) const;
private:
TimeMapPtr m_timeMap;
std::map<std::string , WellPtr> m_wells;
void addWell(const std::string& wellName);
void initTimeMap(DeckConstPtr deck);
void initWells(DeckConstPtr deck);
void initFromDeck(DeckConstPtr deck);
void createTimeMap(DeckConstPtr deck);
void iterateScheduleSection(DeckConstPtr deck);
void addWell(const std::string& wellName);
void handleWELSPECS(DeckKeywordConstPtr keyword);
void handleWCONHIST(DeckKeywordConstPtr keyword , size_t currentStep);
void handleDATES(DeckKeywordConstPtr keyword);
void handleTSTEP(DeckKeywordConstPtr keyword);
};
typedef boost::shared_ptr<Schedule> SchedulePtr;
typedef boost::shared_ptr<const Schedule> ScheduleConstPtr;

View File

@@ -17,7 +17,7 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#define BOOST_TEST_MODULE ParserIntegrationTests
#define BOOST_TEST_MODULE ScheduleIntegrationTests
#include <math.h>
#include <boost/test/unit_test.hpp>
@@ -54,10 +54,8 @@ BOOST_AUTO_TEST_CASE( WellTesting ) {
BOOST_CHECK( sched->hasWell("OP_1"));
BOOST_CHECK( sched->hasWell("OP_2"));
BOOST_CHECK( sched->hasWell("OP_3"));
{
WellPtr well1 = sched->getWell("OP_1");
BOOST_CHECK_EQUAL( 14000 , well1->getOilRate( 8 ));
}
}