16 template <
class ScalarType>
19 return 1.0/(z*z + 1.0);
29 const int EnsembleSize = 8;
53 "This example computes the PC expansion of a simple function.\n");
55 CLP.
setOption(
"order", &p,
"Polynomial order");
57 CLP.
setOption(
"sparse",
"tensor", &sparse,
58 "Use sparse grid or tensor product quadrature");
61 CLP.
parse( argc, argv );
65 Array< RCP<const OneDOrthogPolyBasis<int,double> > > bases(d);
66 for (
int i=0; i<d; i++) {
67 bases[i] =
rcp(
new HermiteBasis<int,double>(p,
true));
69 RCP<const CompletePolynomialBasis<int,double> > basis =
70 rcp(
new CompletePolynomialBasis<int,double>(bases));
71 const int pce_size = basis->size();
72 std::cout <<
"basis size = " << pce_size << std::endl;
75 RCP<const Quadrature<int,double> > quad;
77 const TotalOrderIndexSet<int> index_set(d, p);
78 quad =
rcp(
new SmolyakSparseGridQuadrature<int,double>(basis, index_set));
81 quad =
rcp(
new TensorProductQuadrature<int,double>(basis));
83 std::cout <<
"quadrature size = " << quad->size() << std::endl;
86 RCP<Sparse3Tensor<int,double> > Cijk =
87 basis->computeTripleProductTensor();
90 RCP<QuadOrthogPolyExpansion<int,double> > expn =
91 rcp(
new QuadOrthogPolyExpansion<int,double>(basis, Cijk, quad));
106 const int num_quad_points = quad->size();
107 const Array<double>& quad_weights = quad->getQuadWeights();
108 const Array< Array<double> >& quad_points = quad->getQuadPoints();
109 const Array< Array<double> >& quad_values = quad->getBasisAtQuadPoints();
113 ensemble_type u_ensemble;
114 for (
int qp_block=0; qp_block<num_quad_points; qp_block+=EnsembleSize) {
115 const int qp_sz = qp_block+EnsembleSize <= num_quad_points ?
116 EnsembleSize : num_quad_points-qp_block;
119 for (
int qp=0; qp<qp_sz; ++qp)
120 u_ensemble.fastAccessCoeff(qp) =
121 u.evaluate(quad_points[qp_block+qp], quad_values[qp_block+qp]);
122 for (
int qp=qp_sz; qp<EnsembleSize; ++qp)
123 u_ensemble.fastAccessCoeff(qp) = u_ensemble.fastAccessCoeff(qp_sz-1);
129 for (
int pc=0; pc<pce_size; ++pc)
130 for (
int qp=0; qp<qp_sz; ++qp)
131 v.fastAccessCoeff(pc) += v_ensemble.fastAccessCoeff(qp)*quad_weights[qp_block+qp]*quad_values[qp_block+qp][pc];
145 std::cout <<
"\tu = ";
147 std::cout <<
"\tv = ";
151 double mean = v.mean();
152 double std_dev = v.standard_deviation();
156 for (
int i=0; i<d; i++)
158 double up = u.evaluate(pt);
160 double vp2 = v.evaluate(pt);
163 std::cout <<
"\tv mean = " << mean << std::endl;
164 std::cout <<
"\tv std. dev. = " << std_dev << std::endl;
165 std::cout <<
"\tv(0.25) (true) = " << vp << std::endl;
166 std::cout <<
"\tv(0.25) (pce) = " << vp2 << std::endl;
170 std::cout <<
"\nExample Passed!" << std::endl;
172 catch (std::exception& e) {
173 std::cout << e.what() << std::endl;
ScalarType simple_function(const ScalarType &u)
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.
Statically allocated storage class.
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...