61 double operator() (
const double& a,
const double& b)
const {
79 const unsigned int d = 2;
80 const unsigned int pmin = 1;
81 const unsigned int pmax = 15;
82 const unsigned int np = pmax-pmin+1;
83 bool use_pce_quad_points =
false;
84 bool normalize =
false;
85 bool project_integrals =
false;
87 bool sparse_grid =
true;
88 #ifndef HAVE_STOKHOS_DAKOTA
100 for (
unsigned int p=pmin; p<=pmax; p++) {
102 std::cout <<
"p = " << p << std::endl;
105 for (
unsigned int i=0; i<d; i++)
113 for (
unsigned int i=0; i<d; i++) {
117 double x_pt = x.evaluate(eval_pt);
122 #ifdef HAVE_STOKHOS_DAKOTA
125 Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(basis, p));
133 basis->computeTripleProductTensor();
149 if (project_integrals) {
156 st_bases[0] = stp_basis_u;
157 st_bases[1] = stp_basis_v;
166 st_bases[0] = st_basis_u;
167 st_bases[1] = st_basis_v;
174 normalize, project_integrals, Cijk));
178 normalize, project_integrals, Cijk));
189 if (project_integrals) {
190 u_st.term(0, 0) = stp_basis_u->getNewCoeffs(0);
191 u_st.term(0, 1) = stp_basis_u->getNewCoeffs(1);
192 v_st.term(0, 0) = stp_basis_v->getNewCoeffs(0);
193 v_st.term(1, 1) = stp_basis_v->getNewCoeffs(1);
196 u_st.term(0, 0) = st_basis_u->getNewCoeffs(0);
197 u_st.term(0, 1) = st_basis_u->getNewCoeffs(1);
198 v_st.term(0, 0) = st_basis_v->getNewCoeffs(0);
199 v_st.term(1, 1) = st_basis_v->getNewCoeffs(1);
203 u_st.term(0, 0) = u.mean();
204 u_st.term(0, 1) = 1.0;
205 v_st.term(0, 0) = v.mean();
206 v_st.term(1, 1) = 1.0;
211 st_basis->computeTripleProductTensor();
215 if (!use_pce_quad_points) {
216 #ifdef HAVE_STOKHOS_DAKOTA
218 st_quad =
Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(st_basis, p));
227 st_bases[0]->getQuadPoints(p+1, st_points_0, st_weights_0, st_values_0);
231 st_bases[1]->getQuadPoints(p+1, st_points_1, st_weights_1, st_values_1);
234 for (
int i=0; i<st_points_0.
size(); i++) {
235 (*st_points)[i].resize(2);
236 (*st_points)[i][0] = st_points_0[i];
237 (*st_points)[i][1] = st_points_1[i];
255 st_quad_exp.
divide(w_st, u_st, v_st);
266 mean_st[n] = w2.
mean();
267 std_dev[n] = w.standard_deviation();
269 pt[n] = w.evaluate(eval_pt);
276 std::cout <<
"Statistical error:" << std::endl;
278 << std::setw(wi) <<
"mean" <<
" "
279 << std::setw(wi) <<
"mean_st" <<
" "
280 << std::setw(wi) <<
"std_dev" <<
" "
281 << std::setw(wi) <<
"std_dev_st" <<
" "
282 << std::setw(wi) <<
"point" <<
" "
283 << std::setw(wi) <<
"point_st" << std::endl;
284 for (
unsigned int p=pmin; p<pmax; p++) {
285 std::cout.precision(3);
286 std::cout.setf(std::ios::scientific);
287 std::cout << p <<
" "
288 << std::setw(wi) <<
rel_err(mean[n], mean[np-1]) <<
" "
289 << std::setw(wi) <<
rel_err(mean_st[n], mean[np-1]) <<
" "
290 << std::setw(wi) <<
rel_err(std_dev[n], std_dev[np-1]) <<
" "
291 << std::setw(wi) <<
rel_err(std_dev_st[n], std_dev[np-1])
293 << std::setw(wi) <<
rel_err(pt[n], pt_true) <<
" "
294 << std::setw(wi) <<
rel_err(pt_st[n], pt_true)
300 catch (std::exception& e) {
301 std::cout << e.what() << std::endl;
void binary_op(const FuncT &func, 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)
Nonlinear binary function.
Generates three-term recurrence using the Lanczos procedure applied to a polynomial chaos expansion i...
void sin(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
value_type evaluate(const Teuchos::Array< value_type > &point) const
Evaluate polynomial approximation at a point.
void exp(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
pce_quad_func(const Stokhos::OrthogPolyApprox< int, double > &pce_, const Stokhos::OrthogPolyBasis< int, double > &basis_)
void plusEqual(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const value_type &x)
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
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.
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(const PCE< Storage > &a)
Legendre polynomial basis.
int main(int argc, char **argv)
double rel_err(double a, double b)
KOKKOS_INLINE_FUNCTION PCE< Storage > sin(const PCE< Storage > &a)
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...