48 template <
class ScalarType>
51 return 1.0/(z*z + 1.0);
61 const int EnsembleSize = 8;
85 "This example computes the PC expansion of a simple function.\n");
87 CLP.
setOption(
"order", &p,
"Polynomial order");
89 CLP.
setOption(
"sparse",
"tensor", &sparse,
90 "Use sparse grid or tensor product quadrature");
93 CLP.
parse( argc, argv );
97 Array< RCP<const OneDOrthogPolyBasis<int,double> > > bases(d);
98 for (
int i=0; i<d; i++) {
99 bases[i] =
rcp(
new HermiteBasis<int,double>(p,
true));
101 RCP<const CompletePolynomialBasis<int,double> > basis =
102 rcp(
new CompletePolynomialBasis<int,double>(bases));
103 const int pce_size = basis->size();
104 std::cout <<
"basis size = " << pce_size << std::endl;
107 RCP<const Quadrature<int,double> > quad;
109 const TotalOrderIndexSet<int> index_set(d, p);
110 quad =
rcp(
new SmolyakSparseGridQuadrature<int,double>(basis, index_set));
113 quad =
rcp(
new TensorProductQuadrature<int,double>(basis));
115 std::cout <<
"quadrature size = " << quad->size() << std::endl;
118 RCP<Sparse3Tensor<int,double> > Cijk =
119 basis->computeTripleProductTensor();
122 RCP<QuadOrthogPolyExpansion<int,double> > expn =
123 rcp(
new QuadOrthogPolyExpansion<int,double>(basis, Cijk, quad));
138 const int num_quad_points = quad->size();
139 const Array<double>& quad_weights = quad->getQuadWeights();
140 const Array< Array<double> >& quad_points = quad->getQuadPoints();
141 const Array< Array<double> >& quad_values = quad->getBasisAtQuadPoints();
145 ensemble_type u_ensemble;
146 for (
int qp_block=0; qp_block<num_quad_points; qp_block+=EnsembleSize) {
147 const int qp_sz = qp_block+EnsembleSize <= num_quad_points ?
148 EnsembleSize : num_quad_points-qp_block;
151 for (
int qp=0; qp<qp_sz; ++qp)
152 u_ensemble.fastAccessCoeff(qp) =
153 u.evaluate(quad_points[qp_block+qp], quad_values[qp_block+qp]);
154 for (
int qp=qp_sz; qp<EnsembleSize; ++qp)
155 u_ensemble.fastAccessCoeff(qp) = u_ensemble.fastAccessCoeff(qp_sz-1);
161 for (
int pc=0; pc<pce_size; ++pc)
162 for (
int qp=0; qp<qp_sz; ++qp)
163 v.fastAccessCoeff(pc) += v_ensemble.fastAccessCoeff(qp)*quad_weights[qp_block+qp]*quad_values[qp_block+qp][pc];
177 std::cout <<
"\tu = ";
179 std::cout <<
"\tv = ";
183 double mean = v.mean();
184 double std_dev = v.standard_deviation();
188 for (
int i=0; i<d; i++)
190 double up = u.evaluate(pt);
192 double vp2 = v.evaluate(pt);
195 std::cout <<
"\tv mean = " << mean << std::endl;
196 std::cout <<
"\tv std. dev. = " << std_dev << std::endl;
197 std::cout <<
"\tv(0.25) (true) = " << vp << std::endl;
198 std::cout <<
"\tv(0.25) (pce) = " << vp2 << std::endl;
202 std::cout <<
"\nExample Passed!" << std::endl;
204 catch (std::exception& e) {
205 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...