mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Refactor run() into prepareRun_()
We would like to add a step() method to simulators.cpp, that will let a Python script advance the simulator one report step at a time. Before calling step(), the Python script will have to call a step_init() method that initializes the simulator, similar to what is done in run() now. In order to avoid duplication of code in run() and step_init() the run() method is here refactored into a prepareRun_() function that can be called from both step_init() and from run().
This commit is contained in:
parent
9f5a13fcfb
commit
c66b564b35
@ -267,10 +267,22 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int run()
|
int run()
|
||||||
|
{
|
||||||
|
if (prepareRun_()) {
|
||||||
|
return Opm::flowEbosBlackoilMain(argc_, argv_, outputCout_, outputFiles_);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
bool prepareRun_()
|
||||||
{
|
{
|
||||||
int argc = argc_;
|
int argc = argc_;
|
||||||
char **argv = argv_;
|
char **argv = argv_;
|
||||||
|
|
||||||
Dune::Timer externalSetupTimer;
|
Dune::Timer externalSetupTimer;
|
||||||
externalSetupTimer.start();
|
externalSetupTimer.start();
|
||||||
|
|
||||||
@ -315,9 +327,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
std::string deckFilename;
|
||||||
std::string outputDir;
|
std::string outputDir;
|
||||||
@ -343,7 +355,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputCout) {
|
if (outputCout_) {
|
||||||
Opm::FlowMainEbos<PreTypeTag>::printBanner();
|
Opm::FlowMainEbos<PreTypeTag>::printBanner();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,7 +366,7 @@ public:
|
|||||||
deckFilename,
|
deckFilename,
|
||||||
outputDir,
|
outputDir,
|
||||||
EWOMS_GET_PARAM(PreTypeTag, std::string, OutputMode),
|
EWOMS_GET_PARAM(PreTypeTag, std::string, OutputMode),
|
||||||
outputCout, "STDOUT_LOGGER");
|
outputCout_, "STDOUT_LOGGER");
|
||||||
|
|
||||||
if (mpiRank == 0) {
|
if (mpiRank == 0) {
|
||||||
setupMessageLimiter(schedule_->getMessageLimits(), "STDOUT_LOGGER");
|
setupMessageLimiter(schedule_->getMessageLimits(), "STDOUT_LOGGER");
|
||||||
@ -372,16 +384,16 @@ public:
|
|||||||
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_);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
eclipseState_.reset( new Opm::EclipseState(*deck_, parseContext, errorGuard ));
|
eclipseState_.reset( new Opm::EclipseState(*deck_, parseContext, errorGuard ));
|
||||||
@ -402,26 +414,26 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto& phases = Opm::Runspec(*deck_).phases();
|
const auto& phases = Opm::Runspec(*deck_).phases();
|
||||||
bool outputFiles = (outputMode != FileOutputMode::OUTPUT_NONE);
|
outputFiles_ = (outputMode != FileOutputMode::OUTPUT_NONE);
|
||||||
|
|
||||||
// Blackoil case
|
// Blackoil case
|
||||||
if( phases.size() == 3 ) {
|
if( phases.size() == 3 ) {
|
||||||
Opm::flowEbosBlackoilSetDeck(externalSetupTimer.elapsed(), *deck_, *eclipseState_, *schedule_, *summaryConfig_);
|
Opm::flowEbosBlackoilSetDeck(externalSetupTimer.elapsed(), *deck_, *eclipseState_, *schedule_, *summaryConfig_);
|
||||||
return Opm::flowEbosBlackoilMain(argc, argv, outputCout, outputFiles);
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (outputCout)
|
if (outputCout_)
|
||||||
std::cerr << "Only blackoil configuration is supported!" << std::endl;
|
std::cerr << "Only blackoil configuration is supported!" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
int argc_;
|
int argc_;
|
||||||
char **argv_;
|
char **argv_;
|
||||||
|
bool outputCout_; // copy of EWOMS parameter "EnableTerminalOutput"
|
||||||
|
bool outputFiles_; // output files?
|
||||||
|
|
||||||
std::shared_ptr<Opm::Deck> deck_;
|
std::shared_ptr<Opm::Deck> deck_;
|
||||||
std::shared_ptr<Opm::EclipseState> eclipseState_;
|
std::shared_ptr<Opm::EclipseState> eclipseState_;
|
||||||
@ -439,4 +451,4 @@ PYBIND11_MODULE(simulators, m)
|
|||||||
.def("setEclipseState", &BlackOilSimulator::setEclipseState)
|
.def("setEclipseState", &BlackOilSimulator::setEclipseState)
|
||||||
.def("setSchedule", &BlackOilSimulator::setSchedule)
|
.def("setSchedule", &BlackOilSimulator::setSchedule)
|
||||||
.def("setSummaryConfig", &BlackOilSimulator::setSummaryConfig);
|
.def("setSummaryConfig", &BlackOilSimulator::setSummaryConfig);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user