SG++
MR_Plotting.cpp

This example can be found under combigrid/examples/MR_Plotting.cpp.

// Copyright (C) 2008-today The SG++ project
// This file is part of the SG++ project. For conditions of distribution and
// use, please see the copyright notice provided with SG++ or at
// sgpp.sparsegrids.org
// include all combigrid headers
#include <cmath>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
// Plotting B-Spline basis functions
int main() {
size_t d = 1;
size_t degree = 5;
size_t level = 5;
// std::vector<double> GridPoints = { 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875};
// sgpp::combigrid::FloatScalarVector EvalPoint(0.5);
// EvalPoint[0].value() = 0.25;
// EvalPoint[1].value() = 0.5;
// EvalPoint[2].value() = 0.75;
// uniform grid
double gridwidth = 0.001;
for (size_t i = 0; i < 1 / gridwidth + 1; i++) {
EvalPoints[i] = static_cast<double>(i) * gridwidth;
}
std::string plotstr = "/home/rehmemk/SGS_Sync/Plotting/combigrid_bsplines/bsplines.dat";
remove(plotstr.c_str());
std::ofstream plotfile;
plotfile.open(plotstr.c_str(), std::ios::app);
plotfile << "#Basis functions \n";
// sgpp::combigrid::CombiEvaluators::MultiCollection evaluators(
// d, sgpp::combigrid::CombiEvaluators::multiLinearInterpolation());
for (size_t dim = 0; dim < d; ++dim) {
evalCopy[dim] = evaluators[dim]->cloneLinear();
bool needsSorted = true;
auto GridPoints = grids[dim]->getPoints(level, needsSorted);
for (size_t i = 0; i < GridPoints.size(); i++) {
std::cout << GridPoints[i] << " ";
}
std::cout << "\n";
evalCopy[dim]->setGridPoints(GridPoints);
evalCopy[dim]->setParameter(EvalPoints);
std::vector<FloatArrayVector> basisValues1D = evalCopy[dim]->getBasisValues();
for (size_t i = 0; i < EvalPoints.size(); i++) {
plotfile << EvalPoints[i].value() << ", ";
for (size_t j = 0; j < GridPoints.size() - 1; j++) {
plotfile << basisValues1D[j][i].value() << ", ";
}
plotfile << basisValues1D[GridPoints.size() - 1][i].value() << "\n";
}
}
plotfile.close();
}