23 static const int N = Num;
30 for (
int i=0; i<Num; i++)
32 return 1.0 / (prod -
a);
62 const int np = pmax-pmin+1;
64 bool use_pce_quad_points =
false;
65 bool normalize =
false;
66 bool project_integrals =
false;
68 bool sparse_grid =
true;
69 #ifndef HAVE_STOKHOS_DAKOTA
82 for (
int p=pmin; p<=pmax; p++) {
84 std::cout <<
"p = " << p << std::endl;
87 for (
int i=0; i<d; i++)
95 for (
int i=0; i<d; i++) {
97 xi[i]->term(i, 1) = 1.0;
102 #ifdef HAVE_STOKHOS_DAKOTA
105 Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(basis, p));
113 basis->computeTripleProductTensor();
122 for (
int i=0; i<d; i++)
124 quad_exp.
nary_op(s_func,s,xip);
125 quad_exp.
divide(t1,1.0,s);
130 for (
int i=0; i<d; i++)
131 xx[i] = xi[i]->evaluate(eval_pt);
132 pt_true = s_func(&(xx[0]));
133 pt_true = 1.0/pt_true;
140 if (project_integrals) {
144 st_bases[0] = stp_basis_s;
150 st_bases[0] = st_basis_s;
157 normalize, project_integrals, Cijk));
167 if (project_integrals) {
168 s_st.term(0, 0) = stp_basis_s->getNewCoeffs(0);
169 s_st.term(0, 1) = stp_basis_s->getNewCoeffs(1);
172 s_st.term(0, 0) = st_basis_s->getNewCoeffs(0);
173 s_st.term(0, 1) = st_basis_s->getNewCoeffs(1);
177 s_st.term(0, 0) = s.mean();
178 s_st.term(0, 1) = 1.0;
183 st_basis->computeTripleProductTensor();
187 #ifdef HAVE_STOKHOS_DAKOTA
189 st_quad =
Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(st_basis, p));
200 st_quad_exp.
divide(t_st, 1.0, s_st);
211 mean_st[n] = t2.
mean();
212 std_dev[n] = t1.standard_deviation();
214 pt[n] = t1.evaluate(eval_pt);
218 for (
int i=0; i<d; i++)
224 std::cout <<
"Statistical error:" << std::endl;
226 << std::setw(wi) <<
"mean" <<
" "
227 << std::setw(wi) <<
"mean_st" <<
" "
228 << std::setw(wi) <<
"std_dev" <<
" "
229 << std::setw(wi) <<
"std_dev_st" <<
" "
230 << std::setw(wi) <<
"point" <<
" "
231 << std::setw(wi) <<
"point_st" << std::endl;
232 for (
int p=pmin; p<pmax; p++) {
233 std::cout.precision(3);
234 std::cout.setf(std::ios::scientific);
235 std::cout << p <<
" "
236 << std::setw(wi) <<
rel_err(mean[n], mean[np-1]) <<
" "
237 << std::setw(wi) <<
rel_err(mean_st[n], mean[np-1]) <<
" "
238 << std::setw(wi) <<
rel_err(std_dev[n], std_dev[np-1]) <<
" "
239 << std::setw(wi) <<
rel_err(std_dev_st[n], std_dev[np-1])
241 << std::setw(wi) <<
rel_err(pt[n], pt_true) <<
" "
242 << std::setw(wi) <<
rel_err(pt_st[n], pt_true)
248 catch (std::exception& e) {
249 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.