def test_output_units(self): n = 10 a = 1 grid = GridGen.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_EGRID( self ): grid = EclGrid(self.egrid_file()) self.assertTrue(grid) dims = grid.getDims() self.assertEqual(dims[0] , grid.getNX()) self.assertEqual(dims[1] , grid.getNY()) self.assertEqual(dims[2] , grid.getNZ())
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 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_coarse(self): #work_area = TestArea("python/grid-test/testCoarse") with TestAreaContext("python/grid-test/testCoarse"): testGRID = True g1 = EclGrid(self.createTestPath("Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2.EGRID")) g1.save_EGRID("LGC.EGRID") g2 = EclGrid("LGC.EGRID") self.assertTrue(g1.equal(g2, verbose=True)) if testGRID: g1.save_GRID("LGC.GRID") g3 = EclGrid("LGC.GRID") self.assertTrue(g1.equal(g3, verbose=True)) self.assertTrue(g1.coarse_groups() == 3384)
def test_create(self): ensemble_config = EnsembleConfig() obs = EnkfObs(ensemble_config) self.assertEqual(len(obs), 0) self.assertFalse(obs.valid) with self.assertRaises(ValueError): obs.load(self.obs_config) self.assertEqual(len(obs), 0) time_map = TimeMap() obs = EnkfObs(ensemble_config, external_time_map=time_map) self.assertEqual(len(obs), 0) grid = EclGrid(self.grid) refcase = EclSum(self.refcase) history = History(refcase, False) obs = EnkfObs(ensemble_config, grid=grid, history=history) self.assertTrue(obs.valid) with self.assertRaises(IOError): obs.load("/does/not/exist") obs.load(self.obs_config) self.assertTrue(obs.valid) self.assertEqual(len(obs), 33) obs.clear() self.assertEqual(len(obs), 0) obs.load(self.obs_config) self.assertEqual(len(obs), 33) self.assertNotIn("RFT2", obs) obs.load(self.obs_config2) self.assertEqual(len(obs), 35) self.assertIn("RFT2", obs)
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 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())
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_save(self): with TestAreaContext("python/grid-test/testSave"): g1 = EclGrid(self.egrid_file()) g1.save_EGRID("test.EGRID") g2 = EclGrid("test.EGRID") self.assertTrue(g1.equal(g2)) g1.save_GRID("test.GRID") g2 = EclGrid("test.GRID") self.assertTrue(g1.equal(g2)) fileH = open("test.grdecl", "w") g1.save_grdecl(fileH) fileH.close() g2 = self.create("test.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_no_such_well(self): grid_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") rst_path1 = self.createTestPath("nosuch/path/ECLIPSE.X001") rst_path2 = self.createTestPath("nosuch/path/ECLIPSE.X002") grid = EclGrid(grid_path) with self.assertRaises(IOError): _ = WellInfo(grid, rst_path1) with self.assertRaises(IOError): _ = WellInfo(grid, [rst_path1, rst_path2])
def grid(self): if self._grid: return self._grid if isfile(self._grid_file): self._grid = EclGrid(self._grid_file) self._grid.init = self.init self._grid.region = self._region return self._grid return None
def test_volume_kw(self): grid = EclGrid(self.egrid_file()) vol = grid.createVolumeKeyword( ) self.assertEqual( len(vol) , grid.getNumActive()) for active_index , volume in enumerate(vol): self.assertEqual( volume , grid.cell_volume( active_index = active_index )) vol = grid.createVolumeKeyword( active_size = False ) self.assertEqual( len(vol) , grid.getGlobalSize()) for global_index , volume in enumerate(vol): self.assertEqual( volume , grid.cell_volume( global_index = global_index ))
def test_truncated_file(self): grid = GridGen.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_load(self): g = EclGrid(self.grid_file) f = EclRestartFile(g, self.unrst_file) head = f["INTEHEAD"][0] self.assertTrue(isinstance(head, EclKW)) swat = f["SWAT"][0] self.assertTrue(isinstance(swat, Ecl3DKW)) pressure = f["PRESSURE"][0] self.assertTrue(isinstance(pressure, Ecl3DKW))
def test_load(self): g = EclGrid(self.grid_file) f = EclInitFile(g, self.init_file) head = f["INTEHEAD"][0] self.assertTrue(isinstance(head, EclKW)) porv = f["PORV"][0] self.assertTrue(isinstance(porv, Ecl3DKW)) poro = f["PORO"][0] self.assertTrue(isinstance(poro, Ecl3DKW))
def test_headers(self): g = EclGrid(self.grid_file) f = EclRestartFile(g, self.unrst_file) headers = f.headers() self.assertEqual(len(headers), 63) with self.assertRaises(IndexError): f.get_header(1000) header = f.get_header(10) details = header.well_details() self.assertTrue("NXCONZ" in details) self.assertTrue("NCWMAX" in details)
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 getWellInfo(self): """ @rtype: WellInfo """ if EclWellTest.__well_info is None: grid_path = self.createTestPath("Statoil/ECLIPSE/Troll/MSW/T07-4A-W2012-16-F3.EGRID") rst_path_1 = self.createTestPath("Statoil/ECLIPSE/Troll/MSW/T07-4A-W2012-16-F3.X0135") grid = EclGrid(grid_path) rst_file = EclFile(rst_path_1, EclFileFlagEnum.ECL_FILE_CLOSE_STREAM) EclWellTest.__well_info = WellInfo(grid, rst_file) return EclWellTest.__well_info
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_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 )
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_lgr_get(self): grid = EclGrid(self.createTestPath("Statoil/ECLIPSE/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID")) for (nr,name) in [ ( 104 , "LG003017"), (2 , "LG006024"), ( 4 , "LG005025"), ( 82 , "LG011029"), (100 , "LG007021"), (110 , "LG003014")]: lgr_name = grid.get_lgr( name ) lgr_nr = grid.get_lgr( nr ) self.assertEqual( lgr_name , lgr_nr ) with self.assertRaises(KeyError): grid.get_lgr("NO/SUCHLGR") with self.assertRaises(KeyError): grid.get_lgr(1024)
def test_dual(self): with TestAreaContext("python/grid-test/testDual"): grid = EclGrid(self.egrid_file()) self.assertFalse(grid.dualGrid()) self.assertTrue(grid.getNumActiveFracture() == 0) grid2 = EclGrid(self.grid_file()) self.assertFalse(grid.dualGrid()) self.assertTrue(grid.getNumActiveFracture() == 0) dgrid = EclGrid( self.createTestPath( "Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.EGRID")) self.assertTrue( dgrid.getNumActive() == dgrid.getNumActiveFracture()) self.assertTrue(dgrid.getNumActive() == 46118) dgrid2 = EclGrid( self.createTestPath( "Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.GRID")) self.assertTrue( dgrid.getNumActive() == dgrid.getNumActiveFracture()) self.assertTrue(dgrid.getNumActive() == 46118) self.assertTrue(dgrid.equal(dgrid2)) # The DUAL_DIFF grid has been manipulated to create a # situation where some cells are only matrix active, and some # cells are only fracture active. dgrid = EclGrid( self.createTestPath( "Statoil/ECLIPSE/DualPoro/DUAL_DIFF.EGRID")) self.assertTrue(dgrid.getNumActive() == 106) self.assertTrue(dgrid.getNumActiveFracture() == 105) self.assertTrue( dgrid.get_active_fracture_index(global_index=0) == -1) self.assertTrue( dgrid.get_active_fracture_index(global_index=2) == -1) self.assertTrue( dgrid.get_active_fracture_index(global_index=3) == 0) self.assertTrue( dgrid.get_active_fracture_index(global_index=107) == 104) self.assertTrue(dgrid.get_active_index(global_index=1) == 1) self.assertTrue(dgrid.get_active_index(global_index=105) == 105) self.assertTrue(dgrid.get_active_index(global_index=106) == -1) self.assertTrue(dgrid.get_global_index1F(2) == 5) dgrid.save_EGRID("DUAL_DIFF.EGRID") dgrid2 = EclGrid("DUAL_DIFF.EGRID") self.assertTrue(dgrid.equal(dgrid2, verbose=True))
def test_construction(self): grid_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") rst_path_1 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0011") rst_path_2 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0022") rst_path_3 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0035") rst_path_4 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0061") grid = EclGrid(grid_path) def checkWellInfo(well_info, well_count, report_step_count): self.assertEqual(len(well_info), well_count) for index, well_time_line in enumerate(well_info): self.assertEqual(len(well_time_line), report_step_count[index]) well_info = WellInfo(grid, rst_path_1) checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1]) well_info = WellInfo(grid, EclFile(rst_path_1)) checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1]) well_info = WellInfo(grid, [rst_path_1, rst_path_2, rst_path_3]) checkWellInfo(well_info, well_count=8, report_step_count=[3, 3, 3, 3, 3, 2, 2, 2]) well_info = WellInfo(grid, [EclFile(rst_path_1), EclFile(rst_path_2), rst_path_3, EclFile(rst_path_4)]) checkWellInfo(well_info, well_count=8, report_step_count=[4, 4, 4, 4, 4, 3, 3, 3]) well_info = WellInfo(grid) well_info.addWellFile(rst_path_1, True) checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1]) well_info.addWellFile(EclFile(rst_path_2), True) checkWellInfo(well_info, well_count=8, report_step_count=[2, 2, 2, 2, 2, 1, 1, 1]) well_info.addWellFile(EclFile(rst_path_3), True) checkWellInfo(well_info, well_count=8, report_step_count=[3, 3, 3, 3, 3, 2, 2, 2]) well_info.addWellFile(rst_path_4, True) checkWellInfo(well_info, well_count=8, report_step_count=[4, 4, 4, 4, 4, 3, 3, 3])
def test_unified(self): g = EclGrid(self.grid_file) f_unrst = EclRestartFile(g, self.unrst_file) f_x0 = EclRestartFile(g, self.xrst_file0) f_x10 = EclRestartFile(g, self.xrst_file10) f_x20 = EclRestartFile(g, self.xrst_file20) self.assertTrue(f_unrst.unified()) self.assertFalse(f_x0.unified()) self.assertFalse(f_x10.unified()) self.assertFalse(f_x20.unified()) self.assertEqual( [(10, datetime.datetime(2000, 10, 1, 0, 0, 0), 274.0)], f_x10.timeList()) unrst_timeList = f_unrst.timeList() self.assertEqual(len(unrst_timeList), 63) self.assertEqual( (62, datetime.datetime(2004, 12, 31, 0, 0, 0), 1826.0), unrst_timeList[62])
def test_all_iters(self): fk = self.createTestPath('local/ECLIPSE/faarikaal/faarikaal1.EGRID') grid = EclGrid(fk) cell = grid[3455] self.assertEqual(3455, cell.global_index) cell = grid[(4,1,82)] self.assertEqual(3455, cell.global_index) self.assertEqual(grid.cell(global_index=3455), grid.cell(active_index=2000)) self.assertEqual(grid.cell(global_index=3455), grid.cell(i=4, j=1, k=82)) na = grid.get_num_active() self.assertEqual(na, 4160) cnt = 0 for c in grid.cells(active=True): cnt += 1 self.assertTrue(c.active) self.assertEqual(cnt, 4160) cnt = len([c for c in grid.cells()]) self.assertEqual(cnt, len(grid))
def test_type(self): g = EclGrid(self.grid_file) with self.assertRaises(ValueError): f = EclRestartFile(g, "NOT_A_RESTART_FILE")
def test_wrong_type(self): g = EclGrid(self.grid_file) with self.assertRaises(ValueError): f = EclInitFile(g, self.grid_file)