This example can be found under combigrid/examples/bspline_pce.cpp
.
#include <cmath>
#include <iostream>
#include <vector>
return 4. * x[0] * (1. - x[0]);
}
size_t numDims = 2;
size_t q = 1;
size_t degree = 3;
numDims, func, degree);
op->getLevelManager()->addRegularLevels(q);
numDims, func, degree);
quad_op->getLevelManager()->addLevelsFromStructure(op->getLevelManager()->getLevelStructure());
double mean = quad_op->getResult();
auto tensor_op =
numDims, func, degree);
tensor_op->getLevelManager()->addLevelsFromStructure(op->getLevelManager()->getLevelStructure());
size_t numTerms = 0;
double variance = 0.0;
std::cout << " ----------------------------------" << std::endl;
for (
auto it = tensor_result.
getValues()->getStoredDataIterator(); it->isValid();
it->moveToNext()) {
double ocoeff = it->value().value();
variance += ocoeff * ocoeff;
numTerms += 1;
auto ix = it->getMultiIndex();
std::cout << numTerms << ": (" << ix[0] << ", " << ix[1] << ") -> " << ocoeff << std::endl;
}
std::cout << "---------------------------------------------------------" << std::endl;
std::cout << "#gp = " << tensor_op->getLevelManager()->numGridPoints() << std::endl;
std::cout << "#terms = " << numTerms << std::endl;
std::cout <<
"E(u) = " << model.
mean(numDims) <<
" ~ " << mean << std::endl;
std::cout <<
"Var(u) = " << model.
variance(numDims) <<
" ~ " << variance << std::endl;
std::cout << "---------------------------------------------------------" << std::endl;
}