2020-08-17 09:10:18 -05:00
|
|
|
/*
|
|
|
|
Copyright 2013, 2014, 2015 SINTEF ICT, Applied Mathematics.
|
|
|
|
Copyright 2014 Dr. Blatt - HPC-Simulation-Software & Services
|
|
|
|
Copyright 2015 IRIS AS
|
|
|
|
Copyright 2014 STATOIL ASA.
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#if HAVE_MPI
|
|
|
|
#include "mpi.h"
|
|
|
|
#endif
|
|
|
|
#include "readDeck.hpp"
|
|
|
|
|
|
|
|
#include <opm/common/utility/String.hpp>
|
|
|
|
|
|
|
|
#include <opm/io/eclipse/EclIOdata.hpp>
|
|
|
|
|
|
|
|
#include <opm/output/eclipse/RestartIO.hpp>
|
|
|
|
#include <opm/io/eclipse/rst/state.hpp>
|
|
|
|
|
|
|
|
#include <opm/parser/eclipse/EclipseState/checkDeck.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/ArrayDimChecker.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
|
|
|
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
|
|
|
|
|
|
|
|
#include <opm/simulators/flow/MissingFeatures.hpp>
|
|
|
|
#include <opm/simulators/utils/ParallelEclipseState.hpp>
|
|
|
|
#include <opm/simulators/utils/ParallelSerialization.hpp>
|
|
|
|
|
2020-09-14 12:17:55 -05:00
|
|
|
#include <cstdlib>
|
|
|
|
|
2020-08-17 09:10:18 -05:00
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
|
|
|
void ensureOutputDirExists_(const std::string& cmdline_output_dir)
|
|
|
|
{
|
|
|
|
if (!Opm::filesystem::is_directory(cmdline_output_dir)) {
|
|
|
|
try {
|
|
|
|
Opm::filesystem::create_directories(cmdline_output_dir);
|
|
|
|
}
|
|
|
|
catch (...) {
|
|
|
|
throw std::runtime_error("Creation of output directory '" + cmdline_output_dir + "' failed\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
|
|
|
|
if (!cmdline_output_dir.empty()) {
|
|
|
|
ensureOutputDirExists_(cmdline_output_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
// create logFile
|
|
|
|
using Opm::filesystem::path;
|
|
|
|
path fpath(deck_filename);
|
|
|
|
std::string baseName;
|
|
|
|
std::ostringstream debugFileStream;
|
|
|
|
std::ostringstream logFileStream;
|
|
|
|
|
|
|
|
// Strip extension "." or ".DATA"
|
|
|
|
std::string extension = uppercase(fpath.extension().string());
|
|
|
|
if (extension == ".DATA" || extension == ".") {
|
|
|
|
baseName = uppercase(fpath.stem().string());
|
|
|
|
} else {
|
|
|
|
baseName = uppercase(fpath.filename().string());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string output_dir = cmdline_output_dir;
|
|
|
|
if (output_dir.empty()) {
|
|
|
|
output_dir = fpath.has_parent_path()
|
|
|
|
? absolute(fpath.parent_path()).generic_string()
|
|
|
|
: Opm::filesystem::current_path().generic_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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mpi_rank_ == 0) {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void readDeck(int rank, std::string& deckFilename, std::unique_ptr<Opm::Deck>& deck, std::unique_ptr<Opm::EclipseState>& eclipseState,
|
|
|
|
std::unique_ptr<Opm::Schedule>& schedule, std::unique_ptr<Opm::SummaryConfig>& summaryConfig,
|
2020-08-18 05:35:55 -05:00
|
|
|
std::unique_ptr<ErrorGuard> errorGuard, std::shared_ptr<Opm::Python>& python, std::unique_ptr<ParseContext> parseContext,
|
2020-08-17 09:10:18 -05:00
|
|
|
bool initFromRestart, bool checkDeck)
|
|
|
|
{
|
2020-08-18 05:35:55 -05:00
|
|
|
if (!errorGuard)
|
|
|
|
{
|
|
|
|
errorGuard = std::make_unique<ErrorGuard>();
|
|
|
|
}
|
2020-08-17 09:10:18 -05:00
|
|
|
|
2020-09-14 05:53:02 -05:00
|
|
|
int parseSuccess = 1; // > 0 is success
|
2020-08-17 09:10:18 -05:00
|
|
|
std::string failureMessage;
|
|
|
|
|
|
|
|
if (rank==0) {
|
|
|
|
try
|
|
|
|
{
|
2020-08-18 05:35:55 -05:00
|
|
|
if ( (!deck || !schedule || !summaryConfig ) && !parseContext)
|
|
|
|
{
|
|
|
|
OPM_THROW(std::logic_error, "We need a parse context if deck, schedule, or summaryConfig are not initialized");
|
|
|
|
}
|
|
|
|
|
2020-08-17 09:10:18 -05:00
|
|
|
if (!deck)
|
2020-08-18 05:35:55 -05:00
|
|
|
{
|
|
|
|
Opm::Parser parser;
|
2020-08-18 09:27:51 -05:00
|
|
|
deck = std::make_unique<Opm::Deck>( parser.parseFile(deckFilename , *parseContext, *errorGuard));
|
2020-08-18 05:35:55 -05:00
|
|
|
Opm::MissingFeatures::checkKeywords(*deck, *parseContext, *errorGuard);
|
|
|
|
if ( checkDeck )
|
|
|
|
Opm::checkDeck(*deck, parser, *parseContext, *errorGuard);
|
|
|
|
}
|
2020-08-17 09:10:18 -05:00
|
|
|
|
|
|
|
if (!eclipseState) {
|
2020-08-18 05:35:55 -05:00
|
|
|
#if HAVE_MPI
|
2020-08-18 09:27:51 -05:00
|
|
|
eclipseState = std::make_unique<Opm::ParallelEclipseState>(*deck);
|
2020-08-17 09:10:18 -05:00
|
|
|
#else
|
2020-08-18 09:27:51 -05:00
|
|
|
eclipseState = std::make_unique<Opm::EclipseState>(*deck);
|
2020-08-17 09:10:18 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
For the time being initializing wells and groups from the
|
|
|
|
restart file is not possible, but work is underways and it is
|
|
|
|
included here as a switch.
|
|
|
|
*/
|
|
|
|
const auto& init_config = eclipseState->getInitConfig();
|
|
|
|
if (init_config.restartRequested() && initFromRestart) {
|
|
|
|
int report_step = init_config.getRestartStep();
|
|
|
|
const auto& rst_filename = eclipseState->getIOConfig().getRestartFileName( init_config.getRestartRootName(), report_step, false );
|
|
|
|
Opm::EclIO::ERst rst_file(rst_filename);
|
|
|
|
const auto& rst_state = Opm::RestartIO::RstState::load(rst_file, report_step);
|
|
|
|
if (!schedule)
|
2020-08-18 09:27:51 -05:00
|
|
|
schedule = std::make_unique<Opm::Schedule>(*deck, *eclipseState, *parseContext, *errorGuard, python, &rst_state);
|
2020-08-17 09:10:18 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!schedule)
|
2020-08-18 09:27:51 -05:00
|
|
|
schedule = std::make_unique<Opm::Schedule>(*deck, *eclipseState, *parseContext, *errorGuard, python);
|
2020-08-17 09:10:18 -05:00
|
|
|
}
|
2020-08-18 12:28:53 -05:00
|
|
|
if (Opm::OpmLog::hasBackend("STDOUT_LOGGER")) // loggers might not be set up!
|
|
|
|
{
|
|
|
|
setupMessageLimiter(schedule->getMessageLimits(), "STDOUT_LOGGER");
|
|
|
|
}
|
2020-08-17 09:10:18 -05:00
|
|
|
if (!summaryConfig)
|
2020-08-18 09:27:51 -05:00
|
|
|
summaryConfig = std::make_unique<Opm::SummaryConfig>(*deck, *schedule, eclipseState->getTableManager(), *parseContext, *errorGuard);
|
2020-09-14 05:53:02 -05:00
|
|
|
|
2020-09-15 01:26:23 -05:00
|
|
|
Opm::checkConsistentArrayDimensions(*eclipseState, *schedule, *parseContext, *errorGuard);
|
2020-08-17 09:10:18 -05:00
|
|
|
}
|
|
|
|
catch(const std::exception& e)
|
|
|
|
{
|
|
|
|
failureMessage = e.what();
|
2020-09-14 05:53:02 -05:00
|
|
|
parseSuccess = 0;
|
2020-08-17 09:10:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#if HAVE_MPI
|
|
|
|
else {
|
|
|
|
if (!summaryConfig)
|
2020-08-18 09:27:51 -05:00
|
|
|
summaryConfig = std::make_unique<Opm::SummaryConfig>();
|
2020-08-17 09:10:18 -05:00
|
|
|
if (!schedule)
|
2020-08-18 09:27:51 -05:00
|
|
|
schedule = std::make_unique<Opm::Schedule>(python);
|
2020-08-17 09:10:18 -05:00
|
|
|
if (!eclipseState)
|
2020-08-18 09:27:51 -05:00
|
|
|
eclipseState = std::make_unique<Opm::ParallelEclipseState>();
|
2020-08-17 09:10:18 -05:00
|
|
|
}
|
2020-09-14 05:53:02 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Opm::eclStateBroadcast(*eclipseState, *schedule, *summaryConfig);
|
|
|
|
}
|
|
|
|
catch(const std::exception& e)
|
|
|
|
{
|
|
|
|
failureMessage = e.what();
|
|
|
|
parseSuccess = 0;
|
|
|
|
}
|
|
|
|
|
2020-09-15 01:27:04 -05:00
|
|
|
#endif
|
|
|
|
|
2020-09-14 05:53:02 -05:00
|
|
|
if (*errorGuard) { // errors encountered
|
|
|
|
parseSuccess = 0;
|
|
|
|
}
|
2020-08-17 09:10:18 -05:00
|
|
|
|
2020-09-15 01:27:04 -05:00
|
|
|
// print errors and warnings!
|
2020-09-14 05:53:02 -05:00
|
|
|
errorGuard->dump();
|
|
|
|
errorGuard->clear();
|
2020-08-17 09:10:18 -05:00
|
|
|
|
2020-09-15 01:27:04 -05:00
|
|
|
auto comm = Dune::MPIHelper::getCollectiveCommunication();
|
2020-09-14 05:53:02 -05:00
|
|
|
parseSuccess = comm.min(parseSuccess);
|
2020-08-17 09:10:18 -05:00
|
|
|
|
2020-09-14 05:53:02 -05:00
|
|
|
if (!parseSuccess)
|
|
|
|
{
|
|
|
|
if (rank == 0)
|
|
|
|
{
|
|
|
|
OpmLog::error(std::string("Unrecoverable errors were encountered while loading input: ")+failureMessage);
|
|
|
|
}
|
|
|
|
#if HAVE_MPI
|
|
|
|
MPI_Finalize();
|
|
|
|
#endif
|
2020-09-15 01:36:20 -05:00
|
|
|
std::exit(EXIT_FAILURE);
|
2020-08-17 09:10:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end namespace Opm
|