Added basic functionality to assemble a timeMap
This commit is contained in:
@@ -22,7 +22,36 @@
|
||||
|
||||
namespace Opm {
|
||||
|
||||
TimeMap::TimeMap() {}
|
||||
TimeMap::TimeMap(boost::gregorian::date startDate) {
|
||||
if (startDate.is_not_a_date())
|
||||
throw std::invalid_argument("Input argument not properly initialized.");
|
||||
|
||||
m_startDate = startDate;
|
||||
m_timeList.push_back( boost::posix_time::ptime(startDate) );
|
||||
}
|
||||
|
||||
|
||||
void TimeMap::addDate(boost::gregorian::date newDate) {
|
||||
boost::posix_time::ptime lastTime = m_timeList.back();
|
||||
if (boost::posix_time::ptime(newDate) > lastTime)
|
||||
m_timeList.push_back( boost::posix_time::ptime(newDate) );
|
||||
else
|
||||
throw std::invalid_argument("Dates added must be in strictly increasing order.");
|
||||
}
|
||||
|
||||
|
||||
void TimeMap::addTStep(boost::posix_time::time_duration step) {
|
||||
if (step.total_seconds() > 0) {
|
||||
boost::posix_time::ptime newTime = m_timeList.back() + step;
|
||||
m_timeList.push_back( newTime );
|
||||
} else
|
||||
throw std::invalid_argument("Can only add positive steps");
|
||||
}
|
||||
|
||||
|
||||
size_t TimeMap::size() const {
|
||||
return m_timeList.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,20 @@
|
||||
#ifndef TIMEMAP_HPP_
|
||||
#define TIMEMAP_HPP_
|
||||
|
||||
#include <boost/date_time.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class TimeMap {
|
||||
public:
|
||||
TimeMap();
|
||||
TimeMap(boost::gregorian::date startDate);
|
||||
void addDate(boost::gregorian::date newDate);
|
||||
void addTStep(boost::posix_time::time_duration step);
|
||||
size_t size() const;
|
||||
|
||||
private:
|
||||
boost::gregorian::date m_startDate;
|
||||
std::vector<boost::posix_time::ptime> m_timeList;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -23,11 +23,64 @@
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CreateTimeMap_InvalidThrow) {
|
||||
boost::gregorian::date startDate;
|
||||
BOOST_CHECK_THROW(Opm::TimeMap timeMap(startDate) , std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CreateTimeMap) {
|
||||
Opm::TimeMap timeMap;
|
||||
boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
|
||||
Opm::TimeMap timeMap(startDate);
|
||||
BOOST_CHECK_EQUAL(1U , timeMap.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(AddDateBeforThrows) {
|
||||
boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
|
||||
Opm::TimeMap timeMap(startDate);
|
||||
|
||||
BOOST_CHECK_THROW( timeMap.addDate( boost::gregorian::date(2009,boost::gregorian::Feb,2)) , std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(AddDateAfterSizeCorrect) {
|
||||
boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
|
||||
Opm::TimeMap timeMap(startDate);
|
||||
|
||||
timeMap.addDate( boost::gregorian::date(2010,boost::gregorian::Feb,2));
|
||||
BOOST_CHECK_EQUAL( 2U , timeMap.size());
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(AddDateNegativeStepThrows) {
|
||||
boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
|
||||
Opm::TimeMap timeMap(startDate);
|
||||
|
||||
BOOST_CHECK_THROW( timeMap.addTStep( boost::posix_time::hours(-1)) , std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(AddStepSizeCorrect) {
|
||||
boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
|
||||
Opm::TimeMap timeMap(startDate);
|
||||
|
||||
timeMap.addTStep( boost::posix_time::hours(1));
|
||||
timeMap.addTStep( boost::posix_time::hours(24));
|
||||
BOOST_CHECK_EQUAL( 3U , timeMap.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user