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, 3.944214576168326e-09)

            receiver = (1000, 1000, topres - seabed - above)

            dz = subsidence.evalGeertsma("S1", None, receiver, youngs_modulus, poisson_ratio, seabed)
            np.testing.assert_almost_equal(dz, 5.8160298201497136e-08)
Example #2
0
    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 )
Example #3
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(dz1-dz2, -1.4102340734935779e-06)

            dz = subsidence.evalGeertsma("S1", "S2", receiver, youngs_modulus, poisson_ratio, seabed)
            np.testing.assert_almost_equal(dz, dz1-dz2)
 def test_fast_open(self):
     with TestAreaContext("index"):
         f0 = EclFile(self.test_file)
         f0.write_index("index")
         f1 = EclFile(self.test_file, 0, "index")
         for kw0, kw1 in zip(f0, f1):
             self.assertEqual(kw0, kw1)
Example #5
0
    def report_list_file_test(self, fname, rlist0):
        rlist = EclFile.file_report_list(fname)
        self.assertListEqual(rlist, rlist0)

        f = EclFile(fname)
        rlist = f.report_list
        self.assertListEqual(rlist, rlist0)
    def test_index(self):
        with TestAreaContext("python/ecl_file/truncated"):
            f0 = EclFile(self.test_file)
            f0.write_index("index")

            f1 = EclFile(self.test_file, index_filename="index")
            for kw0, kw1 in zip(f0, f1):
                self.assertEqual(kw0, kw1)
Example #7
0
    def test_dates(self):
        f = EclFile(self.u_file)
        dates = f.dates
        self.assertTrue(len(dates) == 63)

        f = EclFile(self.xfile0)
        dates = f.dates
        self.assertTrue(len(dates) == 1)
        self.assertTrue(dates[0] == datetime.datetime(2000, 1, 1))
Example #8
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 #9
0
    def test_truncated(self):
        with TestAreaContext("python/ecl_file/truncated") as work_area:
            work_area.copy_file(self.test_file)
            size = os.path.getsize("ECLIPSE.UNRST")
            with open("ECLIPSE.UNRST" , "r+") as f:
                f.truncate( size / 2 )

            with self.assertRaises(IOError):
                rst_file = EclFile("ECLIPSE.UNRST")

            with self.assertRaises(IOError):
                rst_file = EclFile("ECLIPSE.UNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
Example #10
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 #11
0
    def test_save_kw(self):
        with TestAreaContext("python/ecl_file/save_kw"):
            data = range(1000)
            kw = EclKW("MY_KEY", len(data), EclDataType.ECL_INT)
            for index, val in enumerate(data):
                kw[index] = val

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

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

            self.assertFilesAreEqual(clean_dump, test_file)

            ecl_file = EclFile(test_file,
                               flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
            loaded_kw = ecl_file["MY_KEY"][0]
            self.assertTrue(kw.equal(loaded_kw))

            ecl_file.save_kw(loaded_kw)
            ecl_file.close()

            self.assertFilesAreEqual(clean_dump, test_file)

            ecl_file = EclFile(test_file)
            loaded_kw = ecl_file["MY_KEY"][0]
            self.assertTrue(kw.equal(loaded_kw))
Example #12
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 #13
0
File: case.py Project: pgdr/recl
 def summary(self):
     if self._smry:
         return self._smry
     if isfile(self._smry_file):
         self._smry = EclFile(self._smry_file)
         return self._smry
     return None
Example #14
0
File: case.py Project: pgdr/recl
 def init(self):
     if self._init:
         return self._init
     if isfile(self._init_file):
         self._init = EclFile(self._init_file)
         return self._init
     return None
Example #15
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 #16
0
    def test_truncate(self):
        kw1 = EclKW("KW1", 2, EclDataType.ECL_INT)
        kw2 = EclKW("KW2", 2, EclDataType.ECL_INT)

        kw1[0] = 99
        kw1[1] = 77
        kw2[0] = 113
        kw2[1] = 335

        with TestAreaContext("python/fortio/ftruncate") as t:
            with openFortIO("file" , mode = FortIO.WRITE_MODE) as f:
                kw1.fwrite(f)
                pos1 = f.getPosition( )
                kw2.fwrite(f)
            
            t.sync( ) 
            # Truncate file in read mode; should fail hard.
            with openFortIO("file") as f:
                with self.assertRaises(IOError):
                    f.truncate( )


            with openFortIO("file" , mode = FortIO.READ_AND_WRITE_MODE) as f:
                f.seek( pos1 )
                f.truncate( )


            f = EclFile("file")
            self.assertEqual( len(f) , 1)
            kw1_ = f[0]
            self.assertEqual( kw1 , kw1_)
Example #17
0
def loadKeywords(name):
    kw_list = []
    f = EclFile(name)
    for kw in f:
        kw_list.append(kw)

    return kw_list
Example #18
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:
         err = 'The input filename "%s" does not correspond to a restart file.'
         err += '  Please follow the Eclipse naming conventions.'
         raise ValueError(err % filename)
Example #19
0
    def test_EclFile_name_property(self):
        with TestAreaContext("name") as t:
            kw = EclKW("TEST", 3, EclDataType.ECL_INT)
            with openFortIO("TEST", mode=FortIO.WRITE_MODE) as f:
                kw.fwrite(f)

            t.sync()
            f = EclFile("TEST")
Example #20
0
    def test_ecl_file_indexed_read(self):
        with TestAreaContext("ecl_file_indexed_read") as area:
            fortio = FortIO("ecl_file_index_test", mode=FortIO.WRITE_MODE)

            element_count = 100000
            ecl_kw_1 = EclKW("TEST1", element_count, EclDataType.ECL_INT)
            ecl_kw_2 = EclKW("TEST2", element_count, EclDataType.ECL_INT)

            for index in range(element_count):
                ecl_kw_1[index] = index
                ecl_kw_2[index] = index + 3

            ecl_kw_1.fwrite(fortio)
            ecl_kw_2.fwrite(fortio)

            fortio.close()

            ecl_file = EclFile("ecl_file_index_test")

            index_map = IntVector()
            index_map.append(2)
            index_map.append(3)
            index_map.append(5)
            index_map.append(7)
            index_map.append(11)
            index_map.append(13)
            index_map.append(313)
            index_map.append(1867)
            index_map.append(5227)
            index_map.append(7159)
            index_map.append(12689)
            index_map.append(18719)
            index_map.append(32321)
            index_map.append(37879)
            index_map.append(54167)
            index_map.append(77213)
            index_map.append(88843)
            index_map.append(99991)

            char_buffer_1 = ctypes.create_string_buffer(
                len(index_map) * ctypes.sizeof(ctypes.c_int))
            char_buffer_2 = ctypes.create_string_buffer(
                len(index_map) * ctypes.sizeof(ctypes.c_int))

            self._eclFileIndexedRead(ecl_file, "TEST2", 0, index_map,
                                     char_buffer_2)
            self._eclFileIndexedRead(ecl_file, "TEST1", 0, index_map,
                                     char_buffer_1)

            int_buffer_1 = ctypes.cast(char_buffer_1,
                                       ctypes.POINTER(ctypes.c_int))
            int_buffer_2 = ctypes.cast(char_buffer_2,
                                       ctypes.POINTER(ctypes.c_int))

            for index, index_map_value in enumerate(index_map):
                self.assertEqual(index_map_value, int_buffer_1[index])
                self.assertEqual(index_map_value, int_buffer_2[index] - 3)
Example #21
0
    def test_broken_file(self):
        with TestAreaContext("test_broken_file"):
            with open("CASE.FINIT", "w") as f:
                f.write(
                    "This - is not a ECLISPE file\nsdlcblhcdbjlwhc\naschscbasjhcasc\nascasck c s s aiasic asc"
                )

            with self.assertRaises(IOError):
                f = EclFile("CASE.FINIT")
Example #22
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 #23
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 #24
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(), EclDataType.ECL_FLOAT)
        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 #25
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 #26
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 #27
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 #28
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 #29
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), EclDataType.ECL_DOUBLE)
            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 #30
0
    def test_equal(self):
        kw1 = EclKW("TEST", 3, EclDataType.ECL_CHAR)
        kw1[0] = "Test1"
        kw1[1] = "Test13"
        kw1[2] = "Test15"

        kw2 = EclKW("TEST", 3, EclDataType.ECL_CHAR)
        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))