/** * If during the refinement one or more points of the shadow register are added * to the actual grid then we have to remove these points from the shadow storage. */ void PrewaveletGridGenerator::consolidateShadow() { GridStorage* temp = new GridStorage(storage->dim()); for (size_t i = 0; i < shadowstorage->size(); i++) { temp->insert(*shadowstorage->get(i)); } shadowstorage->emptyStorage(); for (size_t i = 0; i < temp->size(); i++) { if (storage->find(temp->get(i)) == storage->end()) { shadowstorage->insert(*temp->get(i)); } } delete temp; }
int main() { // create a two-dimensional piecewise bilinear grid size_t dim = 2; Grid* grid = Grid::createLinearGrid(dim); GridStorage* gridStorage = grid->getStorage(); std::cout << "dimensionality: " << gridStorage->dim() << std::endl; // create regular grid, level 3 size_t level = 3; GridGenerator* gridGen = grid->createGridGenerator(); gridGen->regular(level); std::cout << "number of initial grid points: " << gridStorage->size() << std::endl; // create coefficient vector DataVector alpha(gridStorage->size()); alpha.setAll(0.0); std::cout << "length of alpha vector: " << alpha.getSize() << std::endl; GridIndex* gp; // refine adaptively 5 times for (int step = 0; step < 5; step++) { // set function values in alpha for (size_t i = 0; i < gridStorage->size(); i++) { gp = gridStorage->get(i); alpha[i] = f(gp->getCoord(0), gp->getCoord(1)); } // hierarchize SGPP::op_factory::createOperationHierarchisation(*grid)->doHierarchisation( alpha); // refine a single grid point each time gridGen->refine(new SurplusRefinementFunctor(&alpha, 1)); std::cout << "refinement step " << step + 1 << ", new grid size: " << alpha.getSize() << std::endl; // extend alpha vector (new entries uninitialized) alpha.resize(gridStorage->size()); } delete grid; }
void testHierarchisationDehierarchisation(SGPP::base::Grid* grid, size_t level, SGPP::float_t (*func)(DataVector&), SGPP::float_t tolerance = 0.0, bool naiveOp = false, bool doStretch = false) { GridGenerator* gridGen = grid->createGridGenerator(); gridGen->regular(level); GridStorage* gridStore = grid->getStorage(); size_t dim = gridStore->dim(); Stretching* stretch = NULL; if (doStretch) stretch = gridStore->getStretching(); DataVector node_values = DataVector(gridStore->size()); DataVector coords = DataVector(dim); for (size_t n = 0; n < gridStore->size(); n++) { if (doStretch) { gridStore->get(n)->getCoordsStretching(coords, *stretch); } else { gridStore->get(n)->getCoords(coords); } node_values[n] = func(coords); } DataVector alpha = DataVector(node_values); OperationHierarchisation* hierarchisation = SGPP::op_factory::createOperationHierarchisation(*grid); hierarchisation->doHierarchisation(alpha); if (naiveOp == true) { OperationNaiveEval* op = SGPP::op_factory::createOperationNaiveEval(*grid); for (size_t n = 0; n < gridStore->size(); n++) { if (doStretch) { gridStore->get(n)->getCoordsStretching(coords, *stretch); } else { gridStore->get(n)->getCoords(coords); } SGPP::float_t eval = op->eval(alpha, coords); BOOST_CHECK_CLOSE(eval, node_values[n], tolerance); } } else { OperationEval* op = SGPP::op_factory::createOperationEval(*grid); for (size_t n = 0; n < gridStore->size(); n++) { if (doStretch) { gridStore->get(n)->getCoordsStretching(coords, *stretch); } else { gridStore->get(n)->getCoords(coords); } SGPP::float_t eval = op->eval(alpha, coords); BOOST_CHECK_CLOSE(eval, node_values[n], tolerance); } } DataVector node_values_back = DataVector(alpha); hierarchisation->doDehierarchisation(node_values_back); for (size_t n = 0; n < gridStore->size(); n++) { BOOST_CHECK_CLOSE(node_values_back[n], node_values[n], tolerance); } }