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_fault_barrier(self): nx = 120 ny = 60 nz = 43 grid = EclGrid.createRectangular( (nx , ny , nz) , (1,1,1) ) with TestAreaContext("python/faults/line_order"): with open("faults.grdecl" , "w") as f: f.write("""FAULTS \'F\' 105 107 50 50 1 43 \'Y\' / \'F\' 108 108 50 50 1 43 \'X\' / \'F\' 108 108 50 50 22 43 \'Y\' / \'F\' 109 109 49 49 1 43 \'Y\' / \'F\' 110 110 49 49 1 43 \'X\' / \'F\' 111 111 48 48 1 43 \'Y\' / / """) with open("faults.grdecl") as f: faults = FaultCollection( grid , "faults.grdecl" ) # Fault layout: # # +---+---+---+---+ # | # +---+ + # | # +---+ fault = faults["F"] layer = Layer(nx,ny) fault_pairs = [((104,49),(104,50)), ((105,49),(105,50)), ((106,49),(106,50)), ((107,49),(108,49)), ((107,49),(107,50)), ((108,48),(108,49)), ((109,48),(110,48)), ((110,47),(110,48))] gap_pair = ((109,48),(109,49)) for p1,p2 in fault_pairs: self.assertTrue(layer.cellContact( p1 , p2 )) p1,p2 = gap_pair self.assertTrue(layer.cellContact( p1 , p2 )) layer.addFaultBarrier(fault , 30 , link_segments = False) for p1,p2 in fault_pairs: self.assertFalse(layer.cellContact( p1 , p2 )) p1,p2 = gap_pair self.assertTrue(layer.cellContact( p1 , p2 )) layer.addFaultBarrier(fault , 30) p1,p2 = gap_pair self.assertFalse(layer.cellContact( p1 , p2 ))
def test_load(self): grid = self.loadGrid() faults_file = self.createTestPath( "Statoil/ECLIPSE/Faults/faults.grdecl") faults = FaultCollection(grid, faults_file) for fault in faults: for layer in fault: for fl in layer: fl.verify()
def test_load(self): faults = FaultCollection(self.grid, self.faults1) self.assertEqual(3, len(faults)) faults.load(self.grid, self.faults2) self.assertEqual(7, len(faults)) fault1 = faults["F1"] layer8 = fault1[8] self.assertEqual(len(layer8), 1) with self.assertRaises(IOError): faults.load(self.grid, "No/this/does/not/exist")
def test_iter(self): faults = FaultCollection(self.grid, self.faults1, self.faults2) self.assertEqual(7, len(faults)) c = 0 for f in faults: c += 1 self.assertEqual(c, len(faults)) for f in ["F1", "F2", "F3", "F4"]: self.assertTrue(f in faults) self.assertFalse("FX" in faults)
def test_internal_blocks(self): nx = 8 ny = 8 nz = 1 grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) layer = FaultBlockLayer(grid, 0) with TestAreaContext("python/FaultBlocks/internal_blocks"): 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 4 4 1 2 5 5 2 \n") fileH.write("1 4 4 1 2 5 5 2 \n") fileH.write("1 1 1 1 2 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("1 1 3 1 1 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("/\n") kw = EclKW.read_grdecl(open("faultblock.grdecl"), "FAULTBLK", ecl_type=EclDataType.ECL_INT) with open("faults.grdecl", "w") as f: f.write("FAULTS\n") f.write("\'FX\' 4 4 1 4 1 1 'X' /\n") f.write("\'FX\' 5 5 4 4 1 1 'Y' /\n") f.write("\'FX\' 5 5 5 8 1 1 'X' /\n") f.write("/") faults = FaultCollection(grid, "faults.grdecl") layer.loadKeyword(kw) layer.addFaultBarrier(faults["FX"]) b1 = layer.getBlock(1) b2 = layer.getBlock(2) b3 = layer.getBlock(3) b4 = layer.getBlock(4) b5 = layer.getBlock(5) nb = b1.getNeighbours() for b in nb: print('Block:%d' % b.getBlockID()) self.assertTrue(len(nb) == 2) self.assertTrue(b3 in nb) self.assertTrue(b4 in nb) nb = b2.getNeighbours() self.assertTrue(len(nb) == 1) self.assertTrue(b5 in nb)
def test_empty_collection(self): faults = FaultCollection() self.assertEqual(0, len(faults)) self.assertFalse(faults.hasFault("FX")) with self.assertRaises(TypeError): f = faults[[]] with self.assertRaises(KeyError): f = faults["FX"] with self.assertRaises(IndexError): f = faults[0] self.assertFalse("NAME" in faults)
def test_splitLine(self): faults = FaultCollection(self.grid) with self.assertRaises(ValueError): # Not slash terminated t = faults.splitLine("'F1' 149 149 29 29 1 43 'Y'") with self.assertRaises(ValueError): # Not integer t = faults.splitLine("'F1' 149 149 29 29 1 43X 'Y' /") with self.assertRaises(ValueError): # Missing item t = faults.splitLine("'F1' 149 29 29 1 43 'Y' /") with self.assertRaises(ValueError): # Quote fuckup t = faults.splitLine("'F1 149 149 29 29 1 43 'X' /")
def test_contact(self): nx = 20 ny = 10 layer = Layer(nx,ny) grid = EclGrid.createRectangular( (nx,ny,1) , (1,1,1) ) with self.assertRaises(IndexError): layer.cellContact( (-1,0),(1,1) ) with self.assertRaises(IndexError): layer.cellContact( (20,0),(1,1) ) self.assertFalse( layer.cellContact((0,0) , (2,0)) ) self.assertFalse( layer.cellContact((1,0) , (1,0)) ) self.assertTrue( layer.cellContact((0,0) , (1,0)) ) self.assertTrue( layer.cellContact((1,0) , (0,0)) ) self.assertTrue( layer.cellContact((0,0) , (0,1)) ) self.assertTrue( layer.cellContact((0,1) , (0,0)) ) self.assertFalse( layer.cellContact((0,0) , (1,1)) ) self.assertFalse( layer.cellContact((1,1) , (0,0)) ) self.assertTrue( layer.cellContact((4,0) , (5,0)) ) self.assertTrue( layer.cellContact((0,4) , (0,5)) ) with TestAreaContext("Layer/barrier"): with open("faults.grdecl" , "w") as f: f.write("FAULTS\n") f.write("\'FX\' 5 5 1 10 1 1 'X' /\n") f.write("\'FY\' 1 10 5 5 1 1 'Y' /\n") f.write("/") faults = FaultCollection( grid , "faults.grdecl") layer.addFaultBarrier( faults["FX"] , 0 ) self.assertFalse( layer.cellContact((4,0) , (5,0)) ) layer.addFaultBarrier( faults["FY"] , 0 ) self.assertFalse( layer.cellContact((0,4) , (0,5)) ) self.assertFalse( layer.cellContact((9,4) , (9,5)) ) self.assertTrue( layer.cellContact((10,4) , (10,5)) )
def test_num_linesegment(self): nx = 10 ny = 10 nz = 1 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 \'F1\' 1 4 2 2 1 1 \'Y\' / \'F1\' 6 8 2 2 1 1 \'Y\' / \'F2\' 1 8 2 2 1 1 \'Y\' / / """) faults = FaultCollection(grid, "faults.grdecl") f1 = faults["F1"] f2 = faults["F2"] self.assertEqual(2, f1.numLines(0)) self.assertEqual(1, f2.numLines(0))
def test_neighbours3(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("1 1 1 1 1 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("1 1 1 1 1 2 2 2 \n") fileH.write("/\n") kw = EclKW.read_grdecl(open("faultblock.grdecl"), "FAULTBLK", ecl_type=EclDataType.ECL_INT) with open("faults.grdecl", "w") as f: f.write("FAULTS\n") f.write("\'FX\' 4 4 1 4 1 1 'X' /\n") f.write("\'FX\' 5 5 5 8 1 1 'X' /\n") f.write("/") faults = FaultCollection(grid, "faults.grdecl") layer.loadKeyword(kw) b1 = layer.getBlock(1) b2 = layer.getBlock(2) nb = b1.getNeighbours() self.assertTrue(b2 in nb) layer.addFaultBarrier(faults["FX"], link_segments=False) nb = b1.getNeighbours() self.assertTrue(b2 in nb)
def test_collection_invalid_arg(self): with self.assertRaises(ValueError): faults = FaultCollection(self.faults1) with self.assertRaises(ValueError): faults = FaultCollection(self.faults1, self.faults2)
def test_neighbour_cells(self): nx = 10 ny = 8 nz = 7 grid = EclGrid.createRectangular((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_fault_line(self): faults = FaultCollection(self.grid, self.faults1, self.faults2) for fault in faults: for layer in fault: for fl in layer: fl.verify()
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=EclDataType.ECL_INT) 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)