diff --git a/opm/simulators/timestepping/SimulatorTimer.cpp b/opm/simulators/timestepping/SimulatorTimer.cpp index db4b5aac0..337723dbe 100644 --- a/opm/simulators/timestepping/SimulatorTimer.cpp +++ b/opm/simulators/timestepping/SimulatorTimer.cpp @@ -29,8 +29,9 @@ namespace Opm /// Default constructor. SimulatorTimer::SimulatorTimer() - : current_step_(0), - current_time_(0.0) + : current_step_(0), + current_time_(0.0), + start_date_(2012,1,1) // A really arbitrary default starting value?! { } @@ -39,31 +40,32 @@ namespace Opm /// stepsize_days (default 1) void SimulatorTimer::init(const parameter::ParameterGroup& param) { - const int num_psteps = param.getDefault("num_psteps", 1); - const double stepsize_days = param.getDefault("stepsize_days", 1.0); - const double stepsize = Opm::unit::convert::from(stepsize_days, Opm::unit::day); - timesteps_.clear(); - timesteps_.resize(num_psteps, stepsize); - total_time_ = num_psteps*stepsize; + const int num_psteps = param.getDefault("num_psteps", 1); + const double stepsize_days = param.getDefault("stepsize_days", 1.0); + const double stepsize = Opm::unit::convert::from(stepsize_days, Opm::unit::day); + timesteps_.clear(); + timesteps_.resize(num_psteps, stepsize); + total_time_ = num_psteps*stepsize; } /// Initialize from TSTEP field. void SimulatorTimer::init(const EclipseGridParser& deck) { - timesteps_ = deck.getTSTEP().tstep_; - total_time_ = std::accumulate(timesteps_.begin(), timesteps_.end(), 0.0); + timesteps_ = deck.getTSTEP().tstep_; + total_time_ = std::accumulate(timesteps_.begin(), timesteps_.end(), 0.0); + start_date_ = deck.getStartDate(); } /// Total number of steps. int SimulatorTimer::numSteps() const { - return timesteps_.size(); + return timesteps_.size(); } /// Current step number. int SimulatorTimer::currentStepNum() const { - return current_step_; + return current_step_; } /// Set current step number. @@ -82,20 +84,28 @@ namespace Opm /// Current step length. double SimulatorTimer::currentStepLength() const { - ASSERT(!done()); - return timesteps_[current_step_]; + ASSERT(!done()); + return timesteps_[current_step_]; } /// Current time. double SimulatorTimer::currentTime() const { - return current_time_; + return current_time_; } + + boost::posix_time::ptime SimulatorTimer::currentDateTime() const + { + return boost::posix_time::ptime(start_date_) + boost::posix_time::seconds( (int) current_time_ ); + } + + + /// Total time. double SimulatorTimer::totalTime() const { - return total_time_; + return total_time_; } /// Set total time. @@ -104,32 +114,32 @@ namespace Opm /// access to later timesteps. void SimulatorTimer::setTotalTime(double time) { - total_time_ = time; + total_time_ = time; } /// Print a report with current and total time etc. void SimulatorTimer::report(std::ostream& os) const { os << "\n\n--------------- Simulation step number " << currentStepNum() << " ---------------" - << "\n Current time (days) " << Opm::unit::convert::to(currentTime(), Opm::unit::day) - << "\n Current stepsize (days) " << Opm::unit::convert::to(currentStepLength(), Opm::unit::day) - << "\n Total time (days) " << Opm::unit::convert::to(totalTime(), Opm::unit::day) - << "\n" << std::endl; + << "\n Current time (days) " << Opm::unit::convert::to(currentTime(), Opm::unit::day) + << "\n Current stepsize (days) " << Opm::unit::convert::to(currentStepLength(), Opm::unit::day) + << "\n Total time (days) " << Opm::unit::convert::to(totalTime(), Opm::unit::day) + << "\n" << std::endl; } /// Next step. SimulatorTimer& SimulatorTimer::operator++() { - ASSERT(!done()); - current_time_ += timesteps_[current_step_]; - ++current_step_; - return *this; + ASSERT(!done()); + current_time_ += timesteps_[current_step_]; + ++current_step_; + return *this; } /// Return true if op++() has been called numSteps() times. bool SimulatorTimer::done() const { - return int(timesteps_.size()) == current_step_; + return int(timesteps_.size()) == current_step_; } diff --git a/opm/simulators/timestepping/SimulatorTimer.hpp b/opm/simulators/timestepping/SimulatorTimer.hpp index d9a35a168..832cdef95 100644 --- a/opm/simulators/timestepping/SimulatorTimer.hpp +++ b/opm/simulators/timestepping/SimulatorTimer.hpp @@ -22,6 +22,8 @@ #include #include +#include +#include namespace Opm { @@ -33,57 +35,60 @@ namespace Opm class SimulatorTimer { public: - /// Default constructor. - SimulatorTimer(); + /// Default constructor. + SimulatorTimer(); - /// Initialize from parameters. Accepts the following: - /// num_psteps (default 1) - /// stepsize_days (default 1) - void init(const parameter::ParameterGroup& param); + /// Initialize from parameters. Accepts the following: + /// num_psteps (default 1) + /// stepsize_days (default 1) + void init(const parameter::ParameterGroup& param); - /// Initialize from TSTEP field. - void init(const EclipseGridParser& deck); + /// Initialize from TSTEP field. + void init(const EclipseGridParser& deck); - /// Total number of steps. - int numSteps() const; + /// Total number of steps. + int numSteps() const; - /// Current step number. - int currentStepNum() const; + /// Current step number. + int currentStepNum() const; /// Set current step number. void setCurrentStepNum(int step); - /// Current step length. - /// Note: if done(), it is an error to call currentStepLength(). - double currentStepLength() const; + /// Current step length. + /// Note: if done(), it is an error to call currentStepLength(). + double currentStepLength() const; - /// Current time. - double currentTime() const; + /// Current time. + double currentTime() const; - /// Total time. - double totalTime() const; + boost::posix_time::ptime currentDateTime() const; + + /// 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); + 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; + /// 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; - /// Next step. - SimulatorTimer& operator++(); + /// Next step. + SimulatorTimer& operator++(); - /// Return true if op++() has been called numSteps() times. - bool done() const; + /// Return true if op++() has been called numSteps() times. + bool done() const; private: - std::vector timesteps_; - int current_step_; - double current_time_; - double total_time_; + std::vector timesteps_; + int current_step_; + double current_time_; + double total_time_; + boost::gregorian::date start_date_; };