Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add end step #5911

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion opm/simulators/flow/FlowMain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace Opm::Parameters {
// Do not merge parallel output files or warn about them
struct EnableLoggingFalloutWarning { static constexpr bool value = false; };
struct OutputInterval { static constexpr int value = 1; };
struct EndStep { static constexpr int value = std::numeric_limits<int>::max(); };

} // namespace Opm::Parameters

Expand Down Expand Up @@ -103,6 +104,7 @@ namespace Opm {
("Developer option to see whether logging was on non-root processors. "
"In that case it will be appended to the *.DBG or *.PRT files");

Parameters::Register<Parameters::EndStep>("End step for simulering");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's try the other norwegian language.

// register the base parameters
registerAllParameters_<TypeTag>(/*finalizeRegistration=*/false);

Expand Down Expand Up @@ -421,7 +423,8 @@ namespace Opm {

// initialize variables
const auto& initConfig = eclState().getInitConfig();
simtimer_->init(schedule, static_cast<std::size_t>(initConfig.getRestartStep()));
int end_step = Parameters::Get<Parameters::EndStep>();
simtimer_->init(schedule, static_cast<std::size_t>(initConfig.getRestartStep()), static_cast<std::size_t>(end_step));

if (this->output_cout_) {
std::ostringstream oss;
Expand Down
15 changes: 12 additions & 3 deletions opm/simulators/timestepping/SimulatorTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Opm
SimulatorTimer::SimulatorTimer()
: current_step_(0),
current_time_(0.0),
end_time_(std::numeric_limit<std::size_t>::max()),
start_date_(2012,1,1) // A really arbitrary default starting value?!
{
}
Expand All @@ -48,6 +49,7 @@ namespace Opm
res.current_step_ = 4;
res.current_time_ = 5.0;
res.total_time_ = 6.0;
res.end_step_ = 8;
res.start_date_ = boost::gregorian::date(2023,1,31);

return res;
Expand All @@ -59,22 +61,24 @@ namespace Opm
void SimulatorTimer::init(const ParameterGroup& param)
{
const int num_psteps = param.getDefault("num_psteps", 1);
const int end_step = param.getDefault("end_step", 50000);
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);
end_step_ = end_step;
total_time_ = num_psteps*stepsize;
}

/// Use the SimulatorTimer as a shim around opm-parser's Opm::TimeMap
void SimulatorTimer::init(const Schedule& schedule, std::size_t report_step)
void SimulatorTimer::init(const Schedule& schedule, std::size_t report_step, std::size_t end_step)
{
total_time_ = schedule.seconds( schedule.size() - 1 );
timesteps_.resize(schedule.size() - 1);
for (std::size_t i = 0; i < schedule.size() - 1; ++i) {
timesteps_[i] = schedule.stepLength(i);
}

end_step_ = end_step;
setCurrentStepNum(report_step);
start_date_ = boost::posix_time::from_time_t(schedule.getStartTime()).date();
}
Expand Down Expand Up @@ -167,7 +171,11 @@ namespace Opm
/// Return true if op++() has been called numSteps() times.
bool SimulatorTimer::done() const
{
return int(timesteps_.size()) == current_step_;
if(current_step_ < end_step_){
return int(timesteps_.size()) == current_step_;
}else{
return true;
}
}

/// return copy of object
Expand All @@ -183,6 +191,7 @@ namespace Opm
this->current_step_ == rhs.current_step_ &&
this->current_time_ == rhs.current_time_ &&
this->total_time_ == rhs.total_time_ &&
this->end_step_ == rhs.end_step_ &&
this->start_date_ == rhs.start_date_;
}

Expand Down
4 changes: 3 additions & 1 deletion opm/simulators/timestepping/SimulatorTimer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace Opm
void init(const ParameterGroup& param);

/// Use the SimulatorTimer as a shim around opm-commons Schedule class
void init(const Schedule& schedule, std::size_t report_step = 0);
void init(const Schedule& schedule, std::size_t report_step, std::size_t end_step);

/// Whether the current step is the first step.
bool initialStep() const override;
Expand Down Expand Up @@ -127,6 +127,7 @@ namespace Opm
serializer(current_step_);
serializer(current_time_);
serializer(total_time_);
serializer(end_step_);
serializer(start_date_);
}

Expand All @@ -137,6 +138,7 @@ namespace Opm
int current_step_;
double current_time_;
double total_time_;
int end_step_;
boost::gregorian::date start_date_;
};

Expand Down
2 changes: 1 addition & 1 deletion tests/test_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(CreateTimer)
boost::gregorian::date defaultStartDate( 2012, 1, 1);
BOOST_CHECK_EQUAL( boost::posix_time::ptime(defaultStartDate), simtimer.currentDateTime() );

simtimer.init(schedule);
simtimer.init(schedule, 0, std::numeric_limits<std::size_t>::max());
boost::gregorian::date startDate( 2014, 3, 26);
BOOST_CHECK_EQUAL( boost::posix_time::ptime(startDate), simtimer.currentDateTime() );

Expand Down