def createGrid(grid, dim, deg=1, addTruncatedBorder=False): # create new grid gridType = grid.getType() deg = max(deg, grid.getDegree()) # print( gridType, deg ) if deg > 1 and gridType in [GridType_Linear]: return Grid.createPolyGrid(dim, deg) if deg > 1 and gridType in [ GridType_LinearBoundary, GridType_LinearL0Boundary ]: return Grid.createPolyBoundaryGrid(dim, deg) elif deg > 1 and gridType in [GridType_LinearClenshawCurtis]: return Grid.createPolyClenshawCurtisGrid(dim, deg) elif deg > 1 and gridType in [GridType_LinearClenshawCurtisBoundary]: return Grid.createPolyClenshawCurtisBoundaryGrid(dim, deg) elif deg > 1 and gridType in [GridType_ModLinear]: return Grid.createModPolyGrid(dim, deg) elif deg > 1 and gridType in [GridType_ModLinearClenshawCurtis]: return Grid.createModPolyClenshawCurtisGrid(dim, deg) else: gridConfig = RegularGridConfiguration() gridConfig.type_ = gridType gridConfig.dim_ = dim gridConfig.maxDegree_ = deg return Grid.createGrid(gridConfig)
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
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()) # -------------------------------------------------------------------------- # alpha = hierarchizeEvalHierToTop(grid, nodalValues) # -------------------------------------------------------------------------- alpha_vec = DataVector(nodalValues) createOperationHierarchisation(grid).doHierarchisation(alpha_vec) grids.append((grid, alpha_vec))