43 #include "Teuchos_CommandLineProcessor.hpp" 47 template <
class ScalarType>
50 return 1.0/(z*z + 1.0);
77 Teuchos::CommandLineProcessor
CLP;
79 "This example computes the PC expansion of a simple function.\n");
81 CLP.setOption(
"order", &p,
"Polynomial order");
83 CLP.setOption(
"sparse",
"tensor", &sparse,
84 "Use sparse grid or tensor product quadrature");
91 Array< RCP<const OneDOrthogPolyBasis<int,double> > > bases(d);
92 for (
int i=0; i<d; i++) {
93 bases[i] = rcp(
new HermiteBasis<int,double>(p,
true));
95 RCP<const CompletePolynomialBasis<int,double> > basis =
96 rcp(
new CompletePolynomialBasis<int,double>(bases));
97 std::cout <<
"basis size = " << basis->size() << std::endl;
100 RCP<const Quadrature<int,double> > quad;
102 const TotalOrderIndexSet<int> index_set(d, p);
103 quad = rcp(
new SmolyakSparseGridQuadrature<int,double>(basis, index_set));
106 quad = rcp(
new TensorProductQuadrature<int,double>(basis));
108 std::cout <<
"quadrature size = " << quad->size() << std::endl;
111 RCP<Sparse3Tensor<int,double> > Cijk =
112 basis->computeTripleProductTensor();
115 RCP<QuadOrthogPolyExpansion<int,double> > expn =
116 rcp(
new QuadOrthogPolyExpansion<int,double>(basis, Cijk, quad));
130 std::cout <<
"\tu = ";
132 std::cout <<
"\tv = ";
136 double mean = v.mean();
137 double std_dev = v.standard_deviation();
140 Teuchos::Array<double> pt(d);
141 for (
int i=0; i<d; i++)
143 double up = u.evaluate(pt);
145 double vp2 = v.evaluate(pt);
148 std::cout <<
"\tv mean = " << mean << std::endl;
149 std::cout <<
"\tv std. dev. = " << std_dev << std::endl;
150 std::cout <<
"\tv(0.25) (true) = " << vp << std::endl;
151 std::cout <<
"\tv(0.25) (pce) = " << vp2 << std::endl;
155 std::cout <<
"\nExample Passed!" << std::endl;
157 catch (std::exception& e) {
158 std::cout << e.what() << std::endl;
Stokhos::StandardStorage< int, double > storage_type
Hermite polynomial basis.
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
Sacado::PCE::OrthogPoly< double, Storage > pce_type
Defines quadrature for a tensor product basis by Smolyak sparse grids.
Abstract base class for quadrature methods.
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
Legendre polynomial basis.
An isotropic total order index set.
Abstract base class for 1-D orthogonal polynomials.
int main(int argc, char **argv)
Orthogonal polynomial expansions based on numerical quadrature.
KOKKOS_INLINE_FUNCTION PCE< Storage > log(const PCE< Storage > &a)
ScalarType simple_function(const ScalarType &u)
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...