diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 350030677..cd5a1b990 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -197,6 +197,7 @@ if(ENABLE_ECL_INPUT) python/cxx/parsecontext.cpp python/cxx/parser.cpp python/cxx/schedule.cpp + python/cxx/summary_state.cpp python/cxx/table_manager.cpp python/cxx/unit_system.cpp python/cxx/well.cpp diff --git a/python/cxx/export.cpp b/python/cxx/export.cpp index 46054e227..4eb46e5e3 100644 --- a/python/cxx/export.cpp +++ b/python/cxx/export.cpp @@ -19,6 +19,7 @@ void python::common::export_all(py::module& module) { export_UnitSystem(module); export_Log(module); export_IO(module); + export_SummaryState(module); } diff --git a/python/cxx/export.hpp b/python/cxx/export.hpp index 0dc60a142..154eebcbe 100644 --- a/python/cxx/export.hpp +++ b/python/cxx/export.hpp @@ -30,6 +30,7 @@ void export_TableManager(py::module& module); void export_Well(py::module& module); void export_Log(py::module& module); void export_IO(py::module& module); +void export_SummaryState(py::module& module); } #endif //SUNBEAM_HPP diff --git a/python/cxx/summary_state.cpp b/python/cxx/summary_state.cpp new file mode 100644 index 000000000..a46ef1ff4 --- /dev/null +++ b/python/cxx/summary_state.cpp @@ -0,0 +1,55 @@ +/* + Copyright 2019 Equinor ASA. + + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . +*/ +#include + +#include + +#include +#include +#include "export.hpp" + +namespace { + + +std::vector groups(const SummaryState * st) { + return st->groups(); +} + +std::vector wells(const SummaryState * st) { + return st->wells(); +} + + +} + + +void python::common::export_SummaryState(py::module& module) { + + py::class_(module, "SummaryState") + .def(py::init()) + .def("update", &SummaryState::update) + .def("update_well_var", &SummaryState::update_well_var) + .def("update_group_var", &SummaryState::update_group_var) + .def("well_var", &SummaryState::get_well_var) + .def("group_var", &SummaryState::get_group_var) + .def("elapsed", &SummaryState::get_elapsed) + .def_property_readonly("groups", groups) + .def_property_readonly("wells", wells) + .def("__getitem__", &SummaryState::get); +} diff --git a/python/python/opm/_common.py b/python/python/opm/_common.py index df593dfb3..d1a8298c6 100644 --- a/python/python/opm/_common.py +++ b/python/python/opm/_common.py @@ -19,6 +19,7 @@ from .libopmcommon_python import Schedule from .libopmcommon_python import OpmLog from .libopmcommon_python import SummaryConfig from .libopmcommon_python import EclFile, eclArrType +from .libopmcommon_python import SummaryState #from .schedule import Well, Connection, Schedule #from .config import EclipseConfig diff --git a/python/python/opm/io/sim/__init__.py b/python/python/opm/io/sim/__init__.py new file mode 100644 index 000000000..1098038c5 --- /dev/null +++ b/python/python/opm/io/sim/__init__.py @@ -0,0 +1 @@ +from opm._common import SummaryState diff --git a/python/setup.py b/python/setup.py index e651b5a35..5f12da5c0 100644 --- a/python/setup.py +++ b/python/setup.py @@ -49,6 +49,7 @@ ext_modules = [ 'cxx/parsecontext.cpp', 'cxx/parser.cpp', 'cxx/schedule.cpp', + 'cxx/summary_state.cpp', 'cxx/table_manager.cpp', 'cxx/well.cpp', 'cxx/export.cpp' diff --git a/python/tests/test_summarystate.py b/python/tests/test_summarystate.py new file mode 100644 index 000000000..b41bedd8d --- /dev/null +++ b/python/tests/test_summarystate.py @@ -0,0 +1,42 @@ +import datetime +import unittest + +import opm.io.sim + +class TestSummaryState(unittest.TestCase): + + def setUp(self): + pass + + def test_create(self): + st = opm.io.sim.SummaryState(datetime.datetime.now()) + st.update("FOPT", 100) + self.assertEqual(st["FOPT"], 100) + + + with self.assertRaises(IndexError): + x = st["FWPR"] + + st.update_well_var("OP1", "WOPR", 100) + st.update_well_var("OP2", "WOPR", 200) + st.update_well_var("OP3", "WOPR", 300) + self.assertEqual(st.well_var("OP1", "WOPR"), 100) + + st.update_group_var("G1", "GOPR", 100) + st.update_group_var("G2", "GOPR", 200) + st.update_group_var("G3", "GOPR", 300) + self.assertEqual(st.group_var("G3", "GOPR"), 300) + + groups = st.groups + self.assertEqual(len(groups), 3) + self.assertTrue( "G1" in groups ) + self.assertTrue( "G2" in groups ) + self.assertTrue( "G3" in groups ) + + wells = st.wells + self.assertEqual(len(wells), 3) + self.assertTrue( "OP1" in wells ) + self.assertTrue( "OP2" in wells ) + self.assertTrue( "OP3" in wells ) + + el = st.elapsed()