def test_truth_and_size(self): actnum = IntVector( initial_size = 100, default_value = 0) actnum[0:50] = 1 grid = EclGrid.createRectangular( (10,10,1) , (1,1,1), actnum = actnum) region = EclRegion(grid, False) self.assertFalse( region ) self.assertEqual( 0, region.active_size( )) self.assertEqual( 0, region.global_size( )) region.select_all( ) self.assertTrue( region ) self.assertEqual( 50, region.active_size( )) self.assertEqual( 100, region.global_size( )) region.deselect_all() self.assertFalse( region ) self.assertEqual( 0, region.active_size( )) self.assertEqual( 0, region.global_size( )) region = EclRegion(grid, False) region.select_inactive() self.assertTrue( region ) self.assertEqual( 0 , region.active_size( )) self.assertEqual( 50, region.global_size( ))
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:int(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_contact2(self): nx = 10 ny = 10 layer = Layer(nx,ny) grid = EclGrid.createRectangular( (nx,ny,1) , (1,1,1) ) # Too short with self.assertRaises(ValueError): layer.addIJBarrier( [(1,5)] ) # Out of range with self.assertRaises(ValueError): layer.addIJBarrier( [(10,15),(5,5)] ) # Out of range with self.assertRaises(ValueError): layer.addIJBarrier( [(7,7),(-5,5)] ) # Must have either i1 == i2 or j1 == j2 with self.assertRaises(ValueError): layer.addIJBarrier( [(7,8),(6,5)] ) p1 = (0 , 4) p2 = (0 , 5) self.assertTrue(layer.cellContact( p1 , p2 )) layer.addIJBarrier( [(0,5) , (nx , 5)] ) self.assertFalse(layer.cellContact( p1 , p2 ))
def test_connectWithPolyline(self): grid = EclGrid.createRectangular( (4,4,1) , (1 , 1 , 1)) # o o o o o # # o o o o o # # o---o---o---o---o # # o o o o o # | # o o o o o fault1 = Fault(grid , "Fault1") fault1.addRecord(0 , 3 , 1 , 1 , 0 , 0 , "Y") fault2 = Fault(grid , "Fault2") fault2.addRecord(1 , 1 , 0 , 0 , 0 , 0 , "X") fault3 = Fault(grid , "Fault3") fault3.addRecord(1 , 1 , 0 , 2 , 0 , 0 , "X") self.assertIsNone( fault3.connect( fault1 , 0 )) intersect = fault2.connect( fault1 , 0 ) self.assertEqual( len(intersect) , 2 ) p1 = intersect[0] p2 = intersect[1] self.assertEqual( p1 , (2,1)) self.assertEqual( p2 , (2,2))
def test_extend_to_polyline(self): grid = EclGrid.createRectangular( (3,3,1) , (1 , 1 , 1)) # o o o o # # o---o---o---o # # o===+ o o # | # o o o o fault1 = Fault(grid , "Fault") fault1.addRecord(0 , 0 , 0 , 0 , 0 , 0 , "X-") fault1.addRecord(0 , 0 , 0 , 0 , 0 , 0 , "Y") polyline = CPolyline( init_points = [(0,2) , (3,2)]) points = fault1.extendToPolyline( polyline , 0 ) self.assertEqual( points , [(1,1) , (2,2)]) end_join = fault1.endJoin( polyline , 0 ) self.assertEqual( end_join, [(1,1) , (0,2)] ) polyline2 = CPolyline( init_points = [(0.8,2) , (0.8,0.8)]) end_join = fault1.endJoin( polyline2 , 0 ) self.assertIsNone( end_join )
def test_extend_polyline_on(self): grid = EclGrid.createRectangular( (3,3,1) , (1 , 1 , 1)) # o o o o # # o---o---o---o # # o===o===o===o # # o o o o fault1 = Fault(grid , "Fault") fault1.addRecord(0 , 2 , 0 , 0 , 0 , 0 , "Y") polyline0 = CPolyline( init_points = [(0,2)]) polyline1 = CPolyline( init_points = [(0,2) , (3,2)]) polyline2 = CPolyline( init_points = [(1,3) , (1,2)]) polyline3 = CPolyline( init_points = [(1,3) , (1,0)]) with self.assertRaises(ValueError): fault1.extendPolylineOnto( polyline0 , 0 ) points = fault1.extendPolylineOnto( polyline1 , 0 ) self.assertIsNone( points ) points = fault1.extendPolylineOnto( polyline2 , 0) self.assertEqual( points , [(1,2) , (1,1)]) points = fault1.extendPolylineOnto( polyline3 , 0) self.assertIsNone( points )
def test_contact(self): grid = EclGrid.createRectangular( (100,100,10) , (1,1,1)) # Fault1 Fault4 # | | # | | # | | # | ----------------------+-- Fault2 # | | # | | # # -------- Fault3 # fault1 = Fault(grid , "Fault1") fault2 = Fault(grid , "Fault2") fault3 = Fault(grid , "Fault3") fault4 = Fault(grid , "Fault4") fault1.addRecord(1 , 1 , 10 , grid.getNY() - 1 , 0 , 0 , "X") fault2.addRecord(5 , 30 , 15 , 15 , 0 , 0 , "Y") fault3.addRecord(2 , 10 , 9 , 9 , 0 , 0 , "Y") fault4.addRecord(20 , 20 , 10 , grid.getNY() - 1 , 0 , 0 , "X") #self.assertFalse( fault1.intersectsFault(fault2 , 0) ) #self.assertFalse( fault2.intersectsFault(fault1 , 0) ) #self.assertTrue( fault2.intersectsFault(fault4 , 0) ) #self.assertTrue( fault4.intersectsFault(fault2 , 0) ) self.assertTrue( fault1.intersectsFault(fault1 , 0) )
def test_fault_line_order(self): nx = 120 ny = 60 nz = 43 grid = EclGrid.createRectangular( (nx , ny , nz) , (1,1,1) ) with TestAreaContext("python/faults/line_order"): with open("faults.grdecl" , "w") as f: f.write("""FAULTS \'F\' 105 107 50 50 1 43 \'Y\' / \'F\' 108 108 50 50 1 43 \'X\' / \'F\' 108 108 50 50 22 43 \'Y\' / \'F\' 109 109 49 49 1 43 \'Y\' / \'F\' 110 110 49 49 1 43 \'X\' / \'F\' 111 111 48 48 1 43 \'Y\' / / """) faults = FaultCollection( grid , "faults.grdecl" ) fault = faults["F"] layer = fault[29] self.assertEqual(len(layer) , 2) line1 = layer[0] line2 = layer[1] self.assertEqual(len(line1) , 4) self.assertEqual(len(line2) , 2) seg0 = line1[0] seg1 = line1[1] seg2 = line1[2] seg3 = line1[3] self.assertEqual( seg0.getCorners() , (50 * (nx + 1) + 104 , 50 * (nx + 1) + 107)) self.assertEqual( seg1.getCorners() , (50 * (nx + 1) + 107 , 50 * (nx + 1) + 108)) self.assertEqual( seg2.getCorners() , (50 * (nx + 1) + 108 , 49 * (nx + 1) + 108)) self.assertEqual( seg3.getCorners() , (49 * (nx + 1) + 108 , 49 * (nx + 1) + 109))
def test_join_faults(self): grid = EclGrid.createRectangular( (100,100,10) , (1,1,1)) # Fault1 Fault4 # | | # | | # | | # | ------- Fault2 | # | | # | | # # -------- Fault3 # fault1 = Fault(grid , "Fault1") fault2 = Fault(grid , "Fault2") fault3 = Fault(grid , "Fault3") fault4 = Fault(grid , "Fault4") fault1.addRecord(1 , 1 , 10 , grid.getNY() - 1 , 0 , 0 , "X") fault2.addRecord(5 , 10 , 15 , 15 , 0 , 0 , "Y") fault3.addRecord(5 , 10 , 5 , 5 , 0 , 0 , "Y") fault4.addRecord(20 , 20 , 10 , grid.getNY() - 1 , 0 , 0 , "X") rays = fault1.getEndRays(0) self.assertEqual( rays[0] , [(2,10) , (0,-1)]) self.assertEqual( rays[1] , [(2,100) , (0,1)]) extra = Fault.joinFaults( fault1 , fault3 , 0) self.assertEqual( extra , [(2,10) , (2,6) , (5,6)] )
def test_boundingBox(self): grid = EclGrid.createRectangular((10,10,10) , (1,1,1)) with self.assertRaises(ValueError): bbox = grid.getBoundingBox2D(layer = -1 ) with self.assertRaises(ValueError): bbox = grid.getBoundingBox2D( layer = 11 ) bbox = grid.getBoundingBox2D( layer = 10 ) self.assertEqual( bbox , ((0,0) , (10, 0) , (10 , 10) , (0,10))) with self.assertRaises(ValueError): grid.getBoundingBox2D( lower_left = (-1,0) ) with self.assertRaises(ValueError): grid.getBoundingBox2D( lower_left = (6,10) ) bbox = grid.getBoundingBox2D( lower_left = (3,3) ) self.assertEqual( bbox , ((3,3) , (10,3) , (10,10) , (3,10))) with self.assertRaises(ValueError): grid.getBoundingBox2D( lower_left = (3,3) , upper_right = (2,2)) bbox = grid.getBoundingBox2D( lower_left = (3,3) , upper_right = (7,7)) self.assertEqual( bbox , ((3,3) , (7,3) , (7,7) , (3,7)))
def test_grdecl_load(self): with self.assertRaises(IOError): grid = EclGrid.loadFromGrdecl("/file/does/not/exists") with TestAreaContext("python/grid-test/grdeclLoad"): with open("grid.grdecl","w") as f: f.write("Hei ...") with self.assertRaises(ValueError): grid = EclGrid.loadFromGrdecl("grid.grdecl") actnum = IntVector(default_value = 1 , initial_size = 1000) actnum[0] = 0 g1 = EclGrid.createRectangular((10,10,10) , (1,1,1) , actnum = actnum ) self.assertEqual( g1.getNumActive() , actnum.elementSum() ) g1.save_EGRID("G.EGRID") with open("grid.grdecl" , "w") as f2: f2.write("SPECGRID\n") f2.write(" 10 10 10 \'F\' /\n") with openEclFile("G.EGRID") as f: with copen("grid.grdecl" , "a") as f2: coord_kw = f["COORD"][0] coord_kw.write_grdecl( f2 ) zcorn_kw = f["ZCORN"][0] zcorn_kw.write_grdecl( f2 ) actnum_kw = f["ACTNUM"][0] actnum_kw.write_grdecl( f2 ) g2 = EclGrid.loadFromGrdecl("grid.grdecl") self.assertTrue( g1.equal( g2 ))
def test_get_ijk(self): with TestAreaContext("python/fault_block_layer/neighbour") as work_area: with open("kw.grdecl","w") as fileH: fileH.write("FAULTBLK \n") fileH.write("1 1 1 0 0\n") fileH.write("1 2 2 0 3\n") fileH.write("4 2 2 3 3\n") fileH.write("4 4 4 0 0\n") fileH.write("4 4 4 0 5\n") fileH.write("/\n") with cwrap.open("kw.grdecl") as f: kw = EclKW.read_grdecl( f, "FAULTBLK", ecl_type=EclDataType.ECL_INT) grid = EclGrid.createRectangular( (5,5,1) , (1,1,1) ) layer = FaultBlockLayer( grid , 0 ) layer.loadKeyword( kw ) block = layer[0,0] self.assertEqual( block.getBlockID() , 1 ) block = layer[2,2] self.assertEqual( block.getBlockID() , 2 ) with self.assertRaises(ValueError): layer[3,3] with self.assertRaises(IndexError): layer[5,5]
def test_rect(self): with TestAreaContext("python/grid-test/testRect"): a1 = 1.0 a2 = 2.0 a3 = 3.0 grid = EclGrid.createRectangular((9, 9, 9), (a1, a2, a3)) grid.save_EGRID("rect.EGRID") grid2 = EclGrid("rect.EGRID") self.assertTrue(grid) self.assertTrue(grid2) (x, y, z) = grid.get_xyz(ijk=(4, 4, 4)) self.assertAlmostEqualList([x, y, z], [4.5 * a1, 4.5 * a2, 4.5 * a3]) v = grid.cell_volume(ijk=(4, 4, 4)) self.assertFloatEqual(v, a1 * a2 * a3) z = grid.depth(ijk=(4, 4, 4 )) self.assertFloatEqual(z, 4.5 * a3) g1 = grid.global_index(ijk=(2, 2, 2)) g2 = grid.global_index(ijk=(4, 4, 4)) (dx, dy, dz) = grid.distance(g2, g1) self.assertAlmostEqualList([dx, dy, dz], [2 * a1, 2 * a2, 2 * a3]) self.assertTrue(grid.cell_contains(2.5 * a1, 2.5 * a2, 2.5 * a3, ijk=(2, 2, 2)))
def make_grid( ): grid = EclGrid.createRectangular( (nx,ny,nz) , (1,1,1) ) if not os.path.isdir("grid"): os.makedirs("grid") grid.save_EGRID("grid/CASE.EGRID") return grid
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_fault_barrier(self): nx = 120 ny = 60 nz = 43 grid = EclGrid.createRectangular( (nx , ny , nz) , (1,1,1) ) with TestAreaContext("python/faults/line_order"): with open("faults.grdecl" , "w") as f: f.write("""FAULTS \'F\' 105 107 50 50 1 43 \'Y\' / \'F\' 108 108 50 50 1 43 \'X\' / \'F\' 108 108 50 50 22 43 \'Y\' / \'F\' 109 109 49 49 1 43 \'Y\' / \'F\' 110 110 49 49 1 43 \'X\' / \'F\' 111 111 48 48 1 43 \'Y\' / / """) with open("faults.grdecl") as f: faults = FaultCollection( grid , "faults.grdecl" ) # Fault layout: # # +---+---+---+---+ # | # +---+ + # | # +---+ fault = faults["F"] layer = Layer(nx,ny) fault_pairs = [((104,49),(104,50)), ((105,49),(105,50)), ((106,49),(106,50)), ((107,49),(108,49)), ((107,49),(107,50)), ((108,48),(108,49)), ((109,48),(110,48)), ((110,47),(110,48))] gap_pair = ((109,48),(109,49)) for p1,p2 in fault_pairs: self.assertTrue(layer.cellContact( p1 , p2 )) p1,p2 = gap_pair self.assertTrue(layer.cellContact( p1 , p2 )) layer.addFaultBarrier(fault , 30 , link_segments = False) for p1,p2 in fault_pairs: self.assertFalse(layer.cellContact( p1 , p2 )) p1,p2 = gap_pair self.assertTrue(layer.cellContact( p1 , p2 )) layer.addFaultBarrier(fault , 30) p1,p2 = gap_pair self.assertFalse(layer.cellContact( p1 , p2 ))
def test_fault_block_edge(self): grid = EclGrid.createRectangular( (5,5,1) , (1,1,1) ) kw = EclKW( "FAULTBLK" , grid.getGlobalSize() , EclDataType.ECL_INT ) kw.assign( 0 ) for j in range(1,4): for i in range(1,4): g = i + j*grid.getNX() kw[g] = 1 layer = FaultBlockLayer( grid , 0 )
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_add_polyline_barrier(self): d = 10 layer = Layer(d,d) grid = EclGrid.createRectangular( (d,d,1) , (1,1,1) ) pl = CPolyline( init_points = [(0 , 0) , (d/2 , d/2) , (d,d)]) layer.addPolylineBarrier( pl , grid , 0) for i in range(d): self.assertTrue( layer.bottomBarrier(i,i) ) if i < (d - 1): self.assertTrue( layer.leftBarrier(i+1,i) )
def test_connect_faults(self): grid = EclGrid.createRectangular( (100,100,10) , (1,1,1)) # Fault1 Fault4 # | | # | | # | | # | ------- Fault2 | # | | # | | # # -------- Fault3 # fault1 = Fault(grid , "Fault1") fault2 = Fault(grid , "Fault2") fault3 = Fault(grid , "Fault3") fault4 = Fault(grid , "Fault4") fault1.addRecord(1 , 1 , 10 , grid.getNY() - 1 , 0 , 0 , "X") fault2.addRecord(5 , 10 , 15 , 15 , 0 , 0 , "Y") fault3.addRecord(5 , 10 , 5 , 5 , 0 , 0 , "Y") fault4.addRecord(20 , 20 , 10 , grid.getNY() - 1 , 0 , 0 , "X") for other_fault in [fault2 , fault3,fault4]: with self.assertRaises(ValueError): fault1.extendToFault( other_fault ,0) with self.assertRaises(ValueError): fault2.extendToFault( fault3 , 0) for other_fault in [fault1 , fault2,fault4]: with self.assertRaises(ValueError): fault3.extendToFault( other_fault ,0 ) for other_fault in [fault1 , fault2,fault3]: with self.assertRaises(ValueError): fault4.extendToFault( other_fault , 0) ext21 = fault2.extendToFault( fault1 , 0) self.assertEqual(len(ext21) , 2) p0 = ext21[0] p1 = ext21[1] self.assertEqual(p0 , (5 , 16)) self.assertEqual(p1 , (2 , 16)) ext24 = fault2.extendToFault( fault4,0 ) self.assertEqual(len(ext24) , 2) p0 = ext24[0] p1 = ext24[1] self.assertEqual(p0 , (11 , 16)) self.assertEqual(p1 , (21 , 16))
def setUp(self): self.grid = EclGrid.createRectangular( (10,10,10) , (1,1,1) ) self.kw = EclKW( "FAULTBLK" , self.grid.getGlobalSize() , EclDataType.ECL_INT ) self.kw.assign( 1 ) reg = EclRegion( self.grid , False ) for k in range(self.grid.getNZ()): reg.clear( ) reg.select_kslice( k , k ) self.kw.assign( k , mask = reg ) self.kw[ k * self.grid.getNX() * self.grid.getNY() + 7] = 177
def test_PolylineIJ(self): nx = 10 ny = 10 nz = 10 grid = EclGrid.createRectangular( (nx,ny,nz) , (0.1,0.1,0.1)) f = Fault(grid , "F") f.addRecord(0 , 1 , 0 , 0 , 0,0 , "Y-") f.addRecord(2 , 2 , 0 , 1 , 0,0 , "X-") f.addRecord(2 , 2 , 1 , 1 , 0,0 , "Y") pl = f.getIJPolyline( 0 ) self.assertEqual(pl , [(0,0) , (2,0) , (2,2) , (3,2)])
def test_internal_blocks(self): nx = 8 ny = 8 nz = 1 grid = EclGrid.createRectangular( (nx , ny , nz) , (1,1,1) ) layer = FaultBlockLayer( grid , 0 ) with TestAreaContext("python/FaultBlocks/internal_blocks"): with open("faultblock.grdecl","w") as fileH: fileH.write("FAULTBLK \n") fileH.write("1 1 1 1 2 2 2 2 \n") fileH.write("1 4 4 1 2 5 5 2 \n") fileH.write("1 4 4 1 2 5 5 2 \n") fileH.write("1 1 1 1 2 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("1 1 3 1 1 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("/\n") with cwrap.open("faultblock.grdecl") as f: kw = EclKW.read_grdecl( f, "FAULTBLK", ecl_type=EclDataType.ECL_INT) with open("faults.grdecl", "w") as f: f.write("FAULTS\n") f.write("\'FX\' 4 4 1 4 1 1 'X' /\n") f.write("\'FX\' 5 5 4 4 1 1 'Y' /\n") f.write("\'FX\' 5 5 5 8 1 1 'X' /\n") f.write("/") faults = FaultCollection( grid , "faults.grdecl") layer.loadKeyword( kw ) layer.addFaultBarrier( faults["FX"] ) b1 = layer.getBlock( 1 ) b2 = layer.getBlock( 2 ) b3 = layer.getBlock( 3 ) b4 = layer.getBlock( 4 ) b5 = layer.getBlock( 5 ) nb = b1.getNeighbours() for b in nb: print('Block:%d' % b.getBlockID()) self.assertTrue( len(nb) == 2 ) self.assertTrue( b3 in nb ) self.assertTrue( b4 in nb ) nb = b2.getNeighbours() self.assertTrue( len(nb) == 1 ) self.assertTrue( b5 in nb )
def test_active(self): d = 10 layer = Layer(d,d) with self.assertRaises( ValueError ): layer.activeCell(d+1,d+2) self.assertTrue( layer.activeCell(1,2) ) grid = EclGrid.createRectangular( (d,d+1,1) , (1,1,1) ) with self.assertRaises( ValueError ): layer.updateActive( grid , 0 ) grid = EclGrid.createRectangular( (d,d,1) , (1,1,1) ) with self.assertRaises( ValueError ): layer.updateActive( grid , 10 ) actnum = IntVector( initial_size = d*d*1 , default_value = 1) actnum[0] = 0 grid = EclGrid.createRectangular( (d,d,1) , (1,1,1) , actnum = actnum) layer.updateActive( grid , 0 ) self.assertTrue( layer.activeCell(1,2) ) self.assertFalse( layer.activeCell(0,0) )
def test_neighbours(self): with TestAreaContext("python/fault_block_layer/neighbour") as work_area: with open("kw.grdecl","w") as fileH: fileH.write("FAULTBLK \n") fileH.write("1 1 1 0 0\n") fileH.write("1 2 2 0 3\n") fileH.write("4 2 2 3 3\n") fileH.write("4 4 4 0 0\n") fileH.write("4 4 4 0 5\n") fileH.write("/\n") with cwrap.open("kw.grdecl") as f: kw = EclKW.read_grdecl( f, "FAULTBLK", ecl_type=EclDataType.ECL_INT) grid = EclGrid.createRectangular( (5,5,1) , (1,1,1) ) layer = FaultBlockLayer( grid , 0 ) layer.loadKeyword( kw ) block1 = layer.getBlock( 1 ) block2 = layer.getBlock( 2 ) block3 = layer.getBlock( 3 ) block4 = layer.getBlock( 4 ) block5 = layer.getBlock( 5 ) self.assertEqual( block1.getParentLayer() , layer ) #Expected: 1 -> {2,4}, 2 -> {1,3,4}, 3 -> {2}, 4 -> {1,2}, 5-> {} neighbours = block1.getNeighbours() self.assertEqual( len(neighbours) , 2) self.assertTrue( block2 in neighbours ) self.assertTrue( block4 in neighbours ) neighbours = block2.getNeighbours() self.assertEqual( len(neighbours) , 3) self.assertTrue( block1 in neighbours ) self.assertTrue( block3 in neighbours ) self.assertTrue( block4 in neighbours ) neighbours = block3.getNeighbours() self.assertEqual( len(neighbours) , 1) self.assertTrue( block2 in neighbours ) neighbours = block4.getNeighbours() self.assertEqual( len(neighbours) , 2) self.assertTrue( block1 in neighbours ) self.assertTrue( block2 in neighbours ) neighbours = block5.getNeighbours() self.assertEqual( len(neighbours) , 0)
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 )
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_add_polyline_barrier1(self): grid = EclGrid.createRectangular( (4,1,1) , (1,1,1) ) layer = FaultBlockLayer( self.grid , 0 ) polyline = Polyline( init_points = [ (1.99 , 0.001) , (2.01 , 0.99)]) points = [((1,0) , (2,0))] geo_layer = layer.getGeoLayer() for p1,p2 in points: self.assertTrue(geo_layer.cellContact( p1 , p2 )) layer.addPolylineBarrier( polyline ) for p1,p2 in points: print(p1,p2) self.assertFalse(geo_layer.cellContact( p1 , p2 ))
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_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_neighbours3(self): nx = 8 ny = 8 nz = 1 grid = EclGrid.createRectangular( (nx , ny , nz) , (1,1,1) ) layer = FaultBlockLayer( grid , 0 ) with TestAreaContext("python/FaultBlocks/neighbours"): with open("faultblock.grdecl","w") as fileH: fileH.write("FAULTBLK \n") fileH.write("1 1 1 1 2 2 2 2 \n") fileH.write("1 1 1 1 2 2 2 2 \n") fileH.write("1 1 1 1 2 2 2 2 \n") fileH.write("1 1 1 1 2 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("/\n") kw = EclKW.read_grdecl(open("faultblock.grdecl") , "FAULTBLK" , ecl_type = EclDataType.ECL_INT) with open("faults.grdecl" , "w") as f: f.write("FAULTS\n") f.write("\'FX\' 4 4 1 4 1 1 'X' /\n") f.write("\'FX\' 5 5 5 8 1 1 'X' /\n") f.write("/") faults = FaultCollection( grid , "faults.grdecl") layer.loadKeyword( kw ) b1 = layer.getBlock( 1 ) b2 = layer.getBlock( 2 ) nb = b1.getNeighbours() self.assertTrue( b2 in nb ) layer.addFaultBarrier( faults["FX"] , link_segments = False) nb = b1.getNeighbours() self.assertTrue( b2 in nb )
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:int(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_add_polyline_barrier2(self): grid = EclGrid.createRectangular( (10,10,1) , (1,1,1) ) layer = FaultBlockLayer( self.grid , 0 ) polyline = Polyline( init_points = [ (0.1 , 0.9) , (8.9,0.9) , (8.9,8.9) ]) points = [((0,0) , (0,1)), ((2,0) , (2,1)), ((4,0) , (4,1)), ((6,0) , (6,1)), ((8,0) , (8,1)), # ((8,1) , (9,1)), ((8,3) , (9,3)), ((8,5) , (9,5)), ((8,7) , (9,7))] geo_layer = layer.getGeoLayer() for p1,p2 in points: self.assertTrue(geo_layer.cellContact( p1 , p2 )) layer.addPolylineBarrier( polyline ) for p1,p2 in points: print(p1,p2) self.assertFalse(geo_layer.cellContact( p1 , p2 ))
def test_grdecl_load(self): with self.assertRaises(IOError): grid = EclGrid.loadFromGrdecl("/file/does/not/exists") with TestAreaContext("python/grid-test/grdeclLoad"): with open("grid.grdecl", "w") as f: f.write("Hei ...") with self.assertRaises(ValueError): grid = EclGrid.loadFromGrdecl("grid.grdecl") actnum = IntVector(default_value=1, initial_size=1000) actnum[0] = 0 g1 = EclGrid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) self.assertEqual(g1.getNumActive(), actnum.elementSum()) g1.save_EGRID("G.EGRID") with open("grid.grdecl", "w") as f2: f2.write("SPECGRID\n") f2.write(" 10 10 10 \'F\' /\n") with openEclFile("G.EGRID") as f: with copen("grid.grdecl", "a") as f2: coord_kw = f["COORD"][0] coord_kw.write_grdecl(f2) zcorn_kw = f["ZCORN"][0] zcorn_kw.write_grdecl(f2) actnum_kw = f["ACTNUM"][0] actnum_kw.write_grdecl(f2) g2 = EclGrid.loadFromGrdecl("grid.grdecl") self.assertTrue(g1.equal(g2))
def setUp(self): self.grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1))
def setUpClass(cls): cls.grid = EclGrid.createRectangular((151, 100, 50), (1, 1, 1))
def test_neighbour_cells(self): nx = 10 ny = 8 nz = 7 grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) faults_file = self.createTestPath( "local/ECLIPSE/FAULTS/faults_nb.grdecl") faults = FaultCollection(grid, faults_file) fault = faults["FY"] self.assertEqual(len(fault), 1) fault_layer = fault[0] fl1 = fault_layer[0] nb_cells1 = fl1.getNeighborCells() true_nb_cells1 = [(0, nx), (1, nx + 1), (2, nx + 2), (3, nx + 3), (4, nx + 4)] self.assertListEqual(nb_cells1, true_nb_cells1) fl2 = fault_layer[1] nb_cells2 = fl2.getNeighborCells() true_nb_cells2 = [(6, nx + 6), (7, nx + 7), (8, nx + 8), (9, nx + 9)] self.assertListEqual(nb_cells2, true_nb_cells2) nb_cells = fault_layer.getNeighborCells() self.assertListEqual(nb_cells, true_nb_cells1 + true_nb_cells2) fault = faults["FY0"] fault_layer = fault[0] fl1 = fault_layer[0] nb_cells1 = fl1.getNeighborCells() true_nb_cells1 = [(-1, 0), (-1, 1), (-1, 2)] self.assertListEqual(nb_cells1, true_nb_cells1) fault = faults["FYNY"] fault_layer = fault[0] fl1 = fault_layer[0] nb_cells1 = fl1.getNeighborCells() true_nb_cells1 = [(nx * (ny - 1), -1), (nx * (ny - 1) + 1, -1), (nx * (ny - 1) + 2, -1)] self.assertListEqual(nb_cells1, true_nb_cells1) fault = faults["FX"] fault_layer = fault[0] fl1 = fault_layer[0] nb_cells1 = fl1.getNeighborCells() true_nb_cells1 = [(0, 1), (nx, nx + 1), (2 * nx, 2 * nx + 1)] self.assertListEqual(nb_cells1, true_nb_cells1) fault = faults["FX0"] fault_layer = fault[0] fl1 = fault_layer[0] nb_cells1 = fl1.getNeighborCells() true_nb_cells1 = [(-1, 0), (-1, nx), (-1, 2 * nx)] self.assertListEqual(nb_cells1, true_nb_cells1) fault = faults["FXNX"] fault_layer = fault[0] fl1 = fault_layer[0] nb_cells1 = fl1.getNeighborCells() true_nb_cells1 = [(nx - 1, -1), (2 * nx - 1, -1), (3 * nx - 1, -1)] self.assertListEqual(nb_cells1, true_nb_cells1)
def test_neighbours2(self): nx = 8 ny = 8 nz = 1 grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) layer = FaultBlockLayer(grid, 0) with TestAreaContext("python/FaultBlocks/neighbours"): with open("faultblock.grdecl", "w") as fileH: fileH.write("FAULTBLK \n") fileH.write("1 1 1 1 2 2 2 2 \n") fileH.write("1 1 1 1 2 2 2 2 \n") fileH.write("1 1 1 1 2 2 2 2 \n") fileH.write("1 1 1 1 2 2 2 2 \n") fileH.write("3 3 3 3 2 2 2 2 \n") fileH.write("3 3 3 3 2 2 2 2 \n") fileH.write("3 3 3 3 2 2 2 2 \n") fileH.write("3 3 3 3 2 2 2 2 \n") fileH.write("/\n") with cwrap.open("faultblock.grdecl") as f: kw = EclKW.read_grdecl(f, "FAULTBLK", ecl_type=EclDataType.ECL_INT) with open("faults.grdecl", "w") as f: f.write("FAULTS\n") f.write("\'FY\' 1 4 4 4 1 1 'Y' /\n") f.write("\'FX\' 4 4 1 8 1 1 'X' /\n") f.write("/") faults = FaultCollection(grid, "faults.grdecl") layer.loadKeyword(kw) b1 = layer.getBlock(1) b2 = layer.getBlock(2) b3 = layer.getBlock(3) nb = b1.getNeighbours() self.assertTrue(b2 in nb) self.assertTrue(b3 in nb) polylines1 = CPolylineCollection() p1 = polylines1.createPolyline(name="P1") p1.addPoint(4, 0) p1.addPoint(4, 4) p1.addPoint(4, 8) nb = b1.getNeighbours(polylines=polylines1) self.assertFalse(b2 in nb) self.assertTrue(b3 in nb) polylines2 = CPolylineCollection() p1 = polylines2.createPolyline(name="P2") p1.addPoint(0, 4) p1.addPoint(4, 4) nb = b1.getNeighbours(polylines=polylines2) self.assertTrue(b2 in nb) self.assertFalse(b3 in nb) layer.addFaultBarrier(faults["FY"]) nb = b1.getNeighbours() self.assertTrue(b2 in nb) self.assertFalse(b3 in nb) layer.addFaultBarrier(faults["FX"]) nb = b1.getNeighbours() self.assertEqual(len(nb), 0)
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())