当前位置: 首页>>代码示例>>Python>>正文


Python pysgpp.Grid类代码示例

本文整理汇总了Python中pysgpp.Grid的典型用法代码示例。如果您正苦于以下问题:Python Grid类的具体用法?Python Grid怎么用?Python Grid使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Grid类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testSerializationLinearBoudaryBoundingBox

    def testSerializationLinearBoudaryBoundingBox(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid
        
        factory = Grid.createLinearBoundaryGrid(2)
        self.failIfEqual(factory, None)

        gen = factory.createGridGenerator()
        gen.regular(3)

        boundingBox = factory.getBoundingBox()
        tempBound = boundingBox.getBoundary(0)
        tempBound.leftBoundary = 0.0
        tempBound.rightBoundary = 100.0
        tempBound.bDirichletLeft = False;
        tempBound.bDirichletRight = False;
        boundingBox.setBoundary(0, tempBound)

        str = factory.serialize()
        self.assert_(len(str) > 0)
        
        newfac = Grid.unserialize(str)
        self.failIfEqual(newfac, None)
        
        self.assertEqual(factory.getStorage().size(), newfac.getStorage().size())
            
        boundingBox = newfac.getBoundingBox()
        tempBound = boundingBox.getBoundary(0)
        self.assertEqual(0.0, tempBound.leftBoundary)
        self.assertEqual(100.0, tempBound.rightBoundary)
        self.assertEqual(False, tempBound.bDirichletLeft)
        self.assertEqual(False, tempBound.bDirichletRight)
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:32,代码来源:test_GridFactory.py

示例2: createGrid

def createGrid(grid, dim, deg=1, addTruncatedBorder=False):
    # create new grid
    gridType = grid.getType()

    if gridType in [Poly, PolyBoundary]:
        deg = max(deg, grid.getDegree())

    # print gridType, deg
    if deg > 1:
        if gridType in [LinearBoundary, PolyBoundary]:
            return Grid.createPolyBoundaryGrid(dim, deg)
        elif gridType == LinearL0Boundary:
            raise NotImplementedError("there is no full boundary polynomial grid")
        elif gridType in [Linear, Poly]:
            return Grid.createPolyGrid(dim, deg)
        else:
            raise Exception('unknown grid type %s' % gridType)
    else:
        if gridType == Linear:
            return Grid.createLinearGrid(dim)
        elif gridType == LinearBoundary:
            return Grid.createLinearBoundaryGrid(dim)
        elif gridType == LinearL0Boundary:
            return Grid.createLinearBoundaryGrid(dim, 0)
        else:
            raise Exception('unknown grid type %s' % gridType)
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:26,代码来源:sparse_grid.py

示例3: testRefinement2d_two

    def testRefinement2d_two(self):
        from pysgpp import Grid, DataVector, SurplusRefinementFunctor
        factory = Grid.createLinearBoundaryGrid(2)
        storage = factory.getStorage()
        
        gen = factory.createGridGenerator()
        gen.regular(0)
        
        alpha = DataVector(4)
    
        for i in xrange(len(alpha)):
            alpha[i] = 0.0

        alpha[0] = 1.0
        func = SurplusRefinementFunctor(alpha)
            
        gen.refine(func)
        
        alpha2 = DataVector(8)
    
        for i in xrange(len(alpha2)):
            alpha2[i] = 0.0

        alpha2[4] = 1.0
        func = SurplusRefinementFunctor(alpha2)
            
        gen.refine(func)    
        self.failUnlessEqual(storage.size(), 13)        
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:28,代码来源:test_GridFactory.py

示例4: testOperationB

 def testOperationB(self):
     from pysgpp import Grid, DataVector, DataMatrix
     factory = Grid.createLinearBoundaryGrid(1)
     gen = factory.createGridGenerator()
     gen.regular(2)
     
     alpha = DataVector(factory.getStorage().size())
     p = DataMatrix(1,1)
     beta = DataVector(1)
     
     
     alpha.setAll(0.0)
     p.set(0,0,0.25)
     beta[0] = 1.0
     
     opb = factory.createOperationB()
     opb.mult(beta, p, alpha)
     
     self.failUnlessAlmostEqual(alpha[0], 0.75)
     self.failUnlessAlmostEqual(alpha[1], 0.25)
     self.failUnlessAlmostEqual(alpha[2], 0.5)
     self.failUnlessAlmostEqual(alpha[3], 1.0)
     self.failUnlessAlmostEqual(alpha[4], 0.0)
     
     alpha.setAll(0.0)
     alpha[2] = 1.0
     
     p.set(0,0, 0.25)
     
     beta[0] = 0.0
     
     opb.multTranspose(alpha, p, beta)
     self.failUnlessAlmostEqual(beta[0], 0.5)
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:33,代码来源:test_GridFactory.py

示例5: checkPositivity

def checkPositivity(grid, alpha):
    # define a full grid of maxlevel of the grid
    gs = grid.getStorage()
    fullGrid = Grid.createLinearGrid(gs.dim())
    fullGrid.createGridGenerator().full(gs.getMaxLevel())
    fullHashGridStorage = fullGrid.getStorage()
    A = DataMatrix(fullHashGridStorage.size(), fullHashGridStorage.dim())
    p = DataVector(gs.dim())
    for i in xrange(fullHashGridStorage.size()):
        fullHashGridStorage.get(i).getCoords(p)
        A.setRow(i, p)

    res = evalSGFunctionMulti(grid, alpha, A)
    ymin, ymax, cnt = 0, -1e10, 0
    for i, yi in enumerate(res.array()):
        if yi < 0. and abs(yi) > 1e-13:
            cnt += 1
            ymin = min(ymin, yi)
            ymax = max(ymax, yi)
            A.getRow(i, p)
            print "  %s = %g" % (p, yi)
    if cnt > 0:
        print "warning: function is not positive"
        print "%i/%i: [%g, %g]" % (cnt, fullHashGridStorage.size(), ymin, ymax)
    return cnt == 0
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:25,代码来源:sparse_grid.py

示例6: testOperationTest_test

    def testOperationTest_test(self):
        from pysgpp import Grid, DataVector, DataMatrix

        factory = Grid.createLinearBoundaryGrid(1)
        gen = factory.createGridGenerator()
        gen.regular(1)
        
        alpha = DataVector(factory.getStorage().size())        
        
        data = DataMatrix(1,1)
        data.setAll(0.25)
        classes = DataVector(1)
        classes.setAll(1.0)

        testOP = factory.createOperationTest()

        alpha[0] = 0.0
        alpha[1] = 0.0
        alpha[2] = 1.0
        
        c = testOP.test(alpha, data, classes)
        self.failUnless(c > 0.0)
        
        alpha[0] = 0.0
        alpha[1] = 0.0
        alpha[2] = -1.0
        c = testOP.test(alpha, data, classes)
        self.failUnless(c == 0.0)
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:28,代码来源:test_GridFactory.py

示例7: eval_fullGrid

def eval_fullGrid(level, dim, border=True):
    if border:
        grid = Grid.createLinearBoundaryGrid(dim)
    else:
        grid = Grid.createLinearGrid(dim)

    grid.createGridGenerator().full(level)
    gs = grid.getStorage()
    ans = DataMatrix(gs.size(), dim)
    p = DataVector(dim)

    for i in xrange(gs.size()):
        gs.get(i).getCoords(p)
        ans.setRow(i, p)

    return ans
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:16,代码来源:tools.py

示例8: test34

 def test34(self):
     from pysgpp import Grid, DataVector, FullGrid, FullGridSet
     
     dim = 2
     level = 9
     function = buildParableBoundary(dim)
     grid = Grid.createLinearBoundaryGrid(dim)
     testFG(self, grid, level, function)
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:8,代码来源:test_combi.py

示例9: testHierarchisationDModLinear

 def testHierarchisationDModLinear(self):
     from pysgpp import Grid
     
     dim = 3
     level = 5
     function = buildParable(dim)
     grid = Grid.createModLinearGrid(dim)
     testHierarchisationDehierarchisation(self, grid, level, function)
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:8,代码来源:test_hierarchisation.py

示例10: testSerializationLinearBoudary

    def testSerializationLinearBoudary(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid
        
        factory = Grid.createLinearBoundaryGrid(2)
        self.failIfEqual(factory, None)

        gen = factory.createGridGenerator()
        gen.regular(3)

        str = factory.serialize()
        self.assert_(len(str) > 0)
        
        newfac = Grid.unserialize(str)
        self.failIfEqual(newfac, None)
        
        self.assertEqual(factory.getStorage().size(), newfac.getStorage().size())        
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:17,代码来源:test_GridFactory.py

示例11: testHierarchisationDBoundary

 def testHierarchisationDBoundary(self):
     from pysgpp import Grid
     
     dim = 3
     level = 5
     function = buildParableBoundary(dim)
     grid = Grid.createLinearBoundaryGrid(dim)
     testHierarchisationDehierarchisation(self, grid, level, function)
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:8,代码来源:test_hierarchisation.py

示例12: test44

 def test44(self):
     from pysgpp import Grid, DataVector, FullGrid, FullGridSet
     
     dim = 2
     level = 8
     function = buildParableBoundary(dim)
     grid = Grid.createSquareRootGrid(dim)
     testFG(self, grid, level, function)  
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:8,代码来源:test_combi.py

示例13: testCreation

 def testCreation(self):
     """Uses Linear grid for tests"""
     from pysgpp import Grid
     
     factory = Grid.createLinearGrid(2)
     self.failIfEqual(factory, None)
     
     storage = factory.getStorage()
     self.failIfEqual(storage, None)
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:9,代码来源:test_GridFactory.py

示例14: setUp

 def setUp(self):
     self.grid = Grid.createLinearGrid(2)  # a simple 2D grid
     self.grid.createGridGenerator().regular(3)  # max level 3 => 17 points
     self.HashGridStorage = self.grid.getStorage()
     alpha = DataVector(self.grid.getSize())
     alpha.setAll(1.0)
     for i in [9, 10, 11, 12]:
         alpha[i] = 0.0
     coarseningFunctor = SurplusCoarseningFunctor(alpha, 4, 0.5)
     self.grid.createGridGenerator().coarsen(coarseningFunctor, alpha)
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:10,代码来源:test_HashRefinementInconsistent.py

示例15: testHatRegulardD_two

    def testHatRegulardD_two(self):
        from pysgpp import Grid
        
        factory = Grid.createLinearBoundaryGrid(3)

        m = generateLaplaceMatrix(factory, 4)
        m_ref = readReferenceMatrix(self, factory.getStorage(), 'data/C_laplace_phi_li_hut_l0_rand_dim_3_nopsgrid_297_float.dat.gz')

        # compare
        compareStiffnessMatrices(self, m, m_ref)    
开发者ID:samhelmholtz,项目名称:skinny-dip,代码行数:10,代码来源:test_laplace.py


注:本文中的pysgpp.Grid类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。