47 template <
class ScalarType>
50 return 1.0/(z*z + 1.0);
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");
87 CLP.
parse( argc, argv );
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();
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;
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...