Example #1
0
    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)
Example #2
0
    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)
Example #3
0
 def test_fwrite( self ):
     #work_area = TestArea("python/ecl_file/fwrite")
     with TestAreaContext("python/ecl_file/fwrite"):
         rst_file = EclFile(self.test_file)
         fortio = FortIO("ECLIPSE.UNRST", FortIO.WRITE_MODE)
         rst_file.fwrite(fortio)
         fortio.close()
         rst_file.close()
         self.assertFilesAreEqual("ECLIPSE.UNRST", self.test_file)
Example #4
0
    def test_report_list(self):
        rlist0 = range(63)
        self.report_list_file_test(self.u_file, rlist0)

        rlist0 = [0]
        self.report_list_file_test(self.xfile0, rlist0)

        f = EclFile(self.grid_file)
        with self.assertRaises(ArgumentError): #argumentError wraps the expected TypeError
            EclFile.file_report_list(f)
Example #5
0
    def test_kw( self ):
        f = EclFile(self.u_file)
        kw1 = f["SWAT"][40]
        kw2 = f.restart_get_kw("SWAT", datetime.datetime(2003, 3, 1))
        kw3 = f.restart_get_kw("SWAT", datetime.datetime(2003, 3, 1), copy=True)

        self.assertTrue(kw1.equal(kw2))
        self.assertTrue(kw1.equal(kw3))

        kw4 = f.restart_get_kw("SWAT", datetime.datetime(2009, 3, 1))
        self.assertIsNone(kw4)
Example #6
0
    def test_kw( self ):
        f = EclFile(self.u_file)
        kw1 = f["SWAT"][40]
        kw2 = f.restart_get_kw("SWAT", datetime.datetime(2003, 3, 1))
        kw3 = f.restart_get_kw("SWAT", datetime.datetime(2003, 3, 1), copy=True)

        self.assertTrue(kw1.equal(kw2))
        self.assertTrue(kw1.equal(kw3))
        
        with self.assertRaises(IndexError):
            kw4 = f.restart_get_kw("SWAT", datetime.datetime(2009, 3, 17))
Example #7
0
    def report_file_test(self, fname):
        self.assertTrue(EclFile.contains_report_step(fname, 4))
        self.assertTrue(EclFile.contains_report_step(fname, 0))
        self.assertTrue(EclFile.contains_report_step(fname, 62))
        self.assertFalse(EclFile.contains_report_step(fname, -1))
        self.assertFalse(EclFile.contains_report_step(fname, 100))

        f = EclFile(fname)
        self.assertTrue(f.has_report_step(4))
        self.assertTrue(f.has_report_step(0))
        self.assertTrue(f.has_report_step(62))

        self.assertFalse(f.has_report_step(-1))
        self.assertFalse(f.has_report_step(100))
Example #8
0
    def test_block_view(self):
        with TestAreaContext("python/ecl_file/view"):
            with openFortIO("TEST" , mode = FortIO.WRITE_MODE) as f:
                for i in range(5):
                    header = EclKW("HEADER" , 1 , EclTypeEnum.ECL_INT_TYPE )
                    header[0] = i
                    
                    data1 = EclKW("DATA1" , 100 , EclTypeEnum.ECL_INT_TYPE )
                    data1.assign( i )


                    data2 = EclKW("DATA2" , 100 , EclTypeEnum.ECL_INT_TYPE )
                    data2.assign( i*10 )

                    header.fwrite( f )
                    data1.fwrite( f )
                    data2.fwrite( f )

                    
            ecl_file = EclFile("TEST")
            with self.assertRaises(KeyError):
                ecl_file.blockView("NO" , 1)

            with self.assertRaises(IndexError):
                ecl_file.blockView("HEADER" , 100)

            for i in range(5):
                view = ecl_file.blockView("HEADER" , i)
                self.assertEqual( len(view) , 3)
                header = view["HEADER"][0]
                data1 = view["DATA1"][0]
                data2 = view["DATA2"][0]
                
                self.assertEqual( header[0] , i )
                self.assertEqual( data1[99] , i )
                self.assertEqual( data2[99] , i*10 )


            for i in range(5):
                view = ecl_file.blockView2("HEADER" , "DATA2", i )
                self.assertEqual( len(view) , 2)
                header = view["HEADER"][0]
                data1 = view["DATA1"][0]
                
                self.assertEqual( header[0] , i )
                self.assertEqual( data1[99] , i )

                self.assertFalse( "DATA2" in view )

            view = ecl_file.blockView2("HEADER" , None, 0 )
            self.assertEqual( len(view) , len(ecl_file))

            view = ecl_file.blockView2(None , "DATA2", 0 )
Example #9
0
    def __init__(self , grid , filename , flags = 0):
        """Will open an Eclipse restart file.

        The EclRestartFile class will open an eclipse restart file, in
        unified or non unified format. The constructor will infer the
        file type based on the filename, and will raise a ValueError
        exception if the file type is not ECL_RESTART_FILE or
        ECL_UNIFIED_RESTART_FILE.

        The EclRestartFile will use a grid reference to create Ecl3DKw
        instances for all the keyword elements which have either
        'nactive' or 'nx*ny*nz' elements.
        """

        file_type , report_step , fmt_file = EclFile.getFileType( filename )
        if not file_type in [EclFileEnum.ECL_RESTART_FILE, EclFileEnum.ECL_UNIFIED_RESTART_FILE]:
            raise ValueError("The input filename:%s does not correspond to a restart file - please follow the Eclipse naming conventions" % filename)
            
        super(EclRestartFile , self).__init__( grid, filename , flags)
        self.rst_headers = None
        if file_type == EclFileEnum.ECL_RESTART_FILE:
            self.is_unified = False
            self.report_step = report_step
        else:
            self.is_unified = True
Example #10
0
    def report_list_file_test(self, fname, rlist0):
        rlist = EclFile.file_report_list(fname)
        self.assertAlmostEqualList(rlist, rlist0)

        f = EclFile(fname)
        rlist = f.report_list
        self.assertAlmostEqualList(rlist, rlist0)
Example #11
0
    def test_date(self):
        f = EclFile(self.u_file)
        self.assertTrue(f.has_sim_time(datetime.datetime(2001, 6, 1)))
        self.assertFalse(f.has_sim_time(datetime.datetime(2005, 6, 1)))
        self.assertFalse(f.has_sim_time(datetime.datetime(1999, 6, 1)))
        self.assertFalse(f.has_sim_time(datetime.datetime(2001, 6, 11)))

        self.assertTrue(EclFile.contains_sim_time(self.u_file, datetime.datetime(2001, 6, 1)))
        self.assertFalse(EclFile.contains_sim_time(self.u_file, datetime.datetime(2005, 6, 1)))
        self.assertFalse(EclFile.contains_sim_time(self.u_file, datetime.datetime(1999, 6, 1)))
        self.assertFalse(EclFile.contains_sim_time(self.u_file, datetime.datetime(2001, 6, 11)))
 def test_compareRestartKeyword_differentData_PRESSURE_deviationstats_are_correct(
         self):
     restart_file_A = EclFile("../testdata/SPE1AUTODIFF.UNRST")
     restart_file_B = EclFile("../testdata/SPE1ECLIPSE.UNRST")
     comparison_result = compareRestarts(restart_file_A, restart_file_B,
                                         "PRESSURE")
     self.assertAlmostEqual(6e-04,
                            comparison_result.getAverageRelativeDeviation(),
                            4)
     self.assertAlmostEqual(3.76085,
                            comparison_result.getAverageAbsoluteDeviation(),
                            4)
     self.assertAlmostEqual(3.334,
                            comparison_result.getMedianAbsoluteDeviation(),
                            3)
     self.assertAlmostEqual(0.00052,
                            comparison_result.getMedianRelativeDeviation(),
                            5)
     comparison_result.printInformation(True)
Example #13
0
    def test_fortio_size(self):
        unrst_file_path = self.createTestPath(
            "Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST")
        unrst_file = EclFile(unrst_file_path)
        size = 0
        for kw in unrst_file:
            size += kw.fortIOSize()

        stat = os.stat(unrst_file_path)
        self.assertTrue(size == stat.st_size)
Example #14
0
    def test_restart_view(self):
        f = EclFile(self.test_file)
        with self.assertRaises(ValueError):
            v = f.restartView()

        v = f.restartView(sim_days=274)
        v = f.restartView(sim_time=datetime.date(2004, 1, 1))
        v = f.restartView(report_step=30)
        v = f.restartView(seqnum_index=30)
Example #15
0
    def test_create(self):
        # The init file created here only contains a PORO field. More
        # properties must be added to this before it can be used for
        # any usefull gravity calculations.
        poro = EclKW( "PORO" , self.grid.getGlobalSize() , EclTypeEnum.ECL_FLOAT_TYPE )
        with TestAreaContext("grav_init"):
            with openFortIO( "TEST.INIT" , mode = FortIO.WRITE_MODE ) as f:
                poro.fwrite( f )
            self.init = EclFile( "TEST.INIT")

            grav = EclGrav( self.grid , self.init )
Example #16
0
    def test_EclFile_name_property(self):
        with TestAreaContext("name") as t:
            kw = EclKW("TEST", 3, EclTypeEnum.ECL_INT_TYPE)
            with openFortIO("TEST" , mode = FortIO.WRITE_MODE) as f:
                kw.fwrite( f )

            t.sync()
            
            f = EclFile( "TEST" )
            with self.assertRaises(DeprecationWarning):
                name = f.name
Example #17
0
    def test_construction(self):
        grid_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID")
        rst_path_1 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0011")
        rst_path_2 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0022")
        rst_path_3 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0035")
        rst_path_4 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0061")

        grid = EclGrid(grid_path)

        def checkWellInfo(well_info, well_count, report_step_count):
            self.assertEqual(len(well_info), well_count)

            for index, well_time_line in enumerate(well_info):
                self.assertEqual(len(well_time_line), report_step_count[index])

        well_info = WellInfo(grid, rst_path_1)
        checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1])

        well_info = WellInfo(grid, EclFile(rst_path_1))
        checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1])

        well_info = WellInfo(grid, [rst_path_1, rst_path_2, rst_path_3])
        checkWellInfo(well_info, well_count=8, report_step_count=[3, 3, 3, 3, 3, 2, 2, 2])

        well_info = WellInfo(grid, [EclFile(rst_path_1), EclFile(rst_path_2), rst_path_3, EclFile(rst_path_4)])
        checkWellInfo(well_info, well_count=8, report_step_count=[4, 4, 4, 4, 4, 3, 3, 3])


        well_info = WellInfo(grid)
        well_info.addWellFile(rst_path_1, True)

        checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1])

        well_info.addWellFile(EclFile(rst_path_2), True)
        checkWellInfo(well_info, well_count=8, report_step_count=[2, 2, 2, 2, 2, 1, 1, 1])

        well_info.addWellFile(EclFile(rst_path_3), True)
        checkWellInfo(well_info, well_count=8, report_step_count=[3, 3, 3, 3, 3, 2, 2, 2])

        well_info.addWellFile(rst_path_4, True)
        checkWellInfo(well_info, well_count=8, report_step_count=[4, 4, 4, 4, 4, 3, 3, 3])
Example #18
0
def main():
    grid = EclGrid('/home/pgdr/statoil/norne/NORNE_ATW2013.EGRID')
    init = EclFile('/home/pgdr/statoil/norne/NORNE_ATW2013.INIT')
    rest = EclFile('/home/pgdr/statoil/norne/NORNE_ATW2013.UNRST')
    wp = Wpath('/home/pgdr/statoil/norne/norne-test-2-mid.w')
    swat, sgas = rest._iget_named_kw('SWAT', 0), rest._iget_named_kw('SGAS', 0)
    permx = init._iget_named_kw('PERMX', 0)

    wall = constructWall(grid, wp, swat, sgas, permx)
    drawWall(wall)
Example #19
0
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)
Example #20
0
    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, 8.65322541521704e-07)

            dz2 = subsidence.evalGeertsma("S2", None, receiver, youngs_modulus,
                                          poisson_ratio, seabed)
            np.testing.assert_almost_equal(dz2, 2.275556615015282e-06)

            np.testing.assert_almost_equal(dz2 - dz1, 1.4102340734935779e-06)

            dz = subsidence.evalGeertsma("S1", "S2", receiver, youngs_modulus,
                                         poisson_ratio, seabed)
            np.testing.assert_almost_equal(dz, 1.4102340734935779e-06)
Example #21
0
    def test_restart_days(self):
        rst_file = EclFile( self.test_file )
        self.assertAlmostEqual(  0.0 , rst_file.iget_restart_sim_days(0) )
        self.assertAlmostEqual( 31.0 , rst_file.iget_restart_sim_days(1) )
        self.assertAlmostEqual( 274.0 , rst_file.iget_restart_sim_days(10) )

        with self.assertRaises(KeyError):
            rst_file.restart_get_kw("Missing" , dtime = datetime.date( 2004,1,1))

        with self.assertRaises(IndexError):
            rst_file.restart_get_kw("SWAT" , dtime = datetime.date( 1985 , 1 , 1))
Example #22
0
    def test_date(self):
        f = EclFile(self.u_file)
        self.assertTrue(f.has_sim_time(datetime.datetime(2001, 6, 1)))
        self.assertFalse(f.has_sim_time(datetime.datetime(2005, 6, 1)))
        self.assertFalse(f.has_sim_time(datetime.datetime(1999, 6, 1)))
        self.assertFalse(f.has_sim_time(datetime.datetime(2001, 6, 11)))

        self.assertTrue(
            EclFile.contains_sim_time(self.u_file,
                                      datetime.datetime(2001, 6, 1)))
        self.assertFalse(
            EclFile.contains_sim_time(self.u_file,
                                      datetime.datetime(2005, 6, 1)))
        self.assertFalse(
            EclFile.contains_sim_time(self.u_file,
                                      datetime.datetime(1999, 6, 1)))
        self.assertFalse(
            EclFile.contains_sim_time(self.u_file,
                                      datetime.datetime(2001, 6, 11)))
Example #23
0
    def getWellInfo(self):
        """ @rtype: WellInfo """
        if EclWellTest.__well_info is None:
            grid_path = self.createTestPath("Statoil/ECLIPSE/Troll/MSW/T07-4A-W2012-16-F3.EGRID")
            rst_path_1 = self.createTestPath("Statoil/ECLIPSE/Troll/MSW/T07-4A-W2012-16-F3.X0135")

            grid = EclGrid(grid_path)

            rst_file = EclFile(rst_path_1, EclFileFlagEnum.ECL_FILE_CLOSE_STREAM)

            EclWellTest.__well_info = WellInfo(grid, rst_file)


        return EclWellTest.__well_info
Example #24
0
    def test_restart_view(self):
        f = EclFile( self.test_file )
        with self.assertRaises(ValueError):
            v = f.restartView( )

        v = f.restartView( sim_days = 274 )
        v = f.restartView( sim_time = datetime.date( 2004,1,1) )
        v = f.restartView( report_step = 30 )
        v = f.restartView( seqnum_index = 30 )
Example #25
0
 def test_fwrite(self):
     #work_area = TestArea("python/ecl_file/fwrite")
     with TestAreaContext("python/ecl_file/fwrite"):
         rst_file = EclFile(self.test_file)
         fortio = FortIO("ECLIPSE.UNRST", FortIO.WRITE_MODE)
         rst_file.fwrite(fortio)
         fortio.close()
         rst_file.close()
         self.assertFilesAreEqual("ECLIPSE.UNRST", self.test_file)
Example #26
0
    def test_kw_write(self):
        with TestAreaContext("python/ecl_kw/writing"):

            data = [random.random() for i in range(10000)]

            kw = EclKW("TEST", len(data), EclTypeEnum.ECL_DOUBLE_TYPE)
            i = 0
            for d in data:
                kw[i] = d
                i += 1

            pfx = 'EclKW('
            self.assertEqual(pfx, repr(kw)[:len(pfx)])

            fortio = FortIO("ECL_KW_TEST", FortIO.WRITE_MODE)
            kw.fwrite(fortio)
            fortio.close()

            fortio = FortIO("ECL_KW_TEST")

            kw2 = EclKW.fread(fortio)

            self.assertTrue(kw.equal(kw2))

            ecl_file = EclFile("ECL_KW_TEST",
                               flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
            kw3 = ecl_file["TEST"][0]
            self.assertTrue(kw.equal(kw3))
            ecl_file.save_kw(kw3)
            ecl_file.close()

            fortio = FortIO("ECL_KW_TEST", FortIO.READ_AND_WRITE_MODE)
            kw4 = EclKW.fread(fortio)
            self.assertTrue(kw.equal(kw4))
            fortio.seek(0)
            kw4.fwrite(fortio)
            fortio.close()

            ecl_file = EclFile("ECL_KW_TEST")
            kw5 = ecl_file["TEST"][0]
            self.assertTrue(kw.equal(kw5))
Example #27
0
    def test_equal(self):
        kw1 = EclKW("TEST", 3, EclTypeEnum.ECL_CHAR_TYPE)
        kw1[0] = "Test1"
        kw1[1] = "Test13"
        kw1[2] = "Test15"

        kw2 = EclKW("TEST", 3, EclTypeEnum.ECL_CHAR_TYPE)
        kw2[0] = "Test1"
        kw2[1] = "Test13"
        kw2[2] = "Test15"

        self.assertTrue(kw1.equal(kw2))
        self.assertTrue(kw1.equal_numeric(kw2))

        kw2[2] = "Test15X"
        self.assertFalse(kw1.equal(kw2))
        self.assertFalse(kw1.equal_numeric(kw2))

        unrst_file_path = self.createTestPath(
            "Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST")
        unrst_file = EclFile(unrst_file_path)
        kw1 = unrst_file["PRESSURE"][0]
        kw2 = kw1.deep_copy()

        self.assertTrue(kw1.equal(kw2))
        self.assertTrue(kw1.equal_numeric(kw2))

        kw2 *= 1.00001
        self.assertFalse(kw1.equal(kw2))
        self.assertFalse(kw1.equal_numeric(kw2, epsilon=1e-8))
        self.assertTrue(kw1.equal_numeric(kw2, epsilon=1e-2))

        kw1 = unrst_file["ICON"][10]
        kw2 = kw1.deep_copy()
        self.assertTrue(kw1.equal(kw2))
        self.assertTrue(kw1.equal_numeric(kw2))

        kw1[-1] += 1
        self.assertFalse(kw1.equal(kw2))
        self.assertFalse(kw1.equal_numeric(kw2))
Example #28
0
    def test_sub_copy(self):
        unrst_file_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST")
        unrst_file = EclFile(unrst_file_path)
        swat = unrst_file["SWAT"][0]

        swat1 = swat.sub_copy(0, -1)
        swat2 = swat.sub_copy(0, swat.size)

        self.assertTrue(swat.equal(swat1))
        self.assertTrue(swat.equal(swat2))

        swat3 = swat.sub_copy(20000, 100, new_header="swat")
        self.assertTrue(swat3.name == "swat")
        self.assertTrue(swat3.size == 100)
        equal = True
        for i in range(swat3.size):
            if swat3[i] != swat[i + 20000]:
                equal = False
        self.assertTrue(equal)

        self.assertRaises(IndexError, copy_long)
        self.assertRaises(IndexError, copy_offset)
Example #29
0
    def test_fmt(self):
        kw1 = EclKW( "NAME1" , 100 , EclDataType.ECL_INT)
        kw2 = EclKW( "NAME2" , 100 , EclDataType.ECL_INT)

        for i in range(len(kw1)):
            kw1[i] = i + 1
            kw2[i] = len(kw1) - kw1[i]
            
        with TestAreaContext("ecl_kw/fmt") as ta:
            with openFortIO( "TEST.FINIT" , FortIO.WRITE_MODE , fmt_file = True ) as f:
                kw1.fwrite( f )
                kw2.fwrite( f )
                
            with openFortIO( "TEST.FINIT" , fmt_file = True ) as f:
                kw1b = EclKW.fread( f )
                kw2b = EclKW.fread( f )

            self.assertTrue( kw1 == kw1b )
            self.assertTrue( kw2 == kw2b )

            f = EclFile( "TEST.FINIT" )
            self.assertTrue( kw1 == f[0] )
            self.assertTrue( kw2 == f[1] )
Example #30
0
    def test_kw_write(self):
        with TestAreaContext("python/ecl_kw/writing"):

            data = [random.random() for i in range(10000)]

            kw = EclKW("TEST", len(data), EclTypeEnum.ECL_DOUBLE_TYPE)
            i = 0
            for d in data:
                kw[i] = d
                i += 1

            fortio = FortIO("ECL_KW_TEST", FortIO.WRITE_MODE)
            kw.fwrite(fortio)
            fortio.close()

            fortio = FortIO("ECL_KW_TEST")

            kw2 = EclKW.fread(fortio)

            self.assertTrue(kw.equal(kw2))

            ecl_file = EclFile("ECL_KW_TEST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
            kw3 = ecl_file["TEST"][0]
            self.assertTrue(kw.equal(kw3))
            ecl_file.save_kw(kw3)
            ecl_file.close()

            fortio = FortIO("ECL_KW_TEST", FortIO.READ_AND_WRITE_MODE)
            kw4 = EclKW.fread(fortio)
            self.assertTrue(kw.equal(kw4))
            fortio.seek(0)
            kw4.fwrite(fortio)
            fortio.close()

            ecl_file = EclFile("ECL_KW_TEST")
            kw5 = ecl_file["TEST"][0]
            self.assertTrue(kw.equal(kw5))
Example #31
0
 def test_iget_named(self):
     f = EclFile(self.test_file)
     N = f.num_named_kw( "SWAT" )
     with self.assertRaises(KeyError):
         s = f.iget_named_kw( "SWAT" , N + 1)
Example #32
0
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()
Example #33
0
    def test_ecl_file_block(self):

        with TestAreaContext("name") as t:
            kw = EclKW("TEST", 3, EclTypeEnum.ECL_INT_TYPE)
            with openFortIO("TEST" , mode = FortIO.WRITE_MODE) as f:
                kw.fwrite( f )

            t.sync()
            
            f = EclFile( "TEST" )
            with self.assertRaises(NotImplementedError):
                f.select_block( "KW" , 100 )

            with self.assertRaises(NotImplementedError):
                f.select_global( )

            with self.assertRaises(NotImplementedError):
                f.select_restart_section( index = None , report_step = None , sim_time = None)

            with self.assertRaises(NotImplementedError):
                f.select_restart_section( )

            with self.assertRaises(NotImplementedError):
                EclFile.restart_block( "TEST" )
Example #34
0
 def assertFileType(self , filename , expected):
     file_type , step , fmt_file = EclFile.getFileType(filename)
     self.assertEqual( file_type , expected[0] )
     self.assertEqual( fmt_file , expected[1] )
     self.assertEqual( step , expected[2] )
Example #35
0
 def test_IOError(self):
     with self.assertRaises(IOError):
         EclFile("No/Does/not/exist")
Example #36
0
 def assertFileType(self, filename, expected):
     file_type, step, fmt_file = EclFile.getFileType(filename)
     self.assertEqual(file_type, expected[0])
     self.assertEqual(fmt_file, expected[1])
     self.assertEqual(step, expected[2])
Example #37
0
 def getInit(self):
     if self._init is None and self._initFile:
         self._init = EclFile(self.initFile())
     return self._init
Example #38
0
    def report_file_test(self, fname):
        self.assertTrue(EclFile.contains_report_step(fname, 4))
        self.assertTrue(EclFile.contains_report_step(fname, 0))
        self.assertTrue(EclFile.contains_report_step(fname, 62))
        self.assertFalse(EclFile.contains_report_step(fname, -1))
        self.assertFalse(EclFile.contains_report_step(fname, 100))

        f = EclFile(fname)
        self.assertTrue(f.has_report_step(4))
        self.assertTrue(f.has_report_step(0))
        self.assertTrue(f.has_report_step(62))

        self.assertFalse(f.has_report_step(-1))
        self.assertFalse(f.has_report_step(100))
Example #39
0
    def test_save(self):
        #work_area = TestArea("python/ecl_file/save")
        with TestAreaContext("python/ecl_file/save",
                             store_area=False) as work_area:
            work_area.copy_file(self.test_file)
            rst_file = EclFile("ECLIPSE.UNRST",
                               flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
            swat0 = rst_file["SWAT"][0]
            swat0.assign(0.75)
            rst_file.save_kw(swat0)
            rst_file.close()
            self.assertFilesAreNotEqual("ECLIPSE.UNRST", self.test_file)

            rst_file1 = EclFile(self.test_file)
            rst_file2 = EclFile("ECLIPSE.UNRST",
                                flags=EclFileFlagEnum.ECL_FILE_WRITABLE)

            swat1 = rst_file1["SWAT"][0]
            swat2 = rst_file2["SWAT"][0]
            swat2.assign(swat1)

            rst_file2.save_kw(swat2)
            self.assertTrue(swat1.equal(swat2))
            rst_file1.close()
            rst_file2.close()

            # Random failure ....
            self.assertFilesAreEqual("ECLIPSE.UNRST", self.test_file)
Example #40
0
    def test_name(self):
        f = EclFile(self.u_file)
        self.assertTrue(f.getFilename() == self.u_file)

        f = EclFile(self.xfile0)
        self.assertTrue(f.getFilename() == self.xfile0)
Example #41
0
 def test_iget_named(self):
     f = EclFile(self.test_file)
     N = f.num_named_kw("SWAT")
     with self.assertRaises(KeyError):
         s = f.iget_named_kw("SWAT", N + 1)
Example #42
0
    def test_ecl_file_block(self):

        with TestAreaContext("name") as t:
            kw = EclKW("TEST", 3, EclTypeEnum.ECL_INT_TYPE)
            with openFortIO("TEST" , mode = FortIO.WRITE_MODE) as f:
                kw.fwrite( f )

            t.sync()
            
            f = EclFile( "TEST" )
            with self.assertRaises(NotImplementedError):
                f.select_block( "KW" , 100 )

            with self.assertRaises(NotImplementedError):
                f.select_global( )

            with self.assertRaises(NotImplementedError):
                f.select_restart_section( index = None , report_step = None , sim_time = None)

            with self.assertRaises(NotImplementedError):
                f.select_restart_section( )

            with self.assertRaises(NotImplementedError):
                EclFile.restart_block( "TEST" )
Example #43
0
    def test_name(self):
        f = EclFile(self.u_file)
        self.assertTrue(f.name == self.u_file)

        f = EclFile(self.xfile0)
        self.assertTrue(f.name == self.xfile0)
Example #44
0
    def test_save(self):
        #work_area = TestArea("python/ecl_file/save")
        with TestAreaContext("python/ecl_file/save", store_area=False) as work_area:
            work_area.copy_file(self.test_file)
            rst_file = EclFile("ECLIPSE.UNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
            swat0 = rst_file["SWAT"][0]
            swat0.assign(0.75)
            rst_file.save_kw(swat0)
            rst_file.close()
            self.assertFilesAreNotEqual("ECLIPSE.UNRST",self.test_file)

            rst_file1 = EclFile(self.test_file)
            rst_file2 = EclFile("ECLIPSE.UNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE)

            swat1 = rst_file1["SWAT"][0]
            swat2 = rst_file2["SWAT"][0]
            swat2.assign(swat1)

            rst_file2.save_kw(swat2)
            self.assertTrue(swat1.equal(swat2))
            rst_file1.close()
            rst_file2.close()

            # Random failure ....
            self.assertFilesAreEqual("ECLIPSE.UNRST", self.test_file)
Example #45
0
    def test_block_view(self):
        with TestAreaContext("python/ecl_file/view"):
            with openFortIO("TEST" , mode = FortIO.WRITE_MODE) as f:
                for i in range(5):
                    header = EclKW("HEADER" , 1 , EclDataType.ECL_INT )
                    header[0] = i

                    data1 = EclKW("DATA1" , 100 , EclDataType.ECL_INT )
                    data1.assign( i )


                    data2 = EclKW("DATA2" , 100 , EclDataType.ECL_INT )
                    data2.assign( i*10 )

                    header.fwrite( f )
                    data1.fwrite( f )
                    data2.fwrite( f )


            ecl_file = EclFile("TEST")
            pfx = 'EclFile('
            self.assertEqual(pfx, repr(ecl_file)[:len(pfx)])
            with self.assertRaises(KeyError):
                ecl_file.blockView("NO" , 1)

            with self.assertRaises(IndexError):
                ecl_file.blockView("HEADER" , 100)

            with self.assertRaises(IndexError):
                ecl_file.blockView("HEADER" , 1000)

            bv = ecl_file.blockView("HEADER" , -1)


            for i in range(5):
                view = ecl_file.blockView("HEADER" , i)
                self.assertEqual( len(view) , 3)
                header = view["HEADER"][0]
                data1 = view["DATA1"][0]
                data2 = view["DATA2"][0]

                self.assertEqual( header[0] , i )
                self.assertEqual( data1[99] , i )
                self.assertEqual( data2[99] , i*10 )


            for i in range(5):
                view = ecl_file.blockView2("HEADER" , "DATA2", i )
                self.assertEqual( len(view) , 2)
                header = view["HEADER"][0]
                data1 = view["DATA1"][0]

                self.assertEqual( header[0] , i )
                self.assertEqual( data1[99] , i )

                self.assertFalse( "DATA2" in view )

            view = ecl_file.blockView2("HEADER" , None, 0 )
            self.assertEqual( len(view) , len(ecl_file))

            view = ecl_file.blockView2(None , "DATA2", 0 )
Example #46
0
 def __init__(self , grid , filename , flags = 0):
     file_type , report_step , fmt_file = EclFile.getFileType( filename )
     if file_type == EclFileEnum.ECL_INIT_FILE:
         super(EclInitFile , self).__init__( grid, filename , flags)
     else:
         raise ValueError("The input filename:%s does not correspond to a restart file - please follow the Eclipse naming conventions" % filename)
Example #47
0
 def getRestart(self):
     if self._restart is None:
         self._restart = EclFile(self.restartFile())
     return self._restart