15 template <
class ScalarType>
18 return 1.0/(z*z + 1.0);
47 "This example computes the PC expansion of a simple function.\n");
49 CLP.
setOption(
"order", &p,
"Polynomial order");
51 CLP.
setOption(
"sparse",
"tensor", &sparse,
52 "Use sparse grid or tensor product quadrature");
55 CLP.
parse( argc, argv );
59 Array< RCP<const OneDOrthogPolyBasis<int,double> > > bases(d);
60 for (
int i=0; i<d; i++) {
61 bases[i] =
rcp(
new HermiteBasis<int,double>(p,
true));
63 RCP<const CompletePolynomialBasis<int,double> > basis =
64 rcp(
new CompletePolynomialBasis<int,double>(bases));
65 std::cout <<
"basis size = " << basis->size() << std::endl;
68 RCP<const Quadrature<int,double> > quad;
70 const TotalOrderIndexSet<int> index_set(d, p);
71 quad =
rcp(
new SmolyakSparseGridQuadrature<int,double>(basis, index_set));
74 quad =
rcp(
new TensorProductQuadrature<int,double>(basis));
76 std::cout <<
"quadrature size = " << quad->size() << std::endl;
79 RCP<Sparse3Tensor<int,double> > Cijk =
80 basis->computeTripleProductTensor();
83 RCP<QuadOrthogPolyExpansion<int,double> > expn =
84 rcp(
new QuadOrthogPolyExpansion<int,double>(basis, Cijk, quad));
98 std::cout <<
"\tu = ";
100 std::cout <<
"\tv = ";
104 double mean = v.mean();
105 double std_dev = v.standard_deviation();
109 for (
int i=0; i<d; i++)
111 double up = u.evaluate(pt);
113 double vp2 = v.evaluate(pt);
116 std::cout <<
"\tv mean = " << mean << std::endl;
117 std::cout <<
"\tv std. dev. = " << std_dev << std::endl;
118 std::cout <<
"\tv(0.25) (true) = " << vp << std::endl;
119 std::cout <<
"\tv(0.25) (pce) = " << vp2 << std::endl;
123 std::cout <<
"\nExample Passed!" << std::endl;
125 catch (std::exception& e) {
126 std::cout << e.what() << std::endl;
ScalarType simple_function(const ScalarType &u)
Stokhos::StandardStorage< int, double > storage_type
Hermite polynomial basis.
Sacado::ETPCE::OrthogPoly< double, Stokhos::StandardStorage< int, double > > pce_type
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
Defines quadrature for a tensor product basis by Smolyak sparse grids.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Abstract base class for quadrature methods.
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
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.
int main(int argc, char **argv)
An isotropic total order index set.
Abstract base class for 1-D orthogonal polynomials.
void setDocString(const char doc_string[])
Orthogonal polynomial expansions based on numerical quadrature.
KOKKOS_INLINE_FUNCTION PCE< Storage > log(const PCE< Storage > &a)
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...