Merge pull request #525 from andlaus/SimulatorTimer_allow_to_be_limited_to_subranges
SimulatorTimer: allow it to be limited to a sub-range of all report steps
This commit is contained in:
commit
f4c899db4b
@ -59,21 +59,46 @@ namespace Opm
|
|||||||
|
|
||||||
/// Use the SimulatorTimer as a shim around opm-parser's Opm::TimeMap
|
/// Use the SimulatorTimer as a shim around opm-parser's Opm::TimeMap
|
||||||
void SimulatorTimer::init(Opm::TimeMapConstPtr timeMap,
|
void SimulatorTimer::init(Opm::TimeMapConstPtr timeMap,
|
||||||
int timeStepIdx)
|
size_t beginReportStepIdx,
|
||||||
|
size_t endReportStepIdx)
|
||||||
{
|
{
|
||||||
timeMap_ = timeMap;
|
timeMap_ = timeMap;
|
||||||
current_step_ = timeStepIdx;
|
current_step_ = 0;
|
||||||
|
beginReportStepIdx_ = beginReportStepIdx;
|
||||||
|
endReportStepIdx_ = std::min(timeMap_->numTimesteps() + 1, endReportStepIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Total number of steps.
|
/// Total number of steps.
|
||||||
int SimulatorTimer::numSteps() const
|
int SimulatorTimer::numSteps() const
|
||||||
{
|
{
|
||||||
if (timeMap_)
|
if (timeMap_)
|
||||||
return timeMap_->numTimesteps();
|
return endReportStepIdx_ - beginReportStepIdx_;
|
||||||
else
|
else
|
||||||
return timesteps_.size();
|
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.
|
/// Current step number.
|
||||||
int SimulatorTimer::currentStepNum() const
|
int SimulatorTimer::currentStepNum() const
|
||||||
{
|
{
|
||||||
@ -99,7 +124,7 @@ namespace Opm
|
|||||||
{
|
{
|
||||||
assert(!done());
|
assert(!done());
|
||||||
if (timeMap_)
|
if (timeMap_)
|
||||||
return timeMap_->getTimeStepLength(current_step_);
|
return timeMap_->getTimeStepLength(beginReportStepIdx_ + current_step_);
|
||||||
else
|
else
|
||||||
return timesteps_[current_step_];
|
return timesteps_[current_step_];
|
||||||
}
|
}
|
||||||
@ -108,7 +133,7 @@ namespace Opm
|
|||||||
{
|
{
|
||||||
assert(current_step_ > 0);
|
assert(current_step_ > 0);
|
||||||
if (timeMap_)
|
if (timeMap_)
|
||||||
return timeMap_->getTimeStepLength(current_step_ - 1);
|
return timeMap_->getTimeStepLength(beginReportStepIdx_ + current_step_ - 1);
|
||||||
else
|
else
|
||||||
return timesteps_[current_step_ - 1];
|
return timesteps_[current_step_ - 1];
|
||||||
}
|
}
|
||||||
@ -117,7 +142,9 @@ namespace Opm
|
|||||||
double SimulatorTimer::simulationTimeElapsed() const
|
double SimulatorTimer::simulationTimeElapsed() const
|
||||||
{
|
{
|
||||||
if (timeMap_)
|
if (timeMap_)
|
||||||
return timeMap_->getTimePassedUntil(current_step_);
|
return
|
||||||
|
timeMap_->getTimePassedUntil(beginReportStepIdx_ + current_step_)
|
||||||
|
- timeMap_->getTimePassedUntil(beginReportStepIdx_);
|
||||||
else
|
else
|
||||||
return current_time_;
|
return current_time_;
|
||||||
}
|
}
|
||||||
@ -132,7 +159,7 @@ namespace Opm
|
|||||||
boost::posix_time::ptime SimulatorTimer::currentDateTime() const
|
boost::posix_time::ptime SimulatorTimer::currentDateTime() const
|
||||||
{
|
{
|
||||||
if (timeMap_)
|
if (timeMap_)
|
||||||
return timeMap_->getStartTime(current_step_);
|
return timeMap_->getStartTime(beginReportStepIdx_ + current_step_);
|
||||||
else
|
else
|
||||||
return boost::posix_time::ptime(start_date_) + boost::posix_time::seconds( (int) current_time_ );
|
return boost::posix_time::ptime(start_date_) + boost::posix_time::seconds( (int) current_time_ );
|
||||||
}
|
}
|
||||||
@ -143,7 +170,9 @@ namespace Opm
|
|||||||
double SimulatorTimer::totalTime() const
|
double SimulatorTimer::totalTime() const
|
||||||
{
|
{
|
||||||
if (timeMap_)
|
if (timeMap_)
|
||||||
return timeMap_->getTotalTime();
|
return
|
||||||
|
timeMap_->getTimePassedUntil(endReportStepIdx_) -
|
||||||
|
timeMap_->getTimePassedUntil(beginReportStepIdx_);
|
||||||
else
|
else
|
||||||
return total_time_;
|
return total_time_;
|
||||||
}
|
}
|
||||||
@ -187,7 +216,7 @@ namespace Opm
|
|||||||
bool SimulatorTimer::done() const
|
bool SimulatorTimer::done() const
|
||||||
{
|
{
|
||||||
if (timeMap_)
|
if (timeMap_)
|
||||||
return int(timeMap_->numTimesteps()) <= current_step_;
|
return current_step_ > int(endReportStepIdx_ - beginReportStepIdx_ - 1);
|
||||||
else
|
else
|
||||||
return int(timesteps_.size()) == current_step_;
|
return int(timesteps_.size()) == current_step_;
|
||||||
}
|
}
|
||||||
|
@ -51,11 +51,18 @@ namespace Opm
|
|||||||
|
|
||||||
/// Use the SimulatorTimer as a shim around opm-parser's Opm::TimeMap
|
/// Use the SimulatorTimer as a shim around opm-parser's Opm::TimeMap
|
||||||
void init(TimeMapConstPtr 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.
|
/// Total number of steps.
|
||||||
int numSteps() const;
|
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
|
/// Current step number. This is the number of timesteps that
|
||||||
/// has been completed from the start of the run. The time
|
/// has been completed from the start of the run. The time
|
||||||
/// after initialization but before the simulation has started
|
/// after initialization but before the simulation has started
|
||||||
@ -112,6 +119,8 @@ namespace Opm
|
|||||||
private:
|
private:
|
||||||
Opm::TimeMapConstPtr timeMap_;
|
Opm::TimeMapConstPtr timeMap_;
|
||||||
std::vector<double> timesteps_;
|
std::vector<double> timesteps_;
|
||||||
|
size_t beginReportStepIdx_;
|
||||||
|
size_t endReportStepIdx_;
|
||||||
int current_step_;
|
int current_step_;
|
||||||
double current_time_;
|
double current_time_;
|
||||||
double total_time_;
|
double total_time_;
|
||||||
|
Loading…
Reference in New Issue
Block a user