Skip to content

Commit

Permalink
Merge pull request Ensembles#1479 from joakim-hove/type-fixup
Browse files Browse the repository at this point in the history
Type fixup
  • Loading branch information
joakim-hove authored Apr 5, 2017
2 parents 78ddecf + 19c51b8 commit 270d0c4
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 182 deletions.
2 changes: 1 addition & 1 deletion libecl/src/ecl_region.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void ecl_region_deselect_cell( ecl_region_type * region , int i , int j , int k)
static void ecl_region_select_equal__( ecl_region_type * region , const ecl_kw_type * ecl_kw, int value , bool select) {
bool global_kw;
ecl_region_assert_kw( region , ecl_kw , &global_kw);
if (ecl_type_is_int(ecl_kw_get_data_type( ecl_kw )))
if (!ecl_type_is_int(ecl_kw_get_data_type( ecl_kw )))
util_abort("%s: sorry - select by equality is only supported for integer keywords \n",__func__);
{
const int * kw_data = ecl_kw_get_int_ptr( ecl_kw );
Expand Down
3 changes: 3 additions & 0 deletions python/python/ert/ecl/ecl_kw.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,9 @@ def data_type( self ):
def type_name( self ):
return self.data_type.type_name

def typeName( self ):
return self.data_type.type_name

def getEclType(self):
warnings.warn("EclTypeEnum is deprecated. " +
"You should instead provide an EclDataType",
Expand Down
4 changes: 4 additions & 0 deletions python/python/ert/ecl/ecl_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ def select_equal( self , ecl_kw , value , intersect = False):
region.select_equal( pvtnum_kw , 4 )
"""
if not ecl_kw.data_type.is_int():
raise ValueError("The select_equal method must have an integer valued keyword - got:%s" % ecl_kw.typeName( ))
self._select_equal( ecl_kw , value )


Expand All @@ -426,6 +428,8 @@ def deselect_equal( self , ecl_kw , value ):
See select_equal() for further documentation.
"""
if not ecl_kw.data_type.is_int():
raise ValueError("The select_equal method must have an integer valued keyword - got:%s" % ecl_kw.typeName( ))
self._deselect_equal( ecl_kw , value )

@select_method
Expand Down
4 changes: 3 additions & 1 deletion python/tests/core/ecl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(TEST_SOURCES
test_layer.py
test_npv.py
test_region.py
test_region_statoil.py
test_restart.py
test_rft.py
test_rft_statoil.py
Expand Down Expand Up @@ -62,6 +63,7 @@ addPythonTest(ecl.ecl_file ecl.test_ecl_file.EclFileTest)
addPythonTest(ecl.ecl_grav ecl.test_grav.EclGravTest)
addPythonTest(ecl.ecl_geertsma ecl.test_geertsma.GeertsmaTest)
addPythonTest(ecl.ecl_type ecl.test_ecl_type.EclDataTypeTest)
addPythonTest(ecl.ecl_region ecl.test_region.RegionTest)


if (STATOIL_TESTDATA_ROOT)
Expand All @@ -72,7 +74,7 @@ if (STATOIL_TESTDATA_ROOT)
addPythonTest(ecl.ecl_init_file ecl.test_ecl_init_file.InitFileTest LABELS StatoilData)
addPythonTest(ecl.ecl_restart_file ecl.test_ecl_restart_file.RestartFileTest LABELS StatoilData)
addPythonTest(ecl.ecl_restart ecl.test_restart.RestartTest LABELS StatoilData )
addPythonTest(ecl.ecl_region ecl.test_region.RegionTest LABELS StatoilData)
addPythonTest(ecl.ecl_region_statoil ecl.test_region_statoil.RegionTest LABELS StatoilData)
addPythonTest(ecl.ecl_rft_statoil ecl.test_rft_statoil.RFTTest LABELS StatoilData)
addPythonTest(ecl.ecl_sum1 ecl.test_sum_statoil.SumTest LABELS StatoilData)
addPythonTest(ecl.ecl_sum_vector ecl.test_ecl_sum_vector.EclSumVectorTest LABELS StatoilData)
Expand Down
5 changes: 5 additions & 0 deletions python/tests/core/ecl/test_ecl_kw.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,8 @@ def test_resize(self):
for i in range(N/2):
self.assertEqual( kw[i] , i )


def test_typename(self):
kw = EclKW("KW" , 100 , EclDataType.ECL_INT)

self.assertEqual( kw.typeName( ) , "INTE")
192 changes: 12 additions & 180 deletions python/tests/core/ecl/test_region.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (C) 2012 Statoil ASA, Norway.
# Copyright (C) 2017 Statoil ASA, Norway.
#
# The file 'test_region.py' is part of ERT - Ensemble based Reservoir Tool.
#
Expand All @@ -14,192 +14,24 @@
#
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
# for more details.
from ert.ecl import EclFile, EclGrid, EclRegion
from ert.ecl import EclGrid, EclKW, EclRegion, EclDataType
from ert.ecl.faults import Layer
from ert.test import ExtendedTestCase


class RegionTest(ExtendedTestCase):
def setUp(self):
case = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE")
self.grid = EclGrid(case)
self.rst_file = EclFile("%s.UNRST" % case)
self.init_file = EclFile("%s.INIT" % case)


def test_kw_imul(self):
P = self.rst_file["PRESSURE"][5]
fipnum = self.init_file["FIPNUM"][0]
fipnum_copy = fipnum.deep_copy()

reg = EclRegion(self.grid, False)
reg.select_more(P, 260)
fipnum.mul(-1, mask=reg)
self.assertFalse(fipnum.equal(fipnum_copy))

fipnum.mul(-1, mask=reg)
self.assertTrue(fipnum.equal(fipnum_copy))

def test_equal(self):
reg1 = EclRegion(self.grid , False)
reg2 = EclRegion(self.grid , False)

self.assertTrue( reg1 == reg2 )

reg1.select_islice(4 , 6)
self.assertFalse( reg1 == reg2 )
reg2.select_islice(4,7)
self.assertFalse( reg1 == reg2 )
reg1.select_islice(7,7)
self.assertTrue( reg1 == reg2 )


def test_kw_idiv(self):
P = self.rst_file["PRESSURE"][5]
fipnum = self.init_file["FIPNUM"][0]
fipnum_copy = fipnum.deep_copy()

reg = EclRegion(self.grid, False)
reg.select_more(P, 260)
fipnum.div(-1, mask=reg)
self.assertFalse(fipnum.equal(fipnum_copy))

fipnum.div(-1, mask=reg)
self.assertTrue(fipnum.equal(fipnum_copy))


def test_kw_iadd(self):
P = self.rst_file["PRESSURE"][5]
fipnum = self.init_file["FIPNUM"][0]
fipnum_copy = fipnum.deep_copy()

reg = EclRegion(self.grid, False)
reg.select_more(P, 260)
fipnum.add(1, mask=reg)
self.assertFalse(fipnum.equal(fipnum_copy))

reg.invert()
fipnum.add(1, mask=reg)

fipnum.sub(1)
self.assertTrue(fipnum.equal(fipnum_copy))


def test_kw_isub(self):
P = self.rst_file["PRESSURE"][5]
fipnum = self.init_file["FIPNUM"][0]
fipnum_copy = fipnum.deep_copy()

reg = EclRegion(self.grid, False)
reg.select_more(P, 260)
fipnum.sub(1, mask=reg)
self.assertFalse(fipnum.equal(fipnum_copy))
fipnum.add(1, mask=reg)
self.assertTrue(fipnum.equal(fipnum_copy))


def test_slice(self):
reg = EclRegion(self.grid, False)
reg.select_islice(0, 5)
OK = True

global_list = reg.getGlobalList()
self.assertEqual(global_list.parent(), reg)

for gi in global_list:
(i, j, k) = self.grid.get_ijk(global_index=gi)
if i > 5:
OK = False
self.assertTrue(OK)
self.assertTrue(self.grid.getNY() * self.grid.getNZ() * 6 == len(reg.getGlobalList()))

reg.select_jslice(7, 8, intersect=True)
OK = True
for gi in reg.getGlobalList():
(i, j, k) = self.grid.get_ijk(global_index=gi)
if i > 5:
OK = False

if j < 7 or j > 8:
OK = False
grid = EclGrid.createRectangular( (10,10,1) , (1,1,1))
kw_int = EclKW( "INT" , grid.getGlobalSize( ) , EclDataType.ECL_INT )
kw_float = EclKW( "FLOAT" , grid.getGlobalSize( ) , EclDataType.ECL_FLOAT )

self.assertTrue(OK)
self.assertTrue(2 * self.grid.getNZ() * 6 == len(reg.getGlobalList()))

reg2 = EclRegion(self.grid, False)
reg2.select_kslice(3, 5)
reg &= reg2
OK = True
for gi in reg.getGlobalList():
(i, j, k) = self.grid.get_ijk(global_index=gi)
if i > 5:
OK = False

if j < 7 or j > 8:
OK = False

if k < 3 or k > 5:
OK = False

self.assertTrue(OK)
self.assertTrue(2 * 3 * 6 == len(reg.getGlobalList()))



def test_index_list(self):
reg = EclRegion(self.grid, False)
reg.select_islice(0, 5)
active_list = reg.getActiveList()
global_list = reg.getGlobalList()



def test_polygon(self):
reg = EclRegion(self.grid, False)
(x,y,z) = self.grid.get_xyz( ijk=(10,10,0) )
dx = 0.1
dy = 0.1
reg.select_inside_polygon( [(x-dx,y-dy) , (x-dx,y+dy) , (x+dx,y+dy) , (x+dx,y-dy)] )
self.assertTrue( self.grid.getNZ() == len(reg.getGlobalList()))


def test_heidrun(self):
root = self.createTestPath("Statoil/ECLIPSE/Heidrun")
grid = EclGrid( "%s/FF12_2013B2_AMAP_AOP-J15_NO62_MOVEX.EGRID" % root)

polygon = []
with open("%s/polygon.ply" % root) as fileH:
for line in fileH.readlines():
tmp = line.split()
polygon.append( (float(tmp[0]) , float(tmp[1])))
self.assertEqual( len(polygon) , 11 )

reg = EclRegion( grid , False )
reg.select_inside_polygon( polygon )
self.assertEqual( 0 , len(reg.getGlobalList()) % grid.getNZ())


def test_layer(self):
region = EclRegion(self.grid, False)
layer = Layer( self.grid.getNX() , self.grid.getNY() + 1)
with self.assertRaises(ValueError):
region.selectFromLayer( layer , 0 , 1 )

layer = Layer( self.grid.getNX() , self.grid.getNY() )
layer[0,0] = 1
layer[1,1] = 1
layer[2,2] = 1

with self.assertRaises(ValueError):
region.selectFromLayer( layer , -1 , 1 )

with self.assertRaises(ValueError):
region.selectFromLayer( layer , self.grid.getNZ() , 1 )

region.selectFromLayer( layer , 0 , 2 )
kw_int[0:49] = 1
region = EclRegion(grid, False)
region.select_equal( kw_int , 1 )
glist = region.getGlobalList()
self.assertEqual(0 , len(glist))
for g in glist:
self.assertEqual( kw_int[g] , 1 )

region.selectFromLayer( layer , 0 , 1 )
glist = region.getGlobalList()
self.assertEqual(3 , len(glist))
with self.assertRaises(ValueError):
region.select_equal( kw_float , 1 )
Loading

0 comments on commit 270d0c4

Please sign in to comment.