mirror of
https://github.com/OPM/opm-simulators.git
synced 2026-09-05 04:40:19 -05:00
Implements the Python step_init() function.
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).
This commit is contained in:
@@ -4,6 +4,7 @@ set_target_properties( simulators PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_
|
||||
|
||||
target_sources(simulators
|
||||
PRIVATE
|
||||
../../opm/simulators/utils/moduleVersion.cpp
|
||||
../../flow/flow_ebos_blackoil.cpp)
|
||||
|
||||
target_link_libraries( simulators PRIVATE opmsimulators )
|
||||
|
||||
@@ -5,34 +5,56 @@
|
||||
#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;
|
||||
|
||||
class BlackOilSimulator
|
||||
namespace Opm::Pybind {
|
||||
BlackOilSimulator::BlackOilSimulator( const std::string &deckFilename)
|
||||
: deckFilename_(deckFilename), hasRunInit_(false)
|
||||
{
|
||||
public:
|
||||
}
|
||||
|
||||
BlackOilSimulator( const std::string &deckFilename) : deckFilename_(deckFilename)
|
||||
{
|
||||
}
|
||||
int BlackOilSimulator::run()
|
||||
{
|
||||
auto mainObject = Opm::Main( deckFilename_ );
|
||||
return mainObject.runDynamic();
|
||||
}
|
||||
|
||||
int 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;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string deckFilename_;
|
||||
};
|
||||
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_<BlackOilSimulator>(m, "BlackOilSimulator")
|
||||
py::class_<Opm::Pybind::BlackOilSimulator>(m, "BlackOilSimulator")
|
||||
.def(py::init< const std::string& >())
|
||||
.def("run", &BlackOilSimulator::run);
|
||||
.def("run", &Opm::Pybind::BlackOilSimulator::run)
|
||||
.def("step_init", &Opm::Pybind::BlackOilSimulator::step_init);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user