コード例 #1
0
    def addFullGridPoints(self, grid, alpha):
        """
        Add all those full grid points with |accLevel|_1 <= n, where n is the
        maximun level of the sparse grid
        @param grid: Grid sparse grid to be discretized
        @param alpha: numpy array hierarchical coefficients
        """

        # make grid isotropic by adding all missing hierarchical ancestors
        newGridPoints = []
        # 1. locate candidates to be refined
        candidates = self.findCandidates(grid, alpha)
        # 2. do full grid search locally
        gridPoinsToBeAdded = self.lookupFullGridPoints(grid, alpha, candidates)
        # 3. insert them in a new grid
        for gp in gridPoinsToBeAdded:
            newGridPoints += insertPoint(grid, gp)
            newGridPoints += insertHierarchicalAncestors(grid, gp)
            if grid.getType() in [
                    GridType_LinearBoundary, GridType_PolyBoundary
            ]:
                newGridPoints += insertTruncatedBorder(grid, gp)

        # recompute the leaf property and return the result
        grid.getStorage().recalcLeafProperty()
        return newGridPoints
コード例 #2
0
    def addFullGridPoints(self, grid, alpha):
        """
        Add all those full grid points with |accLevel|_1 <= n, where n is the
        maximun level of the sparse grid
        @param grid: Grid sparse grid to be discretized
        @param alpha: DataVector hierarchical coefficients
        """

        # make grid isotropic by adding all missing hierarchical ancestors
        newGridPoints = []
        # 1. locate candidates to be refined
        candidates = self.findCandidates(grid, alpha)
        # 2. do full grid search locally
        gridPoinsToBeAdded = self.lookupFullGridPoints(grid, alpha, candidates)
        # 3. insert them in a new grid
        for gp in gridPoinsToBeAdded:
            newGridPoints += insertPoint(grid, gp)
            newGridPoints += insertHierarchicalAncestors(grid, gp)
            if grid.getType() in [LinearBoundary, PolyBoundary]:
                newGridPoints += insertTruncatedBorder(grid, gp)

        # recompute the leaf property and return the result
        grid.getStorage().recalcLeafProperty()
        return newGridPoints
コード例 #3
0
    def createGrid(self):
        """
        Creates the specified grid
        """
        grid = None
        if self.__file is not None and os.path.exists(self.__file):
            gridFormatter = GridFormatter()
            grid = gridFormatter.deserializeFromFile(self.__file)
        else:
            if self.__grid is not None:
                self.__dim = self.__grid.getStorage().dim()

            if (self.__dim is None
                    or self.level is None) and self.__grid is None:
                raise AttributeError("Not all attributes assigned to create\
                                     grid")
            if self.__border is not None:
                if self.__border == BorderTypes.TRAPEZOIDBOUNDARY:
                    if self.__deg > 1:
                        grid = Grid.createPolyBoundaryGrid(
                            self.__dim, self.__deg)
                    else:
                        grid = Grid.createLinearBoundaryGrid(self.__dim)
                elif self.__border == BorderTypes.COMPLETEBOUNDARY:
                    if self.__deg > 1:
                        raise NotImplementedError()
                    else:
                        grid = Grid.createLinearBoundaryGrid(self.__dim, 0)
                else:
                    if self.__deg > 1:
                        grid = Grid.createModPolyGrid(self.__dim, self.__deg)
                    else:
                        grid = Grid.createModLinearGrid(self.__dim)
            else:
                # no border points
                if self.__deg > 1:
                    grid = Grid.createPolyGrid(self.__dim, self.__deg)
                else:
                    grid = Grid.createLinearGrid(self.__dim)

            # generate the grid
            if self.level is not None:
                generator = grid.createGridGenerator()
                if not self.__full:
                    generator.regular(self.level)
                else:
                    generator.full(self.level)

            # if there is a grid specified, add all the missing points
            if self.__grid is not None:
                gs = grid.getStorage()
                copygs = self.__grid.getStorage()

                # insert grid points
                for i in xrange(copygs.size()):
                    gp = copygs.get(i)
                    # insert grid point
                    if not gs.has_key(gp):
                        gs.insert(HashGridIndex(gp))
                    if self.__border == BorderTypes.TRAPEZOIDBOUNDARY:
                        insertTruncatedBorder(grid, gp)
                gs.recalcLeafProperty()

        return grid
コード例 #4
0
    def createGrid(self):
        """
        Creates the specified grid
        """
        grid = None
        if self.__file is not None and os.path.exists(self.__file):
            gridFormatter = GridFormatter()
            grid = gridFormatter.deserializeFromFile(self.__file)
        else:
            gridConfig = RegularGridConfiguration()
            gridConfig.dim_ = self.__dim

            if (self.__dim is None or self.level is None) and self.__grid is None:
                raise AttributeError("Not all attributes assigned to create\
                                     grid")
            if self.__boundaryLevel is not None:
                gridConfig.boundaryLevel_ = self.__boundaryLevel

            gridConfig.maxDegree_ = self.__deg

            if self.__gridType not in [GridType_Linear,
                                       GridType_LinearBoundary,
                                       GridType_ModLinear,
                                       GridType_LinearClenshawCurtis,
                                       GridType_LinearClenshawCurtisBoundary,
                                       GridType_ModLinearClenshawCurtis,
                                       GridType_Poly,
                                       GridType_PolyBoundary,
                                       GridType_ModPoly,
                                       GridType_PolyClenshawCurtis,
                                       GridType_PolyClenshawCurtisBoundary,
                                       GridType_ModPolyClenshawCurtis,
                                       GridType_Bspline,
                                       GridType_ModBspline,
                                       GridType_BsplineBoundary,
                                       GridType_BsplineClenshawCurtis,
                                       GridType_ModBsplineClenshawCurtis]:
                print( "Warning: grid type not fully supported" )

            gridConfig.type_ = self.__gridType

            # generate the grid
            grid = Grid.createGrid(gridConfig)

            if self.level is not None:
                generator = grid.getGenerator()
                if not self.__full:
                    generator.regular(self.level)
                else:
                    generator.full(self.level)

            # if there is a grid specified, add all the missing points
            if self.__grid is not None:
                gs = grid.getStorage()
                copygs = self.__grid.getStorage()

                # insert grid points
                for i in range(copygs.getSize()):
                    gp = copygs.getPoint(i)
                    # insert grid point
                    if not gs.isContaining(gp):
                        gs.insert(HashGridPoint(gp))
                    if self.__boundaryLevel == 1:
                        insertTruncatedBorder(grid, gp)
                gs.recalcLeafProperty()

        return grid