Пример #1
0
    def loadVector(self, plot_block_data, fs, report_step, realization_number):
        """
        @type plot_block_data: PlotBlockData
        @type fs: EnkfFs
        @type report_step: int
        @type realization_number: int
        @rtype PlotBlockVector
        """
        config_node = self.__obs_vector.getConfigNode()

        is_private_container = config_node.getImplementationType() == ErtImplType.CONTAINER
        data_node = EnkfNode(config_node, private=is_private_container)

        node_id = NodeId(report_step, realization_number)

        if data_node.tryLoad(fs, node_id):
            block_obs = self.getBlockObservation(report_step)

            data = DoubleVector()
            for index in range(len(block_obs)):
                value = block_obs.getData(data_node.valuePointer(), index, node_id)
                data.append(value)
            data.permute(self.__permutation_vector)

            plot_block_vector = PlotBlockVector(realization_number, data)
            plot_block_data.addPlotBlockVector(plot_block_vector)
Пример #2
0
    def test_vector_operations_with_exceptions(self):
        iv1 = IntVector()
        iv1.append(1)
        iv1.append(2)
        iv1.append(3)

        iv2 = IntVector()
        iv2.append(4)
        iv2.append(5)

        dv1 = DoubleVector()
        dv1.append(0.5)
        dv1.append(0.75)
        dv1.append(0.25)

        #Size mismatch
        with self.assertRaises(ValueError):
            iv3 = iv1 + iv2

        #Size mismatch
        with self.assertRaises(ValueError):
            iv3 = iv1 * iv2

        #Type mismatch
        with self.assertRaises(TypeError):
            iv1 += dv1

        #Type mismatch
        with self.assertRaises(TypeError):
            iv1 *= dv1
Пример #3
0
 def getEdgePolygon(self):
     x_list = DoubleVector()
     y_list = DoubleVector()
     self.cNamespace().trace_edge( self , x_list , y_list )
     p = Polyline()
     for (x,y) in zip(x_list , y_list):
         p.addPoint(x,y)
     return p
Пример #4
0
    def test_element_sum(self):
        dv = DoubleVector()
        iv = IntVector()
        for i in range(10):
            dv.append(i + 1)
            iv.append(i + 1)

        self.assertEqual(dv.elementSum(), 55)
        self.assertEqual(iv.elementSum(), 55)
Пример #5
0
    def test_element_sum(self):
        dv = DoubleVector()
        iv = IntVector()
        for i in range(10):
            dv.append(i+1)
            iv.append(i+1)

        self.assertEqual( dv.elementSum() , 55 )
        self.assertEqual( iv.elementSum() , 55 )
Пример #6
0
    def getEdgePolygon(self):
        x_list = DoubleVector()
        y_list = DoubleVector()
        cell_list = IntVector()

        self._trace_edge(x_list, y_list, cell_list)
        p = Polyline()
        for (x, y) in zip(x_list, y_list):
            p.addPoint(x, y)
        return p
Пример #7
0
    def getDepthValues(self, report_step):
        """ @rtype: DoubleVector """
        block_obs = self.getBlockObservation(report_step)

        depth = DoubleVector()
        for index in block_obs:
            value = block_obs.getDepth(index)
            depth.append(value)

        return depth
Пример #8
0
    def test_stat_quantiles(self):
        v = DoubleVector()
        for i in range(100000):
            v.append(random.random())

        self.assertAlmostEqual(quantile(v, 0.1), 0.1, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.2), 0.2, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.3), 0.3, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.4), 0.4, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.5), 0.5, 2)
Пример #9
0
    def test_stat_quantiles(self):
        v = DoubleVector()
        for i in range(100000):
            v.append(random.random())

        self.assertAlmostEqual(quantile(v, 0.1), 0.1, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.2), 0.2, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.3), 0.3, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.4), 0.4, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.5), 0.5, 2)
Пример #10
0
    def getDepthValues(self, report_step):
        """ @rtype: DoubleVector """
        block_obs = self.getBlockObservation(report_step)

        depth = DoubleVector()
        for index in block_obs:
            value = block_obs.getDepth(index)
            depth.append(value)

        return depth
Пример #11
0
    def test_stat_quantiles(self):
        rng = RandomNumberGenerator()
        rng.setState("0123456789ABCDEF")
        v = DoubleVector()
        for i in range(100000):
            v.append(rng.getDouble( ))

        self.assertAlmostEqual(quantile(v, 0.1), 0.1, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.2), 0.2, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.3), 0.3, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.4), 0.4, 2)
        self.assertAlmostEqual(quantile_sorted(v, 0.5), 0.5, 2)
Пример #12
0
    def test_plot_block_vector(self):
        vector = DoubleVector()
        vector.append(1.5)
        vector.append(2.5)
        vector.append(3.5)
        plot_block_vector = PlotBlockVector(1, vector)

        self.assertEqual(plot_block_vector.getRealizationNumber(), 1)
        self.assertEqual(plot_block_vector[0], 1.5)
        self.assertEqual(plot_block_vector[2], 3.5)

        self.assertEqual(len(plot_block_vector), len(vector))
Пример #13
0
 def blockedProduction(self , totalKey , timeRange):
     node = self.smspec_node(totalKey)
     if node.is_total:
         total = DoubleVector()
         for t in timeRange:
             if t < CTime(self.start_time):
                 total.append( 0 )
             elif t >= CTime( self.end_time):
                 total.append( self.get_last_value( totalKey ))
             else:
                 total.append( self.get_interp( totalKey , date = t ))
         tmp = total << 1
         total.pop()
         return tmp - total
     else:
         raise TypeError("The blockedProduction method must be called with one of the TOTAL keys like e.g. FOPT or GWIT")
Пример #14
0
    def test_plot_block_data(self):
        depth = DoubleVector()
        depth.append(2.5)
        depth.append(3.5)

        data = PlotBlockData(depth)

        self.assertEqual(data.getDepth(), depth)

        vector = PlotBlockVector(1, DoubleVector())
        data.addPlotBlockVector(vector)
        data.addPlotBlockVector(PlotBlockVector(2, DoubleVector()))

        self.assertEqual(len(data), 2)

        self.assertEqual(vector, data[1])
Пример #15
0
    def test_true_false(self):
        v = IntVector(default_value=77)
        self.assertFalse(v)
        v[10] = 77
        self.assertTrue(v)

        v = DoubleVector(default_value=77)
        self.assertFalse(v)
        v[10] = 77
        self.assertTrue(v)
Пример #16
0
 def blockedProduction(self , totalKey , timeRange):
     node = self.smspec_node(totalKey)
     if node.is_total:
         total = DoubleVector()
         for t in timeRange:
             if t < CTime(self.start_time):
                 total.append( 0 )
             elif t >= CTime( self.end_time):
                 total.append( self.get_last_value( totalKey ))
             else:
                 total.append( self.get_interp( totalKey , date = t ))
         tmp = total << 1
         total.pop()
         return tmp - total
     else:
         raise TypeError("The blockedProduction method must be called with one of the TOTAL keys like e.g. FOPT or GWIT")
Пример #17
0
    def test_double_vector(self):
        v = DoubleVector()

        v[0] = 77.25
        v[1] = 123.25
        v[2] = 66.25
        v[3] = 56.25
        v[4] = 111.25
        v[5] = 99.25
        v[12] = 12

        self.assertEqual(len(v), 13)
        self.assertEqual(list(v), [v[0], v[1], v[2], v[3], v[4], v[5], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, v[12]])

        v.clear()
        self.assertEqual(len(v), 0)

        v.clear()

        v[0] = 0.1
        v[1] = 0.2
        v[2] = 0.4
        v[3] = 0.8

        v2 = v * 2

        self.assertEqual(list(v2), [v[0] * 2, v[1] * 2, v[2] * 2, v[3] * 2])

        v2 += v
        self.assertEqual(list(v2), [v[0] * 3, v[1] * 3, v[2] * 3, v[3] * 3])

        v2.assign(0.66)
        self.assertEqual(list(v2), [0.66, 0.66, 0.66, 0.66])

        v.assign(v2)
        self.assertEqual(list(v), [0.66, 0.66, 0.66, 0.66])

        v.clear()
        v.default = 0.75
        self.assertEqual(v.default, 0.75)
        v[2] = 0.0
        self.assertEqual(v[1], 0.75)
Пример #18
0
    def center(self):
        xlist = DoubleVector()
        ylist = DoubleVector()
        for segment in self:
            C1 = segment.getC1()
            C2 = segment.getC2()
            (J1, I1) = divmod(C1, self.__grid.getNX() + 1)
            (J2, I2) = divmod(C2, self.__grid.getNX() + 1)

            (x1, y1, z) = self.__grid.getNodePos(I1, J1, self.__k)
            (x2, y2, z) = self.__grid.getNodePos(I2, J2, self.__k)

            xlist.append(x1)
            xlist.append(x2)

            ylist.append(y1)
            ylist.append(y2)

        N = len(xlist)
        return (xlist.elementSum() / N, ylist.elementSum() / N)
Пример #19
0
    def test_count_equal(self):
        v = IntVector(default_value=77)
        v[0] = 1
        v[10] = 1
        v[20] = 1
        self.assertEqual(v.countEqual(1), 3)

        v = DoubleVector(default_value=77)
        v[0] = 1
        v[10] = 1
        v[20] = 1
        self.assertEqual(v.countEqual(1), 3)
Пример #20
0
    def loadVector(self, plot_block_data, fs, report_step, realization_number):
        """
        @type plot_block_data: PlotBlockData
        @type fs: EnkfFs
        @type report_step: int
        @type realization_number: int
        @rtype PlotBlockVector
        """
        config_node = self.__obs_vector.getConfigNode()

        is_private_container = config_node.getImplementationType() == ErtImplType.CONTAINER
        data_node = EnkfNode(config_node, private=is_private_container)

        node_id = NodeId(report_step, realization_number)

        if data_node.tryLoad(fs, node_id):
            block_obs = self.getBlockObservation(report_step)

            data = DoubleVector()
            for index in range(len(block_obs)):
                value = block_obs.getData(data_node.valuePointer(), index, node_id)
                data.append(value)
            data.permute(self.__permutation_vector)

            plot_block_vector = PlotBlockVector(realization_number, data)
            plot_block_data.addPlotBlockVector(plot_block_vector)
Пример #21
0
    def test_vector_operations_with_exceptions(self):
        iv1 = IntVector()
        iv1.append(1)
        iv1.append(2)
        iv1.append(3)

        iv2 = IntVector()
        iv2.append(4)
        iv2.append(5)

        dv1 = DoubleVector()
        dv1.append(0.5)
        dv1.append(0.75)
        dv1.append(0.25)

        #Size mismatch
        with self.assertRaises(ValueError):
            iv3 = iv1 + iv2

        #Size mismatch
        with self.assertRaises(ValueError):
            iv3 = iv1 * iv2

        #Type mismatch
        with self.assertRaises(TypeError):
            iv1 += dv1

        #Type mismatch
        with self.assertRaises(TypeError):
            iv1 *= dv1
Пример #22
0
 def setValues(self , values):
     if len(values) == len(self):
         if isinstance(values , DoubleVector):
             GenKw.cNamespace().set_values( self , d )
         else:
             d = DoubleVector()
             for (index,v) in enumerate(values):
                 if isinstance(v, (int,long,float)):
                     d[index] = v
                 else:
                     raise TypeError("Values must numeric: %s is invalid" % v)
             GenKw.cNamespace().set_values( self , d )
     else:
         raise ValueError("Size mismatch between GenKW and values")
Пример #23
0
 def test_gc_polyline(self):
     # This should test that the elements in the collection can be
     # safely accessed, even after the polyline objects p1 and p2
     # from create_collection() have gone out of scope.
     c = self.create_collection()
     v = DoubleVector(initial_size = 10000)
     
     p1 = c[0]
     tail  = p1[-1]
     self.assertEqual( tail , (2,12))
     self.assertEqual(p1.getName() , "POLY1")
     
     p2 = c[1]
     tail  = p2[-1]
     self.assertEqual( tail , (20,120))
     self.assertEqual(p2.getName() , "POLY2")
Пример #24
0
    def calculatePrincipalComponent(self,
                                    fs,
                                    local_obsdata,
                                    truncation_or_ncomp=3):
        pc = Matrix(1, 1)
        pc_obs = Matrix(1, 1)
        singular_values = DoubleVector()

        state_map = fs.getStateMap()
        ens_mask = BoolVector(False, self.ert().getEnsembleSize())
        state_map.selectMatching(ens_mask, RealizationStateEnum.STATE_HAS_DATA)
        active_list = ens_mask.createActiveList()

        if len(ens_mask) > 0:
            meas_data = MeasData(ens_mask)
            obs_data = ObsData()

            self.ert().getObservations().getObservationAndMeasureData(
                fs, local_obsdata, active_list, meas_data, obs_data)

            meas_data.deactivateZeroStdSamples(obs_data)

            active_size = len(obs_data)

            if active_size > 0:
                S = meas_data.createS()
                D_obs = obs_data.createDObs()

                truncation, ncomp = self.truncationOrNumberOfComponents(
                    truncation_or_ncomp)

                obs_data.scale(S, D_obs=D_obs)
                EnkfLinalg.calculatePrincipalComponents(
                    S, D_obs, truncation, ncomp, pc, pc_obs, singular_values)
                if self.__prior_singular_values is None:
                    self.__prior_singular_values = singular_values
                else:
                    for row in range(pc.rows()):
                        factor = singular_values[
                            row] / self.__prior_singular_values[row]
                        pc.scaleRow(row, factor)
                        pc_obs.scaleRow(row, factor)

                return PcaPlotData(local_obsdata.getName(), pc, pc_obs,
                                   singular_values)
        return None
Пример #25
0
    def test_permutation_vector(self):
        vector = DoubleVector()

        for i in range(5, 0, -1):
            vector.append(i)

        permutation_vector = vector.permutationSort()

        for index, value in enumerate(range(5, 0, -1)):
            self.assertEqual(vector[index], value)

        vector.permute(permutation_vector)

        for index, value in enumerate(range(1, 6)):
            self.assertEqual(vector[index], value)
Пример #26
0
    def test_plot_block_vector(self):
        vector = DoubleVector()
        vector.append(1.5)
        vector.append(2.5)
        vector.append(3.5)
        plot_block_vector = PlotBlockVector(1, vector)

        self.assertEqual(plot_block_vector.getRealizationNumber(), 1)
        self.assertEqual(plot_block_vector[0], 1.5)
        self.assertEqual(plot_block_vector[2], 3.5)

        self.assertEqual(len(plot_block_vector), len(vector))
Пример #27
0
    def test_polyfit(self):
        x_list = DoubleVector()
        y_list = DoubleVector()
        S = DoubleVector()

        A = 7.25
        B = -4
        C = 0.025

        x = 0
        dx = 0.1
        for i in range(100):
            y = A + B * x + C * x * x
            x_list.append(x)
            y_list.append(y)

            x += dx
            S.append(1.0)

        beta = polyfit(3, x_list, y_list, None)

        self.assertAlmostEqual(A, beta[0])
        self.assertAlmostEqual(B, beta[1])
        self.assertAlmostEqual(C, beta[2])
Пример #28
0
    def center(self):
        xlist = DoubleVector( )
        ylist = DoubleVector( ) 
        for segment in self:
            C1 = segment.getC1()
            C2 = segment.getC2()
            (J1 , I1) = divmod(C1 , self.__grid.getNX() + 1)
            (J2 , I2) = divmod(C2 , self.__grid.getNX() + 1)
            
            (x1,y1,z) = self.__grid.getNodePos( I1 , J1 , self.__k )
            (x2,y2,z) = self.__grid.getNodePos( I2 , J2 , self.__k )

            xlist.append( x1 )
            xlist.append( x2 )

            ylist.append( y1 )
            ylist.append( y2 )

            
        N = len(xlist)
        return (xlist.elementSum()/N , ylist.elementSum()/N )
Пример #29
0
    def test_permutation_vector(self):
        vector = DoubleVector()

        for i in range(5, 0, -1):
            vector.append(i)

        permutation_vector = vector.permutationSort()

        for index, value in enumerate(range(5, 0, -1)):
            self.assertEqual(vector[index], value)

        vector.permute(permutation_vector)

        for index, value in enumerate(range(1, 6)):
            self.assertEqual(vector[index], value)
Пример #30
0
    def test_plot_block_data(self):
        depth = DoubleVector()
        depth.append(2.5)
        depth.append(3.5)

        data = PlotBlockData(depth)

        self.assertEqual(data.getDepth(), depth)

        vector = PlotBlockVector(1, DoubleVector())
        data.addPlotBlockVector(vector)
        data.addPlotBlockVector(PlotBlockVector(2, DoubleVector()))

        self.assertEqual(len(data), 2)

        self.assertEqual(vector, data[1])
Пример #31
0
class GridTest(ExtendedTestCase):
    def egrid_file(self):
        return self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID")


    def grid_file(self):
        return self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID")


    def grdecl_file(self):
        return self.createTestPath("Statoil/ECLIPSE/Gurbat/include/example_grid_sim.GRDECL")

    def test_loadFromFile(self):
        g1 = EclGrid.loadFromFile( self.egrid_file() )
        g2 = EclGrid.loadFromFile( self.grdecl_file() )

        self.assertTrue( isinstance( g1 , EclGrid ) )
        self.assertTrue( isinstance( g2 , EclGrid ) )
        

    def test_corner(self):
        grid = EclGrid(self.egrid_file())
        nx = grid.getNX()
        ny = grid.getNY()
        nz = grid.getNZ()
        
        (x1,y1,z1) = grid.getCellCorner( 0 , ijk = (0,0,0))
        (x2,y2,z2) = grid.getLayerXYZ( 0 , 0 )
        self.assertEqual(x1,x2)
        self.assertEqual(y1,y2)
        self.assertEqual(z1,z2)

        (x1,y1,z1) = grid.getCellCorner( 0 , ijk = (0,1,0))
        (x2,y2,z2) = grid.getLayerXYZ( (nx + 1) , 0 )
        self.assertEqual(x1,x2)
        self.assertEqual(y1,y2)
        self.assertEqual(z1,z2)

        (x1,y1,z1) = grid.getCellCorner( 1 , ijk = (nx - 1,0,0))
        (x2,y2,z2) = grid.getLayerXYZ( nx , 0 )
        self.assertEqual(x1,x2)
        self.assertEqual(y1,y2)
        self.assertEqual(z1,z2)

        (x1,y1,z1) = grid.getCellCorner( 4 , ijk = (0,0,nz-1))
        (x2,y2,z2) = grid.getLayerXYZ( 0 , nz )
        self.assertEqual(x1,x2)
        self.assertEqual(y1,y2)
        self.assertEqual(z1,z2)

        (x1,y1,z1) = grid.getCellCorner( 7 , ijk = (nx-1,ny-1,nz-1))
        (x2,y2,z2) = grid.getLayerXYZ( (nx + 1)*(ny + 1) - 1 , nz )
        self.assertEqual(x1,x2)
        self.assertEqual(y1,y2)
        self.assertEqual(z1,z2)


    
        with self.assertRaises(IndexError):
            grid.getLayerXYZ( -1 , 0 )

        with self.assertRaises(IndexError):
            grid.getLayerXYZ( (nx + 1)*(ny + 1) , 0 )

        with self.assertRaises(IndexError):
            grid.getLayerXYZ( 0 , -1 )

        with self.assertRaises(IndexError):
            grid.getLayerXYZ( 0 , nz + 1 )


    def test_GRID( self ):
        grid = EclGrid(self.grid_file())
        self.assertTrue(grid)
    
    
    
    def test_EGRID( self ):
        grid = EclGrid(self.egrid_file())
        self.assertTrue(grid)
        dims = grid.dims
        self.assertEqual(dims[0] , grid.getNX())
        self.assertEqual(dims[1] , grid.getNY())
        self.assertEqual(dims[2] , grid.getNZ())
    
    
    
    def create(self, filename, load_actnum=True):
        fileH = open(filename, "r")
        specgrid = EclKW.read_grdecl(fileH, "SPECGRID", ecl_type=EclTypeEnum.ECL_INT_TYPE, strict=False)
        zcorn = EclKW.read_grdecl(fileH, "ZCORN")
        coord = EclKW.read_grdecl(fileH, "COORD")
        if load_actnum:
            actnum = EclKW.read_grdecl(fileH, "ACTNUM", ecl_type=EclTypeEnum.ECL_INT_TYPE)
        else:
            actnum = None
    
        mapaxes = EclKW.read_grdecl(fileH, "MAPAXES")
        grid = EclGrid.create(specgrid, zcorn, coord, actnum, mapaxes=mapaxes)
        return grid
    
    
    def test_rect(self):
        with TestAreaContext("python/grid-test/testRect"):
            a1 = 1.0
            a2 = 2.0
            a3 = 3.0
            grid = EclGrid.createRectangular((9, 9, 9), (a1, a2, a3))
            grid.save_EGRID("rect.EGRID")
            grid2 = EclGrid("rect.EGRID")
            self.assertTrue(grid)
            self.assertTrue(grid2)
    
            (x, y, z) = grid.get_xyz(ijk=(4, 4, 4))
            self.assertAlmostEqualList([x, y, z], [4.5 * a1, 4.5 * a2, 4.5 * a3])
    
            v = grid.cell_volume(ijk=(4, 4, 4))
            self.assertFloatEqual(v, a1 * a2 * a3)
    
            z = grid.depth(ijk=(4, 4, 4 ))
            self.assertFloatEqual(z, 4.5 * a3)
    
            g1 = grid.global_index(ijk=(2, 2, 2))
            g2 = grid.global_index(ijk=(4, 4, 4))
            (dx, dy, dz) = grid.distance(g2, g1)
            self.assertAlmostEqualList([dx, dy, dz], [2 * a1, 2 * a2, 2 * a3])
    
            self.assertTrue(grid.cell_contains(2.5 * a1, 2.5 * a2, 2.5 * a3, ijk=(2, 2, 2)))
    
            #ijk = grid.find_cell(1.5 * a1 , 2.5 * a2 , 3.5 * a3)
            #self.assertAlmostEqualList(ijk, [1, 2, 3])
    
    
    def test_create(self):
        grid = self.create(self.grdecl_file())
        self.assertTrue(grid)
    
    
    def test_grdecl_load(self):
        with self.assertRaises(IOError):
            grid = EclGrid.loadFromGrdecl("/file/does/not/exists")

        with TestAreaContext("python/grid-test/grdeclLoad"):
            with open("grid.grdecl","w") as f:
                f.write("Hei ...")
                
            with self.assertRaises(ValueError):
                grid = EclGrid.loadFromGrdecl("grid.grdecl")
        
            actnum = IntVector(default_value = 1 , initial_size = 1000)
            actnum[0] = 0
            g1 = EclGrid.createRectangular((10,10,10) , (1,1,1) , actnum = actnum )
            self.assertEqual( g1.getNumActive() , actnum.elementSum() )
            g1.save_EGRID("G.EGRID")

            with openEclFile("G.EGRID") as f:
                with open("grid.grdecl" , "w") as f2:
                    f2.write("SPECGRID\n")
                    f2.write("  10  10  10  \'F\' /\n")

                    coord_kw = f["COORD"][0]
                    coord_kw.write_grdecl( f2 )
                    
                    zcorn_kw = f["ZCORN"][0]
                    zcorn_kw.write_grdecl( f2 )
                
                    actnum_kw = f["ACTNUM"][0]
                    actnum_kw.write_grdecl( f2 )
            
            g2 = EclGrid.loadFromGrdecl("grid.grdecl")
            self.assertTrue( g1.equal( g2 ))
                    

    
    def test_ACTNUM(self):
        g1 = self.create(self.grdecl_file())
        g2 = self.create(self.grdecl_file(), load_actnum=False)
        self.assertTrue(g1.equal(g2))
    
    
    def test_time(self):
        t0 = time.clock()
        g1 = EclGrid(self.egrid_file())
        t1 = time.clock()
        t = t1 - t0
        self.assertTrue(t < 1.0)
    
    
    def test_save(self):
        with TestAreaContext("python/grid-test/testSave"):
            g1 = EclGrid(self.egrid_file())
    
            g1.save_EGRID("test.EGRID")
            g2 = EclGrid("test.EGRID")
            self.assertTrue(g1.equal(g2))
    
            g1.save_GRID("test.GRID")
            g2 = EclGrid("test.GRID")
            self.assertTrue(g1.equal(g2))
    
            fileH = open("test.grdecl", "w")
            g1.save_grdecl(fileH)
            fileH.close()
            g2 = self.create("test.grdecl")
            self.assertTrue(g1.equal(g2))
    
    @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test of coarse grid skipped!")
    def test_coarse(self):
        #work_area = TestArea("python/grid-test/testCoarse")
        with TestAreaContext("python/grid-test/testCoarse"):
            testGRID = True
            g1 = EclGrid(self.createTestPath("Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2.EGRID"))
    
            g1.save_EGRID("LGC.EGRID")
            g2 = EclGrid("LGC.EGRID")
            self.assertTrue(g1.equal(g2, verbose=True))
    
            if testGRID:
                g1.save_GRID("LGC.GRID")
                g3 = EclGrid("LGC.GRID")
                self.assertTrue(g1.equal(g3, verbose=True))
    
            self.assertTrue(g1.coarse_groups() == 3384)
    
    
    def test_raise_IO_error(self):
        with self.assertRaises(IOError):
            g = EclGrid("/does/not/exist.EGRID")

    def test_boundingBox(self):
        grid = EclGrid.createRectangular((10,10,10) , (1,1,1))
        with self.assertRaises(ValueError):
            bbox = grid.getBoundingBox2D(layer = -1 )

        with self.assertRaises(ValueError):
            bbox = grid.getBoundingBox2D( layer = 11 )

        bbox = grid.getBoundingBox2D( layer = 10 )
        self.assertEqual( bbox , ((0,0) , (10, 0) , (10 , 10) , (0,10)))


        with self.assertRaises(ValueError):
            grid.getBoundingBox2D( lower_left = (-1,0) )

        with self.assertRaises(ValueError):
            grid.getBoundingBox2D( lower_left = (6,10) )

        bbox = grid.getBoundingBox2D( lower_left = (3,3) )
        self.assertEqual( bbox , ((3,3) , (10,3) , (10,10) , (3,10)))

        with self.assertRaises(ValueError):
            grid.getBoundingBox2D( lower_left = (3,3) , upper_right = (2,2))

        bbox = grid.getBoundingBox2D( lower_left = (3,3) , upper_right = (7,7))
        self.assertEqual( bbox , ((3,3) , (7,3) , (7,7) , (3,7)))





    @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test of dual grid skipped!")
    def test_dual(self):
        with TestAreaContext("python/grid-test/testDual"):
            grid = EclGrid(self.egrid_file())
            self.assertFalse(grid.dual_grid)
            self.assertTrue(grid.nactive_fracture == 0)

            grid2 = EclGrid(self.grid_file())
            self.assertFalse(grid.dual_grid)
            self.assertTrue(grid.nactive_fracture == 0)

            dgrid = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.EGRID"))
            self.assertTrue(dgrid.nactive == dgrid.nactive_fracture)
            self.assertTrue(dgrid.nactive == 46118)

            dgrid2 = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.GRID"))
            self.assertTrue(dgrid.nactive == dgrid.nactive_fracture)
            self.assertTrue(dgrid.nactive == 46118)
            self.assertTrue(dgrid.equal(dgrid2))


            # The DUAL_DIFF grid has been manipulated to create a
            # situation where some cells are only matrix active, and some
            # cells are only fracture active.
            dgrid = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUAL_DIFF.EGRID"))
            self.assertTrue(dgrid.nactive == 106)
            self.assertTrue(dgrid.nactive_fracture == 105)

            self.assertTrue(dgrid.get_active_fracture_index(global_index=0) == -1)
            self.assertTrue(dgrid.get_active_fracture_index(global_index=2) == -1)
            self.assertTrue(dgrid.get_active_fracture_index(global_index=3) == 0)
            self.assertTrue(dgrid.get_active_fracture_index(global_index=107) == 104)

            self.assertTrue(dgrid.get_active_index(global_index=1) == 1)
            self.assertTrue(dgrid.get_active_index(global_index=105) == 105)
            self.assertTrue(dgrid.get_active_index(global_index=106) == -1)
            self.assertTrue(dgrid.get_global_index1F(2) == 5)

            dgrid.save_EGRID("DUAL_DIFF.EGRID")
            dgrid2 = EclGrid("DUAL_DIFF.EGRID")
            self.assertTrue(dgrid.equal(dgrid2 , verbose = True))


    @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test of nactive large memory skipped!")
    def test_nactive_large_memory(self):
        case = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE")
        vecList = []
        for i in range(12500):
            vec = DoubleVector()
            vec[81920] = 0
            vecList.append(vec)

        grid1 = EclGrid(case)
        grid2 = EclGrid(case)
        self.assertEqual(grid1.nactive, grid2.nactive)
        self.assertEqual(grid1.nactive, 34770)
Пример #32
0
 def getData(self):
     data = DoubleVector()
     self._export_data(data)
     return data
Пример #33
0
    def test_polyfit(self):
        x_list = DoubleVector()
        y_list = DoubleVector()
        S = DoubleVector()

        A = 7.25
        B = -4
        C = 0.025

        x = 0
        dx = 0.1
        for i in range(100):
            y = A + B * x + C * x * x
            x_list.append(x)
            y_list.append(y)

            x += dx
            S.append(1.0)

        beta = polyfit(3, x_list, y_list, None)

        self.assertAlmostEqual(A, beta[0])
        self.assertAlmostEqual(B, beta[1])
        self.assertAlmostEqual(C, beta[2])
Пример #34
0
 def getData(self):
     data = DoubleVector()
     GenData.cNamespace().export_data(self, data)
     return data
Пример #35
0
    def test_double_vector(self):
        v = DoubleVector()

        v[0] = 77.25
        v[1] = 123.25
        v[2] = 66.25
        v[3] = 56.25
        v[4] = 111.25
        v[5] = 99.25
        v[12] = 12

        self.assertEqual(len(v), 13)
        self.assertEqual(list(v), [
            v[0], v[1], v[2], v[3], v[4], v[5], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            v[12]
        ])

        v.clear()
        self.assertEqual(len(v), 0)

        v.clear()

        v[0] = 0.1
        v[1] = 0.2
        v[2] = 0.4
        v[3] = 0.8

        v2 = v * 2

        self.assertEqual(list(v2), [v[0] * 2, v[1] * 2, v[2] * 2, v[3] * 2])

        v2 += v
        self.assertEqual(list(v2), [v[0] * 3, v[1] * 3, v[2] * 3, v[3] * 3])

        v2.assign(0.66)
        self.assertEqual(list(v2), [0.66, 0.66, 0.66, 0.66])

        v.assign(v2)
        self.assertEqual(list(v), [0.66, 0.66, 0.66, 0.66])

        v.clear()
        v.setDefault(0.75)
        self.assertEqual(v.getDefault(), 0.75)
        v[2] = 0.0
        self.assertEqual(v[1], 0.75)