From 3aef6578f97944cdf7de74f45879ca175ce47e1a Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Tue, 11 Mar 2014 15:06:07 +0100 Subject: [PATCH] SimulatorTimer: rename currentTime() to simulationTimeElapsed() because the name "currentTime()" can be mistaken for the point in real-life time at which the simulation is run (e.g. March 11, 2014, 15:07:45.123), the _point_ in time which the simulator timer currently represents (e.g. Jun 5, 1985, 02:33:12.345) instead of the simulator time in seconds which elapsed since the START date (e.g. 52633.345 s). this rename may lead to some fallout in other modules. I'll fix them after this PR has been merged... --- opm/core/simulator/SimulatorCompressibleTwophase.cpp | 4 ++-- opm/core/simulator/SimulatorIncompTwophase.cpp | 4 ++-- opm/core/simulator/SimulatorOutput.cpp | 2 +- opm/core/simulator/SimulatorTimer.cpp | 12 +++++++++--- opm/core/simulator/SimulatorTimer.hpp | 9 +++++++-- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/opm/core/simulator/SimulatorCompressibleTwophase.cpp b/opm/core/simulator/SimulatorCompressibleTwophase.cpp index a5760716..7284d8d4 100644 --- a/opm/core/simulator/SimulatorCompressibleTwophase.cpp +++ b/opm/core/simulator/SimulatorCompressibleTwophase.cpp @@ -498,13 +498,13 @@ namespace Opm << std::endl; std::cout.precision(8); - watercut.push(timer.currentTime() + timer.currentStepLength(), + watercut.push(timer.simulationTimeElapsed() + timer.currentStepLength(), produced[0]/(produced[0] + produced[1]), tot_produced[0]/tot_porevol_init); if (wells_) { wellreport.push(props_, *wells_, state.pressure(), state.surfacevol(), state.saturation(), - timer.currentTime() + timer.currentStepLength(), + timer.simulationTimeElapsed() + timer.currentStepLength(), well_state.bhp(), well_state.perfRates()); } sreport.total_time = step_timer.secsSinceStart(); diff --git a/opm/core/simulator/SimulatorIncompTwophase.cpp b/opm/core/simulator/SimulatorIncompTwophase.cpp index 12871c76..271cc8fe 100644 --- a/opm/core/simulator/SimulatorIncompTwophase.cpp +++ b/opm/core/simulator/SimulatorIncompTwophase.cpp @@ -578,12 +578,12 @@ namespace Opm dynamic_cast(*tsolver_) .solveGravity(&initial_porevol[0], stepsize, state); } - watercut.push(timer.currentTime() + timer.currentStepLength(), + watercut.push(timer.simulationTimeElapsed() + timer.currentStepLength(), produced[0]/(produced[0] + produced[1]), tot_produced[0]/tot_porevol_init); if (wells_) { wellreport.push(props_, *wells_, state.saturation(), - timer.currentTime() + timer.currentStepLength(), + timer.simulationTimeElapsed() + timer.currentStepLength(), well_state.bhp(), well_state.perfRates()); } } diff --git a/opm/core/simulator/SimulatorOutput.cpp b/opm/core/simulator/SimulatorOutput.cpp index fd7bf85b..ddb375af 100644 --- a/opm/core/simulator/SimulatorOutput.cpp +++ b/opm/core/simulator/SimulatorOutput.cpp @@ -72,7 +72,7 @@ SimulatorOutputBase::operator std::function () { void SimulatorOutputBase::writeOutput () { - const int this_time = timer_->currentTime (); + const int this_time = timer_->simulationTimeElapsed (); // if the simulator signals for timesteps that aren't reporting // times, then ignore them diff --git a/opm/core/simulator/SimulatorTimer.cpp b/opm/core/simulator/SimulatorTimer.cpp index fddc3aa8..b672b613 100644 --- a/opm/core/simulator/SimulatorTimer.cpp +++ b/opm/core/simulator/SimulatorTimer.cpp @@ -113,8 +113,8 @@ namespace Opm return timesteps_[current_step_ - 1]; } - /// Current time. - double SimulatorTimer::currentTime() const + /// time elapsed since the start of the simulation [s]. + double SimulatorTimer::simulationTimeElapsed() const { if (timeMap_) return timeMap_->getTimePassedUntil(current_step_); @@ -122,6 +122,12 @@ namespace Opm return current_time_; } + /// time elapsed since the start of the POSIX epoch (Jan 1st, 1970) [s]. + time_t SimulatorTimer::currentPosixTime() const + { + tm t = boost::posix_time::to_tm(currentDateTime()); + return std::mktime(&t); + } boost::posix_time::ptime SimulatorTimer::currentDateTime() const { @@ -161,7 +167,7 @@ namespace Opm 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 time (days) " << Opm::unit::convert::to(simulationTimeElapsed(), 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; diff --git a/opm/core/simulator/SimulatorTimer.hpp b/opm/core/simulator/SimulatorTimer.hpp index 949859e5..ad49282f 100644 --- a/opm/core/simulator/SimulatorTimer.hpp +++ b/opm/core/simulator/SimulatorTimer.hpp @@ -79,8 +79,13 @@ namespace Opm /// it is an error to call stepLengthTaken(). double stepLengthTaken () const; - /// Current time. - double currentTime() const; + /// Time elapsed since the start of the POSIX epoch (Jan 1st, + /// 1970) until the current time step begins [s]. + time_t currentPosixTime() const; + + /// Time elapsed since the start of the simulation until the + /// beginning of the current time step [s]. + double simulationTimeElapsed() const; /// Return the current time as a posix time object. boost::posix_time::ptime currentDateTime() const;