def test_create(self): with self.assertRaises(ValueError): grid = EclGrid.createRectangular( (10,20,30) , (1,1,1) , actnum = [0,1,1,2]) with self.assertRaises(ValueError): grid = EclGrid.createRectangular( (10,20,30) , (1,1,1) , actnum = IntVector(initial_size = 10)) actnum = IntVector(default_value = 1 , initial_size = 6000) actnum[0] = 0 actnum[1] = 0 grid = EclGrid.createRectangular( (10,20,30) , (1,1,1) , actnum = actnum) self.assertEqual( grid.getNumActive( ) , 30*20*10 - 2)
def test_create(self): with self.assertRaises(ValueError): grid = EclGrid.createRectangular( (10,20,30) , (1,1,1) , actnum = [0,1,1,2]) with self.assertRaises(ValueError): grid = EclGrid.createRectangular( (10,20,30) , (1,1,1) , actnum = IntVector(initial_size = 10)) actnum = IntVector(default_value = 1 , initial_size = 6000) actnum[0] = 0 actnum[1] = 0 grid = EclGrid.createRectangular( (10,20,30) , (1,1,1) , actnum = actnum) self.assertEqual( grid.getNumActive( ) , 30*20*10 - 2)
def test_geertsma_kernel(): grid = EclGrid.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50)) with TestAreaContext("Subsidence"): p1 = [1] create_restart(grid, "TEST", p1) create_init(grid, "TEST") init = EclFile("TEST.INIT") restart_file = EclFile("TEST.UNRST") restart_view1 = restart_file.restartView( sim_time=datetime.date(2000, 1, 1)) subsidence = EclSubsidence(grid, init) subsidence.add_survey_PRESSURE("S1", restart_view1) youngs_modulus = 5E8 poisson_ratio = 0.3 seabed = 0 above = 100 topres = 2000 receiver = (1000, 1000, 0) dz = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus, poisson_ratio, seabed) np.testing.assert_almost_equal(dz, 3.944214576168326e-09) receiver = (1000, 1000, topres - seabed - above) dz = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus, poisson_ratio, seabed) np.testing.assert_almost_equal(dz, 5.8160298201497136e-08)
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_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_numpy3D(self): nx = 10 ny = 7 nz = 5 grid = EclGrid.createRectangular((nx,ny,nz) , (1,1,1)) kw = EclKW( "SWAT" , nx*ny*nz , EclTypeEnum.ECL_FLOAT_TYPE ) numpy_3d = grid.create3D( kw )
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_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_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 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_oom_grid(self): nx = 2000 ny = 2000 nz = 2000 with self.assertRaises(MemoryError): grid = EclGrid.createRectangular( (nx,ny,nz), (1,1,1))
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_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 openEclFile("G.EGRID") as f: with open("grid.grdecl" , "w") as f2: f2.write("SPECGRID\n") f2.write(" 10 10 10 \'F\' /\n") 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_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_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_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_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_oom_grid(self): nx = 2000 ny = 2000 nz = 2000 with self.assertRaises(MemoryError): grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1))
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_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_numpy3D(self): nx = 10 ny = 7 nz = 5 grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) kw = EclKW("SWAT", nx * ny * nz, EclTypeEnum.ECL_FLOAT_TYPE) numpy_3d = grid.create3D(kw)
def test_create(self): grid = EclGrid.createRectangular( (10,20,5) , (1,1,1) ) field_config = FieldConfig("PRESSURE" , grid) block_obs = BlockObservation("P-CONFIG" , field_config , grid) self.assertEqual( len(block_obs) , 0 ) block_obs.addPoint(1,2,3,100,25) self.assertEqual( len(block_obs) , 1 ) self.assertEqual( block_obs.getValue(0) , 100 ) self.assertEqual( block_obs.getStd(0) , 25 ) self.assertEqual( block_obs.getStdScaling(0) , 1 ) block_obs.addPoint(1,2,4,200,50) self.assertEqual( len(block_obs) , 2 ) self.assertEqual( block_obs.getValue(1) , 200 ) self.assertEqual( block_obs.getStd(1) , 50 ) self.assertEqual( block_obs.getStdScaling(1) , 1 ) active_list = ActiveList( ) block_obs.updateStdScaling( 0.50 , active_list ) self.assertEqual( block_obs.getStdScaling(0) , 0.50 ) self.assertEqual( block_obs.getStdScaling(1) , 0.50 ) active_list.addActiveIndex( 1 ) block_obs.updateStdScaling( 2.00 , active_list ) self.assertEqual( block_obs.getStdScaling(0) , 0.50 ) self.assertEqual( block_obs.getStdScaling(1) , 2.00 )
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") kw = EclKW.read_grdecl(open("kw.grdecl") , "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_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_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_geertsma_kernel(): grid = EclGrid.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50)) with TestAreaContext("Subsidence"): p1 = [1] create_restart(grid, "TEST", p1) create_init(grid, "TEST") init = EclFile("TEST.INIT") restart_file = EclFile("TEST.UNRST") restart_view1 = restart_file.restartView(sim_time=datetime.date(2000, 1, 1)) subsidence = EclSubsidence(grid, init) subsidence.add_survey_PRESSURE("S1", restart_view1) youngs_modulus = 5E8 poisson_ratio = 0.3 seabed = 0 above = 100 topres = 2000 receiver = (1000, 1000, 0) dz = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus, poisson_ratio, seabed) np.testing.assert_almost_equal(dz, -1.256514072122196e-07) receiver = (1000, 1000, topres - seabed - above) dz = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus, poisson_ratio, seabed) np.testing.assert_almost_equal(dz, 6.530473913611929e-05)
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_polyline_intersection(self): grid = EclGrid.createRectangular((100, 100, 10), (0.25, 0.25, 1)) # Fault1 Fault4 # | | # | | # | | # | ------- Fault2 | # | | # | | # (5 , 2.50) # -------- 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") polyline = Polyline(init_points=[(4, 4), (8, 4)]) self.assertTrue(fault4.intersectsPolyline(polyline, 0)) cpolyline = CPolyline(init_points=[(4, 4), (8, 4)]) self.assertTrue(fault4.intersectsPolyline(cpolyline, 0)) polyline = Polyline(init_points=[(8, 4), (16, 4)]) self.assertFalse(fault4.intersectsPolyline(polyline, 0)) cpolyline = CPolyline(init_points=[(8, 4), (16, 4)]) self.assertFalse(fault4.intersectsPolyline(cpolyline, 0))
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_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_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_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_output_units(self): n = 10 a = 1 grid = EclGrid.createRectangular((n, n, n), (a, a, a)) with TestAreaContext("python/ecl_grid/units"): grid.save_EGRID("CASE.EGRID", output_unit=EclUnitTypeEnum.ECL_FIELD_UNITS) f = EclFile("CASE.EGRID") g = f["GRIDUNIT"][0] self.assertEqual(g[0].strip(), "FEET") g2 = EclGrid("CASE.EGRID") self.assertFloatEqual(g2.cell_volume(global_index=0), 3.28084 * 3.28084 * 3.28084) grid.save_EGRID("CASE.EGRID") f = EclFile("CASE.EGRID") g = f["GRIDUNIT"][0] self.assertEqual(g[0].strip(), "METRES") grid.save_EGRID("CASE.EGRID", output_unit=EclUnitTypeEnum.ECL_LAB_UNITS) f = EclFile("CASE.EGRID") g = f["GRIDUNIT"][0] self.assertEqual(g[0].strip(), "CM") g2 = EclGrid("CASE.EGRID") self.assertFloatEqual(g2.cell_volume(global_index=0), 100 * 100 * 100)
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_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 test_geertsma_kernel_2_source_points_2_vintages(): grid = EclGrid.createRectangular(dims=(2, 1, 1), dV=(100, 100, 100)) with TestAreaContext("Subsidence"): p1 = [1, 10] p2 = [10, 20] create_restart(grid, "TEST", p1, p2) create_init(grid, "TEST") init = EclFile("TEST.INIT") restart_file = EclFile("TEST.UNRST") restart_view1 = restart_file.restartView(sim_time=datetime.date(2000, 1, 1)) restart_view2 = restart_file.restartView(sim_time=datetime.date(2010, 1, 1)) subsidence = EclSubsidence(grid, init) subsidence.add_survey_PRESSURE("S1", restart_view1) subsidence.add_survey_PRESSURE("S2", restart_view2) youngs_modulus = 5E8 poisson_ratio = 0.3 seabed = 0 receiver = (1000, 1000, 0) dz1 = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus, poisson_ratio, seabed) np.testing.assert_almost_equal(dz1, -5.538064265738908e-05) dz2 = subsidence.evalGeertsma("S2", None, receiver, youngs_modulus, poisson_ratio, seabed) np.testing.assert_almost_equal(dz2, -1.456356233609781e-04) np.testing.assert_almost_equal(dz2-dz1, -9.025498070358901e-05) dz = subsidence.evalGeertsma("S1", "S2", receiver, youngs_modulus, poisson_ratio, seabed) np.testing.assert_almost_equal(dz, -9.025498070358901e-05)
def test_dims(self): grid = EclGrid.createRectangular( (10,20,30) , (1,1,1) ) self.assertEqual( grid.getNX() , 10 ) self.assertEqual( grid.getNY() , 20 ) self.assertEqual( grid.getNZ() , 30 ) self.assertEqual( grid.getGlobalSize() , 30*10*20 ) self.assertEqual( grid.getDims() , (10,20,30,6000) )
def test_compressed_copy(self): nx = 10 ny = 10 nz = 10 grid = EclGrid.createRectangular( (nx,ny,nz) , (1,1,1) ) kw1 = EclKW.create("KW" , 1001 , EclTypeEnum.ECL_INT_TYPE ) with self.assertRaises(ValueError): cp = grid.compressedKWCopy( kw1 )
def test_compressed_copy(self): nx = 10 ny = 10 nz = 10 grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) kw1 = EclKW.create("KW", 1001, EclTypeEnum.ECL_INT_TYPE) with self.assertRaises(ValueError): cp = grid.compressedKWCopy(kw1)
def test_dims(self): grid = EclGrid.createRectangular((10, 20, 30), (1, 1, 1)) self.assertEqual(grid.getNX(), 10) self.assertEqual(grid.getNY(), 20) self.assertEqual(grid.getNZ(), 30) self.assertEqual(grid.getGlobalSize(), 30 * 10 * 20) self.assertEqual(grid.getDims(), (10, 20, 30, 6000))
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_ecl_region_name(self): grid = EclGrid.createRectangular((10,20,30) , (1,1,1) ) region = EclRegion( grid , False ) with self.assertRaises(DeprecationWarning): region.name = "NAME" with self.assertRaises(DeprecationWarning): region.get_name( )
def test_ecl_region_name(self): grid = EclGrid.createRectangular((10,20,30) , (1,1,1) ) region = EclRegion( grid , False ) with self.assertRaises(DeprecationWarning): region.name = "NAME" with self.assertRaises(DeprecationWarning): region.get_name( )
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_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_dxdydz(self): nx = 10 ny = 10 nz = 10 grid = EclGrid.createRectangular( (nx,ny,nz) , (2,3,4) ) (dx,dy,dz) = grid.getCellDims( active_index = 0 ) self.assertEqual( dx , 2 ) self.assertEqual( dy , 3 ) self.assertEqual( dz , 4 )
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_dxdydz(self): nx = 10 ny = 10 nz = 10 grid = EclGrid.createRectangular((nx, ny, nz), (2, 3, 4)) (dx, dy, dz) = grid.getCellDims(active_index=0) self.assertEqual(dx, 2) self.assertEqual(dy, 3) self.assertEqual(dz, 4)
def test_init_ACTNUM(self): nx = 10 ny = 23 nz = 7 grid = EclGrid.createRectangular( (nx,ny,nz) , (1,1,1) ) actnum = grid.exportACTNUM() self.assertEqual( len(actnum) , nx*ny*nz ) self.assertEqual( actnum[0] , 1 ) self.assertEqual( actnum[nx*ny*nz - 1] , 1 )
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_truncated_file(self): grid = EclGrid.createRectangular( (10,20,30) , (1,1,1) ) with TestAreaContext("python/ecl_grid/truncated"): grid.save_EGRID( "TEST.EGRID") size = os.path.getsize( "TEST.EGRID") with open("TEST.EGRID" , "r+") as f: f.truncate( size / 2 ) with self.assertRaises(IOError): EclGrid("TEST.EGRID")
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 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)])