OPM 199: Added new methods to TimeMap and corresponding tests

This commit is contained in:
chflo
2015-05-24 14:33:11 +02:00
parent a7b97a3748
commit a40d867704
3 changed files with 68 additions and 0 deletions

View File

@@ -22,6 +22,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
#include <opm/parser/eclipse/Deck/DeckDoubleItem.hpp>
namespace Opm {
TimeMap::TimeMap(boost::posix_time::ptime startDate) {
if (startDate.is_not_a_date_time())
@@ -224,6 +225,42 @@ namespace Opm {
return static_cast<double>(deltaT.total_milliseconds())/1000.0;
}
void TimeMap::initFirstTimestepsMonths(std::vector<size_t>& timesteps, size_t start_timestep) const {
boost::gregorian::date prev_date;
for (size_t timestepIndex = start_timestep; timestepIndex < m_timeList.size(); ++timestepIndex) {
const boost::posix_time::ptime& ptime = getStartTime(timestepIndex);
if (start_timestep == timestepIndex) {
prev_date = ptime.date();
timesteps.push_back(timestepIndex);
} else {
boost::gregorian::date cur_date = ptime.date();
if (cur_date.month() != prev_date.month()) {
timesteps.push_back(timestepIndex);
}
prev_date = cur_date;
}
}
}
void TimeMap::initFirstTimestepsYears(std::vector<size_t>& timesteps, size_t start_timestep) const {
boost::gregorian::date prev_date;
for (size_t timestepIndex = start_timestep; timestepIndex < m_timeList.size(); ++timestepIndex) {
const boost::posix_time::ptime& ptime = getStartTime(timestepIndex);
if (start_timestep == timestepIndex) {
prev_date = ptime.date();
timesteps.push_back(timestepIndex);
} else {
boost::gregorian::date cur_date = ptime.date();
if (cur_date.year() != prev_date.year()) {
timesteps.push_back(timestepIndex);
}
prev_date = cur_date;
}
}
}
}

View File

@@ -21,6 +21,8 @@
#ifndef TIMEMAP_HPP_
#define TIMEMAP_HPP_
#include <vector>
#include <boost/date_time.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
@@ -46,6 +48,10 @@ namespace Opm {
double getTimePassedUntil(size_t tLevelIdx) const;
/// Return the length of a given time step in seconds.
double getTimeStepLength(size_t tStepIdx) const;
/// Return a list of the first timesteps of each month
void initFirstTimestepsMonths(std::vector<size_t>& timesteps, size_t timestep=0) const;
/// Return a list of the first timesteps of each year
void initFirstTimestepsYears(std::vector<size_t>& timesteps, size_t start_timestep=0) const;
static boost::posix_time::ptime timeFromEclipse(DeckRecordConstPtr dateRecord);
static boost::posix_time::ptime timeFromEclipse(int day , const std::string& month, int year, const std::string& eclipseTimeString = "00:00:00.000");
static boost::posix_time::time_duration dayTimeFromEclipse(const std::string& eclipseTimeString);

View File

@@ -269,4 +269,29 @@ BOOST_AUTO_TEST_CASE(TimeStepsCorrect) {
boost::posix_time::milliseconds(123)));
BOOST_CHECK_EQUAL(tmap.getTimeStepLength(/*index=*/8), 6*24*60*60);
BOOST_CHECK_EQUAL(tmap.getTimeStepLength(/*index=*/9), 7*24*60*60);
std::vector<size_t> first_timestep_of_each_month;
tmap.initFirstTimestepsMonths(first_timestep_of_each_month);
BOOST_CHECK_EQUAL(3, first_timestep_of_each_month.size());
int expected_results[3] = {0,5,6};
BOOST_CHECK_EQUAL_COLLECTIONS(expected_results, expected_results+3, first_timestep_of_each_month.begin(), first_timestep_of_each_month.end());
first_timestep_of_each_month.clear();
tmap.initFirstTimestepsMonths(first_timestep_of_each_month, 5);
BOOST_CHECK_EQUAL(2, first_timestep_of_each_month.size());
int expected_results2[2] = {5,6};
BOOST_CHECK_EQUAL_COLLECTIONS(expected_results2, expected_results2+2, first_timestep_of_each_month.begin(), first_timestep_of_each_month.end());
std::vector<size_t> first_timestep_of_each_year;
tmap.initFirstTimestepsYears(first_timestep_of_each_year);
BOOST_CHECK_EQUAL(2, first_timestep_of_each_year.size());
int expected_results_years[2] = {0,6};
BOOST_CHECK_EQUAL_COLLECTIONS(expected_results_years, expected_results_years+2, first_timestep_of_each_year.begin(), first_timestep_of_each_year.end());
first_timestep_of_each_year.clear();
tmap.initFirstTimestepsYears(first_timestep_of_each_year, 6);
BOOST_CHECK_EQUAL(1, first_timestep_of_each_year.size());
BOOST_CHECK_EQUAL(6, first_timestep_of_each_year[0]);
}