From 969ce5ca53b92a70b1f2b988a4085e0ef7ee13fd Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Mon, 13 Jun 2016 13:43:50 +0800 Subject: [PATCH 1/4] add blank line before and after "Reading Parameters" --- opm/autodiff/FlowMain.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index 982e29874..820bdddb9 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -297,7 +297,7 @@ namespace Opm { // Read parameters. if ( output_cout_ ) { - std::cout << "--------------- Reading parameters ---------------" << std::endl; + std::cout << "\n--------------- Reading parameters ---------------\n" << std::endl; } param_ = parameter::ParameterGroup(argc, argv, false, output_cout_); From 936cd8dc33660f056cc93614cebf4fe1be4ccfea Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Wed, 15 Jun 2016 15:24:05 +0800 Subject: [PATCH 2/4] Add separate function for setup logging. --- opm/autodiff/FlowMain.hpp | 74 ++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index 820bdddb9..351ac6b18 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -137,6 +137,7 @@ namespace Opm if (!ok) { return EXIT_FAILURE; } + asImpl().setupLogging(); asImpl().setupOutput(); asImpl().readDeckInput(); asImpl().setupGridAndProps(); @@ -295,10 +296,6 @@ namespace Opm // Returns true if ok, false if not. bool setupParameters(int argc, char** argv) { - // Read parameters. - if ( output_cout_ ) { - std::cout << "\n--------------- Reading parameters ---------------\n" << std::endl; - } param_ = parameter::ParameterGroup(argc, argv, false, output_cout_); // See if a deck was specified on the command line. @@ -328,6 +325,44 @@ namespace Opm + + void setupLogging() + { + std::string deck_filename = param_.get("deck_filename"); + // create logFile + using boost::filesystem::path; + path fpath(deck_filename); + std::string baseName; + std::string debugFile; + if (boost::to_upper_copy(path(fpath.extension()).string()) == ".DATA") { + baseName = path(fpath.stem()).string(); + } else { + baseName = path(fpath.filename()).string(); + } + if (param_.has("output_dir")) { + logFile_ = output_dir_ + "/" + baseName + ".PRT"; + debugFile = output_dir_ + "/." + baseName + ".DEBUG"; + } else { + logFile_ = baseName + ".PRT"; + debugFile = "." + baseName + ".DEBUG"; + } + std::shared_ptr prtLog = std::make_shared(logFile_ , Log::NoDebugMessageTypes); + std::shared_ptr streamLog = std::make_shared(std::cout, Log::StdoutMessageTypes); + OpmLog::addBackend( "ECLIPSEPRTLOG" , prtLog ); + OpmLog::addBackend( "STREAMLOG", streamLog); + std::shared_ptr debugLog = std::make_shared(debugFile, Log::DefaultMessageTypes); + OpmLog::addBackend( "DEBUGLOG" , debugLog); + prtLog->setMessageFormatter(std::make_shared(false)); + streamLog->setMessageLimiter(std::make_shared(10)); + streamLog->setMessageFormatter(std::make_shared(true)); + } + + + + + + + // Set output_to_files_ and set/create output dir. Write parameter file. // Writes to: // output_to_files_ @@ -335,6 +370,8 @@ namespace Opm // Throws std::runtime_error if failed to create (if requested) output dir. void setupOutput() { + // Read parameters. + OpmLog::debug("\n--------------- Reading parameters ---------------\n"); // Write parameters used for later reference. (only if rank is zero) output_to_files_ = output_cout_ && param_.getDefault("output", true); if (output_to_files_) { @@ -367,36 +404,9 @@ namespace Opm void readDeckInput() { std::string deck_filename = param_.get("deck_filename"); - // create logFile - using boost::filesystem::path; - path fpath(deck_filename); - std::string baseName; - std::string debugFile; - if (boost::to_upper_copy(path(fpath.extension()).string()) == ".DATA") { - baseName = path(fpath.stem()).string(); - } else { - baseName = path(fpath.filename()).string(); - } - if (param_.has("output_dir")) { - logFile_ = output_dir_ + "/" + baseName + ".PRT"; - debugFile = output_dir_ + "/." + baseName + ".DEBUG"; - } else { - logFile_ = baseName + ".PRT"; - debugFile = "." + baseName + ".DEBUG"; - } + // Create Parser ParserPtr parser(new Parser()); - { - std::shared_ptr prtLog = std::make_shared(logFile_ , Log::NoDebugMessageTypes); - std::shared_ptr streamLog = std::make_shared(std::cout, Log::StdoutMessageTypes); - OpmLog::addBackend( "ECLIPSEPRTLOG" , prtLog ); - OpmLog::addBackend( "STREAMLOG", streamLog); - std::shared_ptr debugLog = std::make_shared(debugFile, Log::DefaultMessageTypes); - OpmLog::addBackend( "DEBUGLOG" , debugLog); - prtLog->setMessageFormatter(std::make_shared(false)); - streamLog->setMessageLimiter(std::make_shared(10)); - streamLog->setMessageFormatter(std::make_shared(true)); - } // Create Deck and EclipseState. try { From 8224e7cef9abb9a1986c3de1a5d46640d075352d Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Thu, 16 Jun 2016 09:48:39 +0800 Subject: [PATCH 3/4] switch function calling order. --- opm/autodiff/FlowMain.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index 351ac6b18..0b1fd7666 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -137,8 +137,8 @@ namespace Opm if (!ok) { return EXIT_FAILURE; } - asImpl().setupLogging(); asImpl().setupOutput(); + asImpl().setupLogging(); asImpl().readDeckInput(); asImpl().setupGridAndProps(); asImpl().extractMessages(); @@ -355,6 +355,8 @@ namespace Opm prtLog->setMessageFormatter(std::make_shared(false)); streamLog->setMessageLimiter(std::make_shared(10)); streamLog->setMessageFormatter(std::make_shared(true)); + // Read parameters. + OpmLog::debug("\n--------------- Reading parameters ---------------\n"); } @@ -370,8 +372,6 @@ namespace Opm // Throws std::runtime_error if failed to create (if requested) output dir. void setupOutput() { - // Read parameters. - OpmLog::debug("\n--------------- Reading parameters ---------------\n"); // Write parameters used for later reference. (only if rank is zero) output_to_files_ = output_cout_ && param_.getDefault("output", true); if (output_to_files_) { From 49fbf5e49392ba78a0c01b37b88f0ac036599a44 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Thu, 16 Jun 2016 14:02:34 +0800 Subject: [PATCH 4/4] document function and switch implementation. --- opm/autodiff/FlowMain.hpp | 63 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index 0b1fd7666..0bda60bc3 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -325,7 +325,38 @@ namespace Opm + // Set output_to_files_ and set/create output dir. Write parameter file. + // Writes to: + // output_to_files_ + // output_dir_ + // Throws std::runtime_error if failed to create (if requested) output dir. + void setupOutput() + { + // Write parameters used for later reference. (only if rank is zero) + output_to_files_ = output_cout_ && param_.getDefault("output", true); + if (output_to_files_) { + // Create output directory if needed. + output_dir_ = + param_.getDefault("output_dir", std::string(".")); + boost::filesystem::path fpath(output_dir_); + if (!is_directory(fpath)) { + try { + create_directories(fpath); + } + catch (...) { + OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); + } + } + // Write simulation parameters. + param_.writeParam(output_dir_ + "/simulation.param"); + } + } + + + + + // Setup OpmLog backend with output_dir. void setupLogging() { std::string deck_filename = param_.get("deck_filename"); @@ -364,38 +395,6 @@ namespace Opm - - // Set output_to_files_ and set/create output dir. Write parameter file. - // Writes to: - // output_to_files_ - // output_dir_ - // Throws std::runtime_error if failed to create (if requested) output dir. - void setupOutput() - { - // Write parameters used for later reference. (only if rank is zero) - output_to_files_ = output_cout_ && param_.getDefault("output", true); - if (output_to_files_) { - // Create output directory if needed. - output_dir_ = - param_.getDefault("output_dir", std::string(".")); - boost::filesystem::path fpath(output_dir_); - if (!is_directory(fpath)) { - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } - } - // Write simulation parameters. - param_.writeParam(output_dir_ + "/simulation.param"); - } - } - - - - - // Parser the input and creates the Deck and EclipseState objects. // Writes to: // deck_