Skip to content
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
21 changes: 19 additions & 2 deletions opm/simulators/timestepping/AdaptiveSimulatorTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,31 @@ namespace Opm
void AdaptiveSimulatorTimer::
report(std::ostream& os) const
{
os << "Sub steps started at time = " << unit::convert::to( start_time_, unit::day ) << " (days)" << std::endl;
os << "Sub steps started at time = "
<< unit::convert::to(reportStepStartTime(), unit::day) << " (days)" << std::endl;
for (std::size_t i = 0; i < steps_.size(); ++i)
{
os << " step[ " << i << " ] = " << unit::convert::to( steps_[ i ], unit::day ) << " (days)" << std::endl;
os << " step[ " << (report_step_substep_offset_ + i) << " ] = "
<< unit::convert::to(steps_[i], unit::day) << " (days)" << std::endl;
}
os << "sub steps end time = " << unit::convert::to( simulationTimeElapsed(), unit::day ) << " (days)" << std::endl;
}

double AdaptiveSimulatorTimer::reportStepStartTime() const
{
return report_step_start_time_.value_or(start_time_);
}

double AdaptiveSimulatorTimer::reportStepTotalTime() const
{
return report_step_total_time_.value_or(total_time_);
}

int AdaptiveSimulatorTimer::reportStepSubstepNum() const
{
return report_step_substep_offset_ + current_step_;
}

boost::posix_time::ptime AdaptiveSimulatorTimer::startDateTime() const
{
return *start_date_time_;
Expand Down
32 changes: 32 additions & 0 deletions opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <algorithm>
#include <memory>
#include <numeric>
#include <optional>

#include <opm/simulators/timestepping/SimulatorTimerInterface.hpp>

Expand Down Expand Up @@ -112,6 +113,24 @@ namespace Opm
/// \brief tell the timestepper whether timestep failed or not
void setLastStepFailed(bool last_step_failed) { last_step_failed_ = last_step_failed; }

/// \brief Reservoir coupling constructs a fresh timer per sync chunk,
/// so `start_time_`, `total_time_`, and `current_step_` describe the
/// chunk rather than the enclosing report step. The accessors below
/// return a "report step view" that the rescoup outer loop populates
/// (via the setters) so that log lines can show the report-step start
/// and end and a substep counter that increments across chunks. When
/// the view is not set, they fall through to the per-timer fields, so
/// the non-rescoup path's behavior and output are unchanged.
double reportStepStartTime() const;
double reportStepTotalTime() const;
int reportStepSubstepNum() const;

void setReportStepStartTime(double t) { report_step_start_time_ = t; }
void setReportStepTotalTime(double t) { report_step_total_time_ = t; }
void setReportStepSubstepOffset(int n) { report_step_substep_offset_ = n; }

int reportStepSubstepOffset() const { return report_step_substep_offset_; }

/// return copy of object
std::unique_ptr<SimulatorTimerInterface> clone() const override;

Expand All @@ -129,6 +148,19 @@ namespace Opm
std::vector< double > steps_;
bool last_step_failed_;

/// \brief Optional report-step start time for the "report step view"
/// accessors. Set by the rescoup outer loop on each per-sync-chunk
/// timer; unset on a non-rescoup timer.
std::optional<double> report_step_start_time_;
/// \brief Optional report-step end time for the "report step view"
/// accessors. Same population pattern as `report_step_start_time_`.
std::optional<double> report_step_total_time_;
/// \brief Number of substeps already taken in this report step before
/// this timer was constructed (i.e. in earlier sync chunks). Added to
/// `current_step_` by `reportStepSubstepNum()` to give a counter that
/// increments across sync chunks. Zero on a non-rescoup timer.
int report_step_substep_offset_ = 0;

};

} // namespace Opm
Expand Down
4 changes: 2 additions & 2 deletions opm/simulators/timestepping/AdaptiveTimeStepping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ void logTimer(const AdaptiveSimulatorTimer& substepTimer)
std::ostringstream ss;
boost::posix_time::time_facet* facet = new boost::posix_time::time_facet("%d-%b-%Y");
ss.imbue(std::locale(std::locale::classic(), facet));
ss << "\nStarting time step " << substepTimer.currentStepNum() << ", stepsize "
ss << "\nStarting time step " << substepTimer.reportStepSubstepNum() << ", stepsize "
<< unit::convert::to(substepTimer.currentStepLength(), unit::day) << " days,"
<< " at day " << (double)unit::convert::to(substepTimer.simulationTimeElapsed(), unit::day)
<< "/" << (double)unit::convert::to(substepTimer.totalTime(), unit::day);
<< "/" << (double)unit::convert::to(substepTimer.reportStepTotalTime(), unit::day);
if ((substepTimer.currentDateTime() <= boost::posix_time::ptime(boost::posix_time::max_date_time)) &&
(boost::posix_time::ptime(boost::posix_time::min_date_time) <= substepTimer.currentDateTime())) {
ss << ", date = " << substepTimer.currentDateTime();
Expand Down
18 changes: 18 additions & 0 deletions opm/simulators/timestepping/AdaptiveTimeStepping_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@ runStepReservoirCouplingMaster_()
const double original_time_step = this->simulator_timer_.currentStepLength();
double current_time{this->simulator_timer_.simulationTimeElapsed()};
double step_end_time = current_time + original_time_step;
const double report_step_start_time = current_time;
int report_step_substep_offset = 0;
// In RSYNC mode this variable persists across outer iterations and
// carries the previously-chopped sync span into the next iteration. In
// TSYNC mode it is overwritten each iteration by
Expand Down Expand Up @@ -749,6 +751,12 @@ runStepReservoirCouplingMaster_()
/*reportStep=*/this->simulator_timer_.reportStepNum(),
maxTimeStep_()
};
// Make the per-chunk timer log the enclosing report step's span and a
// cumulative substep counter (see AdaptiveSimulatorTimer "report step
// view"). Without this, log lines would show one sync chunk only.
substep_timer.setReportStepStartTime(report_step_start_time);
substep_timer.setReportStepTotalTime(step_end_time);
substep_timer.setReportStepSubstepOffset(report_step_substep_offset);
const bool final_step = ReservoirCoupling::Seconds::compare_gt_or_eq(
current_time + current_step_length, step_end_time
);
Expand All @@ -763,6 +771,7 @@ runStepReservoirCouplingMaster_()
SubStepIteration<Solver> substepIteration{*this, substep_timer, current_step_length, final_step};
const auto sub_steps_report = substepIteration.run();
report += sub_steps_report;
report_step_substep_offset += substep_timer.currentStepNum();
current_time += current_step_length;
if (final_step) {
break;
Expand All @@ -782,6 +791,8 @@ runStepReservoirCouplingSlave_()
const double original_time_step = this->simulator_timer_.currentStepLength();
double current_time{this->simulator_timer_.simulationTimeElapsed()};
double step_end_time = current_time + original_time_step;
const double report_step_start_time = current_time;
int report_step_substep_offset = 0;
SimulatorReport report;
auto report_step_idx = this->simulator_timer_.currentStepNum();
if (report_step_idx == 0 && iteration == 0) {
Expand All @@ -807,6 +818,12 @@ runStepReservoirCouplingSlave_()
this->simulator_timer_.reportStepNum(),
maxTimeStep_()
};
// Make the per-chunk timer log the enclosing report step's span and a
// cumulative substep counter (see AdaptiveSimulatorTimer "report step
// view"). Without this, log lines would show one sync chunk only.
substep_timer.setReportStepStartTime(report_step_start_time);
substep_timer.setReportStepTotalTime(step_end_time);
substep_timer.setReportStepSubstepOffset(report_step_substep_offset);
const bool final_step = ReservoirCoupling::Seconds::compare_gt_or_eq(
current_time + timestep, step_end_time
);
Expand All @@ -817,6 +834,7 @@ runStepReservoirCouplingSlave_()
SubStepIteration<Solver> substepIteration{*this, substep_timer, timestep, final_step};
const auto sub_steps_report = substepIteration.run();
report += sub_steps_report;
report_step_substep_offset += substep_timer.currentStepNum();
current_time += timestep;
if (final_step) {
break;
Expand Down