def test_cell_containment(self): grid_location = "local/ECLIPSE/faarikaal/faarikaal%d.EGRID" well_location = "local/ECLIPSE/faarikaal/faarikaal%d.txt" for i in range(1, 8): grid_file = self.createTestPath(grid_location % i) well_file = self.createTestPath(well_location % i) grid = EclGrid(grid_file) # Load well data with open(well_file, "r") as f: lines = [line.split() for line in f.readlines()] points = [map(float, line[:3:]) for line in lines] exp_cells = [tuple(map(int, line[3::])) for line in lines] msg = "Expected point %s to be in cell %s, was in %s." for point, exp_cell in zip(points, exp_cells): reported_cell = grid.find_cell(*point) self.assertEqual( exp_cell, reported_cell, msg % (str(point), str(exp_cell), str(reported_cell)) )
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_actnum_extraction(self): dims = (4, 4, 4) coord = GridGen.create_coord(dims, (1, 1, 1)) zcorn = GridGen.create_zcorn(dims, (1, 1, 1), offset=0) actnum = EclKW("ACTNUM", reduce(operator.mul, dims), EclDataType.ECL_INT) random.seed(1337) for i in range(len(actnum)): actnum[i] = random.randint(0, 1) grid = EclGrid.create(dims, zcorn, coord, actnum) ijk_bounds = generate_ijk_bounds(dims) for ijk_bound in ijk_bounds: if not decomposition_preserving(ijk_bound): continue sub = GridGen.extract_subgrid_data(dims, coord, zcorn, ijk_bound, actnum=actnum) sub_coord, sub_zcorn, sub_actnum = sub sub_dims = tuple([u - l + 1 for l, u in ijk_bound]) subgrid = EclGrid.create(sub_dims, sub_zcorn, sub_coord, sub_actnum) self.assertEqual(sub_dims, subgrid.getDims()[:-1:]) self.assertSubgrid(grid, subgrid, ijk_bound)
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 setUp(self): self.grid = EclGrid( self.createTestPath("Statoil/ECLIPSE/Mariner/MARINER.EGRID")) fileH = open( self.createTestPath("Statoil/ECLIPSE/Mariner/faultblock.grdecl")) self.kw = EclKW.read_grdecl(fileH, "FAULTBLK", ecl_type=EclDataType.ECL_INT)
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.getGlobalList()) % grid.getNZ())
def test_repr_and_name(self): grid = GridGen.createRectangular((2,2,2), (10,10,10), actnum=[0,0,0,0,1,1,1,1]) pfx = 'EclGrid(' rep = repr(grid) self.assertEqual(pfx, rep[:len(pfx)]) self.assertEqual(type(rep), type('')) self.assertEqual(type(grid.getName()), type('')) with TestAreaContext("python/ecl_grid/repr"): grid.save_EGRID("CASE.EGRID") g2 = EclGrid("CASE.EGRID") r2 = repr(g2) self.assertEqual(pfx, r2[:len(pfx)]) self.assertEqual(type(r2), type('')) self.assertEqual(type(g2.getName()), type(''))
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_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_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_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_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, 8.65322541521704e-07) dz2 = subsidence.evalGeertsma("S2", None, receiver, youngs_modulus, poisson_ratio, seabed) np.testing.assert_almost_equal(dz2, 2.275556615015282e-06) np.testing.assert_almost_equal(dz1-dz2, -1.4102340734935779e-06) dz = subsidence.evalGeertsma("S1", "S2", receiver, youngs_modulus, poisson_ratio, seabed) np.testing.assert_almost_equal(dz, dz1-dz2)
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_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_no_mapaxes_check_for_nan(self): grid_paths = ["Statoil/ECLIPSE/NoMapaxes/ECLIPSE.EGRID", "Statoil/ECLIPSE/NoMapaxes/ECLIPSE.GRID"] for grid_path in grid_paths: test_grid_path = self.createTestPath(grid_path) grid = EclGrid(test_grid_path) xyz = grid.get_xyz(ijk=(0, 0, 0)) self.assertFalse(math.isnan(xyz[0])) self.assertFalse(math.isnan(xyz[1])) self.assertFalse(math.isnan(xyz[2])) xyz = grid.get_xyz(ijk=(1, 1, 1)) self.assertFalse(math.isnan(xyz[0])) self.assertFalse(math.isnan(xyz[1])) self.assertFalse(math.isnan(xyz[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_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_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_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_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_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_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_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_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_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 getGrid(self): if EclWellTest2.grid is None: EclWellTest2.grid = EclGrid( self.createTestPath( "Statoil/ECLIPSE/Troll/Ref2014/T07-4A-W2014-06.EGRID")) return EclWellTest2.grid
def test_sum(self): grid = EclGrid.createRectangular((10, 10, 1), (1, 1, 1)) kw_mask = EclKW("INT", grid.getGlobalSize(), EclDataType.ECL_INT) int_value = EclKW("INT", grid.getGlobalSize(), EclDataType.ECL_INT) float_value = EclKW("FLOAT", grid.getGlobalSize(), EclDataType.ECL_FLOAT) double_value = EclKW("DOUBLE", grid.getGlobalSize(), EclDataType.ECL_DOUBLE) bool_value = EclKW("BOOL", grid.getGlobalSize(), EclDataType.ECL_BOOL) kw_mask[0:50] = 1 for i in range(len(int_value)): float_value[i] = i double_value[i] = i int_value[i] = i bool_value[i] = True region = EclRegion(grid, False) region.select_equal(kw_mask, 1) self.assertEqual(int_value.sum(), 99 * 100 / 2) self.assertEqual(int_value.sum(mask=region), 49 * 50 / 2) self.assertEqual(double_value.sum(mask=region), 1.0 * 49 * 50 / 2) self.assertEqual(float_value.sum(mask=region), 1.0 * 49 * 50 / 2) self.assertEqual(bool_value.sum(mask=region), 50)
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 create_single_cell_grid(cls, corners): """ Provided with the corners of the grid in a similar manner as the eight corners are output for a single cell, this method will create a grid consisting of a single cell with the specified corners as its corners. """ zcorn = [corners[i][2] for i in range(8)] coord = [(corners[i], corners[i + 4]) for i in range(4)] coord = flatten(flatten(coord)) def construct_floatKW(name, values): kw = EclKW(name, len(values), EclDataType.ECL_FLOAT) for i in range(len(values)): kw[i] = values[i] return kw grid = EclGrid.create((1, 1, 1), construct_floatKW("ZCORN", zcorn), construct_floatKW("COORD", coord), None) if not corners == [grid.getCellCorner(i, 0) for i in range(8)]: raise AssertionError("Failed to generate single cell grid. " + "Did not end up the expected corners.") return grid
def test_rates(self): grid_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") rst_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") sum_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC") grid = EclGrid(grid_path) well_info = WellInfo(grid, rst_path) sum = EclSum(sum_path) for wtl in well_info: for well_state in wtl: # print "%03d %g %g " % (R , well_state.oilRate(), sum.get_from_report( "WOPR:%s" % well , R)) if wtl.getName() == "OP_4": pass # print well_state.oilRate(), well_state.waterRate(), well_state.gasRate(), well_state.volumeRate() # print well_state.oilRateSI(), well_state.waterRateSI(), well_state.gasRateSI(), well_state.volumeRateSI() self.assertEqual(well_state.oilRate(), well_state.oilRateSI()) self.assertEqual(well_state.waterRate(), well_state.waterRateSI()) self.assertEqual(well_state.gasRate(), well_state.gasRateSI()) self.assertEqual(well_state.volumeRate(), well_state.volumeRateSI()) # print sum.get_from_report("WOPR:%s" % wtl.getName(), 1) # print sum.get_from_report( "WWPR:%s" % wtl.getName(), 30 ) for conn in well_state.globalConnections(): # print conn.gasRate(), conn.waterRate(), conn.oilRate() # print conn.gasRateSI(), conn.waterRateSI(), conn.oilRateSI() self.assertEqual(conn.gasRate(), conn.gasRateSI()) self.assertEqual(conn.waterRate(), conn.waterRateSI()) self.assertEqual(conn.oilRate(), conn.oilRateSI()) self.assertEqual(conn.volumeRate(), conn.volumeRateSI())
p3 = None if not region_id in result: result[region_id] = [[],[],[]] result[region_id][0].append(p1) result[region_id][1].append(p2) result[region_id][2].append(p3) #----------------------------------------------------------------- if __name__ == "__main__": case = sys.argv[1] grid = EclGrid("%s.EGRID" % case) rst_file = EclRestartFile(grid, "%s.UNRST" % case) init_file = EclFile("%s.INIT" % case) # Create PORV keyword where all the inactive cells have been removed. pv = grid.compressed_kw_copy( init_file["PORV"][0] ) # Extract an integer region keyword from the init file region_kw = init_file["EQLNUM"][0] sim_days = [] result = {} for header in rst_file.headers(): line = {} rst_block = rst_file.restart_view( report_step = header.get_report_step( ) )
#!/usr/bin/env python import sys from operator import itemgetter from ecl.ecl import EclFile, EclGrid if __name__ == "__main__": case = sys.argv[1] grid_file = EclFile("%s.EGRID" % case) init_file = EclFile("%s.INIT" % case) grid = EclGrid("%s.EGRID" % case) nnc1 = grid_file["NNC1"][0] nnc2 = grid_file["NNC2"][0] tran = init_file["TRANNNC"][0] nnc_list = [] for g1,g2,t in zip(nnc1,nnc2,tran): nnc_list.append((g1,g2,t)) nnc_list = sorted(nnc_list, key = itemgetter(0)) for (g1,g2,T) in nnc_list: i1,j1,k1 = grid.get_ijk( global_index = g1 ) i2,j2,k2 = grid.get_ijk( global_index = g2 ) print "(%02d,%02d,%02d) -> (%02d,%02d,%02d) T:%g" % (i1,j1,k2,i2,j2,k2,T)