Merge pull request #2220 from joakim-hove/sched-state-python
Add very basic Python wrapping for ScheduleState
This commit is contained in:
@@ -88,10 +88,25 @@ namespace {
|
||||
const RestartConfig& restart(const Schedule& sch) {
|
||||
return sch.restart();
|
||||
}
|
||||
|
||||
const ScheduleState& getitem(const Schedule& sch, std::size_t index) {
|
||||
return sch[index];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void python::common::export_Schedule(py::module& module) {
|
||||
|
||||
|
||||
py::class_<ScheduleState>(module, "ScheduleState")
|
||||
.def_property_readonly("nupcol", py::overload_cast<>(&ScheduleState::nupcol, py::const_));
|
||||
|
||||
|
||||
py::class_< Schedule >( module, "Schedule")
|
||||
.def(py::init<const Deck&, const EclipseState& >())
|
||||
.def("_groups", &get_groups )
|
||||
@@ -99,6 +114,8 @@ void python::common::export_Schedule(py::module& module) {
|
||||
.def_property_readonly( "end", &get_end_time )
|
||||
.def_property_readonly( "timesteps", &get_timesteps )
|
||||
.def_property_readonly("restart", &restart)
|
||||
.def("__len__", &Schedule::size)
|
||||
.def("__getitem__", &getitem)
|
||||
.def( "shut_well", &Schedule::shut_well)
|
||||
.def( "open_well", &Schedule::open_well)
|
||||
.def( "stop_well", &Schedule::stop_well)
|
||||
|
||||
@@ -85,5 +85,16 @@ class TestSchedule(unittest.TestCase):
|
||||
self.assertEqual(len(wnames), 2)
|
||||
|
||||
|
||||
def test_getitem(self):
|
||||
deck = Parser().parse(test_path('spe3/SPE3CASE1.DATA'))
|
||||
state = EclipseState(deck)
|
||||
sch = Schedule( deck, state )
|
||||
self.assertEqual(len(sch), 176)
|
||||
with self.assertRaises(IndexError):
|
||||
a = sch[200]
|
||||
|
||||
st100 = sch[100]
|
||||
nupcol = st100.nupcol
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user