Added Schedule class
This commit is contained in:
parent
488782d8c5
commit
d511d2ee2d
@ -47,7 +47,8 @@ Parser/ParserStringItem.cpp
|
||||
)
|
||||
|
||||
set (state_source
|
||||
EclipseState/Schedule/TimeMap.cpp )
|
||||
EclipseState/Schedule/TimeMap.cpp
|
||||
EclipseState/Schedule/Schedule.cpp )
|
||||
|
||||
set( HEADER_FILES
|
||||
RawDeck/RawConsts.hpp
|
||||
@ -75,6 +76,7 @@ Parser/ParserDoubleItem.hpp
|
||||
Parser/ParserStringItem.hpp
|
||||
#
|
||||
EclipseState/Schedule/TimeMap.hpp
|
||||
EclipseState/Schedule/Schedule.hpp
|
||||
)
|
||||
|
||||
add_library(buildParser ${rawdeck_source} ${build_parser_source} ${deck_source})
|
||||
|
62
opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp
Normal file
62
opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright 2013 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
|
||||
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
Schedule::Schedule(DeckConstPtr deck) {
|
||||
if (deck->hasKeyword("SCHEDULE")) {
|
||||
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));
|
||||
|
||||
DeckKeywordConstPtr scheduleKeyword = deck->getKeyword( "SCHEDULE" );
|
||||
size_t deckIndex = scheduleKeyword->getDeckIndex() + 1;
|
||||
while (deckIndex < deck->size()) {
|
||||
DeckKeywordConstPtr keyword = deck->getKeyword( deckIndex );
|
||||
|
||||
if (keyword->name() == "DATES")
|
||||
m_timeMap->addFromDATESKeyword( keyword );
|
||||
else if (keyword->name() == "TSTEP")
|
||||
m_timeMap->addFromTSTEPKeyword( keyword );
|
||||
|
||||
deckIndex++;
|
||||
}
|
||||
} else
|
||||
throw std::invalid_argument("Deck does not contain SCHEDULE section.\n");
|
||||
}
|
||||
|
||||
|
||||
boost::gregorian::date Schedule::getStartDate() const {
|
||||
return m_timeMap->getStartDate();
|
||||
}
|
||||
|
||||
|
||||
TimeMapConstPtr Schedule::getTimeMap() const {
|
||||
return m_timeMap;
|
||||
}
|
||||
|
||||
}
|
46
opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp
Normal file
46
opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
Copyright 2013 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef SCHEDULE_HPP
|
||||
#define SCHEDULE_HPP
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
|
||||
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
|
||||
const boost::gregorian::date defaultStartDate( 1983 , boost::gregorian::Jan , 1);
|
||||
|
||||
class Schedule {
|
||||
public:
|
||||
Schedule(DeckConstPtr deck);
|
||||
boost::gregorian::date getStartDate() const;
|
||||
TimeMapConstPtr getTimeMap() const;
|
||||
private:
|
||||
TimeMapPtr m_timeMap;
|
||||
};
|
||||
typedef boost::shared_ptr<Schedule> SchedulePtr;
|
||||
typedef boost::shared_ptr<const Schedule> ScheduleConstPtr;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,3 +1,8 @@
|
||||
add_executable(runTimeMapTests TimeMapTest.cpp)
|
||||
target_link_libraries(runTimeMapTests Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runTimeMapTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runTimeMapTests )
|
||||
|
||||
|
||||
add_executable(runScheduleTests ScheduleTests.cpp)
|
||||
target_link_libraries(runScheduleTests Parser ${Boost_LIBRARIES})
|
||||
add_test(NAME runScheduleTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runScheduleTests )
|
||||
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
Copyright 2013 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#define BOOST_TEST_MODULE ScheduleTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckStringItem.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CreateScheduleDeckMissingSCHEDULE_Throws) {
|
||||
DeckPtr deck(new Deck());
|
||||
BOOST_CHECK_THROW(Schedule schedule(deck) , std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CreateScheduleDeckMissingReturnsDefaults) {
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr keyword(new DeckKeyword("SCHEDULE"));
|
||||
deck->addKeyword( keyword );
|
||||
Schedule schedule(deck);
|
||||
BOOST_CHECK_EQUAL( schedule.getStartDate() , boost::gregorian::date( 1983 , boost::gregorian::Jan , 1));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CreateScheduleDeckWithStart) {
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr scheduleKeyword(new DeckKeyword("SCHEDULE"));
|
||||
DeckKeywordPtr startKeyword(new DeckKeyword("START"));
|
||||
DeckRecordPtr startRecord(new DeckRecord());
|
||||
DeckIntItemPtr dayItem( new DeckIntItem("DAY") );
|
||||
DeckStringItemPtr monthItem(new DeckStringItem("MONTH") );
|
||||
DeckIntItemPtr yearItem(new DeckIntItem("YEAR"));
|
||||
|
||||
|
||||
dayItem->push_back( 8 );
|
||||
monthItem->push_back( "MAR" );
|
||||
yearItem->push_back( 1998 );
|
||||
|
||||
startRecord->addItem( dayItem );
|
||||
startRecord->addItem( monthItem );
|
||||
startRecord->addItem( yearItem );
|
||||
startKeyword->addRecord( startRecord );
|
||||
|
||||
deck->addKeyword( startKeyword );
|
||||
deck->addKeyword( scheduleKeyword );
|
||||
|
||||
Schedule schedule(deck);
|
||||
BOOST_CHECK_EQUAL( schedule.getStartDate() , boost::gregorian::date( 1998 , boost::gregorian::Mar , 8));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CreateScheduleDeckWithSCHEDULENoThrow) {
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr keyword(new DeckKeyword("SCHEDULE"));
|
||||
deck->addKeyword( keyword );
|
||||
|
||||
BOOST_CHECK_NO_THROW(Schedule schedule(deck));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user