Skip to content

Commit

Permalink
Use the generated .hpp file in the cpp files of opm-common
Browse files Browse the repository at this point in the history
  • Loading branch information
lisajulia committed Jun 17, 2024
1 parent dc62cde commit 5ae5cdc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 104 deletions.
20 changes: 11 additions & 9 deletions pybind11/opmcommon/eclipse_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include "export.hpp"

// NOTE: This file will be generated at compile time and placed in the build directory
// See python/generate_docstring_hpp.py, and python/simulators/CMakeLists.txt for details
#include "OpmCommonPythonDoc.hpp"

namespace {

Expand Down Expand Up @@ -96,29 +99,28 @@ namespace {

void python::common::export_EclipseState(py::module& module) {

using namespace Opm::Common::DocStrings;

// 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", R"pbdoc(
The Opm::EclipseState class - this is a representation of all static properties in the model,
ranging from porosity to relperm tables. The content of the EclipseState is immutable and may not
be changed at runtime.)pbdoc")
py::class_< EclipseState, std::shared_ptr<EclipseState> >( module, "EclipseState", EclipseStateClass_docstring)
.def(py::init<const Deck&>())
.def_property_readonly( "title", &EclipseState::getTitle )
.def( "field_props", &get_field_props, ref_internal)
.def( "grid", &EclipseState::getInputGrid, ref_internal)
.def( "config", &EclipseState::cfg, ref_internal)
.def( "tables", &EclipseState::getTableManager, ref_internal)
.def( "has_input_nnc", &EclipseState::hasInputNNC )
.def( "simulation", &EclipseState::getSimulationConfig, ref_internal)
.def( "input_nnc", &getNNC )
.def( "faultNames", &faultNames )
.def( "faultFaces", &faultFaces, py::arg("fault_name"))
.def( "jfunc", &jfunc )
.def( "simulation", &EclipseState::getSimulationConfig, ref_internal, EclipseState_simulation_docstring)
.def( "input_nnc", &getNNC, EclipseState_input_nnc_docstring)
.def( "faultNames", &faultNames, EclipseState_faultNames_docstring)
.def( "faultFaces", &faultFaces, py::arg("fault_name"), EclipseState_faultFaces_docstring)
.def( "jfunc", &jfunc, EclipseState_jfunc_docstring)
;

}
94 changes: 18 additions & 76 deletions pybind11/opmcommon/schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include <pybind11/chrono.h>
#include "export.hpp"

// NOTE: This file will be generated at compile time and placed in the build directory
// See python/generate_docstring_hpp.py, and python/simulators/CMakeLists.txt for details
#include "OpmCommonPythonDoc.hpp"

namespace {

Expand Down Expand Up @@ -192,95 +195,34 @@ namespace {

void python::common::export_Schedule(py::module& module) {

using namespace Opm::Common::DocStrings;

// Note: In the below class we use 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", R"pbdoc(
The Opm::Schedule class - this is a representation of all the content from
the SCHEDULE section, notably all well and group information and the timestepping.
)pbdoc")
py::class_< Schedule, std::shared_ptr<Schedule> >( module, "Schedule", ScheduleClass_docstring)
.def(py::init<const Deck&, const EclipseState& >(), py::arg("deck"), py::arg("eclipse_state"))
.def("_groups", &get_groups, py::arg("report_step"))
.def("_groups", &get_groups, py::arg("report_step"), Schedule_groups_docstring)
.def_property_readonly( "start", &get_start_time )
.def_property_readonly( "end", &get_end_time )
.def_property_readonly( "timesteps", &get_timesteps )
.def("__len__", &Schedule::size)
.def("__getitem__", &getitem)
.def("shut_well", py::overload_cast<const std::string&, std::size_t>(&Schedule::shut_well), py::arg("well_name"), py::arg("step"), R"(
Shut down a well at a given report step.
Args:
well_name (str): The name of the well to shut down.
report_step (int): The report step at which to shut down the well.
Raises:
ValueError: If the report step is in the past or exceeds the duration of the simulation.
Returns:
None
)")
.def("shut_well", py::overload_cast<const std::string&>(&Schedule::shut_well), py::arg("well_name"), R"(
Shut down a well at the current report step.
Args:
well_name (str): The name of the well to shut down.
Returns:
None
)")
.def("open_well", py::overload_cast<const std::string&, std::size_t>(&Schedule::open_well), py::arg("well_name"), py::arg("step"), R"(
Open a well at a given report step.
Args:
well_name (str): The name of the well to open.
report_step (int): The report step at which to open the well.
Raises:
ValueError: If the report step is in the past or exceeds the duration of the simulation.
Returns:
None
)")
.def("open_well", py::overload_cast<const std::string&>(&Schedule::open_well), py::arg("well_name"), R"(
Open a well at the current report step.
Args:
well_name (str): The name of the well to open.
Returns:
None
)")
.def("stop_well", py::overload_cast<const std::string&, std::size_t>(&Schedule::stop_well), py::arg("well_name"), py::arg("step"), R"(
Stop a well at a given report step.
Args:
well_name (str): The name of the well to stop.
report_step (int): The report step at which to stop the well.
Raises:
ValueError: If the report step is in the past or exceeds the duration of the simulation.
Returns:
None
)")
.def("stop_well", py::overload_cast<const std::string&>(&Schedule::stop_well), py::arg("well_name"), R"(
Stop a well at the current report step.
Args:
well_name (str): The name of the well to stop.
Returns:
None
)")
.def( "get_wells", &Schedule::getWells, py::arg("well_name_pattern"))
.def( "get_injection_properties", &get_injection_properties, py::arg("well_name"), py::arg("report_step"))
.def( "get_production_properties", &get_production_properties, py::arg("well_name"), py::arg("report_step"))
.def("__getitem__", &getitem, py::arg("report_step"), Schedule_getitem_docstring)
.def("shut_well", py::overload_cast<const std::string&, std::size_t>(&Schedule::shut_well), py::arg("well_name"), py::arg("step"), Schedule_shut_well_well_name_step_docstring)
.def("shut_well", py::overload_cast<const std::string&>(&Schedule::shut_well), py::arg("well_name"), Schedule_shut_well_well_name_docstring)
.def("open_well", py::overload_cast<const std::string&, std::size_t>(&Schedule::open_well), py::arg("well_name"), py::arg("step"), Schedule_open_well_well_name_step_docstring)
.def("open_well", py::overload_cast<const std::string&>(&Schedule::open_well), py::arg("well_name"), Schedule_open_well_well_name_docstring)
.def("stop_well", py::overload_cast<const std::string&, std::size_t>(&Schedule::stop_well), py::arg("well_name"), py::arg("step"), Schedule_stop_well_well_name_step_docstring)
.def("stop_well", py::overload_cast<const std::string&>(&Schedule::stop_well), py::arg("well_name"), Schedule_stop_well_well_name_docstring)
.def( "get_wells", &Schedule::getWells, py::arg("well_name_pattern"), Schedule_get_wells_docstring)
.def( "get_injection_properties", &get_injection_properties, py::arg("well_name"), py::arg("report_step"), Schedule_get_injection_properties_docstring)
.def( "get_production_properties", &get_production_properties, py::arg("well_name"), py::arg("report_step"), Schedule_get_production_properties_docstring)
.def("well_names", py::overload_cast<const std::string&>(&Schedule::wellNames, py::const_), py::arg("well_name_pattern"))
.def( "get_well", &get_well, py::arg("well_name"), py::arg("report_step"))
.def( "get_well", &get_well, py::arg("well_name"), py::arg("report_step"), Schedule_get_well_docstring)
.def( "insert_keywords", py::overload_cast<Schedule&, py::list&, std::size_t>(&insert_keywords), py::arg("keywords"), py::arg("step"))
.def( "insert_keywords", py::overload_cast<Schedule&, const std::string&, std::size_t, const UnitSystem&>(&insert_keywords), py::arg("data"), py::arg("step"), py::arg("unit_system"))
.def( "insert_keywords", py::overload_cast<Schedule&, const std::string&, std::size_t>(&insert_keywords), py::arg("data"), py::arg("step"))
Expand Down
10 changes: 8 additions & 2 deletions pybind11/opmcommon/schedule_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include "export.hpp"

// NOTE: This file will be generated at compile time and placed in the build directory
// See python/generate_docstring_hpp.py, and python/simulators/CMakeLists.txt for details
#include "OpmCommonPythonDoc.hpp"

namespace {
const Group& get_group(const ScheduleState& st, const std::string& group_name) {
return st.groups.get(group_name);
Expand All @@ -18,8 +22,10 @@ namespace {
*/
void python::common::export_ScheduleState(py::module& module) {

using namespace Opm::Common::DocStrings;

py::class_<ScheduleState>(module, "ScheduleState")
.def_property_readonly("nupcol", py::overload_cast<>(&ScheduleState::nupcol, py::const_))
.def("group", &get_group, ref_internal, py::arg("group_name"))
.def_property_readonly("nupcol", py::overload_cast<>(&ScheduleState::nupcol, py::const_), ScheduleState_nupcol_docstring)
.def("group", &get_group, ref_internal, py::arg("group_name"), ScheduleState_get_group_docstring)
;
}
29 changes: 16 additions & 13 deletions pybind11/opmcommon/summary_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <pybind11/chrono.h>
#include "export.hpp"

// NOTE: This file will be generated at compile time and placed in the build directory
// See python/generate_docstring_hpp.py, and python/simulators/CMakeLists.txt for details
#include "OpmCommonPythonDoc.hpp"

namespace {


Expand All @@ -42,22 +46,21 @@ std::vector<std::string> wells(const SummaryState * st) {

void python::common::export_SummaryState(py::module& module) {

py::class_<SummaryState, std::shared_ptr<SummaryState>>(module, "SummaryState", R"pbdoc(
The Opm::SummaryState class - this is where the current summary results of the simulator are stored.
The SummaryState class has methods to get hold of well, group and general variables.
)pbdoc")
using namespace Opm::Common::DocStrings;

py::class_<SummaryState, std::shared_ptr<SummaryState>>(module, "SummaryState", SummaryStateClass_docstring)
.def(py::init<std::time_t>())
.def("update", &SummaryState::update)
.def("update_well_var", &SummaryState::update_well_var, py::arg("well_name"), py::arg("variable_name"), py::arg("new_value"))
.def("update_group_var", &SummaryState::update_group_var, py::arg("group_name"), py::arg("variable_name"), py::arg("new_value"))
.def("well_var", py::overload_cast<const std::string&, const std::string&>(&SummaryState::get_well_var, py::const_), py::arg("well_name"), py::arg("variable_name"))
.def("group_var", py::overload_cast<const std::string&, const std::string&>(&SummaryState::get_group_var, py::const_), py::arg("group_name"), py::arg("variable_name"))
.def("elapsed", &SummaryState::get_elapsed)
.def_property_readonly("groups", groups)
.def_property_readonly("wells", wells)
.def("update_well_var", &SummaryState::update_well_var, py::arg("well_name"), py::arg("variable_name"), py::arg("new_value"), SummaryState_update_well_var_docstring)
.def("update_group_var", &SummaryState::update_group_var, py::arg("group_name"), py::arg("variable_name"), py::arg("new_value"), SummaryState_update_group_var_docstring)
.def("well_var", py::overload_cast<const std::string&, const std::string&>(&SummaryState::get_well_var, py::const_), py::arg("well_name"), py::arg("variable_name"), SummaryState_well_var_docstring)
.def("group_var", py::overload_cast<const std::string&, const std::string&>(&SummaryState::get_group_var, py::const_), py::arg("group_name"), py::arg("variable_name"), SummaryState_group_var_docstring)
.def("elapsed", &SummaryState::get_elapsed, SummaryState_elapsed_docstring)
.def_property_readonly("groups", groups, SummaryState_groups_docstring)
.def_property_readonly("wells", wells, SummaryState_wells_docstring)
.def("__contains__", &SummaryState::has)
.def("has_well_var", py::overload_cast<const std::string&, const std::string&>(&SummaryState::has_well_var, py::const_), py::arg("well_name"), py::arg("variable_name"))
.def("has_group_var", py::overload_cast<const std::string&, const std::string&>(&SummaryState::has_group_var, py::const_), py::arg("group_name"), py::arg("variable_name"))
.def("has_well_var", py::overload_cast<const std::string&, const std::string&>(&SummaryState::has_well_var, py::const_), py::arg("well_name"), py::arg("variable_name"), SummaryState_has_well_var_docstring)
.def("has_group_var", py::overload_cast<const std::string&, const std::string&>(&SummaryState::has_group_var, py::const_), py::arg("group_name"), py::arg("variable_name"), SummaryState_has_group_var_docstring)
.def("__setitem__", &SummaryState::set)
.def("__getitem__", py::overload_cast<const std::string&>(&SummaryState::get, py::const_))
;
Expand Down
13 changes: 9 additions & 4 deletions pybind11/opmcommon/well.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <pybind11/stl.h>
#include "export.hpp"

// NOTE: This file will be generated at compile time and placed in the build directory
// See python/generate_docstring_hpp.py, and python/simulators/CMakeLists.txt for details
#include "OpmCommonPythonDoc.hpp"

namespace {

Expand Down Expand Up @@ -34,17 +37,19 @@ namespace {

void python::common::export_Well(py::module& module) {

using namespace Opm::Common::DocStrings;

py::class_< Well >( module, "Well")
.def_property_readonly( "name", &Well::name )
.def_property_readonly( "preferred_phase", &preferred_phase )
.def( "pos", &get_pos )
.def( "pos", &get_pos, Well_pos_docstring)
.def( "status", &status )
.def( "isdefined", &Well::hasBeenDefined )
.def( "isdefined", &Well::hasBeenDefined, Well_isdefined_docstring)
.def( "isinjector", &Well::isInjector )
.def( "isproducer", &Well::isProducer )
.def( "group", &Well::groupName )
.def( "guide_rate", &Well::getGuideRate )
.def( "available_gctrl", &Well::isAvailableForGroupControl )
.def( "connections", &connections );
.def( "available_gctrl", &Well::isAvailableForGroupControl, Well_available_gctrl_docstring)
.def( "connections", &connections, Well_connections_docstring);

}

0 comments on commit 5ae5cdc

Please sign in to comment.