mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Python bindings for the blackoil simulator.
A simplified version of PR #2518 that uses a deck filename to construct the simulator. After private discussion with @joakim-hove it was decided that the construction of the blackoil simulator from Python using deck, ecliseState, schedule and summaryConfig as constructor arguments from \#2518 should be replaced by a constructor taking only the deck filename as parameter. A rewrite of the Python bindings for the blackoil simulator using pybind11 as introduced in PR #2127. The new version uses the refactored flow.cpp introduced in PR #2516 and thus avoids duplication of the code in simulators.cpp. This PR will be the starting point for implementing the Python bindings introduced in PR #2403.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
if(NOT TARGET pybind11)
|
||||
add_subdirectory( pybind11 )
|
||||
add_subdirectory( simulators )
|
||||
endif()
|
||||
|
||||
11
python/simulators/CMakeLists.txt
Normal file
11
python/simulators/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
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 )
|
||||
|
||||
install(TARGETS simulators DESTINATION ${PYTHON_INSTALL_PREFIX}/simulators)
|
||||
38
python/simulators/simulators.cpp
Normal file
38
python/simulators/simulators.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#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 <pybind11/pybind11.h>
|
||||
#include <pybind11/embed.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
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_<BlackOilSimulator>(m, "BlackOilSimulator")
|
||||
.def(py::init< const std::string& >())
|
||||
.def("run", &BlackOilSimulator::run);
|
||||
}
|
||||
Reference in New Issue
Block a user