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", six.functools.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_translation(self): dims = (3,3,3) coord = GridGen.create_coord(dims, (1,1,1)) zcorn = GridGen.create_zcorn(dims, (1,1,1), offset=0) grid = EclGrid.create(dims, zcorn, coord, None) ijk_bound = [(0, d-1) for d in dims] translation = (1, 2, 3) sub_coord, sub_zcorn, _ = GridGen.extract_subgrid_data( dims, coord, zcorn, ijk_bound, translation=translation ) tgrid = EclGrid.create(dims, sub_zcorn, sub_coord, None) self.assertEqual(grid.getGlobalSize(), tgrid.getGlobalSize()) for gi in range(grid.getGlobalSize()): translation = numpy.array(translation) corners = [grid.getCellCorner(i, gi) for i in range(8)] corners = [tuple(numpy.array(c)+translation) for c in corners] tcorners = [tgrid.getCellCorner(i, gi) for i in range(8)] self.assertEqual(corners, tcorners)
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", six.functools.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_export(self): dims = (3, 3, 3) coord = GridGen.create_coord(dims, (1,1,1)) zcorn = GridGen.create_zcorn(dims, (1,1,1), offset=0) grid = EclGrid.create(dims, zcorn, coord, None) self.assertEqual(zcorn, grid.export_zcorn()) self.assertEqual(coord, grid.export_coord())
def test_subgrid_translation(self): grid = GridGen.create_grid((4,4,4), (1,1,1), offset=0.5, irregular=True, irregular_offset=True, concave=True, translation=(10,10,0)) # Create grid with MAPAXES mapaxes = EclKW("MAPAXES", 6, EclDataType.ECL_FLOAT) for i, val in enumerate([1200, 1400, 2500, 2500, 3700, 4000]): mapaxes[i] = val grid = EclGrid.create( grid.getDims(), grid.export_zcorn(), grid.export_coord(), None, mapaxes=mapaxes ) for translation in [ (0,0,0), (10, 10, 100), (-1, -1, -1) ]: subgrid = GridGen.extract_subgrid( grid, ((0,3), (0,3), (0,3)), translation=translation ) self.assertEqual(grid.getDims(), subgrid.getDims()) translation = numpy.array(translation) for gindex in range(grid.getGlobalSize()): grid_corners = [ grid.getCellCorner(i, global_index=gindex) for i in range(8) ] subgrid_corners = [ subgrid.getCellCorner(i, global_index=gindex) for i in range(8) ] subgrid_corners = [ list(numpy.array(corner) - translation) for corner in subgrid_corners ] for gc, sc in zip(grid_corners, subgrid_corners): self.assertAlmostEqualList( gc, sc, msg="Failed to translate corners correctly." + "Expected %s, was %s." % (gc, sc), tolerance=10e-10 )
def test_create(self): with self.assertRaises(ValueError): grid = GridGen.createRectangular( (10,20,30) , (1,1,1) , actnum = [0,1,1,2]) with self.assertRaises(ValueError): grid = GridGen.createRectangular( (10,20,30) , (1,1,1) , actnum = IntVector(initial_size = 10)) grid = GridGen.createRectangular( (10,20,30) , (1,1,1) ) # actnum=None -> all active self.assertEqual( grid.getNumActive( ) , 30*20*10) actnum = IntVector(default_value = 1 , initial_size = 6000) actnum[0] = 0 actnum[1] = 0 grid = GridGen.createRectangular( (10,20,30) , (1,1,1) , actnum = actnum) self.assertEqual( grid.getNumActive( ) , 30*20*10 - 2)
def createContainmentTestBase(): return [ (3, GridGen.create_grid((6,6,6), (1,1,1), offset=1)), (10, GridGen.create_grid((3,3,3), (1,1,1), offset=1, concave=True)), (4, GridGen.create_grid((10,10,1), (1,1,1), offset=0., misalign=True)), (3, GridGen.create_grid((6,6,6), (1,1,1), offset=0., escape_origo_shift=(100, 100, 0), irregular_offset=True, concave=True, irregular=True, scale=1.5, translation=(5,5,0), misalign=True ) ) ]
def test_numpy3D(self): nx = 10 ny = 7 nz = 5 grid = GridGen.createRectangular((nx,ny,nz) , (1,1,1)) kw = EclKW( "SWAT" , nx*ny*nz , EclDataType.ECL_FLOAT ) numpy_3d = grid.create3D( kw )
def test_oom_grid(self): nx = 2000 ny = 2000 nz = 2000 with self.assertRaises(MemoryError): grid = GridGen.createRectangular( (nx,ny,nz), (1,1,1))
def test_create(self): grid = EclGridGenerator.create_rectangular((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_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_cell_corner_containment_compatability(self): grid = GridGen.createRectangular((3, 3, 3), (1, 1, 1)) for x, y, z in itertools.product(range(4), repeat=3): for i in range(27): if grid.cell_contains(x, y, z, i): self.assertEqual(CORNER_HOME[(x, y, z)], i)
def test_extract_grid_slice_spec(self): dims = (4,4,4) zcorn = list(GridGen.create_zcorn(dims, (1,1,1), offset=0)) coord = list(GridGen.create_coord(dims, (1,1,1))) ijk_bounds = generate_ijk_bounds(dims) for ijk in ijk_bounds: ijk = list(ijk) for i in range(3): if len(set(ijk[i])) == 1: ijk[i] = ijk[i][0] GridGen.extract_subgrid_data(dims, coord, zcorn, ijk, decomposition_change=True)
def setUp(self): self.grid = EclGridGenerator.create_rectangular((46, 112, 22), (1, 1, 1)) self.rst_file_ICON0 = self.createTestPath( "local/ECLIPSE/well/missing-ICON/ICON0.X0027") self.rst_file_ICON1 = self.createTestPath( "local/ECLIPSE/well/missing-ICON/ICON1.X0027")
def test_geertsma_TS(setUp): spec, actnum, parms = setUp grid = EclGridGenerator.createRectangular( dims=(2, 2, 2), dV=(100, 100, 100), actnum=actnum ) create_restart(grid, "TEST") create_init(grid, "TEST") grid.save_EGRID("TEST.EGRID") parms.velocity_model = "TEST.segy" int_val = [50, 150] create_segy_file( parms.velocity_model, spec, xl=int_val, il=int_val, cdp_x=int_val, cdp_y=int_val ) ots = OverburdenTimeshift( parms.eclbase, parms.mapaxes, parms.seabed, parms.youngs, parms.poisson, parms.rfactor, parms.convention, parms.above, parms.velocity_model, ) vintage_pairs = [ (datetime.date(2000, 1, 1), datetime.date(2010, 1, 1)), (datetime.date(2010, 1, 1), datetime.date(2011, 1, 1)), ] tshift = ots.geertsma_ts(vintage_pairs) assert tshift[0][0] == pytest.approx(-0.00104, abs=0.0001) parms.convention = -1 ots = OverburdenTimeshift( parms.eclbase, parms.mapaxes, parms.seabed, parms.youngs, parms.poisson, parms.rfactor, parms.convention, parms.above, parms.velocity_model, ) vintage_pairs = [ (datetime.date(2000, 1, 1), datetime.date(2010, 1, 1)), (datetime.date(2010, 1, 1), datetime.date(2011, 1, 1)), ] tshift = ots.geertsma_ts(vintage_pairs) assert tshift[0][0] == pytest.approx(0.00104, abs=0.0001)
def test_dims(self): grid = GridGen.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 = GridGen.createRectangular( (nx,ny,nz) , (1,1,1) ) kw1 = EclKW("KW" , 1001 , EclDataType.ECL_INT ) with self.assertRaises(ValueError): cp = grid.compressedKWCopy( kw1 )
def test_create(setup_spec): spec = setup_spec vel = "TEST.segy" create_segy_file(vel, spec) grid = EclGridGenerator.createRectangular(dims=(2, 2, 2), dV=(100, 100, 100)) res_surface = OTSResSurface(grid=grid, above=0) OTSVelSurface(res_surface, vel)
def test_concvex_cell_containment(self): points = [ (10, 10, 10), (25, 5, 5), (5, 25, 5), (20, 20, 10), (5, 5, 25), (20, 10, 20), (10, 20, 20), (25, 25, 25) ] grid = GridGen.create_single_cell_grid(points) assertPoint = lambda p : self.assertTrue( grid.cell_contains(p[0], p[1], p[2], 0) ) assertNotPoint = lambda p : self.assertFalse( grid.cell_contains(p[0], p[1], p[2], 0) ) # Cell center assertPoint(average(points)); # "Side" center assertPoint(average(points[0:4:])) assertPoint(average(points[4:8:])) assertPoint(average(points[1:8:2])) assertPoint(average(points[0:8:2])) assertPoint(average(points[0:8:4] + points[1:8:4])) assertPoint(average(points[2:8:4] + points[3:8:4])) # Corners for p in points: assertPoint(p) # Edges edges = ([(i, i+1) for i in range(0, 8, 2)] + [(i, i+2) for i in [0, 1, 4, 5]] + [(i, i+4) for i in range(4)] + [(1,2), (2,7), (1,7), (4,7), (2,4), (4,1)]) for a,b in edges: assertPoint(average([points[a], points[b]])) # Epsilon inside from corners middle_point = average(points) for p in points: assertPoint(average(20*[p] + [middle_point])) # Espilon outside middle_point[2] = 0 for p in points[0:4:]: assertNotPoint(average(20*[p] + [middle_point])) middle_point[2] = 30 for p in points[4:8:]: assertNotPoint(average(20*[p] + [middle_point]))
def test_surface_above(tmpdir): grid = EclGridGenerator.createRectangular(dims=(2, 2, 2), dV=(100, 100, 100), actnum=[0, 0, 0, 0, 1, 1, 1, 1]) surface = OTSResSurface(grid=grid, above=10) z = np.ones(4) * (100 - 10) assert np.all(z == surface.z)
def test_cell_corner_containment(self): n = 4 d = 10 grid = GridGen.createRectangular((n, n, n), (d, d, d)) for x, y, z in itertools.product(range(0, n * d + 1, d), repeat=3): self.assertEqual(1, [ grid.cell_contains(x, y, z, i) for i in range(n**3) ].count(True))
def test_cell_corner_containment(self): n = 4 d = 10 grid = GridGen.createRectangular( (n, n, n), (d, d, d)) for x, y, z in itertools.product(range(0, n*d+1, d), repeat=3): self.assertEqual( 1, [grid.cell_contains(x, y, z, i) for i in range(n**3)].count(True) )
def test_z3d(setup_spec): spec = setup_spec vel = "TEST.segy" int_val = [50, 150] create_segy_file(vel, spec, xl=int_val, il=int_val, cdp_x=int_val, cdp_y=int_val) grid = EclGridGenerator.createRectangular(dims=(2, 2, 2), dV=(100, 100, 100)) res_surface = OTSResSurface(grid=grid, above=0) ots_s = OTSVelSurface(res_surface, vel) assert (4, 2) == ots_s.z3d.shape
def test_cell_corner_containment_compatability(self): grid = GridGen.createRectangular( (3,3,3), (1,1,1) ) for x, y, z in itertools.product(range(4), repeat=3): for i in range(27): if grid.cell_contains(x, y, z, i): self.assertEqual( CORNER_HOME[(x,y,z)], i )
def test_dxdydz(self): nx = 10 ny = 10 nz = 10 grid = GridGen.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_create_3d_agrees_with_get_value(self): nx = 5 ny = 3 nz = 2 grid = GridGen.createRectangular((nx, ny, nz), (1, 1, 1)) kw = EclKW("SWAT", nx * ny * nz, EclDataType.ECL_FLOAT) for k, j, i in itertools.product(range(nz), range(ny), range(nx)): kw[i + j * nx + nx * ny * k] = i * j * k numpy_3d = grid.create3D(kw) for k, j, i in itertools.product(range(nz), range(ny), range(nx)): self.assertAlmostEqual(numpy_3d[i, j, k], grid.grid_value(kw, i, j, k))
def test_extract_grid_invalid_bounds(self): dims = (3,3,3) zcorn = list(GridGen.create_zcorn(dims, (1,1,1), offset=0)) coord = list(GridGen.create_coord(dims, (1,1,1))) with self.assertRaises(ValueError): GridGen.extract_subgrid_data(dims, coord, zcorn, ((-1,0), (2,2), (2,2))) with self.assertRaises(ValueError): GridGen.extract_subgrid_data(dims, coord, zcorn, ((1,6), (2,2), (2,2))) with self.assertRaises(ValueError): GridGen.extract_subgrid_data(dims, coord, zcorn, ((1,2), (2,0), (2,2)))
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_create_3d_is_create_kw_inverse(self): nx = 10 ny = 7 nz = 5 grid = GridGen.create_rectangular((nx, ny, nz), (1, 1, 1)) kw1 = EclKW("SWAT", nx * ny * nz, EclDataType.ECL_FLOAT) for k, j, i in itertools.product(range(nz), range(ny), range(nx)): kw1[i + j * nx + nx * ny * k] = i * j * k numpy_3d = grid.create3D(kw1) kw2 = grid.create_kw(numpy_3d, "SWAT", False) self.assertEqual(kw2.name, "SWAT") assert_allclose(grid.create3D(kw2), numpy_3d)
def test_posXY1(self): nx = 4 ny = 1 nz = 1 grid = GridGen.createRectangular( (nx,ny,nz) , (1,1,1) ) (i,j) = grid.findCellXY( 0.5 , 0.5, 0 ) self.assertEqual(i , 0) self.assertEqual(j , 0) (i,j) = grid.findCellXY( 3.5 , 0.5, 0 ) self.assertEqual(i , 3) self.assertEqual(j , 0)
def setUp(self): self.test_base = [ ( list(GridGen.create_coord((4, 4, 4), (1, 1, 1))), list(GridGen.create_zcorn((4, 4, 4), (1, 1, 1), offset=0)), GridGen.create_grid((4, 4, 4), (1, 1, 1), offset=0), ), ( list( GridGen.create_coord((5, 5, 5), (1, 1, 1), translation=(10, 10, 0))), list( GridGen.create_zcorn( (5, 5, 5), (1, 1, 1), offset=0.5, irregular_offset=True, concave=True, irregular=True, )), GridGen.create_grid( (5, 5, 5), (1, 1, 1), offset=0.5, irregular=True, irregular_offset=True, concave=True, translation=(10, 10, 0), ), ), ]
def test_subgrid_extration(self): for _, _, grid in self.test_base[:-1:]: grid_dims = grid.getDims()[:-1:] ijk_bounds = generate_ijk_bounds(grid_dims) for ijk_bound in ijk_bounds: if not decomposition_preserving(ijk_bound): continue sub_dims = tuple([u - l + 1 for l, u in ijk_bound]) subgrid = GridGen.extract_subgrid(grid, ijk_bound) self.assertEqual(sub_dims, subgrid.getDims()[:-1:]) self.assertSubgrid(grid, subgrid, ijk_bound)
def test_len(self): nx = 10 ny = 11 nz = 12 actnum = EclKW( "ACTNUM" , nx*ny*nz , EclDataType.ECL_INT ) actnum[0] = 1 actnum[1] = 1 actnum[2] = 1 actnum[3] = 1 grid = GridGen.createRectangular( (nx,ny,nz) , (1,1,1), actnum = actnum) self.assertEqual( len(grid) , nx*ny*nz ) self.assertEqual( grid.getNumActive( ) , 4 )
def test_cell_face_containment(self): n = 4 d = 10 grid = GridGen.createRectangular( (n, n, n), (d, d, d)) for x, y, z in itertools.product(range(d/2, n*d, d), repeat=3): for axis, direction in itertools.product(range(3), [-1, 1]): p = [x, y, z] p[axis] = p[axis] + direction*d/2 self.assertEqual( 1, [grid.cell_contains(p[0], p[1], p[2], i) for i in range(n**3)].count(True) )
def test_cell_face_containment(self): n = 4 d = 10 grid = GridGen.createRectangular( (n, n, n), (d, d, d)) for x, y, z in itertools.product(range(d//2, n*d, d), repeat=3): for axis, direction in itertools.product(range(3), [-1, 1]): p = [x, y, z] p[axis] = p[axis] + direction*d/2 self.assertEqual( 1, [grid.cell_contains(p[0], p[1], p[2], i) for i in range(n**3)].count(True) )
def test_node_pos(self): grid = GridGen.createRectangular( (10,20,30) , (1,1,1) ) with self.assertRaises(IndexError): grid.getNodePos(-1,0,0) with self.assertRaises(IndexError): grid.getNodePos(11,0,0) p0 = grid.getNodePos(0,0,0) self.assertEqual( p0 , (0,0,0)) p7 = grid.getNodePos(10,20,30) self.assertEqual( p7 , (10,20,30))
def test_subgrid_extration(self): for _, _, grid in self.test_base[:-1:]: grid_dims = grid.getDims()[:-1:] ijk_bounds = generate_ijk_bounds(grid_dims) for ijk_bound in ijk_bounds: if not decomposition_preserving(ijk_bound): continue sub_dims = tuple([u-l+1 for l, u in ijk_bound]) subgrid = GridGen.extract_subgrid(grid, ijk_bound) self.assertEqual(sub_dims, subgrid.getDims()[:-1:]) self.assertSubgrid(grid, subgrid, ijk_bound)
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_init_ACTNUM(self): nx = 10 ny = 23 nz = 7 grid = GridGen.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 ) actnum_kw = grid.exportACTNUMKw( ) self.assertEqual(len(actnum_kw) , len(actnum)) for a1,a2 in zip(actnum, actnum_kw): self.assertEqual(a1, a2)
def test_extract_grid_decomposition_change(self): dims = (4,4,4) zcorn = list(GridGen.create_zcorn(dims, (1,1,1), offset=0)) coord = list(GridGen.create_coord(dims, (1,1,1))) ijk_bounds = generate_ijk_bounds(dims) for ijk_bounds in ijk_bounds: if decomposition_preserving(ijk_bounds): GridGen.extract_subgrid_data(dims, coord, zcorn, ijk_bounds) else: with self.assertRaises(ValueError): GridGen.extract_subgrid_data(dims, coord, zcorn, ijk_bounds) GridGen.extract_subgrid_data(dims, coord, zcorn, ijk_bounds, decomposition_change=True)
def createWrapperGrid(grid): """ Creates a grid that occupies the same space as the given grid, but that consists of a single cell. """ x, y, z = grid.getNX()-1, grid.getNY()-1, grid.getNZ()-1 corner_pos = [ (0, 0, 0), (x, 0, 0), (0, y, 0), (x, y, 0), (0, 0, z), (x, 0, z), (0, y, z), (x, y, z) ] corners = [ grid.getCellCorner(i, ijk=pos) for i, pos in enumerate(corner_pos) ] return GridGen.create_single_cell_grid(corners)
def test_validate_cells(self): for coord, zcorn, grid in self.test_base: grid_dims = grid.getDims()[:-1:] ijk_bounds = generate_ijk_bounds(grid_dims) for ijk_bound in ijk_bounds: if not decomposition_preserving(ijk_bound): continue sub_dims = tuple([u-l+1 for l, u in ijk_bound]) sub_coord, sub_zcorn, _ = GridGen.extract_subgrid_data( grid_dims, coord, zcorn, ijk_bound ) subgrid = EclGrid.create(sub_dims, sub_zcorn, sub_coord, None) self.assertEqual(sub_dims, subgrid.getDims()[:-1:]) self.assertSubgrid(grid, subgrid, ijk_bound)
def test_posXYEdge(self): nx = 10 ny = 11 grid = GridGen.createRectangular( (nx,ny,1) , (1,1,1) ) self.assertEqual( grid.findCellCornerXY(0,0,0) , 0 ) self.assertEqual( grid.findCellCornerXY(nx,0,0) , nx) self.assertEqual( grid.findCellCornerXY(0 , ny , 0) , (nx + 1 ) * ny ) self.assertEqual( grid.findCellCornerXY(nx,ny,0) , (nx + 1 ) * (ny + 1) - 1) self.assertEqual( grid.findCellCornerXY(0.25,0,0) , 0 ) self.assertEqual( grid.findCellCornerXY(0,0.25,0) , 0 ) self.assertEqual( grid.findCellCornerXY(nx - 0.25,0,0) , nx ) self.assertEqual( grid.findCellCornerXY(nx , 0.25,0) , nx ) self.assertEqual( grid.findCellCornerXY(0 , ny - 0.25, 0) , (nx + 1 ) * ny ) self.assertEqual( grid.findCellCornerXY(0.25 , ny , 0) , (nx + 1 ) * ny ) self.assertEqual( grid.findCellCornerXY(nx -0.25 ,ny,0) , (nx + 1 ) * (ny + 1) - 1) self.assertEqual( grid.findCellCornerXY(nx , ny - 0.25,0) , (nx + 1 ) * (ny + 1) - 1)
def test_posXY(self): nx = 10 ny = 23 nz = 7 grid = GridGen.createRectangular( (nx,ny,nz) , (1,1,1) ) with self.assertRaises(IndexError): grid.findCellXY( 1 , 1, -1 ) with self.assertRaises(IndexError): grid.findCellXY( 1 , 1, nz + 1 ) with self.assertRaises(ValueError): grid.findCellXY(15 , 78 , 2) i,j = grid.findCellXY( 1.5 , 1.5 , 2 ) self.assertEqual(i , 1) self.assertEqual(j , 1) for i in range(nx): for j in range(ny): p = grid.findCellXY(i + 0.5 , j+ 0.5 , 0) self.assertEqual( p[0] , i ) self.assertEqual( p[1] , j ) c = grid.findCellCornerXY( 0.10 , 0.10 , 0 ) self.assertEqual(c , 0) c = grid.findCellCornerXY( 0.90 , 0.90 , 0 ) self.assertEqual( c , (nx + 1) + 1 ) c = grid.findCellCornerXY( 0.10 , 0.90 , 0 ) self.assertEqual( c , (nx + 1) ) c = grid.findCellCornerXY( 0.90 , 0.90 , 0 ) self.assertEqual( c , (nx + 1) + 1 ) c = grid.findCellCornerXY( 0.90 , 0.10 , 0 ) self.assertEqual( c , 1 )