Use std::shared_ptr as holder type.

Use std::shared_ptr as holder type for some Pybind11 classes such that
they can be shared with opm.simulators.
This commit is contained in:
Håkon Hægland
2021-09-20 11:43:50 +02:00
parent c0d7ca8136
commit 29c4ffcdc9
4 changed files with 32 additions and 4 deletions

View File

@@ -45,7 +45,14 @@ namespace {
void python::common::export_Deck(py::module &module) {
py::class_< Deck >(module, "Deck")
// Note: In the below class we std::shared_ptr as the holder type, see:
//
// https://pybind11.readthedocs.io/en/stable/advanced/smart_ptrs.html
//
// this makes it possible to share the returned object with e.g. and
// opm.simulators.BlackOilSimulator Python object
//
py::class_< Deck, std::shared_ptr<Deck> >(module, "Deck")
.def( "__len__", &size )
.def( "__contains__", &hasKeyword )
.def("__iter__",

View File

@@ -17,7 +17,14 @@ void python::common::export_EclipseConfig(py::module& module)
py::class_< EclipseConfig >( module, "EclipseConfig" )
.def( "init", py::overload_cast<>(&EclipseConfig::init, py::const_));
py::class_< SummaryConfig >( module, "SummaryConfig")
// Note: In the below class we std::shared_ptr as the holder type, see:
//
// https://pybind11.readthedocs.io/en/stable/advanced/smart_ptrs.html
//
// this makes it possible to share the returned object with e.g. and
// opm.simulators.BlackOilSimulator Python object
//
py::class_< SummaryConfig, std::shared_ptr<SummaryConfig> >( module, "SummaryConfig")
.def(py::init([](const Deck& deck, const EclipseState& state, const Schedule& schedule) {
return SummaryConfig( deck, schedule, state.fieldProps(), state.aquifer() );
} ) )

View File

@@ -93,7 +93,14 @@ namespace {
void python::common::export_EclipseState(py::module& module) {
py::class_< EclipseState >( module, "EclipseState" )
// Note: In the below class we std::shared_ptr as the holder type, see:
//
// https://pybind11.readthedocs.io/en/stable/advanced/smart_ptrs.html
//
// this makes it possible to share the returned object with e.g. and
// opm.simulators.BlackOilSimulator Python object
//
py::class_< EclipseState, std::shared_ptr<EclipseState> >( module, "EclipseState" )
.def(py::init<const Deck&>())
.def_property_readonly( "title", &EclipseState::getTitle )
.def( "field_props", &get_field_props, ref_internal)

View File

@@ -107,7 +107,14 @@ void python::common::export_Schedule(py::module& module) {
.def("group", &get_group, ref_internal);
py::class_< Schedule >( module, "Schedule")
// Note: In the below class we std::shared_ptr as the holder type, see:
//
// https://pybind11.readthedocs.io/en/stable/advanced/smart_ptrs.html
//
// this makes it possible to share the returned object with e.g. and
// opm.simulators.BlackOilSimulator Python object
//
py::class_< Schedule, std::shared_ptr<Schedule> >( module, "Schedule")
.def(py::init<const Deck&, const EclipseState& >())
.def("_groups", &get_groups )
.def_property_readonly( "start", &get_start_time )