def __getitem__(self, index): return_arg = super(Ecl3DFile, self).__getitem__(index) if isinstance(return_arg, list): kw_list = return_arg else: kw_list = [return_arg] # Go through all the keywords and try inplace promotion to Ecl3DKW for kw in kw_list: try: Ecl3DKW.castFromKW(kw, self.grid) except ValueError: pass return return_arg
def test_Load(self): kw = EclKW.read_grdecl(open(self.src_file, "r"), "PERMX") self.assertTrue(kw) grid = EclGrid(self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE")) kw = Ecl3DKW.read_grdecl(grid, open(self.src_file, "r"), "PERMX") self.assertTrue(isinstance(kw, Ecl3DKW))
def test_setitem(self): actnum = IntVector(default_value=1, initial_size=1000) for i in range(100): actnum[i] = 0 grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) kw = Ecl3DKW("KW", grid, EclDataType.ECL_FLOAT, default_value=77) with self.assertRaises(IndexError): kw[1000] with self.assertRaises(IndexError): kw[0, 10, 100] with self.assertRaises(ValueError): kw[1, 1] with self.assertRaises(ValueError): kw[1, 1, 1, 1] kw.assign(99) self.assertEqual(kw[0, 0, 0], 77) self.assertEqual(kw[0, 0, 1], 99) with self.assertRaises(ValueError): kw[0, 0, 0] = 88 kw[0, 0, 1] = 100 self.assertEqual(kw[0, 0, 1], 100)
def test_create( self ): actnum = IntVector(default_value = 1 , initial_size = 1000) for i in range(100): actnum[i] = 0 grid = EclGrid.createRectangular( (10,10,10) , (1,1,1) , actnum = actnum) kw = Ecl3DKW( "KW" , grid , EclDataType.ECL_FLOAT ) self.assertEqual( len(kw) , grid.getNumActive()) self.assertEqual( (10,10,10) , kw.dims() )
def test_cast(self): actnum = IntVector(default_value=1, initial_size=1000) for i in range(100): actnum[i] = 0 grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) kw_wrong_size = EclKW("KW", 27, EclDataType.ECL_FLOAT) kw_global_size = EclKW("KW", grid.getGlobalSize(), EclDataType.ECL_FLOAT) kw_active_size = EclKW("KW", grid.getNumActive(), EclDataType.ECL_FLOAT) with self.assertRaises(ValueError): Ecl3DKW.castFromKW(kw_wrong_size, grid) Ecl3DKW.castFromKW(kw_global_size, grid) self.assertTrue(isinstance(kw_global_size, Ecl3DKW)) Ecl3DKW.castFromKW(kw_active_size, grid, default_value=66) self.assertTrue(isinstance(kw_active_size, Ecl3DKW)) self.assertEqual(kw_active_size[0, 0, 0], 66) with self.assertRaises(ValueError): kw_active_size[0, 0, 0] = 88
def test_create_global_size( self ): actnum = IntVector(default_value = 1 , initial_size = 1000) for i in range(100): actnum[i] = 0 grid = EclGrid.createRectangular( (10,10,10) , (1,1,1) , actnum = actnum) kw = Ecl3DKW( "KW" , grid , EclDataType.ECL_FLOAT , global_active = True) self.assertEqual( len(kw) , grid.getGlobalSize()) kw.assign(50) self.assertEqual( kw[0,0,0] , 50 ) kw[0,0,0] = 45 self.assertEqual( kw[0,0,0] , 45 )
def test_fix_uninitialized(self): nx = 10 ny = 11 nz = 12 grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) kw = Ecl3DKW("REGIONS", grid, EclDataType.ECL_INT, global_active=True) kw.assign(3) self.assertEqual(3 * nx * ny * nz, sum(kw)) kw[1, 1, 1] = 0 kw[3, 3, 3] = 0 kw[6, 6, 6] = 0 self.assertEqual(3 * nx * ny * nz - 9, sum(kw)) kw.fixUninitialized(grid) self.assertEqual(3 * nx * ny * nz, sum(kw))
def test_compressed_copy(self): actnum = IntVector(default_value = 1 , initial_size = 1000) for i in range(500): actnum[2*i + 1] = 0 grid = EclGrid.createRectangular( (10,10,10) , (1,1,1) , actnum = actnum) kw = Ecl3DKW( "KW" , grid , EclDataType.ECL_INT , global_active = True) for i in range(len(kw)): kw[i] = i kw_copy = kw.compressedCopy() self.assertTrue( isinstance( kw_copy , EclKW ) ) self.assertEqual(len(kw_copy) , 500) for i in range(len(kw_copy)): self.assertEqual(kw_copy[i] , 2*i)
def test_region_filter(self): nx = 10 ny = 10 nz = 1 actnum = IntVector(initial_size=nx * ny * nz, default_value=1) actnum[nx * ny - 1] = 0 grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1), actnum=actnum) self.assertEqual(grid.getNumActive(), nx * ny * nz - 1) kw = Ecl3DKW.create("REGIONS", grid, EclDataType.ECL_INT, global_active=True) kw.assign(0) kw[0:nx * ny / 2] = 1 kw[5, 2, 0] = 0 kw[0, 9, 0] = 2 kw.fixUninitialized(grid) # Not assigned because they are in contact with a '2'; these # two are problem cells. self.assertEqual(kw[0, ny - 2, 0], 0) self.assertEqual(kw[1, ny - 1, 0], 0) # Not assigned because it is inactive self.assertEqual(kw[nx - 1, ny - 1, 0], 0) self.assertEqual(kw[5, 2, 0], 1) for j in range(5, 10): self.assertEqual(kw[5, j, 0], 1) for i in range(10): self.assertEqual(kw[i, 7, 0], 1)
def test_default(self): grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1)) kw = Ecl3DKW("KW", grid, EclDataType.ECL_FLOAT) kw.setDefault(55) self.assertTrue(55, kw.getDefault())