Ejemplo n.º 1
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
Ejemplo n.º 2
0
bs = [1, 2, 5, 10, 20, 50, 100, 500]


def g(x, a):
    return (np.abs(4 * x - 2) + a) / (a + 1)


def f(xs, **kws):
    return np.prod([g(x, b) for x, b in zip(xs, bs)])


gridConfig = RegularGridConfiguration()
gridConfig.type_ = GridType_Poly
gridConfig.maxDegree_ = 2
gridConfig.boundaryLevel_ = 0
gridConfig.dim_ = len(bs)

grids = []
for i in range(10):
    # compute a few hundred interpolations
    grid = Grid.createGrid(gridConfig)
    gridStorage = grid.getStorage()
    grid.getGenerator().regular(3)
    nodalValues = np.ndarray(gridStorage.getSize())

    p = DataVector(gridStorage.getDimension())
    for i in range(gridStorage.getSize()):
        gp = gridStorage.getCoordinates(gridStorage.getPoint(i), p)
        nodalValues[i] = f(p.array())