mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-01-25 23:56:30 -06:00
Refactor main_() into initialize_() and dispatch_().
For the Python interface's usage (as opposed to the usage by e.g. flow.cpp), we do not neccessarily want to run the whole simulation by calling run(), it is also useful to just run one report step at a time. According to these different usage scenarios, main_() is refactored into initialize_() and dispatch_() as a preparatory step for implementing the Python interface (to be presented in a later PR).
This commit is contained in:
parent
3f97561380
commit
954d32c3ab
@ -160,10 +160,294 @@ namespace Opm
|
||||
deck_(deck), eclipseState_(eclipseState), schedule_(schedule) { }
|
||||
|
||||
int run() {
|
||||
return main_(argc_, argv_);
|
||||
int exitCode = EXIT_SUCCESS;
|
||||
if (initialize_(exitCode)) {
|
||||
return dispatch_();
|
||||
}
|
||||
else {
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int dispatch_()
|
||||
{
|
||||
#ifdef OPM_FLOW_MAIN
|
||||
const auto& phases = eclipseState_->runspec().phases();
|
||||
// run the actual simulator
|
||||
//
|
||||
// TODO: make sure that no illegal combinations like thermal and twophase are
|
||||
// requested.
|
||||
|
||||
if ( false ) {}
|
||||
#ifndef FLOW_BLACKOIL_ONLY
|
||||
// Twophase cases
|
||||
else if( phases.size() == 2 ) {
|
||||
// oil-gas
|
||||
if (phases.active( Opm::Phase::GAS )) {
|
||||
Opm::flowEbosGasOilSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosGasOilMain(argc_, argv_, outputCout_, outputFiles_);
|
||||
}
|
||||
// oil-water
|
||||
else if ( phases.active( Opm::Phase::WATER ) ) {
|
||||
Opm::flowEbosOilWaterSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosOilWaterMain(argc_, argv_, outputCout_, outputFiles_);
|
||||
}
|
||||
else {
|
||||
if (outputCout_)
|
||||
std::cerr << "No suitable configuration found, valid are Twophase (oilwater and oilgas), polymer, solvent, or blackoil" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
// Polymer case
|
||||
else if ( phases.active( Opm::Phase::POLYMER ) ) {
|
||||
if ( !phases.active( Opm::Phase::WATER) ) {
|
||||
if (outputCout_)
|
||||
std::cerr << "No valid configuration is found for polymer simulation, valid options include "
|
||||
<< "oilwater + polymer and blackoil + polymer" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Need to track the polymer molecular weight
|
||||
// for the injectivity study
|
||||
if ( phases.active( Opm::Phase::POLYMW ) ) {
|
||||
// only oil water two phase for now
|
||||
assert( phases.size() == 4);
|
||||
return Opm::flowEbosOilWaterPolymerInjectivityMain(argc_, argv_, outputCout_, outputFiles_);
|
||||
}
|
||||
|
||||
if ( phases.size() == 3 ) { // oil water polymer case
|
||||
Opm::flowEbosOilWaterPolymerSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosOilWaterPolymerMain(argc_, argv_, outputCout_, outputFiles_);
|
||||
} else {
|
||||
Opm::flowEbosPolymerSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosPolymerMain(argc_, argv_, outputCout_, outputFiles_);
|
||||
}
|
||||
}
|
||||
// Foam case
|
||||
else if ( phases.active( Opm::Phase::FOAM ) ) {
|
||||
Opm::flowEbosFoamSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosFoamMain(argc_, argv_, outputCout_, outputFiles_);
|
||||
}
|
||||
// Brine case
|
||||
else if ( phases.active( Opm::Phase::BRINE ) ) {
|
||||
Opm::flowEbosBrineSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosBrineMain(argc_, argv_, outputCout_, outputFiles_);
|
||||
}
|
||||
// Solvent case
|
||||
else if ( phases.active( Opm::Phase::SOLVENT ) ) {
|
||||
Opm::flowEbosSolventSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosSolventMain(argc_, argv_, outputCout_, outputFiles_);
|
||||
}
|
||||
// Energy case
|
||||
else if (eclipseState_->getSimulationConfig().isThermal()) {
|
||||
Opm::flowEbosEnergySetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosEnergyMain(argc_, argv_, outputCout_, outputFiles_);
|
||||
}
|
||||
#endif // FLOW_BLACKOIL_ONLY
|
||||
// Blackoil case
|
||||
else if( phases.size() == 3 ) {
|
||||
Opm::flowEbosBlackoilSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosBlackoilMain(argc_, argv_, outputCout_, outputFiles_);
|
||||
}
|
||||
else {
|
||||
if (outputCout_)
|
||||
std::cerr << "No suitable configuration found, valid are Twophase, polymer, foam, brine, solvent, energy, blackoil." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#else
|
||||
Opm::flowEbosSetDeck<TypeTag>(deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosMain<TypeTag>(argc_, argv_, outputCout_, outputFiles_);
|
||||
#endif /* OPM_FLOW_MAIN */
|
||||
}
|
||||
|
||||
bool initialize_(int &exitCode)
|
||||
{
|
||||
Dune::Timer externalSetupTimer;
|
||||
externalSetupTimer.start();
|
||||
|
||||
handleVersionCmdLine_(argc_, argv_);
|
||||
// MPI setup.
|
||||
#if HAVE_DUNE_FEM
|
||||
Dune::Fem::MPIManager::initialize(argc_, argv_);
|
||||
int mpiRank = Dune::Fem::MPIManager::rank();
|
||||
#else
|
||||
// the design of the plain dune MPIHelper class is quite flawed: there is no way to
|
||||
// get the instance without having the argc and argv parameters available and it is
|
||||
// not possible to determine the MPI rank and size without an instance. (IOW: the
|
||||
// rank() and size() methods are supposed to be static.)
|
||||
const auto& mpiHelper = Dune::MPIHelper::instance(argc_, argv_);
|
||||
int mpiRank = mpiHelper.rank();
|
||||
#endif
|
||||
|
||||
// we always want to use the default locale, and thus spare us the trouble
|
||||
// with incorrect locale settings.
|
||||
Opm::resetLocale();
|
||||
|
||||
// this is a work-around for a catch 22: we do not know what code path to use without
|
||||
// parsing the deck, but we don't know the deck without having access to the
|
||||
// parameters and this requires to know the type tag to be used. To solve this, we
|
||||
// use a type tag just for parsing the parameters before we instantiate the actual
|
||||
// simulator object. (Which parses the parameters again, but since this is done in an
|
||||
// identical manner it does not matter.)
|
||||
typedef TTAG(FlowEarlyBird) PreTypeTag;
|
||||
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
|
||||
// the program should abort. This is the case e.g. for the --help and the
|
||||
// --print-properties parameters.
|
||||
#if HAVE_MPI
|
||||
MPI_Finalize();
|
||||
#endif
|
||||
exitCode = (status >= 0) ? status : EXIT_SUCCESS;
|
||||
return false;
|
||||
}
|
||||
|
||||
FileOutputMode outputMode = FileOutputMode::OUTPUT_NONE;
|
||||
outputCout_ = false;
|
||||
if (mpiRank == 0)
|
||||
outputCout_ = EWOMS_GET_PARAM(PreTypeTag, bool, EnableTerminalOutput);
|
||||
|
||||
std::string deckFilename;
|
||||
std::string outputDir;
|
||||
if ( eclipseState_ ) {
|
||||
deckFilename = eclipseState_->getIOConfig().fullBasePath();
|
||||
outputDir = eclipseState_->getIOConfig().getOutputDir();
|
||||
}
|
||||
else {
|
||||
deckFilename = EWOMS_GET_PARAM(PreTypeTag, std::string, EclDeckFileName);
|
||||
}
|
||||
|
||||
typedef typename GET_PROP_TYPE(PreTypeTag, Vanguard) PreVanguard;
|
||||
try {
|
||||
deckFilename = PreVanguard::canonicalDeckPath(deckFilename).string();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
if ( mpiRank == 0 )
|
||||
#ifdef OPM_FLOW_MAIN
|
||||
std::cerr << "Exception received: " << e.what() << ". Try '--help' for a usage description.\n";
|
||||
#else
|
||||
Opm::Parameters::printUsage<PreTypeTag>(PreProblem::helpPreamble(
|
||||
argc, const_cast<const char**>(argv)), e.what());
|
||||
#endif
|
||||
#if HAVE_MPI
|
||||
MPI_Finalize();
|
||||
#endif
|
||||
exitCode = EXIT_FAILURE;
|
||||
return false;
|
||||
}
|
||||
if (outputCout_) {
|
||||
Opm::FlowMainEbos<PreTypeTag>::printBanner();
|
||||
}
|
||||
// Create Deck and EclipseState.
|
||||
try {
|
||||
if (outputCout_) {
|
||||
std::cout << "Reading deck file '" << deckFilename << "'\n";
|
||||
std::cout.flush();
|
||||
}
|
||||
auto python = std::make_shared<Opm::Python>();
|
||||
{
|
||||
Opm::Parser parser;
|
||||
Opm::ParseContext parseContext({{Opm::ParseContext::PARSE_RANDOM_SLASH, Opm::InputError::IGNORE},
|
||||
{Opm::ParseContext::PARSE_MISSING_DIMS_KEYWORD, Opm::InputError::WARN},
|
||||
{Opm::ParseContext::SUMMARY_UNKNOWN_WELL, Opm::InputError::WARN},
|
||||
{Opm::ParseContext::SUMMARY_UNKNOWN_GROUP, Opm::InputError::WARN}});
|
||||
Opm::ErrorGuard errorGuard;
|
||||
if (outputDir.empty())
|
||||
outputDir = EWOMS_GET_PARAM(PreTypeTag, std::string, OutputDir);
|
||||
outputMode = setupLogging_(mpiRank,
|
||||
deckFilename,
|
||||
outputDir,
|
||||
EWOMS_GET_PARAM(PreTypeTag, std::string, OutputMode),
|
||||
outputCout_, "STDOUT_LOGGER");
|
||||
|
||||
if (EWOMS_GET_PARAM(PreTypeTag, bool, EclStrictParsing))
|
||||
parseContext.update( Opm::InputError::DELAYED_EXIT1);
|
||||
|
||||
Opm::FlowMainEbos<PreTypeTag>::printPRTHeader(outputCout_);
|
||||
|
||||
if (mpiRank == 0) {
|
||||
if (!deck_)
|
||||
deck_.reset( new Opm::Deck( parser.parseFile(deckFilename , parseContext, errorGuard)));
|
||||
Opm::MissingFeatures::checkKeywords(*deck_, parseContext, errorGuard);
|
||||
if ( outputCout_ )
|
||||
Opm::checkDeck(*deck_, parser, parseContext, errorGuard);
|
||||
|
||||
if (!eclipseState_) {
|
||||
#if HAVE_MPI
|
||||
eclipseState_.reset(new Opm::ParallelEclipseState(*deck_));
|
||||
#else
|
||||
eclipseState_.reset(new Opm::EclipseState(*deck_));
|
||||
#endif
|
||||
}
|
||||
#ifdef OPM_FLOW_MAIN
|
||||
/*
|
||||
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 bool init_from_restart_file = !EWOMS_GET_PARAM(PreTypeTag, bool, SchedRestart);
|
||||
const auto& init_config = eclipseState_->getInitConfig();
|
||||
if (init_config.restartRequested() && init_from_restart_file) {
|
||||
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_)
|
||||
schedule_.reset(new Opm::Schedule(*deck_, *eclipseState_, parseContext, errorGuard, python, &rst_state) );
|
||||
}
|
||||
else {
|
||||
if (!schedule_)
|
||||
schedule_.reset(new Opm::Schedule(*deck_, *eclipseState_, parseContext, errorGuard, python));
|
||||
}
|
||||
#else
|
||||
if (!schedule_)
|
||||
schedule_.reset(new Opm::Schedule(*deck_, *eclipseState_, parseContext, errorGuard, python));
|
||||
#endif /*OPM_FLOW_MAIN */
|
||||
setupMessageLimiter_(schedule_->getMessageLimits(), "STDOUT_LOGGER");
|
||||
if (!summaryConfig_)
|
||||
summaryConfig_.reset( new Opm::SummaryConfig(*deck_, *schedule_, eclipseState_->getTableManager(), parseContext, errorGuard));
|
||||
}
|
||||
#if HAVE_MPI
|
||||
else {
|
||||
if (!summaryConfig_)
|
||||
summaryConfig_.reset(new Opm::SummaryConfig);
|
||||
if (!schedule_)
|
||||
schedule_.reset(new Opm::Schedule(python));
|
||||
if (!eclipseState_)
|
||||
eclipseState_.reset(new Opm::ParallelEclipseState);
|
||||
}
|
||||
Opm::eclStateBroadcast(*eclipseState_, *schedule_, *summaryConfig_);
|
||||
#endif
|
||||
|
||||
Opm::checkConsistentArrayDimensions(*eclipseState_, *schedule_, parseContext, errorGuard);
|
||||
|
||||
if (errorGuard) {
|
||||
errorGuard.dump();
|
||||
errorGuard.clear();
|
||||
|
||||
throw std::runtime_error("Unrecoverable errors were encountered while loading input.");
|
||||
}
|
||||
}
|
||||
setupTime_ = externalSetupTimer.elapsed();
|
||||
outputFiles_ = (outputMode != FileOutputMode::OUTPUT_NONE);
|
||||
}
|
||||
catch (const std::invalid_argument& e)
|
||||
{
|
||||
if (outputCout_) {
|
||||
std::cerr << "Failed to create valid EclipseState object." << std::endl;
|
||||
std::cerr << "Exception caught: " << e.what() << std::endl;
|
||||
}
|
||||
exitCode = EXIT_FAILURE;
|
||||
return false;
|
||||
}
|
||||
|
||||
exitCode = EXIT_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
Opm::filesystem::path simulationCaseName_( const std::string& casename ) {
|
||||
namespace fs = Opm::filesystem;
|
||||
@ -327,283 +611,6 @@ namespace Opm
|
||||
stream_log->setMessageLimiter(std::make_shared<Opm::MessageLimiter>(10, limits));
|
||||
}
|
||||
|
||||
|
||||
// ----------------- Main program -----------------
|
||||
int main_(int argc, char** argv)
|
||||
{
|
||||
Dune::Timer externalSetupTimer;
|
||||
externalSetupTimer.start();
|
||||
|
||||
handleVersionCmdLine_(argc, argv);
|
||||
// MPI setup.
|
||||
#if HAVE_DUNE_FEM
|
||||
Dune::Fem::MPIManager::initialize(argc, argv);
|
||||
int mpiRank = Dune::Fem::MPIManager::rank();
|
||||
#else
|
||||
// the design of the plain dune MPIHelper class is quite flawed: there is no way to
|
||||
// get the instance without having the argc and argv parameters available and it is
|
||||
// not possible to determine the MPI rank and size without an instance. (IOW: the
|
||||
// rank() and size() methods are supposed to be static.)
|
||||
const auto& mpiHelper = Dune::MPIHelper::instance(argc, argv);
|
||||
int mpiRank = mpiHelper.rank();
|
||||
#endif
|
||||
|
||||
// we always want to use the default locale, and thus spare us the trouble
|
||||
// with incorrect locale settings.
|
||||
Opm::resetLocale();
|
||||
|
||||
// this is a work-around for a catch 22: we do not know what code path to use without
|
||||
// parsing the deck, but we don't know the deck without having access to the
|
||||
// parameters and this requires to know the type tag to be used. To solve this, we
|
||||
// use a type tag just for parsing the parameters before we instantiate the actual
|
||||
// simulator object. (Which parses the parameters again, but since this is done in an
|
||||
// identical manner it does not matter.)
|
||||
typedef TTAG(FlowEarlyBird) PreTypeTag;
|
||||
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
|
||||
// the program should abort. This is the case e.g. for the --help and the
|
||||
// --print-properties parameters.
|
||||
#if HAVE_MPI
|
||||
MPI_Finalize();
|
||||
#endif
|
||||
return (status >= 0)?status:0;
|
||||
}
|
||||
|
||||
FileOutputMode outputMode = FileOutputMode::OUTPUT_NONE;
|
||||
outputCout_ = false;
|
||||
if (mpiRank == 0)
|
||||
outputCout_ = EWOMS_GET_PARAM(PreTypeTag, bool, EnableTerminalOutput);
|
||||
|
||||
std::string deckFilename;
|
||||
std::string outputDir;
|
||||
if ( eclipseState_ ) {
|
||||
deckFilename = eclipseState_->getIOConfig().fullBasePath();
|
||||
outputDir = eclipseState_->getIOConfig().getOutputDir();
|
||||
}
|
||||
else {
|
||||
deckFilename = EWOMS_GET_PARAM(PreTypeTag, std::string, EclDeckFileName);
|
||||
}
|
||||
|
||||
typedef typename GET_PROP_TYPE(PreTypeTag, Vanguard) PreVanguard;
|
||||
try {
|
||||
deckFilename = PreVanguard::canonicalDeckPath(deckFilename).string();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
if ( mpiRank == 0 )
|
||||
#ifdef OPM_FLOW_MAIN
|
||||
std::cerr << "Exception received: " << e.what() << ". Try '--help' for a usage description.\n";
|
||||
#else
|
||||
Opm::Parameters::printUsage<PreTypeTag>(PreProblem::helpPreamble(
|
||||
argc, const_cast<const char**>(argv)), e.what());
|
||||
#endif
|
||||
#if HAVE_MPI
|
||||
MPI_Finalize();
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
if (outputCout_) {
|
||||
Opm::FlowMainEbos<PreTypeTag>::printBanner();
|
||||
}
|
||||
// Create Deck and EclipseState.
|
||||
try {
|
||||
if (outputCout_) {
|
||||
std::cout << "Reading deck file '" << deckFilename << "'\n";
|
||||
std::cout.flush();
|
||||
}
|
||||
auto python = std::make_shared<Opm::Python>();
|
||||
{
|
||||
Opm::Parser parser;
|
||||
Opm::ParseContext parseContext({{Opm::ParseContext::PARSE_RANDOM_SLASH, Opm::InputError::IGNORE},
|
||||
{Opm::ParseContext::PARSE_MISSING_DIMS_KEYWORD, Opm::InputError::WARN},
|
||||
{Opm::ParseContext::SUMMARY_UNKNOWN_WELL, Opm::InputError::WARN},
|
||||
{Opm::ParseContext::SUMMARY_UNKNOWN_GROUP, Opm::InputError::WARN}});
|
||||
Opm::ErrorGuard errorGuard;
|
||||
if (outputDir.empty())
|
||||
outputDir = EWOMS_GET_PARAM(PreTypeTag, std::string, OutputDir);
|
||||
outputMode = setupLogging_(mpiRank,
|
||||
deckFilename,
|
||||
outputDir,
|
||||
EWOMS_GET_PARAM(PreTypeTag, std::string, OutputMode),
|
||||
outputCout_, "STDOUT_LOGGER");
|
||||
|
||||
if (EWOMS_GET_PARAM(PreTypeTag, bool, EclStrictParsing))
|
||||
parseContext.update( Opm::InputError::DELAYED_EXIT1);
|
||||
|
||||
Opm::FlowMainEbos<PreTypeTag>::printPRTHeader(outputCout_);
|
||||
|
||||
if (mpiRank == 0) {
|
||||
if (!deck_)
|
||||
deck_.reset( new Opm::Deck( parser.parseFile(deckFilename , parseContext, errorGuard)));
|
||||
Opm::MissingFeatures::checkKeywords(*deck_, parseContext, errorGuard);
|
||||
if ( outputCout_ )
|
||||
Opm::checkDeck(*deck_, parser, parseContext, errorGuard);
|
||||
|
||||
if (!eclipseState_) {
|
||||
#if HAVE_MPI
|
||||
eclipseState_.reset(new Opm::ParallelEclipseState(*deck_));
|
||||
#else
|
||||
eclipseState_.reset(new Opm::EclipseState(*deck_));
|
||||
#endif
|
||||
}
|
||||
#ifdef OPM_FLOW_MAIN
|
||||
/*
|
||||
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 bool init_from_restart_file = !EWOMS_GET_PARAM(PreTypeTag, bool, SchedRestart);
|
||||
const auto& init_config = eclipseState_->getInitConfig();
|
||||
if (init_config.restartRequested() && init_from_restart_file) {
|
||||
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_)
|
||||
schedule_.reset(new Opm::Schedule(*deck_, *eclipseState_, parseContext, errorGuard, python, &rst_state) );
|
||||
}
|
||||
else {
|
||||
if (!schedule_)
|
||||
schedule_.reset(new Opm::Schedule(*deck_, *eclipseState_, parseContext, errorGuard, python));
|
||||
}
|
||||
#else
|
||||
if (!schedule_)
|
||||
schedule_.reset(new Opm::Schedule(*deck_, *eclipseState_, parseContext, errorGuard, python));
|
||||
#endif /*OPM_FLOW_MAIN */
|
||||
setupMessageLimiter_(schedule_->getMessageLimits(), "STDOUT_LOGGER");
|
||||
if (!summaryConfig_)
|
||||
summaryConfig_.reset( new Opm::SummaryConfig(*deck_, *schedule_, eclipseState_->getTableManager(), parseContext, errorGuard));
|
||||
}
|
||||
#if HAVE_MPI
|
||||
else {
|
||||
if (!summaryConfig_)
|
||||
summaryConfig_.reset(new Opm::SummaryConfig);
|
||||
if (!schedule_)
|
||||
schedule_.reset(new Opm::Schedule(python));
|
||||
if (!eclipseState_)
|
||||
eclipseState_.reset(new Opm::ParallelEclipseState);
|
||||
}
|
||||
Opm::eclStateBroadcast(*eclipseState_, *schedule_, *summaryConfig_);
|
||||
#endif
|
||||
|
||||
Opm::checkConsistentArrayDimensions(*eclipseState_, *schedule_, parseContext, errorGuard);
|
||||
|
||||
if (errorGuard) {
|
||||
errorGuard.dump();
|
||||
errorGuard.clear();
|
||||
|
||||
throw std::runtime_error("Unrecoverable errors were encountered while loading input.");
|
||||
}
|
||||
}
|
||||
setupTime_ = externalSetupTimer.elapsed();
|
||||
outputFiles_ = (outputMode != FileOutputMode::OUTPUT_NONE);
|
||||
#ifdef OPM_FLOW_MAIN
|
||||
const auto& phases = eclipseState_->runspec().phases();
|
||||
// run the actual simulator
|
||||
//
|
||||
// TODO: make sure that no illegal combinations like thermal and twophase are
|
||||
// requested.
|
||||
|
||||
if ( false ) {}
|
||||
#ifndef FLOW_BLACKOIL_ONLY
|
||||
// Twophase cases
|
||||
else if( phases.size() == 2 ) {
|
||||
// oil-gas
|
||||
if (phases.active( Opm::Phase::GAS ))
|
||||
{
|
||||
Opm::flowEbosGasOilSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosGasOilMain(argc, argv, outputCout_, outputFiles_);
|
||||
}
|
||||
// oil-water
|
||||
else if ( phases.active( Opm::Phase::WATER ) )
|
||||
{
|
||||
Opm::flowEbosOilWaterSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosOilWaterMain(argc, argv, outputCout_, outputFiles_);
|
||||
}
|
||||
else {
|
||||
if (outputCout_)
|
||||
std::cerr << "No suitable configuration found, valid are Twophase (oilwater and oilgas), polymer, solvent, or blackoil" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
// Polymer case
|
||||
else if ( phases.active( Opm::Phase::POLYMER ) ) {
|
||||
|
||||
if ( !phases.active( Opm::Phase::WATER) ) {
|
||||
if (outputCout_)
|
||||
std::cerr << "No valid configuration is found for polymer simulation, valid options include "
|
||||
<< "oilwater + polymer and blackoil + polymer" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Need to track the polymer molecular weight
|
||||
// for the injectivity study
|
||||
if ( phases.active( Opm::Phase::POLYMW ) ) {
|
||||
// only oil water two phase for now
|
||||
assert( phases.size() == 4);
|
||||
return Opm::flowEbosOilWaterPolymerInjectivityMain(argc, argv, outputCout_, outputFiles_);
|
||||
}
|
||||
|
||||
if ( phases.size() == 3 ) { // oil water polymer case
|
||||
Opm::flowEbosOilWaterPolymerSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosOilWaterPolymerMain(argc, argv, outputCout_, outputFiles_);
|
||||
} else {
|
||||
Opm::flowEbosPolymerSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosPolymerMain(argc, argv, outputCout_, outputFiles_);
|
||||
}
|
||||
}
|
||||
// Foam case
|
||||
else if ( phases.active( Opm::Phase::FOAM ) ) {
|
||||
Opm::flowEbosFoamSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosFoamMain(argc, argv, outputCout_, outputFiles_);
|
||||
}
|
||||
// Brine case
|
||||
else if ( phases.active( Opm::Phase::BRINE ) ) {
|
||||
Opm::flowEbosBrineSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosBrineMain(argc, argv, outputCout_, outputFiles_);
|
||||
}
|
||||
// Solvent case
|
||||
else if ( phases.active( Opm::Phase::SOLVENT ) ) {
|
||||
Opm::flowEbosSolventSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosSolventMain(argc, argv, outputCout_, outputFiles_);
|
||||
}
|
||||
// Energy case
|
||||
else if (eclipseState_->getSimulationConfig().isThermal()) {
|
||||
Opm::flowEbosEnergySetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosEnergyMain(argc, argv, outputCout_, outputFiles_);
|
||||
}
|
||||
#endif // FLOW_BLACKOIL_ONLY
|
||||
// Blackoil case
|
||||
else if( phases.size() == 3 ) {
|
||||
Opm::flowEbosBlackoilSetDeck(setupTime_, deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosBlackoilMain(argc, argv, outputCout_, outputFiles_);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (outputCout_)
|
||||
std::cerr << "No suitable configuration found, valid are Twophase, polymer, foam, brine, solvent, energy, blackoil." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#else
|
||||
Opm::flowEbosSetDeck<TypeTag>(deck_.get(), *eclipseState_, *schedule_, *summaryConfig_);
|
||||
return Opm::flowEbosMain<TypeTag>(argc, argv, outputCout_, outputFiles_);
|
||||
#endif /* OPM_FLOW_MAIN */
|
||||
}
|
||||
catch (const std::invalid_argument& e)
|
||||
{
|
||||
if (outputCout_) {
|
||||
std::cerr << "Failed to create valid EclipseState object." << std::endl;
|
||||
std::cerr << "Exception caught: " << e.what() << std::endl;
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int argc_;
|
||||
char** argv_;
|
||||
bool outputCout_;
|
||||
|
Loading…
Reference in New Issue
Block a user