Merge pull request #1378 from joakim-hove/wrap-summarystate
python wrapper for summarystate
This commit is contained in:
@@ -200,6 +200,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
|
||||
|
||||
@@ -20,6 +20,7 @@ void python::common::export_all(py::module& module) {
|
||||
export_UnitSystem(module);
|
||||
export_Log(module);
|
||||
export_IO(module);
|
||||
export_SummaryState(module);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,6 +31,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
|
||||
|
||||
55
python/cxx/summary_state.cpp
Normal file
55
python/cxx/summary_state.cpp
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <chrono>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
|
||||
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/chrono.h>
|
||||
#include "export.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
std::vector<std::string> groups(const SummaryState * st) {
|
||||
return st->groups();
|
||||
}
|
||||
|
||||
std::vector<std::string> wells(const SummaryState * st) {
|
||||
return st->wells();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void python::common::export_SummaryState(py::module& module) {
|
||||
|
||||
py::class_<SummaryState>(module, "SummaryState")
|
||||
.def(py::init<std::chrono::system_clock::time_point>())
|
||||
.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);
|
||||
}
|
||||
@@ -21,6 +21,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
|
||||
|
||||
1
python/python/opm/io/sim/__init__.py
Normal file
1
python/python/opm/io/sim/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from opm._common import SummaryState
|
||||
@@ -50,6 +50,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'
|
||||
|
||||
42
python/tests/test_summarystate.py
Normal file
42
python/tests/test_summarystate.py
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user