SimulatorTimer: allow it to be limited to a sub-range of all report steps

This commit is contained in:
Andreas Lauser 2014-03-17 16:30:03 +01:00
parent caf10e0e7f
commit f2e9016bd0
2 changed files with 48 additions and 10 deletions

View File

@ -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_;
}

View File

@ -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<size_t>::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<double> timesteps_;
size_t beginReportStepIdx_;
size_t endReportStepIdx_;
int current_step_;
double current_time_;
double total_time_;