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


Python Grid.createPolyGrid方法代码示例

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


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

示例1: createGrid

# 需要导入模块: from pysgpp import Grid [as 别名]
# 或者: from pysgpp.Grid import createPolyGrid [as 别名]
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,代码行数:28,代码来源:sparse_grid.py

示例2: discretizeProduct

# 需要导入模块: from pysgpp import Grid [as 别名]
# 或者: from pysgpp.Grid import createPolyGrid [as 别名]
def discretizeProduct(grid1, alpha1, grid2, alpha2):
    """
    Discretizes the product of two sparse grid functions:

        h(x) := f(x) * g(x)

    on a full grid with piecewise polynomial basis. Therefore
    a maximum number of grid points 10^6 is allowed.

    @param grid1: Grid, grid of f
    @param alpha1: DataVector, hierarchical coefficients of f
    @param grid2: Grid, grid of g
    @param alpha2: DataVector, hierarchical coefficients of g
    """
    # make sure that the grids are either piece wise linear
    # or piecewise polynomial
    if grid1.getType() not in [Linear, Poly]:
        raise AttributeError("grid type '%s' not supported" % grid1.getType())
    if grid2.getType() not in [Linear, Poly]:
        raise AttributeError("grid type '%s' not supported" % grid2.getType())

    # get the degrees of the grid
    maxlevelGrid1 = grid1.getStorage().getMaxLevel()
    maxlevelGrid2 = grid2.getStorage().getMaxLevel()
    deg1 = min(getDegree(grid1), maxlevelGrid1 + 1)
    deg2 = min(getDegree(grid2), maxlevelGrid2 + 1)
    deg = deg1 + deg2
    maxlevel = max(maxlevelGrid1 + deg2, maxlevelGrid2 + deg1)

    # check if maximum number of grid points is goint to be exceeded
    n = 2 ** ((deg - 1) * grid1.getStorage().dim())
    if n > 1e6:
        raise AttributeError("Can not create a full grid of level %i and dimensionality %i. The number of grid points %i would exceed 10^6" % (deg - 1, grid1.getStorage().dim(), n))

    # join the two grids
    joinedGrid = Grid.createPolyGrid(2, deg)
    joinedGrid.createGridGenerator().full(maxlevel)
    # interpolate the product on the new grid
    joinedAlpha = interpolateProduct(grid1, alpha1, grid2, alpha2, joinedGrid)

    return joinedGrid, joinedAlpha
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:43,代码来源:discretizeProduct.py


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