Skip to content

Commit

Permalink
Fixed bug ecl_region_select_equal__( )
Browse files Browse the repository at this point in the history
  • Loading branch information
joakim-hove committed Apr 5, 2017
1 parent b97284f commit 19c51b8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
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
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
2 changes: 2 additions & 0 deletions python/tests/core/ecl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(TEST_SOURCES
test_kw_function.py
test_layer.py
test_npv.py
test_region.py
test_region_statoil.py
test_restart.py
test_rft.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 Down
37 changes: 37 additions & 0 deletions python/tests/core/ecl/test_region.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
# Copyright (C) 2017 Statoil ASA, Norway.
#
# The file 'test_region.py' is part of ERT - Ensemble based Reservoir Tool.
#
# ERT 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.
#
# ERT 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 at <http://www.gnu.org/licenses/gpl.html>
# for more details.
from ert.ecl import EclGrid, EclKW, EclRegion, EclDataType
from ert.ecl.faults import Layer
from ert.test import ExtendedTestCase


class RegionTest(ExtendedTestCase):

def test_equal(self):
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 )

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

with self.assertRaises(ValueError):
region.select_equal( kw_float , 1 )

0 comments on commit 19c51b8

Please sign in to comment.