diff --git a/CMakeLists.txt b/CMakeLists.txt index 115899dba..46aaee513 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,6 +236,7 @@ if (OPM_ENABLE_PYTHON) add_custom_command(OUTPUT python/python/opm/libopmcommon_python.so DEPENDS + python/cxx/unit_system.cpp python/cxx/connection.cpp python/cxx/converters.hpp python/cxx/deck.cpp diff --git a/python/cxx/deck.cpp b/python/cxx/deck.cpp index 27c0dc0ca..d6024fc16 100644 --- a/python/cxx/deck.cpp +++ b/python/cxx/deck.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "converters.hpp" @@ -48,6 +49,15 @@ void python::common::export_Deck(py::module &module) { .def( "__getitem__", &getKeyword_string, ref_internal) .def( "__getitem__", &getKeyword_tuple, ref_internal) .def( "__str__", &str) + + .def("active_unit_system", [](const Deck& deck) -> const UnitSystem& { + return deck.getActiveUnitSystem(); + } ) + + .def("default_unit_system", [](const Deck& deck) -> const UnitSystem& { + return deck.getDefaultUnitSystem(); + } ) + .def( "count", &count ) ; } diff --git a/python/cxx/export.cpp b/python/cxx/export.cpp index ec8289fed..7a9eee1fa 100644 --- a/python/cxx/export.cpp +++ b/python/cxx/export.cpp @@ -3,6 +3,7 @@ void python::common::export_all(py::module& module) { + export_UnitSystem(module); export_ParseContext(module); export_Parser(module); export_Deck(module); diff --git a/python/cxx/export.hpp b/python/cxx/export.hpp index e8019f9ad..18833ec2e 100644 --- a/python/cxx/export.hpp +++ b/python/cxx/export.hpp @@ -14,6 +14,7 @@ const py::return_value_policy move = py::return_value_policy::move; namespace python::common { void export_all(py::module& module); +void export_UnitSystem(py::module& module); void export_Connection(py::module& module); void export_Deck(py::module& module); void export_DeckKeyword(py::module& module); diff --git a/python/cxx/unit_system.cpp b/python/cxx/unit_system.cpp new file mode 100644 index 000000000..8e652d728 --- /dev/null +++ b/python/cxx/unit_system.cpp @@ -0,0 +1,10 @@ +#include + +#include "export.hpp" + + +void python::common::export_UnitSystem(py::module& module) +{ + py::class_(module, "UnitSystem") + .def_property_readonly( "type", &UnitSystem::getName ); +} diff --git a/python/setup.py b/python/setup.py index 33af469c6..2425c7172 100644 --- a/python/setup.py +++ b/python/setup.py @@ -51,6 +51,7 @@ ext_modules = [ Extension( 'libopmcommon_python', [ + 'cxx/unit_system.cpp', 'cxx/connection.cpp', 'cxx/deck.cpp', 'cxx/deck_keyword.cpp', diff --git a/python/tests/test_parser.py b/python/tests/test_parser.py index 94eb1e4b9..a2eb88110 100644 --- a/python/tests/test_parser.py +++ b/python/tests/test_parser.py @@ -41,6 +41,9 @@ FIPNUM def test_create(self): parser = Parser() deck = parser.parse(self.spe3fn) + active_unit_system = deck.active_unit_system() + default_unit_system = deck.default_unit_system() + self.assertEqual(active_unit_system.type, "Field") context = ParseContext() deck = parser.parse(self.spe3fn, context)