mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-01-19 16:22:57 -06:00
3749dcab7d
A resubmission of commit 11eaa3d7
in PR #2403 and PR #2443 and continues
the work in #2555 implementing Python bindings to the flow simulator.
The step_init() method initializes the simulation. It is required for the
Python script to run step_init() before calling the step() method (which
will be implemented in a later commit).
61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
#include "config.h"
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
|
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
|
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
|
|
#define FLOW_BLACKOIL_ONLY
|
|
#include <opm/simulators/flow/Main.hpp>
|
|
#include <opm/simulators/flow/FlowMainEbos.hpp>
|
|
#include <pybind11/pybind11.h>
|
|
#include <pybind11/embed.h>
|
|
// NOTE: EXIT_SUCCESS, EXIT_FAILURE is defined in cstdlib
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <opm/simulators/flow/python/simulators.hpp>
|
|
|
|
namespace py = pybind11;
|
|
|
|
namespace Opm::Pybind {
|
|
BlackOilSimulator::BlackOilSimulator( const std::string &deckFilename)
|
|
: deckFilename_(deckFilename), hasRunInit_(false)
|
|
{
|
|
}
|
|
|
|
int BlackOilSimulator::run()
|
|
{
|
|
auto mainObject = Opm::Main( deckFilename_ );
|
|
return mainObject.runDynamic();
|
|
}
|
|
|
|
int BlackOilSimulator::step_init()
|
|
{
|
|
|
|
if (hasRunInit_) {
|
|
// Running step_init() multiple times is not implemented yet,
|
|
// currently we just do nothing and return
|
|
return EXIT_SUCCESS;
|
|
}
|
|
main_ = std::make_unique<Opm::Main>( deckFilename_ );
|
|
int exitCode = EXIT_SUCCESS;
|
|
mainEbos_ = main_->initFlowEbosBlackoil(exitCode);
|
|
if (mainEbos_) {
|
|
int result = mainEbos_->executeInitStep();
|
|
hasRunInit_ = true;
|
|
return result;
|
|
}
|
|
else {
|
|
return exitCode;
|
|
}
|
|
}
|
|
|
|
} // namespace Opm::Python
|
|
|
|
PYBIND11_MODULE(simulators, m)
|
|
{
|
|
py::class_<Opm::Pybind::BlackOilSimulator>(m, "BlackOilSimulator")
|
|
.def(py::init< const std::string& >())
|
|
.def("run", &Opm::Pybind::BlackOilSimulator::run)
|
|
.def("step_init", &Opm::Pybind::BlackOilSimulator::step_init);
|
|
}
|