61 template <
class ScalarType>
64 return 1.0/(z*z + 1.0);
74 const int EnsembleSize = 8;
95 Array< RCP<const OneDOrthogPolyBasis<int,double> > > bases(d);
96 for (
int i=0; i<d; i++) {
97 bases[i] =
rcp(
new HermiteBasis<int,double>(p));
99 RCP<const CompletePolynomialBasis<int,double> > basis =
100 rcp(
new CompletePolynomialBasis<int,double>(bases));
103 RCP<const Quadrature<int,double> > quad =
104 rcp(
new TensorProductQuadrature<int,double>(basis));
107 RCP<Sparse3Tensor<int,double> > Cijk =
108 basis->computeTripleProductTensor();
111 RCP<QuadOrthogPolyExpansion<int,double> > expn =
112 rcp(
new QuadOrthogPolyExpansion<int,double>(basis, Cijk, quad));
126 const int pce_size = basis->size();
127 const int num_quad_points = quad->size();
128 const Array<double>& quad_weights = quad->getQuadWeights();
129 const Array< Array<double> >& quad_points = quad->getQuadPoints();
130 const Array< Array<double> >& quad_values = quad->getBasisAtQuadPoints();
134 ensemble_type u_ensemble;
135 for (
int qp_block=0; qp_block<num_quad_points; qp_block+=EnsembleSize) {
136 const int qp_sz = qp_block+EnsembleSize <= num_quad_points ?
137 EnsembleSize : num_quad_points-qp_block;
140 for (
int qp=0; qp<qp_sz; ++qp)
141 u_ensemble.fastAccessCoeff(qp) =
142 u.evaluate(quad_points[qp_block+qp], quad_values[qp_block+qp]);
143 for (
int qp=qp_sz; qp<EnsembleSize; ++qp)
144 u_ensemble.fastAccessCoeff(qp) = u_ensemble.fastAccessCoeff(qp_sz-1);
150 for (
int pc=0; pc<pce_size; ++pc) {
151 const double inv_nrm_sq = 1.0 / basis->norm_squared(pc);
152 for (
int qp=0; qp<qp_sz; ++qp) {
153 const double w = quad_weights[qp_block+qp];
154 const double psi = quad_values[qp_block+qp][pc];
155 v.fastAccessCoeff(pc) +=
156 inv_nrm_sq * w * v_ensemble.fastAccessCoeff(qp) * psi;
162 std::cout <<
"\tu = ";
164 std::cout <<
"\tv = ";
168 double mean = v.mean();
169 double std_dev = v.standard_deviation();
173 for (
int i=0; i<d; i++)
175 double up = u.evaluate(pt);
177 double vp2 = v.evaluate(pt);
180 std::cout <<
"\tv mean = " << mean << std::endl;
181 std::cout <<
"\tv std. dev. = " << std_dev << std::endl;
182 std::cout <<
"\tv(0.25) (true) = " << vp << std::endl;
183 std::cout <<
"\tv(0.25) (pce) = " << vp2 << std::endl;
185 catch (std::exception& e) {
186 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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Abstract base class for quadrature methods.
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
int main(int argc, char **argv)
Abstract base class for 1-D orthogonal polynomials.
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...