Setup logging before the simulator is initialized (#1980)

Setup logging before the simulator is initialized
This commit is contained in:
Joakim Hove 2019-08-27 22:41:48 +02:00 committed by GitHub
parent 5b857dd43e
commit c804e85bc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 186 additions and 183 deletions

View File

@ -38,6 +38,10 @@
#include <opm/simulators/flow/MissingFeatures.hpp>
#include <opm/material/common/ResetLocale.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>
@ -112,6 +116,115 @@ namespace detail
}
enum class 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
};
// Setup the OpmLog backends
FileOutputMode setupLogging(int mpi_rank_, const std::string& deck_filename, const std::string& cmdline_output_dir, const std::string& cmdline_output, bool output_cout_, const std::string& stdout_log_id) {
// 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());
}
std::string output_dir = cmdline_output_dir;
if (output_dir.empty()) {
output_dir = absolute(path(baseName).parent_path()).string();
}
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";
FileOutputMode output;
{
static std::map<std::string, FileOutputMode> stringToOutputMode =
{ {"none", FileOutputMode::OUTPUT_NONE },
{"false", FileOutputMode::OUTPUT_LOG_ONLY },
{"log", FileOutputMode::OUTPUT_LOG_ONLY },
{"all" , FileOutputMode::OUTPUT_ALL },
{"true" , FileOutputMode::OUTPUT_ALL }};
auto outputModeIt = stringToOutputMode.find(cmdline_output);
if (outputModeIt != stringToOutputMode.end()) {
output = outputModeIt->second;
}
else {
output = FileOutputMode::OUTPUT_ALL;
std::cerr << "Value " << cmdline_output <<
" is not a recognized output mode. Using \"all\" instead."
<< std::endl;
}
}
if (output > FileOutputMode::OUTPUT_NONE) {
std::shared_ptr<Opm::EclipsePRTLog> prtLog = std::make_shared<Opm::EclipsePRTLog>(logFileStream.str(), Opm::Log::NoDebugMessageTypes, false, output_cout_);
Opm::OpmLog::addBackend("ECLIPSEPRTLOG", prtLog);
prtLog->setMessageLimiter(std::make_shared<Opm::MessageLimiter>());
prtLog->setMessageFormatter(std::make_shared<Opm::SimpleMessageFormatter>(false));
}
if (output >= FileOutputMode::OUTPUT_LOG_ONLY) {
std::string debugFile = debugFileStream.str();
std::shared_ptr<Opm::StreamLog> debugLog = std::make_shared<Opm::EclipsePRTLog>(debugFileStream.str(), Opm::Log::DefaultMessageTypes, false, output_cout_);
Opm::OpmLog::addBackend("DEBUGLOG", debugLog);
}
std::shared_ptr<Opm::StreamLog> streamLog = std::make_shared<Opm::StreamLog>(std::cout, Opm::Log::StdoutMessageTypes);
Opm::OpmLog::addBackend(stdout_log_id, streamLog);
streamLog->setMessageFormatter(std::make_shared<Opm::SimpleMessageFormatter>(true));
return output;
}
void setupMessageLimiter(const Opm::MessageLimits msgLimits, const std::string& stdout_log_id) {
std::shared_ptr<Opm::StreamLog> stream_log = Opm::OpmLog::getBackend<Opm::StreamLog>(stdout_log_id);
const std::map<int64_t, int> limits = {{Opm::Log::MessageType::Note,
msgLimits.getCommentPrintLimit(0)},
{Opm::Log::MessageType::Info,
msgLimits.getMessagePrintLimit(0)},
{Opm::Log::MessageType::Warning,
msgLimits.getWarningPrintLimit(0)},
{Opm::Log::MessageType::Error,
msgLimits.getErrorPrintLimit(0)},
{Opm::Log::MessageType::Problem,
msgLimits.getProblemPrintLimit(0)},
{Opm::Log::MessageType::Bug,
msgLimits.getBugPrintLimit(0)}};
stream_log->setMessageLimiter(std::make_shared<Opm::MessageLimiter>(10, limits));
}
// ----------------- Main program -----------------
int main(int argc, char** argv)
{
@ -146,7 +259,6 @@ int main(int argc, char** argv)
typedef GET_PROP_TYPE(PreTypeTag, Problem) PreProblem;
PreProblem::setBriefDescription("Flow, an advanced reservoir simulator for ECL-decks provided by the Open Porous Media project.");
int status = Opm::FlowMainEbos<PreTypeTag>::setupParameters_(argc, argv);
if (status != 0)
// if setupParameters_ returns a value smaller than 0, there was no error, but
@ -154,6 +266,7 @@ int main(int argc, char** argv)
// --print-properties parameters.
return (status >= 0)?status:0;
FileOutputMode outputMode = FileOutputMode::OUTPUT_NONE;
bool outputCout = false;
if (mpiRank == 0)
outputCout = EWOMS_GET_PARAM(PreTypeTag, bool, EnableTerminalOutput);
@ -190,6 +303,11 @@ int main(int argc, char** argv)
Opm::Parser parser;
Opm::ParseContext parseContext;
Opm::ErrorGuard errorGuard;
outputMode = setupLogging(mpiRank,
deckFilename,
EWOMS_GET_PARAM(PreTypeTag, std::string, OutputDir),
EWOMS_GET_PARAM(PreTypeTag, std::string, OutputMode),
outputCout, "STDOUT_LOGGER");
if (EWOMS_GET_PARAM(PreTypeTag, bool, EclStrictParsing))
parseContext.update( Opm::InputError::DELAYED_EXIT1);
@ -202,13 +320,13 @@ int main(int argc, char** argv)
deck.reset( new Opm::Deck( parser.parseFile(deckFilename , parseContext, errorGuard)));
Opm::MissingFeatures::checkKeywords(*deck, parseContext, errorGuard);
if ( outputCout )
Opm::checkDeck(*deck, parser, parseContext, errorGuard);
eclipseState.reset( new Opm::EclipseState(*deck, parseContext, errorGuard ));
schedule.reset(new Opm::Schedule(*deck, *eclipseState, parseContext, errorGuard));
summaryConfig.reset( new Opm::SummaryConfig(*deck, *schedule, eclipseState->getTableManager(), parseContext, errorGuard));
setupMessageLimiter(schedule->getMessageLimits(), "STDOUT_LOGGER");
Opm::checkConsistentArrayDimensions(*eclipseState, *schedule, parseContext, errorGuard);
@ -220,7 +338,7 @@ int main(int argc, char** argv)
}
}
const auto& phases = Opm::Runspec(*deck).phases();
bool outputFiles = (outputMode != FileOutputMode::OUTPUT_NONE);
// run the actual simulator
//
// TODO: make sure that no illegal combinations like thermal and twophase are
@ -232,13 +350,13 @@ int main(int argc, char** argv)
if (phases.active( Opm::Phase::GAS ))
{
Opm::flowEbosGasOilSetDeck(externalSetupTimer.elapsed(), *deck, *eclipseState, *schedule, *summaryConfig);
return Opm::flowEbosGasOilMain(argc, argv);
return Opm::flowEbosGasOilMain(argc, argv, outputCout, outputFiles);
}
// oil-water
else if ( phases.active( Opm::Phase::WATER ) )
{
Opm::flowEbosOilWaterSetDeck(externalSetupTimer.elapsed(), *deck, *eclipseState, *schedule, *summaryConfig);
return Opm::flowEbosOilWaterMain(argc, argv);
return Opm::flowEbosOilWaterMain(argc, argv, outputCout, outputFiles);
}
else {
if (outputCout)
@ -261,36 +379,36 @@ int main(int argc, char** argv)
if ( phases.active( Opm::Phase::POLYMW ) ) {
// only oil water two phase for now
assert( phases.size() == 4);
return Opm::flowEbosOilWaterPolymerInjectivityMain(argc, argv);
return Opm::flowEbosOilWaterPolymerInjectivityMain(argc, argv, outputCout, outputFiles);
}
if ( phases.size() == 3 ) { // oil water polymer case
Opm::flowEbosOilWaterPolymerSetDeck(externalSetupTimer.elapsed(), *deck, *eclipseState, *schedule, *summaryConfig);
return Opm::flowEbosOilWaterPolymerMain(argc, argv);
return Opm::flowEbosOilWaterPolymerMain(argc, argv, outputCout, outputFiles);
} else {
Opm::flowEbosPolymerSetDeck(externalSetupTimer.elapsed(), *deck, *eclipseState, *schedule, *summaryConfig);
return Opm::flowEbosPolymerMain(argc, argv);
return Opm::flowEbosPolymerMain(argc, argv, outputCout, outputFiles);
}
}
// Foam case
else if ( phases.active( Opm::Phase::FOAM ) ) {
Opm::flowEbosFoamSetDeck(externalSetupTimer.elapsed(), *deck, *eclipseState, *schedule, *summaryConfig);
return Opm::flowEbosFoamMain(argc, argv);
return Opm::flowEbosFoamMain(argc, argv, outputCout, outputFiles);
}
// Solvent case
else if ( phases.active( Opm::Phase::SOLVENT ) ) {
Opm::flowEbosSolventSetDeck(externalSetupTimer.elapsed(), *deck, *eclipseState, *schedule, *summaryConfig);
return Opm::flowEbosSolventMain(argc, argv);
return Opm::flowEbosSolventMain(argc, argv, outputCout, outputFiles);
}
// Energy case
else if (eclipseState->getSimulationConfig().isThermal()) {
Opm::flowEbosEnergySetDeck(externalSetupTimer.elapsed(), *deck, *eclipseState, *schedule, *summaryConfig);
return Opm::flowEbosEnergyMain(argc, argv);
return Opm::flowEbosEnergyMain(argc, argv, outputCout, outputFiles);
}
// Blackoil case
else if( phases.size() == 3 ) {
Opm::flowEbosBlackoilSetDeck(externalSetupTimer.elapsed(), *deck, *eclipseState, *schedule, *summaryConfig);
return Opm::flowEbosBlackoilMain(argc, argv);
return Opm::flowEbosBlackoilMain(argc, argv, outputCout, outputFiles);
}
else
{

View File

@ -99,5 +99,7 @@ namespace Ewoms {
int main(int argc, char** argv)
{
typedef TTAG(EclFlowProblemSimple) TypeTag;
return mainFlow<TypeTag>(argc, argv);
bool outputCout = true;
bool outputFiles = true;
return mainFlow<TypeTag>(argc, argv, outputCout, outputFiles);
}

View File

@ -47,7 +47,7 @@ void flowEbosBlackoilSetDeck(double setupTime, Deck &deck, EclipseState& eclStat
}
// ----------------- Main program -----------------
int flowEbosBlackoilMain(int argc, char** argv)
int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFiles)
{
// we always want to use the default locale, and thus spare us the trouble
// with incorrect locale settings.
@ -60,7 +60,7 @@ int flowEbosBlackoilMain(int argc, char** argv)
#endif
Opm::FlowMainEbos<TTAG(EclFlowProblem)> mainfunc;
return mainfunc.execute(argc, argv);
return mainfunc.execute(argc, argv, outputCout, outputFiles);
}
}

View File

@ -24,7 +24,7 @@
namespace Opm {
void flowEbosBlackoilSetDeck(double setupTime, Deck &deck, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig);
int flowEbosBlackoilMain(int argc, char** argv);
int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFiles);
}
#endif // FLOW_EBOS_BLACKOIL_HPP

View File

@ -49,7 +49,7 @@ void flowEbosEnergySetDeck(double setupTime, Deck &deck, EclipseState& eclState,
}
// ----------------- Main program -----------------
int flowEbosEnergyMain(int argc, char** argv)
int flowEbosEnergyMain(int argc, char** argv, bool outputCout, bool outputFiles)
{
// we always want to use the default locale, and thus spare us the trouble
// with incorrect locale settings.
@ -63,7 +63,7 @@ int flowEbosEnergyMain(int argc, char** argv)
#endif
Opm::FlowMainEbos<TTAG(EclFlowEnergyProblem)> mainfunc;
return mainfunc.execute(argc, argv);
return mainfunc.execute(argc, argv, outputCout, outputFiles);
}
}

View File

@ -24,7 +24,7 @@
namespace Opm {
void flowEbosEnergySetDeck(double setupTime, Deck &deck, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig);
int flowEbosEnergyMain(int argc, char** argv);
int flowEbosEnergyMain(int argc, char** argv, bool outputCout, bool outputFiles);
}
#endif // FLOW_EBOS_ENERGY_HPP

View File

@ -50,7 +50,7 @@ void flowEbosFoamSetDeck(double setupTime, Deck &deck, EclipseState& eclState, S
// ----------------- Main program -----------------
int flowEbosFoamMain(int argc, char** argv)
int flowEbosFoamMain(int argc, char** argv, bool outputCout, bool outputFiles)
{
// we always want to use the default locale, and thus spare us the trouble
// with incorrect locale settings.
@ -64,7 +64,7 @@ int flowEbosFoamMain(int argc, char** argv)
#endif
Opm::FlowMainEbos<TTAG(EclFlowFoamProblem)> mainfunc;
return mainfunc.execute(argc, argv);
return mainfunc.execute(argc, argv, outputCout, outputFiles);
}
}

View File

@ -25,7 +25,7 @@
namespace Opm {
void flowEbosFoamSetDeck(double setupTime, Deck &deck, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig);
int flowEbosFoamMain(int argc, char** argv);
int flowEbosFoamMain(int argc, char** argv, bool outputCout, bool outputFiles);
}
#endif // FLOW_EBOS_FOAM_HPP

View File

@ -73,7 +73,7 @@ void flowEbosGasOilSetDeck(double setupTime, Deck &deck, EclipseState& eclState,
// ----------------- Main program -----------------
int flowEbosGasOilMain(int argc, char** argv)
int flowEbosGasOilMain(int argc, char** argv, bool outputCout, bool outputFiles)
{
// we always want to use the default locale, and thus spare us the trouble
// with incorrect locale settings.
@ -86,7 +86,7 @@ int flowEbosGasOilMain(int argc, char** argv)
#endif
Opm::FlowMainEbos<TTAG(EclFlowGasOilProblem)> mainfunc;
return mainfunc.execute(argc, argv);
return mainfunc.execute(argc, argv, outputCout, outputFiles);
}
}

View File

@ -24,7 +24,7 @@
namespace Opm {
void flowEbosGasOilSetDeck(double setupTime, Deck &deck, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig);
int flowEbosGasOilMain(int argc, char** argv);
int flowEbosGasOilMain(int argc, char** argv, bool outputCout, bool outputFiles);
}
#endif // FLOW_EBOS_GASOIL_HPP

View File

@ -72,7 +72,7 @@ void flowEbosOilWaterSetDeck(double setupTime, Deck &deck, EclipseState& eclStat
}
// ----------------- Main program -----------------
int flowEbosOilWaterMain(int argc, char** argv)
int flowEbosOilWaterMain(int argc, char** argv, bool outputCout, bool outputFiles)
{
// we always want to use the default locale, and thus spare us the trouble
// with incorrect locale settings.
@ -85,7 +85,7 @@ int flowEbosOilWaterMain(int argc, char** argv)
#endif
Opm::FlowMainEbos<TTAG(EclFlowOilWaterProblem)> mainfunc;
return mainfunc.execute(argc, argv);
return mainfunc.execute(argc, argv, outputCout, outputFiles);
}
}

View File

@ -24,7 +24,7 @@
namespace Opm {
void flowEbosOilWaterSetDeck(double setupTime, Deck &deck, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig);
int flowEbosOilWaterMain(int argc, char** argv);
int flowEbosOilWaterMain(int argc, char** argv, bool outputCout, bool outputFiles);
}
#endif // FLOW_EBOS_OILWATER_HPP

View File

@ -73,7 +73,7 @@ void flowEbosOilWaterPolymerSetDeck(double setupTime, Deck& deck, EclipseState&
}
// ----------------- Main program -----------------
int flowEbosOilWaterPolymerMain(int argc, char** argv)
int flowEbosOilWaterPolymerMain(int argc, char** argv, bool outputCout, bool outputFiles)
{
// we always want to use the default locale, and thus spare us the trouble
// with incorrect locale settings.
@ -86,7 +86,7 @@ int flowEbosOilWaterPolymerMain(int argc, char** argv)
#endif
Opm::FlowMainEbos<TTAG(EclFlowOilWaterPolymerProblem)> mainfunc;
return mainfunc.execute(argc, argv);
return mainfunc.execute(argc, argv, outputCout, outputFiles);
}
}

View File

@ -24,7 +24,7 @@
namespace Opm {
void flowEbosOilWaterPolymerSetDeck(double setupTime, Deck& deck, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig);
int flowEbosOilWaterPolymerMain(int argc, char** argv);
int flowEbosOilWaterPolymerMain(int argc, char** argv, bool outputCout, bool outputFiles);
}
#endif // FLOW_EBOS_OILWATER_POLYMER_HPP

View File

@ -71,7 +71,7 @@ namespace Opm {
} */
// ----------------- Main program -----------------
int flowEbosOilWaterPolymerInjectivityMain(int argc, char** argv)
int flowEbosOilWaterPolymerInjectivityMain(int argc, char** argv, bool outputCout, bool outputFiles)
{
// we always want to use the default locale, and thus spare us the trouble
// with incorrect locale settings.
@ -84,8 +84,7 @@ int flowEbosOilWaterPolymerInjectivityMain(int argc, char** argv)
#endif
Opm::FlowMainEbos<TTAG(EclFlowOilWaterPolymerInjectivityProblem)> mainfunc;
return mainfunc.execute(argc, argv);
return mainfunc.execute(argc, argv, outputCout, outputFiles);
}
}

View File

@ -22,7 +22,7 @@
namespace Opm {
// void flowEbosOilWaterPolymerInjectivitySetDeck(Deck& deck, EclipseState& eclState);
int flowEbosOilWaterPolymerInjectivityMain(int argc, char** argv);
int flowEbosOilWaterPolymerInjectivityMain(int argc, char** argv, bool outputCout, bool outputFiles);
}
#endif // FLOW_EBOS_OILWATER_POLYMER_INJECTIVITY_HPP

View File

@ -49,7 +49,7 @@ void flowEbosPolymerSetDeck(double setupTime, Deck &deck, EclipseState& eclState
}
// ----------------- Main program -----------------
int flowEbosPolymerMain(int argc, char** argv)
int flowEbosPolymerMain(int argc, char** argv, bool outputCout, bool outputFiles)
{
// we always want to use the default locale, and thus spare us the trouble
// with incorrect locale settings.
@ -63,7 +63,7 @@ int flowEbosPolymerMain(int argc, char** argv)
#endif
Opm::FlowMainEbos<TTAG(EclFlowPolymerProblem)> mainfunc;
return mainfunc.execute(argc, argv);
return mainfunc.execute(argc, argv, outputCout, outputFiles);
}
}

View File

@ -24,7 +24,7 @@
namespace Opm {
void flowEbosPolymerSetDeck(double setupTime, Deck &deck, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig);
int flowEbosPolymerMain(int argc, char** argv);
int flowEbosPolymerMain(int argc, char** argv, bool outputCout, bool outputFiles);
}
#endif // FLOW_EBOS_POLYMER_HPP

View File

@ -50,7 +50,7 @@ void flowEbosSolventSetDeck(double setupTime, Deck &deck, EclipseState& eclState
// ----------------- Main program -----------------
int flowEbosSolventMain(int argc, char** argv)
int flowEbosSolventMain(int argc, char** argv, bool outputCout, bool outputFiles)
{
// we always want to use the default locale, and thus spare us the trouble
// with incorrect locale settings.
@ -64,7 +64,7 @@ int flowEbosSolventMain(int argc, char** argv)
#endif
Opm::FlowMainEbos<TTAG(EclFlowSolventProblem)> mainfunc;
return mainfunc.execute(argc, argv);
return mainfunc.execute(argc, argv, outputCout, outputFiles);
}
}

View File

@ -25,7 +25,7 @@
namespace Opm {
void flowEbosSolventSetDeck(double setupTime, Deck &deck, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig);
int flowEbosSolventMain(int argc, char** argv);
int flowEbosSolventMain(int argc, char** argv, bool outoutCout, bool outputFiles);
}
#endif // FLOW_EBOS_SOLVENT_HPP

View File

@ -69,7 +69,7 @@ namespace Opm {
// ----------------- Main program -----------------
template <class TypeTag>
int flowEbosMain(int argc, char** argv)
int flowEbosMain(int argc, char** argv, bool outputCout, bool outputFiles)
{
// we always want to use the default locale, and thus spare us the trouble
// with incorrect locale settings.
@ -81,7 +81,7 @@ namespace Opm {
Dune::MPIHelper::instance(argc, argv);
#endif
Opm::FlowMainEbos<TypeTag> mainfunc;
return mainfunc.execute(argc, argv);
return mainfunc.execute(argc, argv, outputCout, outputFiles);
}
}
@ -123,7 +123,7 @@ namespace detail
// ----------------- Main program -----------------
template<class TypeTag>
int mainFlow(int argc, char** argv)
int mainFlow(int argc, char** argv, bool outputCout, bool outputFiles)
{
// MPI setup.
#if HAVE_DUNE_FEM
@ -160,7 +160,6 @@ int mainFlow(int argc, char** argv)
// --print-properties parameters.
return (status >= 0)?status:0;
bool outputCout = false;
if (mpiRank == 0)
outputCout = EWOMS_GET_PARAM(PreTypeTag, bool, EnableTerminalOutput);
@ -198,7 +197,7 @@ int mainFlow(int argc, char** argv)
std::shared_ptr<Opm::EclipseState> eclipseState = std::make_shared< Opm::EclipseState > ( *deck, parseContext, errorGuard );
Opm::flowEbosSetDeck<TypeTag>(*deck, *eclipseState);
return Opm::flowEbosMain<TypeTag>(argc, argv);
return Opm::flowEbosMain<TypeTag>(argc, argv, outputCout, outputFiles);
}
catch (const std::invalid_argument& e)
{

View File

@ -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