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.dims self.assertEqual(dims[0] , grid.getNX()) self.assertEqual(dims[1] , grid.getNY()) self.assertEqual(dims[2] , grid.getNZ())
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_num_active_large_memory(self): case = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE") vecList = [] for i in range(12500): vec = DoubleVector() vec[81920] = 0 vecList.append(vec) grid1 = EclGrid(case) grid2 = EclGrid(case) self.assertEqual(grid1.getNumActive(), grid2.getNumActive()) self.assertEqual(grid1.getNumActive(), 34770)
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_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_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_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_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_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_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 createSingleCellGrid(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)] flatten = lambda l : [elem for sublist in l for elem in sublist] coord = [(corners[i], corners[i+4]) for i in range(4)] coord = flatten(flatten(coord)) def constructFloatKW(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), constructFloatKW("ZCORN", zcorn), constructFloatKW("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_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_polyline_intersection(self): grid = EclGrid.create_rectangular((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_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_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_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_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_rect(self): with TestAreaContext("python/grid-test/testRect"): a1 = 1.0 a2 = 2.0 a3 = 3.0 grid = EclGrid.create_rectangular((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.assertAlmostEqualScaled(v, a1 * a2 * a3) z = grid.depth(ijk=(4, 4, 4 )) self.assertAlmostEqualScaled(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))) ijk = grid.find_cell(1.5 * a1, 2.5 * a2, 3.5 * a3) self.assertAlmostEqualList(ijk, [1, 2, 3])
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_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_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 = EclTypeEnum.ECL_INT_TYPE) grid = EclGrid.create_rectangular( (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_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 main( eclipse_file_location , opm_file_location , base_name , rel_tolerance, abs_tolerance): print "Using relative tolerance of: " + str(rel_tolerance) print "Using absolute tolerance of: " + str(abs_tolerance) eclipse_restart_file = EclFile(eclipse_file_location + base_name + ".UNRST") eclipse_grid_file = EclGrid(eclipse_file_location + base_name + ".EGRID") opm_restart_file = EclFile(opm_file_location + base_name + ".UNRST") opm_grid_file = EclGrid(opm_file_location + base_name + ".EGRID") grids_equal = eclipse_grid_file.equal(opm_grid_file, include_lgr=True, verbose=True) if not grids_equal: print("The grids in files {0} and {1} are not equal!".format(eclipse_grid_file.name, opm_grid_file.name)) exit(1) compareRestartFiles(eclipse_restart_file, opm_restart_file, rel_tolerance, abs_tolerance)
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_neighbour_cells(self): nx = 10 ny = 8 nz = 7 grid = EclGrid.create_rectangular((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_neighbour_cells(self): nx = 10 ny = 8 nz = 7 grid = EclGrid.create_rectangular((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)
class RegionDefinitionTest(ExtendedTestCase): def setUp(self): self.grid = EclGrid( self.createTestPath("Statoil/ECLIPSE/Mariner/MARINER.EGRID")) with open( self.createTestPath( "Statoil/ECLIPSE/Mariner/faultblock.grdecl")) as fileH: self.kw = EclKW.read_grdecl(fileH, "FAULTBLK", ecl_type=EclTypeEnum.ECL_INT_TYPE) self.faults = FaultCollection( self.grid, self.createTestPath("Statoil/ECLIPSE/Mariner/faults.grdecl")) self.poly_file1 = self.createTestPath( "Statoil/ECLIPSE/Mariner/pol1.xyz") self.poly_file2 = self.createTestPath( "Statoil/ECLIPSE/Mariner/pol2.xyz") self.poly_file3 = self.createTestPath( "Statoil/ECLIPSE/Mariner/pol3.xyz") self.poly_file4 = self.createTestPath( "Statoil/ECLIPSE/Mariner/pol4.xyz") self.poly_file5 = self.createTestPath( "Statoil/ECLIPSE/Mariner/pol5.xyz") self.poly_file6 = self.createTestPath( "Statoil/ECLIPSE/Mariner/pol6.xyz") self.poly_file7 = self.createTestPath( "Statoil/ECLIPSE/Mariner/pol7.xyz") self.poly_file8 = self.createTestPath( "Statoil/ECLIPSE/Mariner/pol8.xyz") self.poly_file9 = self.createTestPath( "Statoil/ECLIPSE/Mariner/pol9.xyz") self.poly_file10 = self.createTestPath( "Statoil/ECLIPSE/Mariner/pol10.xyz") self.poly_file11 = self.createTestPath( "Statoil/ECLIPSE/Mariner/pol11.xyz") self.fault_blocks = [] for k in range(self.grid.getNZ()): blocks = FaultBlockLayer(self.grid, k) blocks.scanKeyword(self.kw) self.fault_blocks.append(blocks) def test_create(self): with self.assertRaises(TypeError): regionDef = RegionDefinition("GG") with self.assertRaises(ValueError): regionDef = RegionDefinition.create(1, self.faults, ["Test", 1]) regionDef = RegionDefinition.create( 1, self.faults, ["DF28_LC", self.poly_file1, self.poly_file2]) def test_create(self): defRegion = RegionDefinition.create(5, self.faults, [ "DF4_MC", "DF15_MC", "DF43_MC", "DF25_LC", "DF21_C", "DF1_C", self.poly_file6, "DF26_MC", "DF34_MCS", "DF32_MC", self.poly_file5 ]) region_kw = EclKW.create("REGIONS", self.grid.getGlobalSize(), EclTypeEnum.ECL_INT_TYPE) region_kw.assign(0) for k in range(self.grid.getNZ()): with self.assertRaises(NotImplementedError): block_list = defRegion.findInternalBlocks( self.grid, self.fault_blocks[k])
def test_large_case(self): grdecl_file = self.createTestPath( "Statoil/ECLIPSE/1.6.0_issueGrdecl/test_aug2016_gridOnly.grdecl") grid = EclGrid.loadFromGrdecl(grdecl_file)
def test_EclRegion_properties(self): grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1)) region = EclRegion(grid, False)
def test_GRID(self): grid = EclGrid(self.grid_file()) self.assertTrue(grid)
def test_loadFromFile(self): g1 = EclGrid.loadFromFile(self.egrid_file()) g2 = EclGrid.loadFromFile(self.grdecl_file()) self.assertTrue(isinstance(g1, EclGrid)) self.assertTrue(isinstance(g2, EclGrid))
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 test_wrong_type(self): g = EclGrid(self.grid_file) with self.assertRaises(ValueError): f = EclInitFile(g, self.grid_file)
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_create(self): grid = EclGrid.createRectangular( (10,10,5) , (1,1,1) ) field_config = FieldConfig("SWAT" , grid)
def test_default(self): grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1)) kw = Ecl3DKW.create("KW", grid, EclTypeEnum.ECL_FLOAT_TYPE) kw.setDefault(55) self.assertTrue(55, kw.getDefault())
def test_raise_IO_error(self): with self.assertRaises(IOError): g = EclGrid("/does/not/exist.EGRID")
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 setUp(self): self.grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1))
def test_time(self): t0 = time.clock() g1 = EclGrid(self.egrid_file()) t1 = time.clock() t = t1 - t0 self.assertTrue(t < 1.0)
def setUpClass(cls): cls.grid = EclGrid.createRectangular( (151,100,50) , (1,1,1))
from ert.ecl import EclFile, EclGrid from ert.ecl import Ecl3DKW from os.path import abspath, expanduser, join norne = abspath(expanduser('~/opm/opm-data/norne/opm-simulation-reference')) print('Using Norne location %s' % norne) rst = EclFile(join(norne, 'NORNE_ATW2013.UNRST')) grd = EclGrid(join(norne, 'NORNE_ATW2013.EGRID')) x = 10 # x in [0, grd.getNX()) y = 10 # y in [0, grd.getNY()) print(grd) print('Plotting SGAS, SOIL, SWAT for x,y pillar (%d, %d)' % (x, y)) swat = rst.iget_named_kw('SWAT', 0) sgas = rst.iget_named_kw('SGAS', 0) swat3d = Ecl3DKW.castFromKW(swat, grd, default_value=0) f_swat = lambda k: swat3d[x, y, k] sgas3d = Ecl3DKW.castFromKW(sgas, grd, default_value=0) f_sgas = lambda k: sgas3d[x, y, k] f_soil = lambda k: max(0, 1 - (f_sgas(k) + f_swat(k))) nz = grd.getNZ()
def test_EclGrid_get_corner_xyz(self): grid = EclGrid.create_rectangular( (10,20,30) , (1,1,1) ) with warnings.catch_warnings(): grid.get_corner_xyz(0 , global_index = 10)
def setUp(self): self.faults1 = self.createTestPath( "local/ECLIPSE/FAULTS/fault1.grdecl") self.faults2 = self.createTestPath( "local/ECLIPSE/FAULTS/fault2.grdecl") self.grid = EclGrid.create_rectangular((151, 100, 50), (1, 1, 1))
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_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") kw = EclKW.read_grdecl(open("faultblock.grdecl"), "FAULTBLK", ecl_type=EclTypeEnum.ECL_INT_TYPE) 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_valid_geometry(self): grid = EclGrid( self.createTestPath( "Statoil/ECLIPSE/GRID_INVALID_CELL/PRED_RESEST_0_R_13_0.GRID")) self.assertTrue(grid.validCellGeometry(ijk=(27, 0, 0))) self.assertFalse(grid.validCellGeometry(ijk=(0, 0, 0)))
def getGrid(self): if self._grid is None: self._grid = EclGrid(self.gridFile()) return self._grid