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.create( "KW" , grid , EclTypeEnum.ECL_FLOAT_TYPE , 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_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 , EclTypeEnum.ECL_INT_TYPE , 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_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 __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_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 , EclTypeEnum.ECL_FLOAT_TYPE , 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 , EclTypeEnum.ECL_FLOAT_TYPE ) self.assertEqual( len(kw) , grid.getNumActive()) self.assertEqual( (10,10,10) , kw.dims() )
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.create( "KW" , grid , EclTypeEnum.ECL_FLOAT_TYPE ) 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 , EclTypeEnum.ECL_FLOAT_TYPE , 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_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.create( "KW" , grid , EclTypeEnum.ECL_FLOAT_TYPE , 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.create("REGIONS" , grid , EclTypeEnum.ECL_INT_TYPE , 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_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 , EclTypeEnum.ECL_INT_TYPE , 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_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.create( "KW" , grid , EclTypeEnum.ECL_INT_TYPE , 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_global_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=False) for i in range(len(kw)): kw[i] = i kw.setDefault(177) kw_copy = kw.globalCopy() self.assertTrue(isinstance(kw_copy, EclKW)) self.assertEqual(len(kw_copy), 1000) for i in range(len(kw)): self.assertEqual(kw_copy[2 * i], i) self.assertEqual(kw_copy[2 * i + 1], kw.getDefault())
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.create( "KW" , 27 , EclTypeEnum.ECL_FLOAT_TYPE ) kw_global_size = EclKW.create( "KW" , grid.getGlobalSize() , EclTypeEnum.ECL_FLOAT_TYPE ) kw_active_size = EclKW.create( "KW" , grid.getNumActive() , EclTypeEnum.ECL_FLOAT_TYPE ) 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_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())
print('Using Norne location %s' % norne) rst = EclFile(join(norne, 'NORNE_ATW2013.UNRST')) grd = EclGrid(join(norne, 'NORNE_ATW2013.EGRID')) x = 10 # x in [0, grd.getNX()) y = 10 # y in [0, grd.getNY()) print(grd) print('Plotting SGAS, SOIL, SWAT for x,y pillar (%d, %d)' % (x, y)) swat = rst.iget_named_kw('SWAT', 0) sgas = rst.iget_named_kw('SGAS', 0) swat3d = Ecl3DKW.castFromKW(swat, grd, default_value=0) f_swat = lambda k: swat3d[x, y, k] sgas3d = Ecl3DKW.castFromKW(sgas, grd, default_value=0) f_sgas = lambda k: sgas3d[x, y, k] f_soil = lambda k: max(0, 1 - (f_sgas(k) + f_swat(k))) nz = grd.getNZ() sgas = [f_sgas(k) for k in range(nz)] soil = [f_soil(k) for k in range(nz)] swat = [f_swat(k) for k in range(nz)] import matplotlib.pyplot as plt plt.plot(sgas, color='r', label='SGAS')
def test_default(self): grid = EclGrid.createRectangular( (10,10,10) , (1,1,1)) kw = Ecl3DKW.create( "KW" , grid , EclTypeEnum.ECL_FLOAT_TYPE ) kw.setDefault(55) self.assertTrue( 55 , kw.getDefault())