From 294ce0b579b267ed7deb31dd09d143cd48e9aeb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Thu, 14 Jun 2012 11:55:33 +0200 Subject: [PATCH] In SimulatorTimer: added setTotalTime(), made setCurrentStepNum() update current time. --- opm/core/utility/SimulatorTimer.cpp | 15 +++++++++++++++ opm/core/utility/SimulatorTimer.hpp | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/opm/core/utility/SimulatorTimer.cpp b/opm/core/utility/SimulatorTimer.cpp index 2e7b64f3..2c6349c0 100644 --- a/opm/core/utility/SimulatorTimer.cpp +++ b/opm/core/utility/SimulatorTimer.cpp @@ -69,7 +69,13 @@ namespace Opm /// Set current step number. void SimulatorTimer::setCurrentStepNum(int step) { + if (current_step_ < 0 || current_step_ > int(timesteps_.size())) { + // Note that we do allow current_step_ == timesteps_.size(), + // that is the done() state. + THROW("Trying to set invalid step number: " << step); + } current_step_ = step; + current_time_ = std::accumulate(timesteps_.begin(), timesteps_.begin() + step, 0.0); } @@ -92,6 +98,15 @@ namespace Opm return total_time_; } + /// Set total time. + /// This is primarily intended for multi-epoch schedules, + /// where a timer for a given epoch does not have + /// access to later timesteps. + void SimulatorTimer::setTotalTime(double time) + { + total_time_ = time; + } + /// Print a report with current and total time etc. void SimulatorTimer::report(std::ostream& os) const { diff --git a/opm/core/utility/SimulatorTimer.hpp b/opm/core/utility/SimulatorTimer.hpp index 7088909b..d9a35a16 100644 --- a/opm/core/utility/SimulatorTimer.hpp +++ b/opm/core/utility/SimulatorTimer.hpp @@ -63,6 +63,12 @@ namespace Opm /// Total time. double totalTime() const; + /// Set total time. + /// This is primarily intended for multi-epoch schedules, + /// where a timer for a given epoch does not have + /// access to later timesteps. + void setTotalTime(double time); + /// Print a report with current and total time etc. /// Note: if done(), it is an error to call report(). void report(std::ostream& os) const;