Made EclipseGrid type with tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
@@ -14,30 +15,33 @@ using namespace Opm;
|
||||
namespace {
|
||||
|
||||
namespace state {
|
||||
py::list getNNC( const EclipseState& state ) {
|
||||
py::list l;
|
||||
for( const auto& x : state.getInputNNC().nncdata() )
|
||||
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]);
|
||||
}
|
||||
py::list getNNC( const EclipseState& state ) {
|
||||
py::list l;
|
||||
for( const auto& x : state.getInputNNC().nncdata() )
|
||||
l.append( py::make_tuple( x.cell1, x.cell2, x.trans ) );
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
namespace grid {
|
||||
py::tuple getXYZ( const EclipseGrid& grid ) {
|
||||
return py::make_tuple( grid.getNX(),
|
||||
grid.getNY(),
|
||||
grid.getNZ());
|
||||
}
|
||||
int getNumActive( const EclipseGrid& grid ) {
|
||||
return grid.getNumActive();
|
||||
}
|
||||
int getCartesianSize( const EclipseGrid& grid ) {
|
||||
return grid.getCartesianSize();
|
||||
}
|
||||
int getGlobalIndex( const EclipseGrid& grid, int i, int j, int k ) {
|
||||
return grid.getGlobalIndex(i, j, k);
|
||||
}
|
||||
py::tuple getIJK( const EclipseGrid& grid, int g ) {
|
||||
const auto& ijk = grid.getIJK(g);
|
||||
return py::make_tuple(ijk[0], ijk[1], ijk[2]);
|
||||
}
|
||||
}
|
||||
|
||||
namespace props {
|
||||
@@ -166,15 +170,19 @@ py::def( "parseData", parseData );
|
||||
|
||||
py::class_< EclipseState >( "EclipseState", py::no_init )
|
||||
.add_property( "title", &EclipseState::getTitle )
|
||||
.def( "_schedule", &EclipseState::getSchedule, ref() )
|
||||
.def( "_schedule", &EclipseState::getSchedule, ref() )
|
||||
.def( "_props", &EclipseState::get3DProperties, ref() )
|
||||
.def( "_grid", &EclipseState::getInputGrid, 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_< EclipseGrid >( "EclipseGrid", py::no_init )
|
||||
.def( "_getXYZ", grid::getXYZ )
|
||||
.def( "nactive", grid::getNumActive )
|
||||
.def( "cartesianSize", grid::getCartesianSize )
|
||||
.def( "globalIndex", grid::getGlobalIndex )
|
||||
.def( "getIJK", grid::getIJK )
|
||||
;
|
||||
|
||||
py::class_< Eclipse3DProperties >( "Eclipse3DProperties", py::no_init )
|
||||
|
||||
@@ -68,10 +68,8 @@ class Eclipse3DProperties(object):
|
||||
def __repr__(self):
|
||||
return 'Eclipse3DProperties()'
|
||||
|
||||
@delegate(lib.EclipseState)
|
||||
class EclipseState(object):
|
||||
def __repr__(self):
|
||||
return 'EclipseState(title = "%s")' % self.title
|
||||
@delegate(lib.EclipseGrid)
|
||||
class EclipseGrid(object):
|
||||
|
||||
def getNX(self):
|
||||
return self._getXYZ()[0]
|
||||
@@ -80,6 +78,21 @@ class EclipseState(object):
|
||||
def getNZ(self):
|
||||
return self._getXYZ()[2]
|
||||
|
||||
def __repr__(self):
|
||||
x,y,z = self._getXYZ()
|
||||
g = self.cartesianSize()
|
||||
na = self.nactive()
|
||||
cnt = '(%d, %d, %d)' % (x,y,z)
|
||||
if na != g:
|
||||
cnt += ', active = %s' % na
|
||||
return 'EclipseGrid(%s)' % cnt
|
||||
|
||||
|
||||
@delegate(lib.EclipseState)
|
||||
class EclipseState(object):
|
||||
def __repr__(self):
|
||||
return 'EclipseState(title = "%s")' % self.title
|
||||
|
||||
@property
|
||||
def schedule(self):
|
||||
return Schedule(self._schedule())
|
||||
@@ -87,6 +100,9 @@ class EclipseState(object):
|
||||
def props(self):
|
||||
return Eclipse3DProperties(self._props())
|
||||
|
||||
def grid(self):
|
||||
return EclipseGrid(self._grid())
|
||||
|
||||
@delegate(lib.Well)
|
||||
class Well(object):
|
||||
|
||||
|
||||
@@ -18,11 +18,13 @@ class TestState(unittest.TestCase):
|
||||
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())
|
||||
grid = self.state.grid()
|
||||
self.assertTrue('EclipseGrid' in repr(grid))
|
||||
self.assertEqual(9, grid.getNX())
|
||||
self.assertEqual(9, grid.getNY())
|
||||
self.assertEqual(4, grid.getNZ())
|
||||
self.assertEqual(9*9*4, grid.nactive())
|
||||
self.assertEqual(9*9*4, grid.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))
|
||||
self.assertEqual(g, grid.globalIndex(i,j,k))
|
||||
self.assertEqual((i,j,k), grid.getIJK(g))
|
||||
|
||||
Reference in New Issue
Block a user