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 open("grid.grdecl" , "w") as f2: f2.write("SPECGRID\n") f2.write(" 10 10 10 \'F\' /\n") with openEclFile("G.EGRID") as f: with copen("grid.grdecl" , "a") as f2: 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_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_context( self ): with TestAreaContext("python/ecl_file/context"): kw1 = EclKW( "KW1" , 100 , EclDataType.ECL_INT) kw2 = EclKW( "KW2" , 100 , EclDataType.ECL_INT) with openFortIO("TEST" , mode = FortIO.WRITE_MODE) as f: kw1.fwrite( f ) kw2.fwrite( f ) with openEclFile("TEST") as ecl_file: self.assertEqual( len(ecl_file) , 2 ) self.assertTrue( ecl_file.has_kw("KW1")) self.assertTrue( ecl_file.has_kw("KW2")) self.assertEqual(ecl_file[1], ecl_file[-1])
def test_missing_smspec_keyword(self): with TestAreaContext("EclSum/truncated_data") as ta: ta.copy_file(self.test_file) ta.copy_file(self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) with openEclFile("ECLIPSE.SMSPEC") as f: kw_list = [] for kw in f: kw_list.append(EclKW.copy(kw)) with openFortIO("ECLIPSE.SMSPEC", mode=FortIO.WRITE_MODE) as f: for kw in kw_list: if kw.getName() == "KEYWORDS": continue kw.fwrite(f) with self.assertRaises(IOError): EclSum("ECLIPSE")
def test_missing_smspec_keyword(self): with TestAreaContext("EclSum/truncated_data") as ta: ta.copy_file(self.test_file) ta.copy_file(self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) with openEclFile("ECLIPSE.SMSPEC") as f: kw_list = [] for kw in f: kw_list.append(EclKW.copy(kw)) with openFortIO("ECLIPSE.SMSPEC", mode=FortIO.WRITE_MODE) as f: for kw in kw_list: if kw.getName() == "KEYWORDS": continue kw.fwrite(f) with self.assertRaises(IOError): EclSum("ECLIPSE")
def test_missing_unsmry_keyword(self): with TestAreaContext("EclSum/truncated_data") as ta: ta.copy_file(self.test_file) ta.copy_file( self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) with openEclFile("ECLIPSE.UNSMRY") as f: kw_list = [] for kw in f: kw_list.append(EclKW.copy(kw)) with openFortIO("ECLIPSE.UNSMRY", mode=FortIO.WRITE_MODE) as f: c = 0 for kw in kw_list: if kw.getName() == "PARAMS": if c % 5 == 0: continue c += 1 kw.fwrite(f) with self.assertRaises(IOError): EclSum("ECLIPSE")