mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Setup logging before the simulator is initialized (#1980)
Setup logging before the simulator is initialized
This commit is contained in:
@@ -34,10 +34,6 @@
|
||||
|
||||
#include <opm/core/props/satfunc/RelpermDiagnostics.hpp>
|
||||
|
||||
#include <opm/common/OpmLog/OpmLog.hpp>
|
||||
#include <opm/common/OpmLog/EclipsePRTLog.hpp>
|
||||
#include <opm/common/OpmLog/LogUtil.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
@@ -76,16 +72,6 @@ namespace Opm
|
||||
template <class TypeTag>
|
||||
class FlowMainEbos
|
||||
{
|
||||
enum FileOutputMode
|
||||
{
|
||||
//! \brief No output to files.
|
||||
OUTPUT_NONE = 0,
|
||||
//! \brief Output only to log files, no eclipse output.
|
||||
OUTPUT_LOG_ONLY = 1,
|
||||
//! \brief Output to all files.
|
||||
OUTPUT_ALL = 3
|
||||
};
|
||||
|
||||
public:
|
||||
typedef typename GET_PROP(TypeTag, MaterialLaw)::EclMaterialLawManager MaterialLawManager;
|
||||
typedef typename GET_PROP_TYPE(TypeTag, Simulator) EbosSimulator;
|
||||
@@ -212,7 +198,7 @@ namespace Opm
|
||||
/// This is the main function of Flow. It runs a complete simulation with the
|
||||
/// given grid and simulator classes, based on the user-specified command-line
|
||||
/// input.
|
||||
int execute(int argc, char** argv)
|
||||
int execute(int argc, char** argv, bool output_cout, bool output_to_files)
|
||||
{
|
||||
try {
|
||||
// deal with some administrative boilerplate
|
||||
@@ -222,10 +208,8 @@ namespace Opm
|
||||
return status;
|
||||
|
||||
setupParallelism();
|
||||
setupOutput();
|
||||
setupEbosSimulator();
|
||||
setupLogging();
|
||||
int unknownKeyWords = printPRTHeader();
|
||||
setupEbosSimulator(output_cout);
|
||||
int unknownKeyWords = printPRTHeader(output_cout);
|
||||
#if HAVE_MPI
|
||||
int globalUnknownKeyWords;
|
||||
MPI_Allreduce(&unknownKeyWords, &globalUnknownKeyWords, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
|
||||
@@ -233,7 +217,7 @@ namespace Opm
|
||||
#endif
|
||||
if ( unknownKeyWords )
|
||||
{
|
||||
if ( output_cout_ )
|
||||
if ( output_cout )
|
||||
{
|
||||
std::string msg = "Aborting simulation due to unknown "
|
||||
"parameters. Please query \"flow --help\" for "
|
||||
@@ -252,14 +236,14 @@ namespace Opm
|
||||
#endif
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
runDiagnostics();
|
||||
runDiagnostics(output_cout);
|
||||
createSimulator();
|
||||
|
||||
// do the actual work
|
||||
runSimulator();
|
||||
runSimulator(output_cout);
|
||||
|
||||
// clean up
|
||||
mergeParallelLogFiles();
|
||||
mergeParallelLogFiles(output_to_files);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -267,7 +251,7 @@ namespace Opm
|
||||
std::ostringstream message;
|
||||
message << "Program threw an exception: " << e.what();
|
||||
|
||||
if (output_cout_) {
|
||||
if (output_cout) {
|
||||
// in some cases exceptions are thrown before the logging system is set
|
||||
// up.
|
||||
if (OpmLog::hasBackend("STREAMLOG")) {
|
||||
@@ -306,107 +290,12 @@ namespace Opm
|
||||
ThreadManager::init();
|
||||
}
|
||||
|
||||
// Extract the minimum priority and determines if log files ought to be created.
|
||||
// Writes to:
|
||||
// output_to_files_
|
||||
// output_
|
||||
void setupOutput()
|
||||
{
|
||||
const std::string outputModeString =
|
||||
EWOMS_GET_PARAM(TypeTag, std::string, OutputMode);
|
||||
static std::map<std::string, FileOutputMode> stringToOutputMode =
|
||||
{ {"none", OUTPUT_NONE },
|
||||
{"false", OUTPUT_LOG_ONLY },
|
||||
{"log", OUTPUT_LOG_ONLY },
|
||||
{"all" , OUTPUT_ALL },
|
||||
{"true" , OUTPUT_ALL }};
|
||||
auto outputModeIt = stringToOutputMode.find(outputModeString);
|
||||
if (outputModeIt != stringToOutputMode.end()) {
|
||||
output_ = outputModeIt->second;
|
||||
}
|
||||
else {
|
||||
output_ = OUTPUT_ALL;
|
||||
std::cerr << "Value " << outputModeString <<
|
||||
" is not a recognized output mode. Using \"all\" instead."
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
output_cout_ = false;
|
||||
if (mpi_rank_ == 0) {
|
||||
output_cout_ = EWOMS_GET_PARAM(TypeTag, bool, EnableTerminalOutput);
|
||||
output_to_files_ = (output_ != OUTPUT_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
// Setup the OpmLog backends
|
||||
void setupLogging()
|
||||
{
|
||||
std::string deck_filename = EWOMS_GET_PARAM(TypeTag, std::string, EclDeckFileName);
|
||||
// create logFile
|
||||
using boost::filesystem::path;
|
||||
path fpath(deck_filename);
|
||||
std::string baseName;
|
||||
std::ostringstream debugFileStream;
|
||||
std::ostringstream logFileStream;
|
||||
|
||||
// Strip extension "." or ".DATA"
|
||||
std::string extension = boost::to_upper_copy(fpath.extension().string());
|
||||
if ( extension == ".DATA" || extension == "." )
|
||||
{
|
||||
baseName = boost::to_upper_copy(fpath.stem().string());
|
||||
}
|
||||
else
|
||||
{
|
||||
baseName = boost::to_upper_copy(fpath.filename().string());
|
||||
}
|
||||
|
||||
const std::string& output_dir = eclState().getIOConfig().getOutputDir();
|
||||
logFileStream << output_dir << "/" << baseName;
|
||||
debugFileStream << output_dir << "/" << baseName;
|
||||
|
||||
if (mpi_rank_ != 0) {
|
||||
// Added rank to log file for non-zero ranks.
|
||||
// This prevents message loss.
|
||||
debugFileStream << "."<< mpi_rank_;
|
||||
// If the following file appears then there is a bug.
|
||||
logFileStream << "." << mpi_rank_;
|
||||
}
|
||||
logFileStream << ".PRT";
|
||||
debugFileStream << ".DBG";
|
||||
|
||||
logFile_ = logFileStream.str();
|
||||
|
||||
if (output_ > OUTPUT_NONE) {
|
||||
std::shared_ptr<EclipsePRTLog> prtLog = std::make_shared<EclipsePRTLog>(logFile_ , Log::NoDebugMessageTypes, false, output_cout_);
|
||||
OpmLog::addBackend( "ECLIPSEPRTLOG" , prtLog );
|
||||
prtLog->setMessageLimiter(std::make_shared<MessageLimiter>());
|
||||
prtLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(false));
|
||||
}
|
||||
|
||||
if (output_ >= OUTPUT_LOG_ONLY) {
|
||||
std::string debugFile = debugFileStream.str();
|
||||
std::shared_ptr<StreamLog> debugLog = std::make_shared<EclipsePRTLog>(debugFile, Log::DefaultMessageTypes, false, output_cout_);
|
||||
OpmLog::addBackend("DEBUGLOG", debugLog);
|
||||
}
|
||||
|
||||
std::shared_ptr<StreamLog> streamLog = std::make_shared<StreamLog>(std::cout, Log::StdoutMessageTypes);
|
||||
OpmLog::addBackend( "STREAMLOG", streamLog);
|
||||
const auto& msgLimits = schedule().getMessageLimits();
|
||||
const std::map<int64_t, int> limits = {{Log::MessageType::Note, msgLimits.getCommentPrintLimit(0)},
|
||||
{Log::MessageType::Info, msgLimits.getMessagePrintLimit(0)},
|
||||
{Log::MessageType::Warning, msgLimits.getWarningPrintLimit(0)},
|
||||
{Log::MessageType::Error, msgLimits.getErrorPrintLimit(0)},
|
||||
{Log::MessageType::Problem, msgLimits.getProblemPrintLimit(0)},
|
||||
{Log::MessageType::Bug, msgLimits.getBugPrintLimit(0)}};
|
||||
streamLog->setMessageLimiter(std::make_shared<MessageLimiter>(10, limits));
|
||||
streamLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(true));
|
||||
}
|
||||
|
||||
// Print an ASCII-art header to the PRT and DEBUG files.
|
||||
// \return Whether unkown keywords were seen during parsing.
|
||||
bool printPRTHeader()
|
||||
bool printPRTHeader(bool output_cout)
|
||||
{
|
||||
if (output_cout_) {
|
||||
if (output_cout) {
|
||||
const std::string version = moduleVersion();
|
||||
const double megabyte = 1024 * 1024;
|
||||
unsigned num_cpu = std::thread::hardware_concurrency();
|
||||
@@ -455,12 +344,12 @@ namespace Opm
|
||||
}
|
||||
}
|
||||
|
||||
void mergeParallelLogFiles()
|
||||
void mergeParallelLogFiles(bool output_to_files)
|
||||
{
|
||||
// force closing of all log files.
|
||||
OpmLog::removeAllBackends();
|
||||
|
||||
if (mpi_rank_ != 0 || mpi_size_ < 2 || !output_to_files_) {
|
||||
if (mpi_rank_ != 0 || mpi_size_ < 2 || !output_to_files) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -485,14 +374,14 @@ namespace Opm
|
||||
EWOMS_GET_PARAM(TypeTag, bool, EnableLoggingFalloutWarning)));
|
||||
}
|
||||
|
||||
void setupEbosSimulator()
|
||||
void setupEbosSimulator(bool output_cout)
|
||||
{
|
||||
ebosSimulator_.reset(new EbosSimulator(/*verbose=*/false));
|
||||
ebosSimulator_->executionTimer().start();
|
||||
ebosSimulator_->model().applyInitialSolution();
|
||||
|
||||
try {
|
||||
if (output_cout_) {
|
||||
if (output_cout) {
|
||||
MissingFeatures::checkKeywords(deck());
|
||||
}
|
||||
|
||||
@@ -516,7 +405,7 @@ namespace Opm
|
||||
}
|
||||
}
|
||||
catch (const std::invalid_argument& e) {
|
||||
std::cerr << "Failed to create valid EclipseState object. See logfile: " << logFile_ << std::endl;
|
||||
std::cerr << "Failed to create valid EclipseState object" << std::endl;
|
||||
std::cerr << "Exception caught: " << e.what() << std::endl;
|
||||
throw;
|
||||
}
|
||||
@@ -541,9 +430,9 @@ namespace Opm
|
||||
// Run diagnostics.
|
||||
// Writes to:
|
||||
// OpmLog singleton.
|
||||
void runDiagnostics()
|
||||
void runDiagnostics(bool output_cout)
|
||||
{
|
||||
if (!output_cout_) {
|
||||
if (!output_cout) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -553,7 +442,7 @@ namespace Opm
|
||||
}
|
||||
|
||||
// Run the simulator.
|
||||
void runSimulator()
|
||||
void runSimulator(bool output_cout)
|
||||
{
|
||||
const auto& schedule = this->schedule();
|
||||
const auto& timeMap = schedule.getTimeMap();
|
||||
@@ -564,7 +453,7 @@ namespace Opm
|
||||
const auto& initConfig = eclState().getInitConfig();
|
||||
simtimer.init(timeMap, (size_t)initConfig.getRestartStep());
|
||||
|
||||
if (output_cout_) {
|
||||
if (output_cout) {
|
||||
std::ostringstream oss;
|
||||
|
||||
// This allows a user to catch typos and misunderstandings in the
|
||||
@@ -577,7 +466,7 @@ namespace Opm
|
||||
}
|
||||
|
||||
if (!ioConfig.initOnly()) {
|
||||
if (output_cout_) {
|
||||
if (output_cout) {
|
||||
std::string msg;
|
||||
msg = "\n\n================ Starting main simulation loop ===============\n";
|
||||
OpmLog::info(msg);
|
||||
@@ -586,7 +475,7 @@ namespace Opm
|
||||
SimulatorReport successReport = simulator_->run(simtimer);
|
||||
SimulatorReport failureReport = simulator_->failureReport();
|
||||
|
||||
if (output_cout_) {
|
||||
if (output_cout) {
|
||||
std::ostringstream ss;
|
||||
ss << "\n\n================ End of simulation ===============\n\n";
|
||||
successReport.reportFullyImplicit(ss, &failureReport);
|
||||
@@ -594,7 +483,7 @@ namespace Opm
|
||||
}
|
||||
|
||||
} else {
|
||||
if (output_cout_) {
|
||||
if (output_cout) {
|
||||
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
||||
}
|
||||
|
||||
@@ -626,12 +515,8 @@ namespace Opm
|
||||
std::unique_ptr<EbosSimulator> ebosSimulator_;
|
||||
int mpi_rank_ = 0;
|
||||
int mpi_size_ = 1;
|
||||
bool output_cout_ = false;
|
||||
FileOutputMode output_ = OUTPUT_ALL;
|
||||
bool output_to_files_ = false;
|
||||
boost::any parallel_information_;
|
||||
std::unique_ptr<Simulator> simulator_;
|
||||
std::string logFile_;
|
||||
};
|
||||
} // namespace Opm
|
||||
|
||||
|
||||
Reference in New Issue
Block a user