From f26bc01f54ea2f7c215da8567b978109a89af0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20Gr=C3=B8n=C3=A5s=20Drange?= Date: Wed, 11 Jan 2017 16:53:52 +0100 Subject: [PATCH] added griddims accessors --- python/sunbeam/sunbeam.cpp | 29 ++++++++++++++++++++++++++--- python/sunbeam/sunbeam.py | 7 +++++++ tests/state.py | 10 ++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/python/sunbeam/sunbeam.cpp b/python/sunbeam/sunbeam.cpp index d00b7922a..bdef56659 100644 --- a/python/sunbeam/sunbeam.cpp +++ b/python/sunbeam/sunbeam.cpp @@ -20,6 +20,24 @@ namespace state { l.append( py::make_tuple( x.cell1, x.cell2, x.trans ) ); return l; } + py::tuple getXYZ( const EclipseState& state ) { + return py::make_tuple( state.getInputGrid().getNX(), + state.getInputGrid().getNY(), + state.getInputGrid().getNZ()); + } + int getNumActive( const EclipseState& state ) { + return state.getInputGrid().getNumActive(); + } + int getCartesianSize( const EclipseState& state ) { + return state.getInputGrid().getCartesianSize(); + } + int getGlobalIndex( const EclipseState& state, int i, int j, int k ) { + return state.getInputGrid().getGlobalIndex(i, j, k); + } + py::tuple getIJK( const EclipseState& state, int g ) { + const auto& ijk = state.getInputGrid().getIJK(g); + return py::make_tuple(ijk[0], ijk[1], ijk[2]); + } } namespace props { @@ -146,10 +164,15 @@ py::def( "parse", parse ); py::class_< EclipseState >( "EclipseState", py::no_init ) .add_property( "title", &EclipseState::getTitle ) - .def( "_schedule", &EclipseState::getSchedule, ref() ) - .def( "_props", &EclipseState::get3DProperties, ref() ) - .def( "has_input_nnc", &EclipseState::hasInputNNC ) + .def( "_schedule", &EclipseState::getSchedule, ref() ) + .def( "_props", &EclipseState::get3DProperties, ref() ) + .def( "has_input_nnc", &EclipseState::hasInputNNC ) .def( "input_nnc", state::getNNC ) + .def( "_getXYZ", state::getXYZ ) + .def( "nactive", state::getNumActive ) + .def( "cartesianSize", state::getCartesianSize ) + .def( "globalIndex", state::getGlobalIndex ) + .def( "getIJK", state::getIJK ) ; py::class_< Eclipse3DProperties >( "Eclipse3DProperties", py::no_init ) diff --git a/python/sunbeam/sunbeam.py b/python/sunbeam/sunbeam.py index 7139cd2a8..924a950ac 100644 --- a/python/sunbeam/sunbeam.py +++ b/python/sunbeam/sunbeam.py @@ -72,6 +72,13 @@ class EclipseState(object): def __repr__(self): return 'EclipseState(title = "%s")' % self.title + def getNX(self): + return self._getXYZ()[0] + def getNY(self): + return self._getXYZ()[1] + def getNZ(self): + return self._getXYZ()[2] + @property def schedule(self): return Schedule(self._schedule()) diff --git a/tests/state.py b/tests/state.py index 8d9790b97..7acb6bf22 100644 --- a/tests/state.py +++ b/tests/state.py @@ -16,3 +16,13 @@ class TestState(unittest.TestCase): def test_state_nnc(self): self.assertFalse(self.state.has_input_nnc()) + + def test_grid(self): + self.assertEqual(9, self.state.getNX()) + self.assertEqual(9, self.state.getNY()) + self.assertEqual(4, self.state.getNZ()) + self.assertEqual(9*9*4, self.state.nactive()) + self.assertEqual(9*9*4, self.state.cartesianSize()) + g,i,j,k = 295,7,5,3 + self.assertEqual(g, self.state.globalIndex(i,j,k)) + self.assertEqual((i,j,k), self.state.getIJK(g))