diff --git a/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp b/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp index 21e9a9c14..9a053c3ff 100644 --- a/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp +++ b/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp @@ -128,170 +128,183 @@ public: /// \param[in,out] state state of reservoir: pressure, fluxes /// \return simulation report, with timing data SimulatorReport run(SimulatorTimer& timer) + { + runInit(timer); + // Main simulation loop. + while (!timer.done()) { + runStep(timer); + } + return runLastStep(); + } + + void runInit(SimulatorTimer &timer) { ebosSimulator_.setEpisodeIndex(-1); // Create timers and file for writing timing info. - Opm::time::StopWatch solverTimer; - Opm::time::StopWatch totalTimer; - totalTimer.start(); + solverTimer_ = std::make_unique(); + totalTimer_ = std::make_unique(); + totalTimer_->start(); // adaptive time stepping - const auto& events = schedule().getEvents(); - std::unique_ptr adaptiveTimeStepping; bool enableAdaptive = EWOMS_GET_PARAM(TypeTag, bool, EnableAdaptiveTimeStepping); bool enableTUNING = EWOMS_GET_PARAM(TypeTag, bool, EnableTuning); if (enableAdaptive) { if (enableTUNING) { - adaptiveTimeStepping.reset(new TimeStepper(schedule().getTuning(timer.currentStepNum()), terminalOutput_)); + adaptiveTimeStepping_ = std::make_unique( + schedule().getTuning(timer.currentStepNum()), terminalOutput_); } else { - adaptiveTimeStepping.reset(new TimeStepper(terminalOutput_)); + adaptiveTimeStepping_ = std::make_unique(terminalOutput_); } if (isRestart()) { // For restarts the ebosSimulator may have gotten some information // about the next timestep size from the OPMEXTRA field - adaptiveTimeStepping->setSuggestedNextStep(ebosSimulator_.timeStepSize()); + adaptiveTimeStepping_->setSuggestedNextStep(ebosSimulator_.timeStepSize()); } } + } - SimulatorReport report; - - // Main simulation loop. - while (!timer.done()) { - if (schedule().exitStatus().has_value()) { - if (terminalOutput_) { - OpmLog::info("Stopping simulation since EXIT was triggered by an action keyword."); - } - report.success.exit_status = schedule().exitStatus().value(); - break; - } - - // Report timestep. + bool runStep(SimulatorTimer& timer) + { + if (schedule().exitStatus().has_value()) { if (terminalOutput_) { - std::ostringstream ss; - timer.report(ss); - OpmLog::debug(ss.str()); + OpmLog::info("Stopping simulation since EXIT was triggered by an action keyword."); } + report_.success.exit_status = schedule().exitStatus().value(); + return false; + } - if (terminalOutput_) { - std::ostringstream stepMsg; - boost::posix_time::time_facet* facet = new boost::posix_time::time_facet("%d-%b-%Y"); - stepMsg.imbue(std::locale(std::locale::classic(), facet)); - stepMsg << "\nReport step " << std::setw(2) <suggestedNextStep() : -1.0; + ebosSimulator_.problem().setNextTimeStepSize(nextstep); + ebosSimulator_.problem().writeOutput(); + report_.success.output_write_time += perfTimer.stop(); + + solver->model().endReportStep(); + + // take time that was used to solve system for this reportStep + solverTimer_->stop(); + + // update timing. + report_.success.solver_time += solverTimer_->secsSinceStart(); + + // Increment timer, remember well state. + ++timer; + + if (terminalOutput_) { + if (!timer.initialStep()) { + const std::string version = moduleVersionName(); + outputTimestampFIP(timer, version); + } + } + + if (terminalOutput_) { + std::string msg = + "Time step took " + std::to_string(solverTimer_->secsSinceStart()) + " seconds; " + "total solver time " + std::to_string(report_.success.solver_time) + " seconds."; + OpmLog::debug(msg); + } + return true; + } + + SimulatorReport runLastStep() + { // make sure all output is written to disk before run is finished { Dune::Timer finalOutputTimer; finalOutputTimer.start(); ebosSimulator_.problem().finalizeOutput(); - report.success.output_write_time += finalOutputTimer.stop(); + report_.success.output_write_time += finalOutputTimer.stop(); } // Stop timer and create timing report - totalTimer.stop(); - report.success.total_time = totalTimer.secsSinceStart(); - report.success.converged = true; + totalTimer_->stop(); + report_.success.total_time = totalTimer_->secsSinceStart(); + report_.success.converged = true; - return report; + return report_; } const Grid& grid() const @@ -353,6 +366,11 @@ protected: PhaseUsage phaseUsage_; // Misc. data bool terminalOutput_; + + SimulatorReport report_; + std::unique_ptr solverTimer_; + std::unique_ptr totalTimer_; + std::unique_ptr adaptiveTimeStepping_; }; } // namespace Opm