diff --git a/opm/simulators/flow/Main.hpp b/opm/simulators/flow/Main.hpp index 15587ef0b..10815af73 100644 --- a/opm/simulators/flow/Main.hpp +++ b/opm/simulators/flow/Main.hpp @@ -64,6 +64,7 @@ #include #endif +#include #include BEGIN_PROPERTIES @@ -126,6 +127,17 @@ namespace Opm }; public: Main(int argc, char** argv) : argc_(argc), argv_(argv) { } + + Main(const std::string &filename) + { + deckFilename_.assign(filename); + flowProgName_.assign("flow"); + argc_ = 2; + saveArgs_[0] = const_cast(flowProgName_.c_str()); + saveArgs_[1] = const_cast(deckFilename_.c_str()); + argv_ = saveArgs_; + } + Main(int argc, char** argv, std::shared_ptr deck, @@ -603,6 +615,9 @@ namespace Opm bool outputCout_; bool outputFiles_; double setupTime_; + std::string deckFilename_; + std::string flowProgName_; + char *saveArgs_[2]; std::shared_ptr deck_; std::shared_ptr eclipseState_; std::shared_ptr schedule_; diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index c57487c72..c40c2122f 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,3 +1,4 @@ if(NOT TARGET pybind11) add_subdirectory( pybind11 ) + add_subdirectory( simulators ) endif() diff --git a/python/simulators/CMakeLists.txt b/python/simulators/CMakeLists.txt new file mode 100644 index 000000000..9de35c142 --- /dev/null +++ b/python/simulators/CMakeLists.txt @@ -0,0 +1,14 @@ +pybind11_add_module(simulators simulators.cpp) + +set_target_properties( simulators PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/python/opm2 ) + +target_sources(simulators + PRIVATE + ../../flow/flow_ebos_blackoil.cpp) + +target_link_libraries( simulators PRIVATE opmsimulators ) + +set(PYTHON_PACKAGE_PATH "site-packages") +set(PYTHON_INSTALL_PREFIX "lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/${PYTHON_PACKAGE_PATH}" CACHE STRING "Subdirectory to install Python modules in") + +install(TARGETS simulators DESTINATION ${DEST_PREFIX}${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX}/opm) diff --git a/python/simulators/simulators.cpp b/python/simulators/simulators.cpp new file mode 100644 index 000000000..bf288fe55 --- /dev/null +++ b/python/simulators/simulators.cpp @@ -0,0 +1,38 @@ +#include "config.h" +#include +#include +#include +#include +#define FLOW_BLACKOIL_ONLY +#include +#include +#include +#include +#include + +namespace py = pybind11; + +class BlackOilSimulator +{ +public: + + BlackOilSimulator( const std::string &deckFilename) : deckFilename_(deckFilename) + { + } + + int run() + { + auto mainObject = Opm::Main( deckFilename_ ); + return mainObject.runDynamic(); + } + +private: + const std::string deckFilename_; +}; + +PYBIND11_MODULE(simulators, m) +{ + py::class_(m, "BlackOilSimulator") + .def(py::init< const std::string& >()) + .def("run", &BlackOilSimulator::run); +}