From 95985f0694c961a05bfb062011fb30c6180f4480 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Mon, 17 Mar 2014 16:30:03 +0100 Subject: [PATCH] SimulatorTimer: allow it to be limited to a sub-range of all report steps --- opm/core/simulator/SimulatorTimer.cpp | 47 ++++++++++++++++++++++----- opm/core/simulator/SimulatorTimer.hpp | 11 ++++++- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/opm/core/simulator/SimulatorTimer.cpp b/opm/core/simulator/SimulatorTimer.cpp index b672b613..4c36c0d7 100644 --- a/opm/core/simulator/SimulatorTimer.cpp +++ b/opm/core/simulator/SimulatorTimer.cpp @@ -59,21 +59,46 @@ namespace Opm /// Use the SimulatorTimer as a shim around opm-parser's Opm::TimeMap void SimulatorTimer::init(Opm::TimeMapConstPtr timeMap, - int timeStepIdx) + size_t beginReportStepIdx, + size_t endReportStepIdx) { timeMap_ = timeMap; - current_step_ = timeStepIdx; + current_step_ = 0; + beginReportStepIdx_ = beginReportStepIdx; + endReportStepIdx_ = std::min(timeMap_->numTimesteps() + 1, endReportStepIdx); } /// Total number of steps. int SimulatorTimer::numSteps() const { if (timeMap_) - return timeMap_->numTimesteps(); + return endReportStepIdx_ - beginReportStepIdx_; else return timesteps_.size(); } + /// Index of the first considered simulation episode + size_t SimulatorTimer::beginReportStepIndex() const + { + if (!timeMap_) { + OPM_THROW(std::runtime_error, "indexFirstEpisode() is only implemented " + "for simulation timers which are based on Opm::TimeMap"); + } + + return beginReportStepIdx_; + } + + /// Index of the last considered simulation episode + size_t SimulatorTimer::endReportStepIndex() const + { + if (!timeMap_) { + OPM_THROW(std::runtime_error, "indexLastEpisode() is only implemented " + "for simulation timers which are based on Opm::TimeMap"); + } + + return endReportStepIdx_; + } + /// Current step number. int SimulatorTimer::currentStepNum() const { @@ -99,7 +124,7 @@ namespace Opm { assert(!done()); if (timeMap_) - return timeMap_->getTimeStepLength(current_step_); + return timeMap_->getTimeStepLength(beginReportStepIdx_ + current_step_); else return timesteps_[current_step_]; } @@ -108,7 +133,7 @@ namespace Opm { assert(current_step_ > 0); if (timeMap_) - return timeMap_->getTimeStepLength(current_step_ - 1); + return timeMap_->getTimeStepLength(beginReportStepIdx_ + current_step_ - 1); else return timesteps_[current_step_ - 1]; } @@ -117,7 +142,9 @@ namespace Opm double SimulatorTimer::simulationTimeElapsed() const { if (timeMap_) - return timeMap_->getTimePassedUntil(current_step_); + return + timeMap_->getTimePassedUntil(beginReportStepIdx_ + current_step_) + - timeMap_->getTimePassedUntil(beginReportStepIdx_); else return current_time_; } @@ -132,7 +159,7 @@ namespace Opm boost::posix_time::ptime SimulatorTimer::currentDateTime() const { if (timeMap_) - return timeMap_->getStartTime(current_step_); + return timeMap_->getStartTime(beginReportStepIdx_ + current_step_); else return boost::posix_time::ptime(start_date_) + boost::posix_time::seconds( (int) current_time_ ); } @@ -143,7 +170,9 @@ namespace Opm double SimulatorTimer::totalTime() const { if (timeMap_) - return timeMap_->getTotalTime(); + return + timeMap_->getTimePassedUntil(endReportStepIdx_) - + timeMap_->getTimePassedUntil(beginReportStepIdx_); else return total_time_; } @@ -187,7 +216,7 @@ namespace Opm bool SimulatorTimer::done() const { if (timeMap_) - return int(timeMap_->numTimesteps()) <= current_step_; + return current_step_ > int(endReportStepIdx_ - beginReportStepIdx_ - 1); else return int(timesteps_.size()) == current_step_; } diff --git a/opm/core/simulator/SimulatorTimer.hpp b/opm/core/simulator/SimulatorTimer.hpp index ad49282f..b743478d 100644 --- a/opm/core/simulator/SimulatorTimer.hpp +++ b/opm/core/simulator/SimulatorTimer.hpp @@ -51,11 +51,18 @@ namespace Opm /// Use the SimulatorTimer as a shim around opm-parser's Opm::TimeMap void init(TimeMapConstPtr timeMap, - int timeStepIdx = 0); + size_t beginReportStepIdx = 0, + size_t endReportStepIdx = std::numeric_limits::max()); /// Total number of steps. int numSteps() const; + /// Index of the first report step considered + size_t beginReportStepIndex() const; + + /// Index of the next-after-last report step to be considered + size_t endReportStepIndex() const; + /// Current step number. This is the number of timesteps that /// has been completed from the start of the run. The time /// after initialization but before the simulation has started @@ -112,6 +119,8 @@ namespace Opm private: Opm::TimeMapConstPtr timeMap_; std::vector timesteps_; + size_t beginReportStepIdx_; + size_t endReportStepIdx_; int current_step_; double current_time_; double total_time_;