57 static const int N = Num;
64 for (
int i=0; i<Num; i++)
66 return 1.0 / (prod -
a);
96 const int np = pmax-pmin+1;
98 bool use_pce_quad_points =
false;
99 bool normalize =
false;
100 bool project_integrals =
false;
102 bool sparse_grid =
true;
103 #ifndef HAVE_STOKHOS_DAKOTA
116 for (
int p=pmin; p<=pmax; p++) {
118 std::cout <<
"p = " << p << std::endl;
121 for (
int i=0; i<d; i++)
129 for (
int i=0; i<d; i++) {
131 xi[i]->term(i, 1) = 1.0;
136 #ifdef HAVE_STOKHOS_DAKOTA
139 Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(basis, p));
147 basis->computeTripleProductTensor();
156 for (
int i=0; i<d; i++)
158 quad_exp.
nary_op(s_func,s,xip);
159 quad_exp.
divide(t1,1.0,s);
164 for (
int i=0; i<d; i++)
165 xx[i] = xi[i]->evaluate(eval_pt);
166 pt_true = s_func(&(xx[0]));
167 pt_true = 1.0/pt_true;
174 if (project_integrals) {
178 st_bases[0] = stp_basis_s;
184 st_bases[0] = st_basis_s;
191 normalize, project_integrals, Cijk));
201 if (project_integrals) {
202 s_st.term(0, 0) = stp_basis_s->getNewCoeffs(0);
203 s_st.term(0, 1) = stp_basis_s->getNewCoeffs(1);
206 s_st.term(0, 0) = st_basis_s->getNewCoeffs(0);
207 s_st.term(0, 1) = st_basis_s->getNewCoeffs(1);
211 s_st.term(0, 0) = s.mean();
212 s_st.term(0, 1) = 1.0;
217 st_basis->computeTripleProductTensor();
221 #ifdef HAVE_STOKHOS_DAKOTA
223 st_quad =
Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(st_basis, p));
234 st_quad_exp.
divide(t_st, 1.0, s_st);
245 mean_st[n] = t2.
mean();
246 std_dev[n] = t1.standard_deviation();
248 pt[n] = t1.evaluate(eval_pt);
252 for (
int i=0; i<d; i++)
258 std::cout <<
"Statistical error:" << std::endl;
260 << std::setw(wi) <<
"mean" <<
" "
261 << std::setw(wi) <<
"mean_st" <<
" "
262 << std::setw(wi) <<
"std_dev" <<
" "
263 << std::setw(wi) <<
"std_dev_st" <<
" "
264 << std::setw(wi) <<
"point" <<
" "
265 << std::setw(wi) <<
"point_st" << std::endl;
266 for (
int p=pmin; p<pmax; p++) {
267 std::cout.precision(3);
268 std::cout.setf(std::ios::scientific);
269 std::cout << p <<
" "
270 << std::setw(wi) <<
rel_err(mean[n], mean[np-1]) <<
" "
271 << std::setw(wi) <<
rel_err(mean_st[n], mean[np-1]) <<
" "
272 << std::setw(wi) <<
rel_err(std_dev[n], std_dev[np-1]) <<
" "
273 << std::setw(wi) <<
rel_err(std_dev_st[n], std_dev[np-1])
275 << std::setw(wi) <<
rel_err(pt[n], pt_true) <<
" "
276 << std::setw(wi) <<
rel_err(pt_st[n], pt_true)
282 catch (std::exception& e) {
283 std::cout << e.what() << std::endl;
Generates three-term recurrence using the Lanczos procedure applied to a polynomial chaos expansion i...
value_type evaluate(const Teuchos::Array< value_type > &point) const
Evaluate polynomial approximation at a point.
pce_quad_func(const Stokhos::OrthogPolyApprox< int, double > &pce_, const Stokhos::OrthogPolyBasis< int, double > &basis_)
double operator()(double x[Num]) const
Teuchos::Array< double > vec
Stokhos::LegendreBasis< int, double > basis_type
void divide(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a, const OrthogPolyApprox< ordinal_type, value_type, node_type > &b)
Generates three-term recurrence using the Discretized Stieltjes procedure applied to a polynomial cha...
value_type standard_deviation() const
Compute standard deviation of expansion.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
const Stokhos::OrthogPolyBasis< int, double > & basis
void nary_op(const FuncT &func, OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > **a)
double operator()(const double &a, const double &b) const
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
const Stokhos::OrthogPolyApprox< int, double > & pce
value_type mean() const
Compute mean of expansion.
Legendre polynomial basis.
int main(int argc, char **argv)
double rel_err(double a, double b)
Generates three-term recurrence using the Lanczos procedure applied to a polynomial chaos expansion i...
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...
void unary_op(const FuncT &func, OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
Nonlinear unary function.