Esempio n. 1
0
    def test_sum(self):
        kw_string = EclKW.create("STRING", 100, EclTypeEnum.ECL_CHAR_TYPE)
        with self.assertRaises(ValueError):
            kw_string.sum()

        kw_int = EclKW.create("INT", 4, EclTypeEnum.ECL_INT_TYPE)
        kw_int[0] = 1
        kw_int[1] = 2
        kw_int[2] = 3
        kw_int[3] = 4
        self.assertEqual(kw_int.sum(), 10)

        kw_d = EclKW.create("D", 4, EclTypeEnum.ECL_DOUBLE_TYPE)
        kw_d[0] = 1
        kw_d[1] = 2
        kw_d[2] = 3
        kw_d[3] = 4
        self.assertEqual(kw_d.sum(), 10)

        kw_f = EclKW.create("F", 4, EclTypeEnum.ECL_FLOAT_TYPE)
        kw_f[0] = 1
        kw_f[1] = 2
        kw_f[2] = 3
        kw_f[3] = 4
        self.assertEqual(kw_f.sum(), 10)

        kw_b = EclKW.create("F", 4, EclTypeEnum.ECL_BOOL_TYPE)
        kw_b[0] = False
        kw_b[1] = True
        kw_b[2] = False
        kw_b[3] = True
        self.assertEqual(kw_b.sum(), 2)
Esempio n. 2
0
    def test_truncate(self):
        kw1 = EclKW.create("KW1", 2, EclTypeEnum.ECL_INT_TYPE)
        kw2 = EclKW.create("KW2", 2, EclTypeEnum.ECL_INT_TYPE)

        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_)
Esempio n. 3
0
    def test_long_name(self):
        with self.assertRaises(ValueError):
            EclKW.create("LONGLONGNAME" , 10 , EclTypeEnum.ECL_INT_TYPE)

        kw = EclKW.create("REGIONS" , 10 , EclTypeEnum.ECL_INT_TYPE)
        with self.assertRaises(ValueError):
            kw.set_name("LONGLONGNAME")
Esempio n. 4
0
    def test_sum( self ):
        kw_string = EclKW.create( "STRING" , 100 , EclTypeEnum.ECL_CHAR_TYPE )
        with self.assertRaises(ValueError):
            kw_string.sum()


        kw_int = EclKW.create( "INT" , 4 , EclTypeEnum.ECL_INT_TYPE )
        kw_int[0] = 1
        kw_int[1] = 2
        kw_int[2] = 3
        kw_int[3] = 4
        self.assertEqual( kw_int.sum() , 10 )

        kw_d = EclKW.create( "D" , 4 , EclTypeEnum.ECL_DOUBLE_TYPE )
        kw_d[0] = 1
        kw_d[1] = 2
        kw_d[2] = 3
        kw_d[3] = 4
        self.assertEqual( kw_d.sum() , 10 )

        kw_f = EclKW.create( "F" , 4 , EclTypeEnum.ECL_FLOAT_TYPE )
        kw_f[0] = 1
        kw_f[1] = 2
        kw_f[2] = 3
        kw_f[3] = 4
        self.assertEqual( kw_f.sum() , 10 )

        kw_b = EclKW.create( "F" , 4 , EclTypeEnum.ECL_BOOL_TYPE )
        kw_b[0] = False
        kw_b[1] = True
        kw_b[2] = False
        kw_b[3] = True
        self.assertEqual( kw_b.sum() , 2 )
Esempio n. 5
0
    def test_kw(self):
        kw1 = EclKW.create("KW1", 2, EclTypeEnum.ECL_INT_TYPE)
        kw2 = EclKW.create("KW2", 2, EclTypeEnum.ECL_INT_TYPE)

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

        with TestAreaContext("python/fortio/write-kw"):
            f = FortIO.writer("test", fmt_file=False)
            kw1.fwrite(f)
            f.close()

            f = FortIO.open("test", mode="a")
            kw2.fwrite(f)
            f.close()

            f = FortIO.open("test", fmt_file=False)
            k1 = EclKW.fread(f)
            k2 = EclKW.fread(f)
            f.close()

            self.assertTrue(k1.equal(kw1))
            self.assertTrue(k2.equal(kw2))
Esempio n. 6
0
    def test_cast(self):
        actnum = IntVector(default_value=1, initial_size=1000)
        for i in range(100):
            actnum[i] = 0

        grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1),
                                         actnum=actnum)
        kw_wrong_size = EclKW.create("KW", 27, EclTypeEnum.ECL_FLOAT_TYPE)
        kw_global_size = EclKW.create("KW", grid.getGlobalSize(),
                                      EclTypeEnum.ECL_FLOAT_TYPE)
        kw_active_size = EclKW.create("KW", grid.getNumActive(),
                                      EclTypeEnum.ECL_FLOAT_TYPE)

        with self.assertRaises(ValueError):
            Ecl3DKW.castFromKW(kw_wrong_size, grid)

        Ecl3DKW.castFromKW(kw_global_size, grid)
        self.assertTrue(isinstance(kw_global_size, Ecl3DKW))

        Ecl3DKW.castFromKW(kw_active_size, grid, default_value=66)
        self.assertTrue(isinstance(kw_active_size, Ecl3DKW))

        self.assertEqual(kw_active_size[0, 0, 0], 66)
        with self.assertRaises(ValueError):
            kw_active_size[0, 0, 0] = 88
Esempio n. 7
0
    def test_long_name(self):
        with self.assertRaises(ValueError):
            EclKW.create("LONGLONGNAME", 10, EclTypeEnum.ECL_INT_TYPE)

        kw = EclKW.create("REGIONS", 10, EclTypeEnum.ECL_INT_TYPE)
        with self.assertRaises(ValueError):
            kw.set_name("LONGLONGNAME")
Esempio n. 8
0
    def test_truncate(self):
        kw1 = EclKW.create("KW1", 2, EclTypeEnum.ECL_INT_TYPE)
        kw2 = EclKW.create("KW2", 2, EclTypeEnum.ECL_INT_TYPE)

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

        with TestAreaContext("python/fortio/ftruncate"):
            with openFortIO("file" , mode = FortIO.WRITE_MODE) as f:
                kw1.fwrite(f)
                pos1 = f.getPosition( )
                kw2.fwrite(f)


            # 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_)
Esempio n. 9
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.create("TEST1", element_count,
                                    EclTypeEnum.ECL_INT_TYPE)
            ecl_kw_2 = EclKW.create("TEST2", element_count,
                                    EclTypeEnum.ECL_INT_TYPE)

            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))

            eclFileIndexedRead(ecl_file, "TEST2", 0, index_map, char_buffer_2)
            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)
Esempio n. 10
0
    def test_fault_block_layer_export(self):
        layer = FaultBlockLayer( self.grid , 1 )
        kw1 = EclKW.create( "FAULTBLK" , self.grid.size + 1 , EclTypeEnum.ECL_INT_TYPE )
        with self.assertRaises(ValueError):
            layer.exportKeyword( kw1 )

        kw2 = EclKW.create( "FAULTBLK" , self.grid.size , EclTypeEnum.ECL_FLOAT_TYPE )
        with self.assertRaises(TypeError):
            layer.exportKeyword(kw2)
Esempio n. 11
0
    def test_context( self ):
        with TestAreaContext("python/ecl_file/context"):
            kw1 = EclKW.create( "KW1" , 100 , EclTypeEnum.ECL_INT_TYPE)
            kw2 = EclKW.create( "KW2" , 100 , EclTypeEnum.ECL_INT_TYPE)
            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"))
Esempio n. 12
0
    def test_context( self ):
        with TestAreaContext("python/ecl_file/context"):
            kw1 = EclKW.create( "KW1" , 100 , EclTypeEnum.ECL_INT_TYPE)
            kw2 = EclKW.create( "KW2" , 100 , EclTypeEnum.ECL_INT_TYPE)
            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"))
Esempio n. 13
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.create("TEST1", element_count, EclTypeEnum.ECL_INT_TYPE)
            ecl_kw_2 = EclKW.create("TEST2", element_count, EclTypeEnum.ECL_INT_TYPE)

            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))

            eclFileIndexedRead(ecl_file, "TEST2", 0, index_map, char_buffer_2)
            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)
Esempio n. 14
0
def make_field(rng , grid , iens):
    permx = EclKW.create( "PERMX" , grid.getGlobalSize( ) , EclTypeEnum.ECL_FLOAT_TYPE)
    permx.assign( rng.getDouble( ) )

    poro = EclKW.create( "PORO" , grid.getGlobalSize( ) , EclTypeEnum.ECL_FLOAT_TYPE)
    poro.assign( rng.getDouble( ) )

    if not os.path.isdir("fields"):
        os.makedirs("fields")

    with open("fields/permx%d.grdecl" % iens,"w") as f:
        permx.write_grdecl( f )

    with open("fields/poro%d.grdecl" % iens ,"w") as f:
        poro.write_grdecl( f )
Esempio n. 15
0
 def test_sliced_set(self):
     kw = EclKW.create("REGIONS" , 10 , EclTypeEnum.ECL_INT_TYPE)
     kw.assign(99)
     kw[0:5] = 66
     self.assertEqual(kw[0] , 66)
     self.assertEqual(kw[4] , 66)
     self.assertEqual(kw[5] , 99)
Esempio n. 16
0
 def test_sliced_set(self):
     kw = EclKW.create("REGIONS", 10, EclTypeEnum.ECL_INT_TYPE)
     kw.assign(99)
     kw[0:5] = 66
     self.assertEqual(kw[0], 66)
     self.assertEqual(kw[4], 66)
     self.assertEqual(kw[5], 99)
Esempio n. 17
0
 def test_compressed_copy(self):
     nx = 10
     ny = 10
     nz = 10
     grid = EclGrid.createRectangular( (nx,ny,nz) , (1,1,1) )
     kw1 = EclKW.create("KW" , 1001 , EclTypeEnum.ECL_INT_TYPE )
     with self.assertRaises(ValueError):
         cp = grid.compressedKWCopy( kw1 )
Esempio n. 18
0
def make_field(rng, grid, iens):
    permx = EclKW.create("PERMX", grid.getGlobalSize(),
                         EclTypeEnum.ECL_FLOAT_TYPE)
    permx.assign(rng.getDouble())

    poro = EclKW.create("PORO", grid.getGlobalSize(),
                        EclTypeEnum.ECL_FLOAT_TYPE)
    poro.assign(rng.getDouble())

    if not os.path.isdir("fields"):
        os.makedirs("fields")

    with open("fields/permx%d.grdecl" % iens, "w") as f:
        permx.write_grdecl(f)

    with open("fields/poro%d.grdecl" % iens, "w") as f:
        poro.write_grdecl(f)
 def test_create(self):
     defRegion = RegionDefinition.create( 5 , self.faults , ["DF4_MC","DF15_MC","DF43_MC","DF25_LC","DF21_C","DF1_C",self.poly_file6, "DF26_MC","DF34_MCS","DF32_MC",self.poly_file5])
     region_kw = EclKW.create( "REGIONS" , self.grid.getGlobalSize() , EclTypeEnum.ECL_INT_TYPE )
     region_kw.assign( 0 )
     
     for k in range(self.grid.getNZ()):
         with self.assertRaises(NotImplementedError):
             block_list = defRegion.findInternalBlocks( self.grid , self.fault_blocks[k] )
Esempio n. 20
0
    def test_abs(self):
        kw = EclKW.create("NAME" , 10 , EclTypeEnum.ECL_CHAR_TYPE)
        with self.assertRaises(TypeError):
            abs_kw = abs(kw)

        kw = EclKW.create("NAME" , 10 , EclTypeEnum.ECL_BOOL_TYPE)
        with self.assertRaises(TypeError):
            abs_kw = abs(kw)

        kw = EclKW.create("NAME" , 10 , EclTypeEnum.ECL_INT_TYPE)
        for i in range(len(kw)):
            kw[i] = -i

        abs_kw = abs(kw)
        for i in range(len(kw)):
            self.assertEqual(kw[i] , -i ) 
            self.assertEqual(abs_kw[i] , i ) 
Esempio n. 21
0
 def test_compressed_copy(self):
     nx = 10
     ny = 10
     nz = 10
     grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1))
     kw1 = EclKW.create("KW", 1001, EclTypeEnum.ECL_INT_TYPE)
     with self.assertRaises(ValueError):
         cp = grid.compressedKWCopy(kw1)
Esempio n. 22
0
 def compressedKWCopy(self, kw):
     if len(kw) == self.getNumActive():
         return EclKW.copy( kw )
     elif len(kw) == self.getGlobalSize():
         kw_copy = EclKW.create( kw.getName() , self.getNumActive() , kw.getEclType())
         cfunc.compressed_kw_copy( self , kw_copy , kw)
         return kw_copy
     else:
         raise ValueError("The input keyword must have nx*n*nz or nactive elements. Size:%d invalid" % len(kw))
Esempio n. 23
0
 def compressedKWCopy(self, kw):
     if len(kw) == self.getNumActive():
         return EclKW.copy( kw )
     elif len(kw) == self.getGlobalSize():
         kw_copy = EclKW.create( kw.getName() , self.getNumActive() , kw.getEclType())
         cfunc.compressed_kw_copy( self , kw_copy , kw)
         return kw_copy
     else:
         raise ValueError("The input keyword must have nx*n*nz or nactive elements. Size:%d invalid" % len(kw))
Esempio n. 24
0
    def test_fault_block_edge(self):
        grid = EclGrid.create_rectangular( (5,5,1) , (1,1,1) )
        kw = EclKW.create( "FAULTBLK" , grid.size , EclTypeEnum.ECL_INT_TYPE )
        kw.assign( 0 )
        for j in range(1,4):
            for i in range(1,4):
                g = i + j*grid.getNX()
                kw[g] = 1

        layer = FaultBlockLayer( grid , 0 )
Esempio n. 25
0
    def test_is_fortran_file(self):
        with TestAreaContext("python/fortio/guess"):
            kw1 = EclKW.create("KW" , 12345 , EclTypeEnum.ECL_FLOAT_TYPE)
            with openFortIO("fortran_file" , mode = FortIO.WRITE_MODE) as f:
                kw1.fwrite( f )
                
            with open("text_file" , "w") as f:
                kw1.write_grdecl( f )

            self.assertTrue( FortIO.isFortranFile( "fortran_file" ))
            self.assertFalse( FortIO.isFortranFile( "text_file" ))
Esempio n. 26
0
    def test_is_fortran_file(self):
        with TestAreaContext("python/fortio/guess"):
            kw1 = EclKW.create("KW" , 12345 , EclTypeEnum.ECL_FLOAT_TYPE)
            with openFortIO("fortran_file" , mode = FortIO.WRITE_MODE) as f:
                kw1.fwrite( f )
                
            with open("text_file" , "w") as f:
                kw1.write_grdecl( f )

            self.assertTrue( FortIO.isFortranFile( "fortran_file" ))
            self.assertFalse( FortIO.isFortranFile( "text_file" ))
Esempio n. 27
0
    def setUp(self):
        self.grid = EclGrid.create_rectangular( (10,10,10) , (1,1,1) )
        self.kw = EclKW.create( "FAULTBLK" , self.grid.size , EclTypeEnum.ECL_INT_TYPE )
        self.kw.assign( 1 )

        reg = EclRegion( self.grid , False )

        for k in range(self.grid.getNZ()):
            reg.clear( )
            reg.select_kslice( k , k )
            self.kw.assign( k , mask = reg )
            self.kw[ k * self.grid.getNX() * self.grid.getNY() + 7] = 177
Esempio n. 28
0
    def test_ecl_kw_indexed_read(self):
        with TestAreaContext("ecl_kw_indexed_read") as area:
            fortio = FortIO("index_test", mode=FortIO.WRITE_MODE)

            element_count = 100000
            ecl_kw = EclKW.create("TEST", element_count,
                                  EclTypeEnum.ECL_INT_TYPE)

            for index in range(element_count):
                ecl_kw[index] = index

            ecl_kw.fwrite(fortio)

            fortio.close()

            fortio = FortIO("index_test", mode=FortIO.READ_MODE)

            new_ecl_kw = EclKW.fread(fortio)

            for index in range(element_count):
                self.assertEqual(new_ecl_kw[index], index)

            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 = ctypes.create_string_buffer(
                len(index_map) * ctypes.sizeof(ctypes.c_int))

            freadIndexedData(fortio, 24, EclTypeEnum.ECL_INT_TYPE,
                             element_count, index_map, char_buffer)

            int_buffer = ctypes.cast(char_buffer, ctypes.POINTER(ctypes.c_int))

            for index, index_map_value in enumerate(index_map):
                self.assertEqual(index_map_value, int_buffer[index])
Esempio n. 29
0
    def test_kw(self):
        kw1 = EclKW.create("KW1", 2, EclTypeEnum.ECL_INT_TYPE)
        kw2 = EclKW.create("KW2", 2, EclTypeEnum.ECL_INT_TYPE)

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

        with TestAreaContext("python/fortio/write-kw"):
            f = FortIO("test", FortIO.WRITE_MODE, fmt_file=False)
            kw1.fwrite(f)

            f = FortIO("test", FortIO.APPEND_MODE)
            kw2.fwrite(f)

            f = FortIO("test", fmt_file=False)
            k1 = EclKW.fread(f)
            k2 = EclKW.fread(f)

            self.assertTrue(k1.equal(kw1))
            self.assertTrue(k2.equal(kw2))
Esempio n. 30
0
    def test_context(self):
        with TestAreaContext("python/fortio/context"):
            kw1 = EclKW.create("KW" , 2456 , EclTypeEnum.ECL_FLOAT_TYPE)
            for i in range(len(kw1)):
                kw1[i] = randint(0,1000)

            with openFortIO("file" , mode = FortIO.WRITE_MODE) as f:
                kw1.fwrite( f )

            with openFortIO("file") as f:
                kw2 = EclKW.fread( f )

            self.assertTrue( kw1 == kw2 )
Esempio n. 31
0
    def test_context(self):
        with TestAreaContext("python/fortio/context"):
            kw1 = EclKW.create("KW" , 2456 , EclTypeEnum.ECL_FLOAT_TYPE)
            for i in range(len(kw1)):
                kw1[i] = randint(0,1000)

            with openFortIO("file" , mode = FortIO.WRITE_MODE) as f:
                kw1.fwrite( f )

            with openFortIO("file") as f:
                kw2 = EclKW.fread( f )

            self.assertTrue( kw1 == kw2 )
Esempio n. 32
0
    def test_cast(self):
        actnum = IntVector(default_value = 1 , initial_size = 1000)
        for i in range(100):
            actnum[i] = 0

        grid = EclGrid.createRectangular( (10,10,10) , (1,1,1) , actnum = actnum)
        kw_wrong_size  = EclKW.create( "KW" , 27 , EclTypeEnum.ECL_FLOAT_TYPE )
        kw_global_size = EclKW.create( "KW" , grid.getGlobalSize() , EclTypeEnum.ECL_FLOAT_TYPE )
        kw_active_size = EclKW.create( "KW" , grid.getNumActive()  , EclTypeEnum.ECL_FLOAT_TYPE )
        
        with self.assertRaises(ValueError):
            Ecl3DKW.castFromKW(kw_wrong_size , grid)

        Ecl3DKW.castFromKW(kw_global_size , grid)
        self.assertTrue( isinstance( kw_global_size , Ecl3DKW))

        Ecl3DKW.castFromKW(kw_active_size , grid , default_value = 66)
        self.assertTrue( isinstance( kw_active_size , Ecl3DKW))

        self.assertEqual( kw_active_size[0,0,0] , 66)
        with self.assertRaises(ValueError):
            kw_active_size[0,0,0] = 88
    def test_create(self):
        defRegion = RegionDefinition.create(5, self.faults, [
            "DF4_MC", "DF15_MC", "DF43_MC", "DF25_LC", "DF21_C", "DF1_C",
            self.poly_file6, "DF26_MC", "DF34_MCS", "DF32_MC", self.poly_file5
        ])
        region_kw = EclKW.create("REGIONS", self.grid.getGlobalSize(),
                                 EclTypeEnum.ECL_INT_TYPE)
        region_kw.assign(0)

        for k in range(self.grid.getNZ()):
            with self.assertRaises(NotImplementedError):
                block_list = defRegion.findInternalBlocks(
                    self.grid, self.fault_blocks[k])
Esempio n. 34
0
    def test_kw(self):
        kw1 = EclKW.create("KW1", 2, EclTypeEnum.ECL_INT_TYPE)
        kw2 = EclKW.create("KW2", 2, EclTypeEnum.ECL_INT_TYPE)

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

        with TestAreaContext("python/fortio/write-kw"):
            f = FortIO("test", FortIO.WRITE_MODE, fmt_file=False)
            kw1.fwrite(f)

            f = FortIO("test", FortIO.APPEND_MODE)
            kw2.fwrite(f)

            f = FortIO("test", fmt_file=False)
            k1 = EclKW.fread(f)
            k2 = EclKW.fread(f)

            self.assertTrue(k1.equal(kw1))
            self.assertTrue(k2.equal(kw2))
Esempio n. 35
0
    def test_ecl_kw_indexed_read(self):
        with TestAreaContext("ecl_kw_indexed_read") as area:
            fortio = FortIO("index_test", mode=FortIO.WRITE_MODE)

            element_count = 100000
            ecl_kw = EclKW.create("TEST", element_count, EclTypeEnum.ECL_INT_TYPE)

            for index in range(element_count):
                ecl_kw[index] = index

            ecl_kw.fwrite(fortio)

            fortio.close()


            fortio = FortIO("index_test", mode=FortIO.READ_MODE)

            new_ecl_kw = EclKW.fread(fortio)

            for index in range(element_count):
                self.assertEqual(new_ecl_kw[index], index)

            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 = ctypes.create_string_buffer(len(index_map) * ctypes.sizeof(ctypes.c_int))

            freadIndexedData(fortio, 24, EclTypeEnum.ECL_INT_TYPE, element_count, index_map, char_buffer)

            int_buffer = ctypes.cast(char_buffer, ctypes.POINTER(ctypes.c_int))

            for index, index_map_value in enumerate(index_map):
                self.assertEqual(index_map_value, int_buffer[index])
Esempio n. 36
0
    def test_fault_block(self):
        grid = EclGrid.create_rectangular( (5,5,1) , (1,1,1) )
        kw = EclKW.create( "FAULTBLK" , grid.size , EclTypeEnum.ECL_INT_TYPE )
        kw.assign( 0 )
        for j in range(1,4):
            for i in range(1,4):
                g = i + j*grid.getNX()
                kw[g] = 1

        layer = FaultBlockLayer( grid , 0 )
        layer.scanKeyword( kw )
        block = layer[1]

        self.assertEqual( (2.50 , 2.50) , block.getCentroid() )
        self.assertEqual( len(block) , 9)
        self.assertEqual( layer , block.getParentLayer() )
Esempio n. 37
0
    def test_update(self):
        reg1 = RegionDefinition(1)
        reg2 = RegionDefinition(2)

        self.assertTrue(not reg1.hasPolygon())

        reg1.addEdge(self.poly1)
        reg2.addEdge(self.poly2)

        self.assertTrue(reg1.hasPolygon())

        region_kw = EclKW.create("REGIONS", self.grid.getGlobalSize(),
                                 EclTypeEnum.ECL_INT_TYPE)
        region_kw.assign(0)
        block_list1 = []
        block_list2 = []

        with self.assertRaises(NotImplementedError):
            block_list1 = reg1.findInternalBlocks(
                self.grid,
                reg1.splitFaultBlocks(self.grid, self.fault_blocks[0]))

        with self.assertRaises(NotImplementedError):
            block_list2 = reg2.findInternalBlocks(
                self.grid,
                reg2.splitFaultBlocks(self.grid, self.fault_blocks[0]))

        if block_list1:
            for block in block_list1:
                region_id = reg1.getRegionID()
                block.assignToRegion(region_id)
                for g in block.getGlobalIndexList():
                    region_kw[g] = region_id

        if block_list2:
            for block in block_list2:
                region_id = reg2.getRegionID()
                block.assignToRegion(region_id)
                for g in block.getGlobalIndexList():
                    region_kw[g] = region_id

        for j in range(4):
            for i in range(4):
                g1 = i + j * self.grid.getNX()
                g2 = i + 12 + (j + 12) * self.grid.getNX()
Esempio n. 38
0
    def test_fprintf_data(self):
        with TestAreaContext("kw_no_header"):
            kw = EclKW.create("REGIONS", 10, EclTypeEnum.ECL_INT_TYPE)
            for i in range(len(kw)):
                kw[i] = i

            fileH = 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)
Esempio n. 39
0
    def test_fprintf_data(self):
        with TestAreaContext("kw_no_header"):
            kw = EclKW.create("REGIONS" , 10 , EclTypeEnum.ECL_INT_TYPE)
            for i in range(len(kw)):
                kw[i] = i
                
            fileH = 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)
Esempio n. 40
0
    def setUp(self):
        self.grid = EclGrid.create_rectangular( (16,16,1) , (1,1,1) )
        self.poly1 = Polyline(init_points = [(0,0) , (0,4) , (5,5) , (0,5)])
        self.poly2 = Polyline(init_points = [(11,11) , (16,12) , (16,16) , (12,16)])
        self.fault_block_kw = EclKW.create( "FAULTBLK" , self.grid.getGlobalSize() , EclTypeEnum.ECL_INT_TYPE )
        self.fault_block_kw.assign( 0 )
        self.faults = FaultCollection( self.grid )
        for j in range(4):
            for i in range(4):
                g1 = i + j*self.grid.getNX()
                g2 = i + 12 + (j + 12)* self.grid.getNX()
                
                self.fault_block_kw[g1] = 1
                self.fault_block_kw[g2] = 2

        self.fault_blocks = []
        for k in range(self.grid.getNZ()):
            block = FaultBlockLayer( self.grid , k)
            block.scanKeyword( self.fault_block_kw )
            self.fault_blocks.append( block )
Esempio n. 41
0
    def test_update(self):
        reg1 = RegionDefinition( 1 )
        reg2 = RegionDefinition( 2 )

        self.assertTrue( not reg1.hasPolygon() )

        reg1.addEdge( self.poly1 )
        reg2.addEdge( self.poly2 )
        
        self.assertTrue( reg1.hasPolygon() )
        

        region_kw = EclKW.create( "REGIONS" , self.grid.getGlobalSize() , EclTypeEnum.ECL_INT_TYPE )
        region_kw.assign( 0 )
        block_list1 = []
        block_list2 = []

        with self.assertRaises(NotImplementedError):
            block_list1 = reg1.findInternalBlocks(self.grid , reg1.splitFaultBlocks(self.grid , self.fault_blocks[0]))

        with self.assertRaises(NotImplementedError):
            block_list2 = reg2.findInternalBlocks(self.grid , reg2.splitFaultBlocks(self.grid , self.fault_blocks[0]))

        if block_list1:
            for block in block_list1:
                region_id = reg1.getRegionID()
                block.assignToRegion( region_id )
                for g in block.getGlobalIndexList():
                    region_kw[g] = region_id

        if block_list2:
            for block in block_list2:
                region_id = reg2.getRegionID()
                block.assignToRegion( region_id )
                for g in block.getGlobalIndexList():
                    region_kw[g] = region_id
                
        for j in range(4):
            for i in range(4):
                g1 = i + j*self.grid.getNX()
                g2 = i + 12 + (j + 12)* self.grid.getNX()
Esempio n. 42
0
    def test_stepped(self):
        grid = EclGrid.create_rectangular((6, 1, 4), (1, 1, 1))
        f = Fault(grid, "F")
        f.addRecord(4, 4, 0, 0, 0, 1, "X")
        f.addRecord(2, 2, 0, 0, 1, 1, "Z")
        f.addRecord(1, 1, 0, 0, 2, 3, "X")

        block_kw = EclKW.create("FAULTBLK", grid.getGlobalSize(),
                                EclTypeEnum.ECL_INT_TYPE)
        block_kw.assign(1)
        block_kw[5] = 2
        block_kw[11] = 2
        block_kw[14:18] = 2
        block_kw[14:18] = 2
        block_kw[20:23] = 2

        layer0 = FaultBlockLayer(grid, 0)
        layer0.scanKeyword(block_kw)
        layer0.addFaultBarrier(f)
        self.assertTrue(layer0.cellContact((0, 0), (1, 0)))
        self.assertFalse(layer0.cellContact((4, 0), (5, 0)))

        layer1 = FaultBlockLayer(grid, 1)
        layer1.scanKeyword(block_kw)
        layer1.addFaultBarrier(f)
        self.assertTrue(layer1.cellContact((0, 0), (1, 0)))
        self.assertFalse(layer1.cellContact((4, 0), (5, 0)))

        layer2 = FaultBlockLayer(grid, 2)
        layer2.scanKeyword(block_kw)
        layer2.addFaultBarrier(f)
        self.assertTrue(layer2.cellContact((0, 0), (1, 0)))
        self.assertFalse(layer2.cellContact((1, 0), (2, 0)))

        layer3 = FaultBlockLayer(grid, 3)
        layer3.scanKeyword(block_kw)
        layer3.addFaultBarrier(f)
        self.assertTrue(layer3.cellContact((0, 0), (1, 0)))
        self.assertFalse(layer3.cellContact((1, 0), (2, 0)))
Esempio n. 43
0
    def test_stepped(self):
        grid = EclGrid.create_rectangular( (6,1,4) , (1,1,1))
        f = Fault(grid , "F")
        f.addRecord(4,4,0,0,0,1,"X")
        f.addRecord(2,2,0,0,1,1,"Z")
        f.addRecord(1,1,0,0,2,3,"X")
        
        block_kw = EclKW.create("FAULTBLK" , grid.getGlobalSize() , EclTypeEnum.ECL_INT_TYPE)
        block_kw.assign(1)
        block_kw[5] = 2
        block_kw[11] = 2
        block_kw[14:18] = 2
        block_kw[14:18] = 2
        block_kw[20:23] = 2
        
        layer0 = FaultBlockLayer( grid , 0 )
        layer0.scanKeyword( block_kw )
        layer0.addFaultBarrier( f )
        self.assertTrue( layer0.cellContact((0,0) , (1,0)))
        self.assertFalse( layer0.cellContact((4,0) , (5,0)))

        layer1 = FaultBlockLayer( grid , 1 )
        layer1.scanKeyword( block_kw )
        layer1.addFaultBarrier( f )
        self.assertTrue( layer1.cellContact((0,0) , (1,0)))
        self.assertFalse( layer1.cellContact((4,0) , (5,0)))

        layer2 = FaultBlockLayer( grid , 2 )
        layer2.scanKeyword( block_kw )
        layer2.addFaultBarrier( f )
        self.assertTrue( layer2.cellContact((0,0) , (1,0)))
        self.assertFalse( layer2.cellContact((1,0) , (2,0)))

        layer3 = FaultBlockLayer( grid , 3 )
        layer3.scanKeyword( block_kw )
        layer3.addFaultBarrier( f )
        self.assertTrue( layer3.cellContact((0,0) , (1,0)))
        self.assertFalse( layer3.cellContact((1,0) , (2,0)))
Esempio n. 44
0
    def setUp(self):
        self.grid = EclGrid.create_rectangular((16, 16, 1), (1, 1, 1))
        self.poly1 = Polyline(init_points=[(0, 0), (0, 4), (5, 5), (0, 5)])
        self.poly2 = Polyline(init_points=[(11, 11), (16, 12), (16,
                                                                16), (12, 16)])
        self.fault_block_kw = EclKW.create("FAULTBLK",
                                           self.grid.getGlobalSize(),
                                           EclTypeEnum.ECL_INT_TYPE)
        self.fault_block_kw.assign(0)
        self.faults = FaultCollection(self.grid)
        for j in range(4):
            for i in range(4):
                g1 = i + j * self.grid.getNX()
                g2 = i + 12 + (j + 12) * self.grid.getNX()

                self.fault_block_kw[g1] = 1
                self.fault_block_kw[g2] = 2

        self.fault_blocks = []
        for k in range(self.grid.getNZ()):
            block = FaultBlockLayer(self.grid, k)
            block.scanKeyword(self.fault_block_kw)
            self.fault_blocks.append(block)
Esempio n. 45
0
 def test_ecl_kw_create(self):
     with self.assertRaises(DeprecationWarning):
         kw = EclKW.create("KW" , 1000 , EclTypeEnum.ECL_INT_TYPE)
Esempio n. 46
0
def copy_long():
    src = EclKW.create("NAME", 100, EclTypeEnum.ECL_FLOAT_TYPE)
    copy = src.sub_copy(0, 2000)
Esempio n. 47
0
 def test_ecl_kw_create(self):
     with self.assertRaises(DeprecationWarning):
         kw = EclKW.create("KW" , 1000 , EclTypeEnum.ECL_INT_TYPE)
Esempio n. 48
0
def copy_offset():
    src = EclKW.create("NAME", 100, EclTypeEnum.ECL_FLOAT_TYPE)
    copy = src.sub_copy(200, 100)
Esempio n. 49
0
def copy_offset():
    src = EclKW.create("NAME", 100, EclTypeEnum.ECL_FLOAT_TYPE)
    copy = src.sub_copy(200, 100)
Esempio n. 50
0
 def exportACTNUMKw(self):
     actnum = EclKW.create("ACTNUM" , self.getGlobalSize() , EclTypeEnum.ECL_INT_TYPE)
     cfunc.init_actnum( self , actnum.getDataPtr() )
     return actnum
Esempio n. 51
0
 def test_create(self):
     with self.assertRaises(ValueError):
         EclKW.create( "ToGodDamnLong" , 100 , EclTypeEnum.ECL_CHAR_TYPE )
Esempio n. 52
0
 def test_create(self):
     with self.assertRaises(ValueError):
         EclKW.create("ToGodDamnLong", 100, EclTypeEnum.ECL_CHAR_TYPE)
Esempio n. 53
0
def copy_long():
    src = EclKW.create("NAME", 100, EclTypeEnum.ECL_FLOAT_TYPE)
    copy = src.sub_copy(0, 2000)
Esempio n. 54
0
 def exportACTNUMKw(self):
     actnum = EclKW.create("ACTNUM", self.getGlobalSize(),
                           EclTypeEnum.ECL_INT_TYPE)
     cfunc.init_actnum(self, actnum.getDataPtr())
     return actnum
Esempio n. 55
0
    def test_fault_block_layer(self):
        with self.assertRaises(ValueError):
            layer = FaultBlockLayer( self.grid , -1 )

        with self.assertRaises(ValueError):
            layer = FaultBlockLayer( self.grid , self.grid.size  )
            
        layer = FaultBlockLayer( self.grid , 1 )
        self.assertEqual( 1 , layer.getK() )

        kw = EclKW.create( "FAULTBLK" , self.grid.size , EclTypeEnum.ECL_FLOAT_TYPE )
        with self.assertRaises(ValueError):
            layer.scanKeyword( kw )

        layer.scanKeyword( self.kw )
        self.assertEqual( 2 , len(layer) )

        with self.assertRaises(TypeError):
            ls = layer["JJ"]

        l = []
        for blk in layer:
            l.append( blk )
        self.assertEqual( len(l) , 2 )

        l0 = layer[0]
        l1 = layer[1]
        self.assertTrue( isinstance(l1 , FaultBlock ))
        l0.getCentroid()
        l1.getBlockID()

        with self.assertRaises(IndexError):
            l2 = layer[2]

            
        self.assertEqual( True , 1 in layer)
        self.assertEqual( True , 2 in layer)
        self.assertEqual( False , 77 in layer)
        self.assertEqual( False , 177 in layer)

        l1 = layer.getBlock( 1 )
        self.assertTrue( isinstance(l1 , FaultBlock ))
        
        with self.assertRaises(KeyError):
            l =layer.getBlock(66)

        with self.assertRaises(KeyError):
            layer.deleteBlock(66)

        layer.deleteBlock(2)
        self.assertEqual( 1 , len(layer))
        blk = layer[0]
        self.assertEqual( blk.getBlockID() , 1 ) 

        with self.assertRaises(KeyError):
            layer.addBlock(1)
            
        blk2 = layer.addBlock(2)
        self.assertEqual( len(layer) , 2 ) 
        
        blk3 = layer.addBlock()
        self.assertEqual( len(layer) , 3 ) 
        

        layer.addBlock(100)
        layer.addBlock(101)
        layer.addBlock(102)
        layer.addBlock(103)

        layer.deleteBlock(2)
        blk1 = layer.getBlock( 103 )
        blk2 = layer[-1]
        self.assertEqual( blk1.getBlockID() , blk2.getBlockID() )

        fault_block = layer[0]
        fault_block.assignToRegion( 2 )
        self.assertEqual( [2] , list(fault_block.getRegionList()))

        fault_block.assignToRegion( 2 )
        self.assertEqual( [2] , list(fault_block.getRegionList()))

        fault_block.assignToRegion( 3 )
        self.assertEqual( [2,3] , list(fault_block.getRegionList()))

        fault_block.assignToRegion( 1 )
        self.assertEqual( [1,2,3] , list(fault_block.getRegionList()))

        fault_block.assignToRegion( 2 )
        self.assertEqual( [1,2,3] , list(fault_block.getRegionList()))