From 431a21d63204f37e54dd08a4186f814186e86960 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Mon, 9 May 2016 13:33:44 +0800 Subject: [PATCH 1/4] write simulation details to log file. --- opm/autodiff/BlackoilModelBase_impl.hpp | 63 +++++++++++++++---------- opm/autodiff/FlowMain.hpp | 17 ++++--- opm/autodiff/SimulatorBase_impl.hpp | 10 +++- 3 files changed, 56 insertions(+), 34 deletions(-) diff --git a/opm/autodiff/BlackoilModelBase_impl.hpp b/opm/autodiff/BlackoilModelBase_impl.hpp index 6ecfa2576..09e997c47 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,10 @@ 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_); + std::cout << msg << std::endl; + OpmLog::info(msg); } } nonlinear_solver.stabilizeNonlinearUpdate(dx, dx_old_, current_relaxation_); @@ -1106,6 +1109,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 +1899,38 @@ 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'; + std::cout << msg << std::endl; + 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()); + std::cout << ss.str() << std::endl; } for (int idx = 0; idx < nm; ++idx) { @@ -2006,21 +2013,25 @@ 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); + std::cout << msg << std::endl; } - 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()); + std::cout << ss.str() << std::endl; } return converged; } diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index 08cc652a1..3579df437 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -264,9 +264,9 @@ namespace Opm std::cout << "**********************************************************************\n"; std::cout << "* *\n"; std::cout << "* This is Flow (version " << version << ")" - << std::string(26 - version.size(), ' ') << "*\n"; + << std::string(26 - version.size(), ' ') << "*\n"; std::cout << "* *\n"; - std::cout << "* Flow is a simulator for fully implicit three-phase black-oil flow, *\n"; + std::cout << "* Flow is a simulator for fully implicit three-phase black-oil flow, *\n"; std::cout << "* and is part of OPM. For more information see: *\n"; std::cout << "* http://opm-project.org *\n"; std::cout << "* *\n"; @@ -677,15 +677,20 @@ 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"; + std::cout << msg << std::endl; + 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); + std::cout << ss.str() << std::endl; + 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 b31a8a617..ba8a23131 100644 --- a/opm/autodiff/SimulatorBase_impl.hpp +++ b/opm/autodiff/SimulatorBase_impl.hpp @@ -129,7 +129,10 @@ namespace Opm step_timer.start(); if ( terminal_output_ ) { - timer.report(std::cout); + std::ostringstream ss; + timer.report(ss); + OpmLog::info(ss.str()); + std::cout << ss.str(); } // Create wells and well state. @@ -209,7 +212,10 @@ 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); + std::cout << msg << std::endl; } if ( output_writer_.output() ) { From f5a57b8a267bf193b3a5f79ebd6f0beccafbeae3 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Tue, 10 May 2016 13:51:10 +0800 Subject: [PATCH 2/4] Let OpmLog control output. --- opm/autodiff/BlackoilModelBase_impl.hpp | 6 ------ opm/autodiff/FlowMain.hpp | 4 ++-- opm/autodiff/SimulatorBase_impl.hpp | 2 -- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/opm/autodiff/BlackoilModelBase_impl.hpp b/opm/autodiff/BlackoilModelBase_impl.hpp index 09e997c47..a1098f1ba 100644 --- a/opm/autodiff/BlackoilModelBase_impl.hpp +++ b/opm/autodiff/BlackoilModelBase_impl.hpp @@ -285,7 +285,6 @@ namespace detail { if (terminalOutputEnabled()) { std::string msg = " Oscillating behavior detected: Relaxation set to " + std::to_string(current_relaxation_); - std::cout << msg << std::endl; OpmLog::info(msg); } } @@ -1108,7 +1107,6 @@ 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; @@ -1910,7 +1908,6 @@ namespace detail { msg += " W-FLUX(" + materialName(idx).substr(0, 1) + ")"; } // std::cout << " WELL-CONT "; - std::cout << msg << std::endl; OpmLog::info(msg); } std::ostringstream ss; @@ -1930,7 +1927,6 @@ namespace detail { ss.precision(oprec); ss.flags(oflags); OpmLog::info(ss.str()); - std::cout << ss.str() << std::endl; } for (int idx = 0; idx < nm; ++idx) { @@ -2019,7 +2015,6 @@ namespace detail { msg += " W-FLUX(" + materialName(idx).substr(0, 1) + ")"; } OpmLog::info(msg); - std::cout << msg << std::endl; } std::ostringstream ss; const std::streamsize oprec = ss.precision(3); @@ -2031,7 +2026,6 @@ namespace detail { ss.precision(oprec); ss.flags(oflags); OpmLog::info(ss.str()); - std::cout << ss.str() << std::endl; } return converged; } diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index 3579df437..dee3cdce1 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -369,7 +369,9 @@ 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); } // Create Deck and EclipseState. @@ -679,7 +681,6 @@ namespace Opm if (output_cout_) { std::string msg; msg = "\n\n================ Starting main simulation loop ===============\n"; - std::cout << msg << std::endl; OpmLog::info(msg); } @@ -689,7 +690,6 @@ namespace Opm std::ostringstream ss; ss << "\n\n================ End of simulation ===============\n\n"; fullReport.reportFullyImplicit(ss); - std::cout << ss.str() << std::endl; OpmLog::info(ss.str()); if (param_.anyUnused()) { // This allows a user to catch typos and misunderstandings in the diff --git a/opm/autodiff/SimulatorBase_impl.hpp b/opm/autodiff/SimulatorBase_impl.hpp index ba8a23131..977dc4f06 100644 --- a/opm/autodiff/SimulatorBase_impl.hpp +++ b/opm/autodiff/SimulatorBase_impl.hpp @@ -132,7 +132,6 @@ namespace Opm std::ostringstream ss; timer.report(ss); OpmLog::info(ss.str()); - std::cout << ss.str(); } // Create wells and well state. @@ -215,7 +214,6 @@ namespace Opm 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); - std::cout << msg << std::endl; } if ( output_writer_.output() ) { From b134455a4de3201170262eef823adc7b3f643441 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Thu, 19 May 2016 10:51:52 +0800 Subject: [PATCH 3/4] use OpmLog to control terminal output limits. --- opm/autodiff/FlowMain.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index dee3cdce1..974ee1822 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -372,6 +372,9 @@ namespace Opm 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. From 626bde704aec98d885e66d9049bc9e13df6edd0f Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Thu, 19 May 2016 17:10:13 +0800 Subject: [PATCH 4/4] fix indentation. --- opm/autodiff/FlowMain.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index 974ee1822..9087b13a9 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -264,9 +264,9 @@ namespace Opm std::cout << "**********************************************************************\n"; std::cout << "* *\n"; std::cout << "* This is Flow (version " << version << ")" - << std::string(26 - version.size(), ' ') << "*\n"; + << std::string(26 - version.size(), ' ') << "*\n"; std::cout << "* *\n"; - std::cout << "* Flow is a simulator for fully implicit three-phase black-oil flow, *\n"; + std::cout << "* Flow is a simulator for fully implicit three-phase black-oil flow, *\n"; std::cout << "* and is part of OPM. For more information see: *\n"; std::cout << "* http://opm-project.org *\n"; std::cout << "* *\n";