def test_kw_vector(self): case1 = create_case() case2 = createEclSum("CSV" , [("FOPR", None , 0, "SM3/DAY") , ("FOPT" , None , 0, "SM3"), ("FWPT" , None , 0, "SM3")], sim_length_days = 100, num_report_step = 10, num_mini_step = 10, func_table = {"FOPT" : fopt, "FOPR" : fopr , "FWPT" : fgpt }) kw_list = EclSumKeyWordVector( case1 ) kw_list.add_keyword("FOPT") kw_list.add_keyword("FGPT") kw_list.add_keyword("FOPR") t = case1.getDataStartTime( ) + datetime.timedelta( days = 43 ); data = case1.get_interp_row( kw_list , t ) for d1,d2 in zip(data, [ case1.get_interp("FOPT", date = t), case1.get_interp("FOPT", date = t), case1.get_interp("FOPT", date = t) ]): self.assertFloatEqual(d1,d2) tmp = [] for key in kw_list: tmp.append(key) for (k1,k2) in zip(kw_list,tmp): self.assertEqual(k1,k2) kw_list2 = kw_list.copy(case2) self.assertIn("FOPT", kw_list2) self.assertIn("FOPR", kw_list2) self.assertIn("FGPT", kw_list2) data2 = case2.get_interp_row( kw_list2 , t ) self.assertEqual(len(data2), 3) self.assertEqual(data[0], data2[0]) self.assertEqual(data[2], data2[2]) with TestAreaContext("sum_vector"): with cwrap.open("f1.txt","w") as f: case1.dumpCSVLine(t, kw_list, f) with cwrap.open("f2.txt", "w") as f: case2.dumpCSVLine(t,kw_list2,f) with open("f1.txt") as f: d1 = f.readline().split(",") with open("f2.txt") as f: d2 = f.readline().split(",") self.assertEqual(d1[0],d2[0]) self.assertEqual(d1[2],d2[2]) self.assertEqual(d2[1],"")
def test_kw_vector(self): case1 = create_case() case2 = createEclSum("CSV" , [("FOPR", None , 0, "SM3/DAY") , ("FOPT" , None , 0, "SM3"), ("FWPT" , None , 0, "SM3")], sim_length_days = 100, num_report_step = 10, num_mini_step = 10, func_table = {"FOPT" : fopt, "FOPR" : fopr , "FWPT" : fgpt }) kw_list = EclSumKeyWordVector( case1 ) kw_list.add_keyword("FOPT") kw_list.add_keyword("FGPT") kw_list.add_keyword("FOPR") t = case1.getDataStartTime( ) + datetime.timedelta( days = 43 ); data = case1.get_interp_row( kw_list , t ) for d1,d2 in zip(data, [ case1.get_interp("FOPT", date = t), case1.get_interp("FOPT", date = t), case1.get_interp("FOPT", date = t) ]): self.assertFloatEqual(d1,d2) tmp = [] for key in kw_list: tmp.append(key) for (k1,k2) in zip(kw_list,tmp): self.assertEqual(k1,k2) kw_list2 = kw_list.copy(case2) self.assertIn("FOPT", kw_list2) self.assertIn("FOPR", kw_list2) self.assertIn("FGPT", kw_list2) data2 = case2.get_interp_row( kw_list2 , t ) self.assertEqual(len(data2), 3) self.assertEqual(data[0], data2[0]) self.assertEqual(data[2], data2[2]) with TestAreaContext("sum_vector"): with cwrap.open("f1.txt","w") as f: case1.dumpCSVLine(t, kw_list, f) with cwrap.open("f2.txt", "w") as f: case2.dumpCSVLine(t,kw_list2,f) with open("f1.txt") as f: d1 = f.readline().split(",") with open("f2.txt") as f: d2 = f.readline().split(",") self.assertEqual(d1[0],d2[0]) self.assertEqual(d1[2],d2[2]) self.assertEqual(d2[1],"")
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") with cwrap.open("kw.grdecl") as f: kw = EclKW.read_grdecl(f, "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_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") with cwrap.open("kw.grdecl") as f: kw = EclKW.read_grdecl( f, "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_is_fortran_file(self): with TestAreaContext("python/fortio/guess"): kw1 = EclKW("KW" , 12345 , EclDataType.ECL_FLOAT) with openFortIO("fortran_file" , mode = FortIO.WRITE_MODE) as f: kw1.fwrite( f ) with cwrap.open("text_file" , "w") as f: kw1.write_grdecl( f ) self.assertTrue( FortIO.isFortranFile( "fortran_file" )) self.assertFalse( FortIO.isFortranFile( "text_file" ))
def test_64bit_memory(self): with TestAreaContext("large_memory"): block_size = 10**6 with open("test.grdecl", "w") as f: f.write("COORD\n") for i in range(1000): f.write("%d*0.15 \n" % block_size) f.write("/\n") with cwrap.open("test.grdecl") as f: kw = EclKW.read_grdecl(f, "COORD")
def test_is_fortran_file(self): with TestAreaContext("python/fortio/guess"): kw1 = EclKW("KW", 12345, EclDataType.ECL_FLOAT) with openFortIO("fortran_file", mode=FortIO.WRITE_MODE) as f: kw1.fwrite(f) with cwrap.open("text_file", "w") as f: kw1.write_grdecl(f) self.assertTrue(FortIO.isFortranFile("fortran_file")) self.assertFalse(FortIO.isFortranFile("text_file"))
def test_neighbours(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") with cwrap.open("kw.grdecl") as f: kw = EclKW.read_grdecl(f, "FAULTBLK", ecl_type=EclDataType.ECL_INT) grid = EclGrid.createRectangular((5, 5, 1), (1, 1, 1)) layer = FaultBlockLayer(grid, 0) layer.loadKeyword(kw) block1 = layer.getBlock(1) block2 = layer.getBlock(2) block3 = layer.getBlock(3) block4 = layer.getBlock(4) block5 = layer.getBlock(5) self.assertEqual(block1.getParentLayer(), layer) #Expected: 1 -> {2,4}, 2 -> {1,3,4}, 3 -> {2}, 4 -> {1,2}, 5-> {} neighbours = block1.getNeighbours() self.assertEqual(len(neighbours), 2) self.assertTrue(block2 in neighbours) self.assertTrue(block4 in neighbours) neighbours = block2.getNeighbours() self.assertEqual(len(neighbours), 3) self.assertTrue(block1 in neighbours) self.assertTrue(block3 in neighbours) self.assertTrue(block4 in neighbours) neighbours = block3.getNeighbours() self.assertEqual(len(neighbours), 1) self.assertTrue(block2 in neighbours) neighbours = block4.getNeighbours() self.assertEqual(len(neighbours), 2) self.assertTrue(block1 in neighbours) self.assertTrue(block2 in neighbours) neighbours = block5.getNeighbours() self.assertEqual(len(neighbours), 0)
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") with cwrap.open("faultblock.grdecl") as f: kw = EclKW.read_grdecl(f, "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_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") with cwrap.open("faultblock.grdecl") as f: kw = EclKW.read_grdecl( f, "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_neighbours(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") with cwrap.open("kw.grdecl") as f: kw = EclKW.read_grdecl( f, "FAULTBLK", ecl_type=EclDataType.ECL_INT) grid = EclGrid.createRectangular( (5,5,1) , (1,1,1) ) layer = FaultBlockLayer( grid , 0 ) layer.loadKeyword( kw ) block1 = layer.getBlock( 1 ) block2 = layer.getBlock( 2 ) block3 = layer.getBlock( 3 ) block4 = layer.getBlock( 4 ) block5 = layer.getBlock( 5 ) self.assertEqual( block1.getParentLayer() , layer ) #Expected: 1 -> {2,4}, 2 -> {1,3,4}, 3 -> {2}, 4 -> {1,2}, 5-> {} neighbours = block1.getNeighbours() self.assertEqual( len(neighbours) , 2) self.assertTrue( block2 in neighbours ) self.assertTrue( block4 in neighbours ) neighbours = block2.getNeighbours() self.assertEqual( len(neighbours) , 3) self.assertTrue( block1 in neighbours ) self.assertTrue( block3 in neighbours ) self.assertTrue( block4 in neighbours ) neighbours = block3.getNeighbours() self.assertEqual( len(neighbours) , 1) self.assertTrue( block2 in neighbours ) neighbours = block4.getNeighbours() self.assertEqual( len(neighbours) , 2) self.assertTrue( block1 in neighbours ) self.assertTrue( block2 in neighbours ) neighbours = block5.getNeighbours() self.assertEqual( len(neighbours) , 0)
def test_eclkw_read_grdecl(tmp_path): block_size = 10 num_blocks = 5 value = 0.15 with open(tmp_path / "test.grdecl", "w") as f: f.write("COORD\n") for _ in range(num_blocks): f.write(f"{block_size}*{value} \n") f.write("/\n") with cwrap.open(str(tmp_path / "test.grdecl")) as f: kw = EclKW.read_grdecl(f, "COORD") assert kw.get_name() == "COORD" assert len(kw.numpy_view()) == block_size * num_blocks assert allclose(kw.numpy_view(), value)
def kw_test(self, data_type, data, fmt): name1 = "file1.txt" name2 = "file2.txt" kw = EclKW("TEST", len(data), data_type) for (i,d) in enumerate(data): kw[i] = d file1 = cwrap.open(name1, "w") kw.fprintf_data(file1, fmt) file1.close() file2 = open(name2, "w") for d in data: file2.write(fmt % d) file2.close() self.assertFilesAreEqual(name1, name2) self.assertEqual(kw.data_type, data_type)
def kw_test(self, data_type, data, fmt): name1 = "file1.txt" name2 = "file2.txt" kw = EclKW("TEST", len(data), data_type) for (i, d) in enumerate(data): kw[i] = d file1 = cwrap.open(name1, "w") kw.fprintf_data(file1, fmt) file1.close() file2 = open(name2, "w") for d in data: file2.write(fmt % d) file2.close() self.assertFilesAreEqual(name1, name2) self.assertEqual(kw.data_type, data_type)
def test_fprintf_data(self): with TestAreaContext("kw_no_header"): kw = EclKW("REGIONS", 10, EclDataType.ECL_INT) for i in range(len(kw)): kw[i] = i fileH = cwrap.open("test", "w") kw.fprintf_data(fileH) fileH.close() fileH = open("test", "r") data = [] for line in fileH.readlines(): tmp = line.split() for elm in tmp: data.append(int(elm)) for (v1, v2) in zip(data, kw): self.assertEqual(v1, v2)
def test_fprintf_data(self): with TestAreaContext("kw_no_header"): kw = EclKW("REGIONS", 10, EclDataType.ECL_INT) for i in range(len(kw)): kw[i] = i fileH = cwrap.open("test", "w") kw.fprintf_data(fileH) fileH.close() fileH = open("test", "r") data = [] for line in fileH.readlines(): tmp = line.split() for elm in tmp: data.append(int(elm)) for (v1,v2) in zip(data,kw): self.assertEqual(v1,v2)
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") with cwrap.open("faultblock.grdecl") as f: kw = EclKW.read_grdecl(f, "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 write_grdecl_file( df_prop: pd.DataFrame, column_name: str, filename: Optional[Union[pathlib.Path, str]] = None, int_type: bool = False, ) -> Optional[str]: """ Writes a list of values as an Eclipse grid file. The values need to be ordered in the "Eclipse way" (e.g. looping over X then Y then Z). Args: df_prop: A dataframe with as many rows as there are grid cells. column_name: Column in the dataframe to use as values. filename: Output filename to write to (e.g. "poro.grdecl"). If not given, return output as string. int_type: If the output file is to use integers (if False, save as floats). Returns: Output as string or None when output is written to a file """ values = (df_prop[column_name].astype( int if int_type else float).values.flatten().tolist()) outputfilename: Union[pathlib.Path, str] = "" if filename is None: _, outputfilename = tempfile.mkstemp() else: outputfilename = filename with cwrap.open(str(outputfilename), "w") as fh: construct_kw(column_name, values, int_type=int_type).write_grdecl(fh) if filename is None: outputfile = pathlib.Path(outputfilename) content = outputfile.read_text() outputfile.unlink() return content return None
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") with cwrap.open("faultblock.grdecl") as f: kw = EclKW.read_grdecl( f, "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_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") with cwrap.open("faultblock.grdecl") as f: kw = EclKW.read_grdecl( f, "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 )
def sector_to_fluxnum(args): """ Wrapper function that generates an ECL DATA file with single FLUXNUM based on user Region-of-Interest. This is the function that executes the different steps in the workflow for generating sector models in ECLIPSE. The sector models have the same resolution as the full-field model """ now = datetime.datetime.now() args.ECLIPSE_CASE = os.path.abspath(args.ECLIPSE_CASE).split(".")[0:1] if not args.ECLIPSE_CASE: raise Exception("ERROR: Case does not exist", " ") # Root name for writing to target directory eclipse_case_root = os.path.basename(args.ECLIPSE_CASE[0]) args.OUTPUT_CASE = args.OUTPUT_CASE.split(".")[0:1] if not args.OUTPUT_CASE: raise Exception("ERROR: Specify OUTPUT_NAME of final FLUX file", " ") if args.restart: args.restart = os.path.abspath(args.restart).split(".")[0:1] print("Reading grid ...") if args.egrid: args.egrid = os.path.abspath(args.egrid).split(".")[0:1] grid = EclGrid(f"{args.egrid[0]}.EGRID") else: grid = EclGrid(f"{args.ECLIPSE_CASE[0]}.EGRID") init = EclFile(f"{args.ECLIPSE_CASE[0]}.INIT") # Finding well completions completion_list, well_list = completions.get_completion_list( f"{args.ECLIPSE_CASE[0]}.DATA") # Check ROI arguments if (args.i is None or args.j is None or args.k is None) and args.fipnum is None: raise Exception("ERROR: Region of interest not set correctly!") if args.fipfile: fluxnum_new = flux_obj.FluxnumFipnum(grid, init, args.i, args.j, args.k, args.fipnum, args.fipfile) else: fluxnum_new = flux_obj.FluxnumFipnum(grid, init, args.i, args.j, args.k, args.fipnum) print("Generating FLUXNUM ...") if args.fluxfile: print("From input file ...") fluxnum_new.set_fluxnum_kw_from_file(args.fluxfile) else: fluxnum_new.set_fluxnum_kw() print("Checking completions ...", " ") # Checks for well completions in multiple FLUXNUM regions print("Including wells ...") fluxnum_new.include_well_completions(completion_list, well_list) # Second iteration to check for wells completed in multiple cells print("Including wells ...") fluxnum_new.include_well_completions(completion_list, well_list) print("Writing FLUXNUM file ...") fluxnum_new_kw = fluxnum_new.get_fluxnum_kw() fluxnum_filename = f"FLUXNUM_FIPNUM_{args.fipnum}_{now.microsecond:d}.grdecl" with cwrap.open(fluxnum_filename, "w") as file_handle: fluxnum_new_kw.write_grdecl(file_handle) print("Writing DUMPFLUX DATA-file ...") new_data_file = datafile_obj.Datafile(f"{args.ECLIPSE_CASE[0]}.DATA") if new_data_file.has_KW("DUMPFLUX") or new_data_file.has_KW("USEFLUX"): raise Exception( "ERROR: FLUX keywords already present in input ECL_CASE") new_data_file.create_DUMPFLUX_file(fluxnum_filename) if args.test: args.test = os.path.abspath(args.test).split(".")[0:1] if not os.path.isfile(f"{args.test[0]}.FLUX"): raise Exception("ERROR: FLUX file from DUMPFLUX run not created") # Needs the coordinates from the print("Generating new FLUX file...") grid_coarse = EclGrid(f"{args.test[0]}.EGRID") grid_fine = EclGrid(f"{args.test[0]}.EGRID") flux_fine = EclFile(f"{args.test[0]}.FLUX") else: print("Executing DUMPFLUX NOSIM run ...") if args.ecl_version: new_data_file.run_DUMPFLUX_nosim(args.ecl_version) else: new_data_file.run_DUMPFLUX_nosim() if not os.path.isfile(f"DUMPFLUX_{eclipse_case_root}.FLUX"): raise Exception("ERROR: FLUX file from DUMPFLUX run not created") # Needs the coordinates from the print("Generating new FLUX file...") grid_coarse = EclGrid(f"DUMPFLUX_{eclipse_case_root}.EGRID") grid_fine = EclGrid(f"DUMPFLUX_{eclipse_case_root}.EGRID") flux_fine = EclFile(f"DUMPFLUX_{eclipse_case_root}.FLUX") # Reads restart file if args.restart: rst_coarse = EclFile(f"{args.restart[0]}.UNRST") else: rst_coarse = EclFile(f"{args.ECLIPSE_CASE[0]}.UNRST") flux_object_fine = fluxfile_obj.Fluxfile(grid_fine, flux_fine) # Creating map f_c_map = fluxfile_obj.create_map_rst(flux_object_fine, grid_coarse, scale_i=1, scale_j=1, scale_k=1) # Importing elements # Open FortIO stream fortio = FortIO(f"{args.OUTPUT_CASE[0]}.FLUX", mode=FortIO.WRITE_MODE) fluxfile_obj.write_new_fluxfile_from_rst(flux_object_fine, grid_coarse, rst_coarse, f_c_map, fortio) # Close FortIO stream fortio.close() # Writing USEFLUX suggestion print("Writing suggestion for USEFLUX DATA-file ...") new_data_file.create_USEFLUX_file(fluxnum_filename, args.OUTPUT_CASE[0]) new_data_file.set_USEFLUX_header(args)
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") with cwrap.open("faultblock.grdecl") as f: kw = EclKW.read_grdecl(f, "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)
def wrapper(prop_name, value, grid_size, fname): prop = EclKW(prop_name, grid_size, EclDataType.ECL_FLOAT) prop.assign(value) with cwrap.open(fname, "w") as f: prop.write_grdecl(f)