def test_EGRID( self ): grid = EclGrid(self.egrid_file()) self.assertTrue(grid) dims = grid.dims self.assertEqual(dims[0] , grid.getNX()) self.assertEqual(dims[1] , grid.getNY()) self.assertEqual(dims[2] , grid.getNZ())
def test_corner(self): grid = EclGrid(self.egrid_file()) nx = grid.getNX() ny = grid.getNY() nz = grid.getNZ() (x1,y1,z1) = grid.getCellCorner( 0 , ijk = (0,0,0)) (x2,y2,z2) = grid.getLayerXYZ( 0 , 0 ) self.assertEqual(x1,x2) self.assertEqual(y1,y2) self.assertEqual(z1,z2) (x1,y1,z1) = grid.getCellCorner( 0 , ijk = (0,1,0)) (x2,y2,z2) = grid.getLayerXYZ( (nx + 1) , 0 ) self.assertEqual(x1,x2) self.assertEqual(y1,y2) self.assertEqual(z1,z2) (x1,y1,z1) = grid.getCellCorner( 1 , ijk = (nx - 1,0,0)) (x2,y2,z2) = grid.getLayerXYZ( nx , 0 ) self.assertEqual(x1,x2) self.assertEqual(y1,y2) self.assertEqual(z1,z2) (x1,y1,z1) = grid.getCellCorner( 4 , ijk = (0,0,nz-1)) (x2,y2,z2) = grid.getLayerXYZ( 0 , nz ) self.assertEqual(x1,x2) self.assertEqual(y1,y2) self.assertEqual(z1,z2) (x1,y1,z1) = grid.getCellCorner( 7 , ijk = (nx-1,ny-1,nz-1)) (x2,y2,z2) = grid.getLayerXYZ( (nx + 1)*(ny + 1) - 1 , nz ) self.assertEqual(x1,x2) self.assertEqual(y1,y2) self.assertEqual(z1,z2) with self.assertRaises(IndexError): grid.getLayerXYZ( -1 , 0 ) with self.assertRaises(IndexError): grid.getLayerXYZ( (nx + 1)*(ny + 1) , 0 ) with self.assertRaises(IndexError): grid.getLayerXYZ( 0 , -1 ) with self.assertRaises(IndexError): grid.getLayerXYZ( 0 , nz + 1 )
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.global_list 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.ny * self.grid.nz * 6 == len(reg.global_list)) reg.select_jslice(7, 8, intersect=True) OK = True for gi in reg.global_list: (i, j, k) = self.grid.get_ijk(global_index=gi) if i > 5: OK = False if j < 7 or j > 8: OK = False self.assertTrue(OK) self.assertTrue(2 * self.grid.nz * 6 == len(reg.global_list)) reg2 = EclRegion(self.grid, False) reg2.select_kslice(3, 5) reg &= reg2 OK = True for gi in reg.global_list: (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.active_list global_list = reg.global_list 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.nz == 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.global_list) % grid.nz) 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 ) glist = region.getGlobalList() self.assertEqual(0 , len(glist)) region.selectFromLayer( layer , 0 , 1 ) glist = region.getGlobalList() self.assertEqual(3 , len(glist))