diff --git a/opm/autodiff/BlackoilModelBase_impl.hpp b/opm/autodiff/BlackoilModelBase_impl.hpp index b9302e26f..46111a34b 100644 --- a/opm/autodiff/BlackoilModelBase_impl.hpp +++ b/opm/autodiff/BlackoilModelBase_impl.hpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -282,8 +283,9 @@ namespace detail { current_relaxation_ -= nonlinear_solver.relaxIncrement(); current_relaxation_ = std::max(current_relaxation_, nonlinear_solver.relaxMax()); if (terminalOutputEnabled()) { - std::cout << " Oscillating behavior detected: Relaxation set to " - << current_relaxation_ << std::endl; + std::string msg = " Oscillating behavior detected: Relaxation set to " + + std::to_string(current_relaxation_); + OpmLog::info(msg); } } nonlinear_solver.stabilizeNonlinearUpdate(dx, dx_old_, current_relaxation_); @@ -1105,7 +1107,7 @@ namespace detail { if (converged) { if ( terminal_output_ ) { - std::cout << "well converged iter: " << it << std::endl; + OpmLog::info("well converged iter: " + std::to_string(it)); } const int nw = wells().number_of_wells; { @@ -1895,35 +1897,36 @@ namespace detail { { // Only rank 0 does print to std::cout if (iteration == 0) { - std::cout << "\nIter"; + std::string msg = "Iter"; for (int idx = 0; idx < nm; ++idx) { - std::cout << " MB(" << materialName(idx).substr(0, 3) << ") "; + msg += " MB(" + materialName(idx).substr(0, 3) + ") "; } for (int idx = 0; idx < nm; ++idx) { - std::cout << " CNV(" << materialName(idx).substr(0, 1) << ") "; + msg += " CNV(" + materialName(idx).substr(0, 1) + ") "; } for (int idx = 0; idx < np; ++idx) { - std::cout << " W-FLUX(" << materialName(idx).substr(0, 1) << ")"; + msg += " W-FLUX(" + materialName(idx).substr(0, 1) + ")"; } // std::cout << " WELL-CONT "; - std::cout << '\n'; + OpmLog::info(msg); } - const std::streamsize oprec = std::cout.precision(3); - const std::ios::fmtflags oflags = std::cout.setf(std::ios::scientific); - std::cout << std::setw(4) << iteration; + std::ostringstream ss; + const std::streamsize oprec = ss.precision(3); + const std::ios::fmtflags oflags = ss.setf(std::ios::scientific); + ss << std::setw(4) << iteration; for (int idx = 0; idx < nm; ++idx) { - std::cout << std::setw(11) << mass_balance_residual[idx]; + ss << std::setw(11) << mass_balance_residual[idx]; } for (int idx = 0; idx < nm; ++idx) { - std::cout << std::setw(11) << CNV[idx]; + ss << std::setw(11) << CNV[idx]; } for (int idx = 0; idx < np; ++idx) { - std::cout << std::setw(11) << well_flux_residual[idx]; + ss << std::setw(11) << well_flux_residual[idx]; } // std::cout << std::setw(11) << residualWell; - std::cout << std::endl; - std::cout.precision(oprec); - std::cout.flags(oflags); + ss.precision(oprec); + ss.flags(oflags); + OpmLog::info(ss.str()); } for (int idx = 0; idx < nm; ++idx) { @@ -2006,21 +2009,23 @@ namespace detail { { // Only rank 0 does print to std::cout if (iteration == 0) { - std::cout << "\nIter"; + std::string msg; + msg = "Iter"; for (int idx = 0; idx < np; ++idx) { - std::cout << " W-FLUX(" << materialName(idx).substr(0, 1) << ")"; + msg += " W-FLUX(" + materialName(idx).substr(0, 1) + ")"; } - std::cout << '\n'; + OpmLog::info(msg); } - const std::streamsize oprec = std::cout.precision(3); - const std::ios::fmtflags oflags = std::cout.setf(std::ios::scientific); - std::cout << std::setw(4) << iteration; + std::ostringstream ss; + const std::streamsize oprec = ss.precision(3); + const std::ios::fmtflags oflags = ss.setf(std::ios::scientific); + ss << std::setw(4) << iteration; for (int idx = 0; idx < np; ++idx) { - std::cout << std::setw(11) << well_flux_residual[idx]; + ss << std::setw(11) << well_flux_residual[idx]; } - std::cout << std::endl; - std::cout.precision(oprec); - std::cout.flags(oflags); + ss.precision(oprec); + ss.flags(oflags); + OpmLog::info(ss.str()); } return converged; } diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index 37fa867f5..29ad684ca 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -385,7 +385,12 @@ namespace Opm ParserPtr parser(new Parser()); { std::shared_ptr prtLog = std::make_shared(logFile_ , Log::DefaultMessageTypes); + std::shared_ptr streamLog = std::make_shared(std::cout, Log::DefaultMessageTypes); OpmLog::addBackend( "ECLIPSEPRTLOG" , prtLog ); + OpmLog::addBackend( "STREAMLOG", streamLog); + prtLog->setMessageFormatter(std::make_shared(false, false)); + streamLog->setMessageLimiter(std::make_shared(10)); + streamLog->setMessageFormatter(std::make_shared(false, true)); } // Create Deck and EclipseState. @@ -692,15 +697,18 @@ namespace Opm if (!schedule->initOnly()) { if (output_cout_) { - std::cout << "\n\n================ Starting main simulation loop ===============\n" - << std::flush; + std::string msg; + msg = "\n\n================ Starting main simulation loop ===============\n"; + OpmLog::info(msg); } SimulatorReport fullReport = simulator_->run(simtimer, *state_); if (output_cout_) { - std::cout << "\n\n================ End of simulation ===============\n\n"; - fullReport.reportFullyImplicit(std::cout); + std::ostringstream ss; + ss << "\n\n================ End of simulation ===============\n\n"; + fullReport.reportFullyImplicit(ss); + OpmLog::info(ss.str()); if (param_.anyUnused()) { // This allows a user to catch typos and misunderstandings in the // use of simulator parameters. diff --git a/opm/autodiff/SimulatorBase_impl.hpp b/opm/autodiff/SimulatorBase_impl.hpp index e401f1ddf..607ce20fb 100644 --- a/opm/autodiff/SimulatorBase_impl.hpp +++ b/opm/autodiff/SimulatorBase_impl.hpp @@ -131,7 +131,9 @@ namespace Opm step_timer.start(); if ( terminal_output_ ) { - timer.report(std::cout); + std::ostringstream ss; + timer.report(ss); + OpmLog::info(ss.str()); } // Create wells and well state. @@ -211,7 +213,9 @@ namespace Opm if ( terminal_output_ ) { - std::cout << "Fully implicit solver took: " << st << " seconds. Total solver time taken: " << stime << " seconds." << std::endl; + std::string msg; + msg = "Fully implicit solver took: " + std::to_string(st) + " seconds. Total solver time taken: " + std::to_string(stime) + " seconds."; + OpmLog::info(msg); } if ( output_writer_.output() ) {