mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-20 11:48:25 -06:00
Added start_date_ property to the SimulatorTimer class
This commit is contained in:
parent
158c33eb53
commit
09b3ef785c
@ -29,8 +29,9 @@ namespace Opm
|
|||||||
|
|
||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
SimulatorTimer::SimulatorTimer()
|
SimulatorTimer::SimulatorTimer()
|
||||||
: current_step_(0),
|
: current_step_(0),
|
||||||
current_time_(0.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)
|
/// stepsize_days (default 1)
|
||||||
void SimulatorTimer::init(const parameter::ParameterGroup& param)
|
void SimulatorTimer::init(const parameter::ParameterGroup& param)
|
||||||
{
|
{
|
||||||
const int num_psteps = param.getDefault("num_psteps", 1);
|
const int num_psteps = param.getDefault("num_psteps", 1);
|
||||||
const double stepsize_days = param.getDefault("stepsize_days", 1.0);
|
const double stepsize_days = param.getDefault("stepsize_days", 1.0);
|
||||||
const double stepsize = Opm::unit::convert::from(stepsize_days, Opm::unit::day);
|
const double stepsize = Opm::unit::convert::from(stepsize_days, Opm::unit::day);
|
||||||
timesteps_.clear();
|
timesteps_.clear();
|
||||||
timesteps_.resize(num_psteps, stepsize);
|
timesteps_.resize(num_psteps, stepsize);
|
||||||
total_time_ = num_psteps*stepsize;
|
total_time_ = num_psteps*stepsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize from TSTEP field.
|
/// Initialize from TSTEP field.
|
||||||
void SimulatorTimer::init(const EclipseGridParser& deck)
|
void SimulatorTimer::init(const EclipseGridParser& deck)
|
||||||
{
|
{
|
||||||
timesteps_ = deck.getTSTEP().tstep_;
|
timesteps_ = deck.getTSTEP().tstep_;
|
||||||
total_time_ = std::accumulate(timesteps_.begin(), timesteps_.end(), 0.0);
|
total_time_ = std::accumulate(timesteps_.begin(), timesteps_.end(), 0.0);
|
||||||
|
start_date_ = deck.getStartDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Total number of steps.
|
/// Total number of steps.
|
||||||
int SimulatorTimer::numSteps() const
|
int SimulatorTimer::numSteps() const
|
||||||
{
|
{
|
||||||
return timesteps_.size();
|
return timesteps_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Current step number.
|
/// Current step number.
|
||||||
int SimulatorTimer::currentStepNum() const
|
int SimulatorTimer::currentStepNum() const
|
||||||
{
|
{
|
||||||
return current_step_;
|
return current_step_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set current step number.
|
/// Set current step number.
|
||||||
@ -82,20 +84,28 @@ namespace Opm
|
|||||||
/// Current step length.
|
/// Current step length.
|
||||||
double SimulatorTimer::currentStepLength() const
|
double SimulatorTimer::currentStepLength() const
|
||||||
{
|
{
|
||||||
ASSERT(!done());
|
ASSERT(!done());
|
||||||
return timesteps_[current_step_];
|
return timesteps_[current_step_];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Current time.
|
/// Current time.
|
||||||
double SimulatorTimer::currentTime() const
|
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.
|
/// Total time.
|
||||||
double SimulatorTimer::totalTime() const
|
double SimulatorTimer::totalTime() const
|
||||||
{
|
{
|
||||||
return total_time_;
|
return total_time_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set total time.
|
/// Set total time.
|
||||||
@ -104,32 +114,32 @@ namespace Opm
|
|||||||
/// access to later timesteps.
|
/// access to later timesteps.
|
||||||
void SimulatorTimer::setTotalTime(double time)
|
void SimulatorTimer::setTotalTime(double time)
|
||||||
{
|
{
|
||||||
total_time_ = time;
|
total_time_ = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Print a report with current and total time etc.
|
/// Print a report with current and total time etc.
|
||||||
void SimulatorTimer::report(std::ostream& os) const
|
void SimulatorTimer::report(std::ostream& os) const
|
||||||
{
|
{
|
||||||
os << "\n\n--------------- Simulation step number " << currentStepNum() << " ---------------"
|
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(currentTime(), Opm::unit::day)
|
||||||
<< "\n Current stepsize (days) " << Opm::unit::convert::to(currentStepLength(), 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 Total time (days) " << Opm::unit::convert::to(totalTime(), Opm::unit::day)
|
||||||
<< "\n" << std::endl;
|
<< "\n" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Next step.
|
/// Next step.
|
||||||
SimulatorTimer& SimulatorTimer::operator++()
|
SimulatorTimer& SimulatorTimer::operator++()
|
||||||
{
|
{
|
||||||
ASSERT(!done());
|
ASSERT(!done());
|
||||||
current_time_ += timesteps_[current_step_];
|
current_time_ += timesteps_[current_step_];
|
||||||
++current_step_;
|
++current_step_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true if op++() has been called numSteps() times.
|
/// Return true if op++() has been called numSteps() times.
|
||||||
bool SimulatorTimer::done() const
|
bool SimulatorTimer::done() const
|
||||||
{
|
{
|
||||||
return int(timesteps_.size()) == current_step_;
|
return int(timesteps_.size()) == current_step_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||||
|
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||||
|
|
||||||
namespace Opm
|
namespace Opm
|
||||||
{
|
{
|
||||||
@ -33,57 +35,60 @@ namespace Opm
|
|||||||
class SimulatorTimer
|
class SimulatorTimer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
SimulatorTimer();
|
SimulatorTimer();
|
||||||
|
|
||||||
/// Initialize from parameters. Accepts the following:
|
/// Initialize from parameters. Accepts the following:
|
||||||
/// num_psteps (default 1)
|
/// num_psteps (default 1)
|
||||||
/// stepsize_days (default 1)
|
/// stepsize_days (default 1)
|
||||||
void init(const parameter::ParameterGroup& param);
|
void init(const parameter::ParameterGroup& param);
|
||||||
|
|
||||||
/// Initialize from TSTEP field.
|
/// Initialize from TSTEP field.
|
||||||
void init(const EclipseGridParser& deck);
|
void init(const EclipseGridParser& deck);
|
||||||
|
|
||||||
/// Total number of steps.
|
/// Total number of steps.
|
||||||
int numSteps() const;
|
int numSteps() const;
|
||||||
|
|
||||||
/// Current step number.
|
/// Current step number.
|
||||||
int currentStepNum() const;
|
int currentStepNum() const;
|
||||||
|
|
||||||
/// Set current step number.
|
/// Set current step number.
|
||||||
void setCurrentStepNum(int step);
|
void setCurrentStepNum(int step);
|
||||||
|
|
||||||
/// Current step length.
|
/// Current step length.
|
||||||
/// Note: if done(), it is an error to call currentStepLength().
|
/// Note: if done(), it is an error to call currentStepLength().
|
||||||
double currentStepLength() const;
|
double currentStepLength() const;
|
||||||
|
|
||||||
/// Current time.
|
/// Current time.
|
||||||
double currentTime() const;
|
double currentTime() const;
|
||||||
|
|
||||||
/// Total time.
|
boost::posix_time::ptime currentDateTime() const;
|
||||||
double totalTime() const;
|
|
||||||
|
/// Total time.
|
||||||
|
double totalTime() const;
|
||||||
|
|
||||||
/// Set total time.
|
/// Set total time.
|
||||||
/// This is primarily intended for multi-epoch schedules,
|
/// This is primarily intended for multi-epoch schedules,
|
||||||
/// where a timer for a given epoch does not have
|
/// where a timer for a given epoch does not have
|
||||||
/// access to later timesteps.
|
/// access to later timesteps.
|
||||||
void setTotalTime(double time);
|
void setTotalTime(double time);
|
||||||
|
|
||||||
/// Print a report with current and total time etc.
|
/// Print a report with current and total time etc.
|
||||||
/// Note: if done(), it is an error to call report().
|
/// Note: if done(), it is an error to call report().
|
||||||
void report(std::ostream& os) const;
|
void report(std::ostream& os) const;
|
||||||
|
|
||||||
/// Next step.
|
/// Next step.
|
||||||
SimulatorTimer& operator++();
|
SimulatorTimer& operator++();
|
||||||
|
|
||||||
/// Return true if op++() has been called numSteps() times.
|
/// Return true if op++() has been called numSteps() times.
|
||||||
bool done() const;
|
bool done() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<double> timesteps_;
|
std::vector<double> timesteps_;
|
||||||
int current_step_;
|
int current_step_;
|
||||||
double current_time_;
|
double current_time_;
|
||||||
double total_time_;
|
double total_time_;
|
||||||
|
boost::gregorian::date start_date_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user