mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Adapting Main.hpp to the Python interface.
Adapting Main.hpp to be called from Python interface, Part 1. Building on PR #2521 and PR #2535, we gradually adapt Main.hpp for being called from the Python interface (to be committed in a later PR) to the flow executable. This PR introduces a new constructor for class Opm::Main that takes a Deck, EclipseState, Schedule, and SummaryConfig as arguments. It also introduces some new class variables that will be useful when the main_() method is split up (in a later commit).
This commit is contained in:
parent
2159a83b49
commit
09230808e0
@ -151,6 +151,13 @@ namespace Opm
|
|||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
Main(int argc, char** argv) : argc_(argc), argv_(argv) { }
|
Main(int argc, char** argv) : argc_(argc), argv_(argv) { }
|
||||||
|
Main(int argc, char** argv,
|
||||||
|
std::shared_ptr<Opm::Deck> deck,
|
||||||
|
std::shared_ptr<Opm::EclipseState> eclipseState,
|
||||||
|
std::shared_ptr<Opm::Schedule> schedule,
|
||||||
|
std::shared_ptr<Opm::SummaryConfig> summaryConfig) :
|
||||||
|
argc_(argc), argv_(argv),
|
||||||
|
deck_(deck), eclipseState_(eclipseState), schedule_(schedule) { }
|
||||||
|
|
||||||
int run() {
|
int run() {
|
||||||
return main_(argc_, argv_);
|
return main_(argc_, argv_);
|
||||||
@ -367,9 +374,9 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileOutputMode outputMode = FileOutputMode::OUTPUT_NONE;
|
FileOutputMode outputMode = FileOutputMode::OUTPUT_NONE;
|
||||||
bool outputCout = false;
|
outputCout_ = false;
|
||||||
if (mpiRank == 0)
|
if (mpiRank == 0)
|
||||||
outputCout = EWOMS_GET_PARAM(PreTypeTag, bool, EnableTerminalOutput);
|
outputCout_ = EWOMS_GET_PARAM(PreTypeTag, bool, EnableTerminalOutput);
|
||||||
|
|
||||||
std::string deckFilename = EWOMS_GET_PARAM(PreTypeTag, std::string, EclDeckFileName);
|
std::string deckFilename = EWOMS_GET_PARAM(PreTypeTag, std::string, EclDeckFileName);
|
||||||
typedef typename GET_PROP_TYPE(PreTypeTag, Vanguard) PreVanguard;
|
typedef typename GET_PROP_TYPE(PreTypeTag, Vanguard) PreVanguard;
|
||||||
@ -389,12 +396,12 @@ namespace Opm
|
|||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (outputCout) {
|
if (outputCout_) {
|
||||||
Opm::FlowMainEbos<PreTypeTag>::printBanner();
|
Opm::FlowMainEbos<PreTypeTag>::printBanner();
|
||||||
}
|
}
|
||||||
// Create Deck and EclipseState.
|
// Create Deck and EclipseState.
|
||||||
try {
|
try {
|
||||||
if (outputCout) {
|
if (outputCout_) {
|
||||||
std::cout << "Reading deck file '" << deckFilename << "'\n";
|
std::cout << "Reading deck file '" << deckFilename << "'\n";
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
}
|
}
|
||||||
@ -414,17 +421,17 @@ namespace Opm
|
|||||||
deckFilename,
|
deckFilename,
|
||||||
EWOMS_GET_PARAM(PreTypeTag, std::string, OutputDir),
|
EWOMS_GET_PARAM(PreTypeTag, std::string, OutputDir),
|
||||||
EWOMS_GET_PARAM(PreTypeTag, std::string, OutputMode),
|
EWOMS_GET_PARAM(PreTypeTag, std::string, OutputMode),
|
||||||
outputCout, "STDOUT_LOGGER");
|
outputCout_, "STDOUT_LOGGER");
|
||||||
|
|
||||||
if (EWOMS_GET_PARAM(PreTypeTag, bool, EclStrictParsing))
|
if (EWOMS_GET_PARAM(PreTypeTag, bool, EclStrictParsing))
|
||||||
parseContext.update( Opm::InputError::DELAYED_EXIT1);
|
parseContext.update( Opm::InputError::DELAYED_EXIT1);
|
||||||
|
|
||||||
Opm::FlowMainEbos<PreTypeTag>::printPRTHeader(outputCout);
|
Opm::FlowMainEbos<PreTypeTag>::printPRTHeader(outputCout_);
|
||||||
|
|
||||||
if (mpiRank == 0) {
|
if (mpiRank == 0) {
|
||||||
deck.reset( new Opm::Deck( parser.parseFile(deckFilename , parseContext, errorGuard)));
|
deck.reset( new Opm::Deck( parser.parseFile(deckFilename , parseContext, errorGuard)));
|
||||||
Opm::MissingFeatures::checkKeywords(*deck, parseContext, errorGuard);
|
Opm::MissingFeatures::checkKeywords(*deck, parseContext, errorGuard);
|
||||||
if ( outputCout )
|
if ( outputCout_ )
|
||||||
Opm::checkDeck(*deck, parser, parseContext, errorGuard);
|
Opm::checkDeck(*deck, parser, parseContext, errorGuard);
|
||||||
|
|
||||||
#if HAVE_MPI
|
#if HAVE_MPI
|
||||||
@ -472,7 +479,8 @@ namespace Opm
|
|||||||
throw std::runtime_error("Unrecoverable errors were encountered while loading input.");
|
throw std::runtime_error("Unrecoverable errors were encountered while loading input.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool outputFiles = (outputMode != FileOutputMode::OUTPUT_NONE);
|
setupTime_ = externalSetupTimer.elapsed();
|
||||||
|
outputFiles_ = (outputMode != FileOutputMode::OUTPUT_NONE);
|
||||||
#ifdef OPM_FLOW_MAIN
|
#ifdef OPM_FLOW_MAIN
|
||||||
const auto& phases = eclipseState->runspec().phases();
|
const auto& phases = eclipseState->runspec().phases();
|
||||||
// run the actual simulator
|
// run the actual simulator
|
||||||
@ -487,17 +495,17 @@ namespace Opm
|
|||||||
// oil-gas
|
// oil-gas
|
||||||
if (phases.active( Opm::Phase::GAS ))
|
if (phases.active( Opm::Phase::GAS ))
|
||||||
{
|
{
|
||||||
Opm::flowEbosGasOilSetDeck(externalSetupTimer.elapsed(), deck.get(), *eclipseState, *schedule, *summaryConfig);
|
Opm::flowEbosGasOilSetDeck(setupTime_, deck.get(), *eclipseState, *schedule, *summaryConfig);
|
||||||
return Opm::flowEbosGasOilMain(argc, argv, outputCout, outputFiles);
|
return Opm::flowEbosGasOilMain(argc, argv, outputCout_, outputFiles_);
|
||||||
}
|
}
|
||||||
// oil-water
|
// oil-water
|
||||||
else if ( phases.active( Opm::Phase::WATER ) )
|
else if ( phases.active( Opm::Phase::WATER ) )
|
||||||
{
|
{
|
||||||
Opm::flowEbosOilWaterSetDeck(externalSetupTimer.elapsed(), deck.get(), *eclipseState, *schedule, *summaryConfig);
|
Opm::flowEbosOilWaterSetDeck(setupTime_, deck.get(), *eclipseState, *schedule, *summaryConfig);
|
||||||
return Opm::flowEbosOilWaterMain(argc, argv, outputCout, outputFiles);
|
return Opm::flowEbosOilWaterMain(argc, argv, outputCout_, outputFiles_);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (outputCout)
|
if (outputCout_)
|
||||||
std::cerr << "No suitable configuration found, valid are Twophase (oilwater and oilgas), polymer, solvent, or blackoil" << std::endl;
|
std::cerr << "No suitable configuration found, valid are Twophase (oilwater and oilgas), polymer, solvent, or blackoil" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
@ -506,7 +514,7 @@ namespace Opm
|
|||||||
else if ( phases.active( Opm::Phase::POLYMER ) ) {
|
else if ( phases.active( Opm::Phase::POLYMER ) ) {
|
||||||
|
|
||||||
if ( !phases.active( Opm::Phase::WATER) ) {
|
if ( !phases.active( Opm::Phase::WATER) ) {
|
||||||
if (outputCout)
|
if (outputCout_)
|
||||||
std::cerr << "No valid configuration is found for polymer simulation, valid options include "
|
std::cerr << "No valid configuration is found for polymer simulation, valid options include "
|
||||||
<< "oilwater + polymer and blackoil + polymer" << std::endl;
|
<< "oilwater + polymer and blackoil + polymer" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -517,57 +525,57 @@ namespace Opm
|
|||||||
if ( phases.active( Opm::Phase::POLYMW ) ) {
|
if ( phases.active( Opm::Phase::POLYMW ) ) {
|
||||||
// only oil water two phase for now
|
// only oil water two phase for now
|
||||||
assert( phases.size() == 4);
|
assert( phases.size() == 4);
|
||||||
return Opm::flowEbosOilWaterPolymerInjectivityMain(argc, argv, outputCout, outputFiles);
|
return Opm::flowEbosOilWaterPolymerInjectivityMain(argc, argv, outputCout_, outputFiles_);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( phases.size() == 3 ) { // oil water polymer case
|
if ( phases.size() == 3 ) { // oil water polymer case
|
||||||
Opm::flowEbosOilWaterPolymerSetDeck(externalSetupTimer.elapsed(), deck.get(), *eclipseState, *schedule, *summaryConfig);
|
Opm::flowEbosOilWaterPolymerSetDeck(setupTime_, deck.get(), *eclipseState, *schedule, *summaryConfig);
|
||||||
return Opm::flowEbosOilWaterPolymerMain(argc, argv, outputCout, outputFiles);
|
return Opm::flowEbosOilWaterPolymerMain(argc, argv, outputCout_, outputFiles_);
|
||||||
} else {
|
} else {
|
||||||
Opm::flowEbosPolymerSetDeck(externalSetupTimer.elapsed(), deck.get(), *eclipseState, *schedule, *summaryConfig);
|
Opm::flowEbosPolymerSetDeck(setupTime_, deck.get(), *eclipseState, *schedule, *summaryConfig);
|
||||||
return Opm::flowEbosPolymerMain(argc, argv, outputCout, outputFiles);
|
return Opm::flowEbosPolymerMain(argc, argv, outputCout_, outputFiles_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Foam case
|
// Foam case
|
||||||
else if ( phases.active( Opm::Phase::FOAM ) ) {
|
else if ( phases.active( Opm::Phase::FOAM ) ) {
|
||||||
Opm::flowEbosFoamSetDeck(externalSetupTimer.elapsed(), deck.get(), *eclipseState, *schedule, *summaryConfig);
|
Opm::flowEbosFoamSetDeck(setupTime_, deck.get(), *eclipseState, *schedule, *summaryConfig);
|
||||||
return Opm::flowEbosFoamMain(argc, argv, outputCout, outputFiles);
|
return Opm::flowEbosFoamMain(argc, argv, outputCout_, outputFiles_);
|
||||||
}
|
}
|
||||||
// Brine case
|
// Brine case
|
||||||
else if ( phases.active( Opm::Phase::BRINE ) ) {
|
else if ( phases.active( Opm::Phase::BRINE ) ) {
|
||||||
Opm::flowEbosBrineSetDeck(externalSetupTimer.elapsed(), deck.get(), *eclipseState, *schedule, *summaryConfig);
|
Opm::flowEbosBrineSetDeck(setupTime_, deck.get(), *eclipseState, *schedule, *summaryConfig);
|
||||||
return Opm::flowEbosBrineMain(argc, argv, outputCout, outputFiles);
|
return Opm::flowEbosBrineMain(argc, argv, outputCout_, outputFiles_);
|
||||||
}
|
}
|
||||||
// Solvent case
|
// Solvent case
|
||||||
else if ( phases.active( Opm::Phase::SOLVENT ) ) {
|
else if ( phases.active( Opm::Phase::SOLVENT ) ) {
|
||||||
Opm::flowEbosSolventSetDeck(externalSetupTimer.elapsed(), deck.get(), *eclipseState, *schedule, *summaryConfig);
|
Opm::flowEbosSolventSetDeck(setupTime_, deck.get(), *eclipseState, *schedule, *summaryConfig);
|
||||||
return Opm::flowEbosSolventMain(argc, argv, outputCout, outputFiles);
|
return Opm::flowEbosSolventMain(argc, argv, outputCout_, outputFiles_);
|
||||||
}
|
}
|
||||||
// Energy case
|
// Energy case
|
||||||
else if (eclipseState->getSimulationConfig().isThermal()) {
|
else if (eclipseState->getSimulationConfig().isThermal()) {
|
||||||
Opm::flowEbosEnergySetDeck(externalSetupTimer.elapsed(), deck.get(), *eclipseState, *schedule, *summaryConfig);
|
Opm::flowEbosEnergySetDeck(setupTime_, deck.get(), *eclipseState, *schedule, *summaryConfig);
|
||||||
return Opm::flowEbosEnergyMain(argc, argv, outputCout, outputFiles);
|
return Opm::flowEbosEnergyMain(argc, argv, outputCout_, outputFiles_);
|
||||||
}
|
}
|
||||||
#endif // FLOW_BLACKOIL_ONLY
|
#endif // FLOW_BLACKOIL_ONLY
|
||||||
// Blackoil case
|
// Blackoil case
|
||||||
else if( phases.size() == 3 ) {
|
else if( phases.size() == 3 ) {
|
||||||
Opm::flowEbosBlackoilSetDeck(externalSetupTimer.elapsed(), deck.get(), *eclipseState, *schedule, *summaryConfig);
|
Opm::flowEbosBlackoilSetDeck(setupTime_, deck.get(), *eclipseState, *schedule, *summaryConfig);
|
||||||
return Opm::flowEbosBlackoilMain(argc, argv, outputCout, outputFiles);
|
return Opm::flowEbosBlackoilMain(argc, argv, outputCout_, outputFiles_);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (outputCout)
|
if (outputCout_)
|
||||||
std::cerr << "No suitable configuration found, valid are Twophase, polymer, foam, brine, solvent, energy, blackoil." << std::endl;
|
std::cerr << "No suitable configuration found, valid are Twophase, polymer, foam, brine, solvent, energy, blackoil." << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
Opm::flowEbosSetDeck<TypeTag>(deck.get(), *eclipseState, *schedule, *summaryConfig);
|
Opm::flowEbosSetDeck<TypeTag>(deck.get(), *eclipseState, *schedule, *summaryConfig);
|
||||||
return Opm::flowEbosMain<TypeTag>(argc, argv, outputCout, outputFiles);
|
return Opm::flowEbosMain<TypeTag>(argc, argv, outputCout_, outputFiles_);
|
||||||
#endif /* OPM_FLOW_MAIN */
|
#endif /* OPM_FLOW_MAIN */
|
||||||
}
|
}
|
||||||
catch (const std::invalid_argument& e)
|
catch (const std::invalid_argument& e)
|
||||||
{
|
{
|
||||||
if (outputCout) {
|
if (outputCout_) {
|
||||||
std::cerr << "Failed to create valid EclipseState object." << std::endl;
|
std::cerr << "Failed to create valid EclipseState object." << std::endl;
|
||||||
std::cerr << "Exception caught: " << e.what() << std::endl;
|
std::cerr << "Exception caught: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
@ -579,6 +587,13 @@ namespace Opm
|
|||||||
|
|
||||||
int argc_;
|
int argc_;
|
||||||
char** argv_;
|
char** argv_;
|
||||||
|
bool outputCout_;
|
||||||
|
bool outputFiles_;
|
||||||
|
double setupTime_;
|
||||||
|
std::shared_ptr<Opm::Deck> deck_;
|
||||||
|
std::shared_ptr<Opm::EclipseState> eclipseState_;
|
||||||
|
std::shared_ptr<Opm::Schedule> schedule_;
|
||||||
|
std::shared_ptr<Opm::SummaryConfig> summaryConfig_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Opm
|
} // namespace Opm
|
||||||
|
Loading…
Reference in New Issue
Block a user