diff --git a/opm/simulators/timestepping/AdaptiveSimulatorTimer.cpp b/opm/simulators/timestepping/AdaptiveSimulatorTimer.cpp index 428e9538949..ba19a11be83 100644 --- a/opm/simulators/timestepping/AdaptiveSimulatorTimer.cpp +++ b/opm/simulators/timestepping/AdaptiveSimulatorTimer.cpp @@ -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_; diff --git a/opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp b/opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp index d9fc3fd9f26..58aa0f16fdd 100644 --- a/opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp +++ b/opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -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 clone() const override; @@ -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 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 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 diff --git a/opm/simulators/timestepping/AdaptiveTimeStepping.cpp b/opm/simulators/timestepping/AdaptiveTimeStepping.cpp index e68917c6fe1..309361b5f48 100644 --- a/opm/simulators/timestepping/AdaptiveTimeStepping.cpp +++ b/opm/simulators/timestepping/AdaptiveTimeStepping.cpp @@ -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(); diff --git a/opm/simulators/timestepping/AdaptiveTimeStepping_impl.hpp b/opm/simulators/timestepping/AdaptiveTimeStepping_impl.hpp index f0507aaf80e..f44b8f37d76 100644 --- a/opm/simulators/timestepping/AdaptiveTimeStepping_impl.hpp +++ b/opm/simulators/timestepping/AdaptiveTimeStepping_impl.hpp @@ -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 @@ -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 ); @@ -763,6 +771,7 @@ runStepReservoirCouplingMaster_() SubStepIteration 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; @@ -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) { @@ -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 ); @@ -817,6 +834,7 @@ runStepReservoirCouplingSlave_() SubStepIteration 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;