mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #2830 from hakonhagland/step_cleanup
Implements a Python step_cleanup() method.
This commit is contained in:
commit
a28bd3ab90
@ -335,6 +335,15 @@ namespace Opm
|
|||||||
return simulator_->runStep(*simtimer_);
|
return simulator_->runStep(*simtimer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called from Python to cleanup after having executed the last
|
||||||
|
// executeStep()
|
||||||
|
int executeStepsCleanup()
|
||||||
|
{
|
||||||
|
SimulatorReport report = simulator_->finalize();
|
||||||
|
runSimulatorAfterSim_(report);
|
||||||
|
return report.success.exit_status;
|
||||||
|
}
|
||||||
|
|
||||||
// Print an ASCII-art header to the PRT and DEBUG files.
|
// Print an ASCII-art header to the PRT and DEBUG files.
|
||||||
// \return Whether unkown keywords were seen during parsing.
|
// \return Whether unkown keywords were seen during parsing.
|
||||||
static void printPRTHeader(bool output_cout)
|
static void printPRTHeader(bool output_cout)
|
||||||
|
@ -35,14 +35,17 @@ public:
|
|||||||
BlackOilSimulator( const std::string &deckFilename);
|
BlackOilSimulator( const std::string &deckFilename);
|
||||||
int run();
|
int run();
|
||||||
int step();
|
int step();
|
||||||
int step_init();
|
int stepInit();
|
||||||
|
int stepCleanup();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string deckFilename_;
|
const std::string deckFilename_;
|
||||||
|
bool hasRunInit_ = false;
|
||||||
|
bool hasRunCleanup_ = false;
|
||||||
|
|
||||||
std::unique_ptr<FlowMainEbosType> mainEbos_;
|
std::unique_ptr<FlowMainEbosType> mainEbos_;
|
||||||
std::unique_ptr<Opm::Main> main_;
|
std::unique_ptr<Opm::Main> main_;
|
||||||
bool hasRunInit_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Opm::Python
|
} // namespace Opm::Pybind
|
||||||
#endif // OPM_SIMULATORS_HEADER_INCLUDED
|
#endif // OPM_SIMULATORS_HEADER_INCLUDED
|
||||||
|
@ -18,7 +18,7 @@ namespace py = pybind11;
|
|||||||
|
|
||||||
namespace Opm::Pybind {
|
namespace Opm::Pybind {
|
||||||
BlackOilSimulator::BlackOilSimulator( const std::string &deckFilename)
|
BlackOilSimulator::BlackOilSimulator( const std::string &deckFilename)
|
||||||
: deckFilename_(deckFilename), hasRunInit_(false)
|
: deckFilename_{deckFilename}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,17 +33,30 @@ int BlackOilSimulator::step()
|
|||||||
if (!hasRunInit_) {
|
if (!hasRunInit_) {
|
||||||
throw std::logic_error("step() called before step_init()");
|
throw std::logic_error("step() called before step_init()");
|
||||||
}
|
}
|
||||||
|
if (hasRunCleanup_) {
|
||||||
|
throw std::logic_error("step() called after step_cleanup()");
|
||||||
|
}
|
||||||
return mainEbos_->executeStep();
|
return mainEbos_->executeStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
int BlackOilSimulator::step_init()
|
int BlackOilSimulator::stepCleanup()
|
||||||
|
{
|
||||||
|
hasRunCleanup_ = true;
|
||||||
|
return mainEbos_->executeStepsCleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
int BlackOilSimulator::stepInit()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (hasRunInit_) {
|
if (hasRunInit_) {
|
||||||
// Running step_init() multiple times is not implemented yet,
|
// Running step_init() multiple times is not implemented yet,
|
||||||
// currently we just do nothing and return
|
if (hasRunCleanup_) {
|
||||||
|
throw std::logic_error("step_init() called again");
|
||||||
|
}
|
||||||
|
else {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
main_ = std::make_unique<Opm::Main>( deckFilename_ );
|
main_ = std::make_unique<Opm::Main>( deckFilename_ );
|
||||||
int exitCode = EXIT_SUCCESS;
|
int exitCode = EXIT_SUCCESS;
|
||||||
mainEbos_ = main_->initFlowEbosBlackoil(exitCode);
|
mainEbos_ = main_->initFlowEbosBlackoil(exitCode);
|
||||||
@ -65,5 +78,6 @@ PYBIND11_MODULE(simulators, m)
|
|||||||
.def(py::init< const std::string& >())
|
.def(py::init< const std::string& >())
|
||||||
.def("run", &Opm::Pybind::BlackOilSimulator::run)
|
.def("run", &Opm::Pybind::BlackOilSimulator::run)
|
||||||
.def("step", &Opm::Pybind::BlackOilSimulator::step)
|
.def("step", &Opm::Pybind::BlackOilSimulator::step)
|
||||||
.def("step_init", &Opm::Pybind::BlackOilSimulator::step_init);
|
.def("step_init", &Opm::Pybind::BlackOilSimulator::stepInit)
|
||||||
|
.def("step_cleanup", &Opm::Pybind::BlackOilSimulator::stepCleanup);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user