27 double operator() (
const double& a,
const double& b)
const {
45 const unsigned int d = 2;
46 const unsigned int pmin = 1;
47 const unsigned int pmax = 15;
48 const unsigned int np = pmax-pmin+1;
49 bool use_pce_quad_points =
false;
50 bool normalize =
false;
51 bool project_integrals =
false;
53 bool sparse_grid =
true;
54 #ifndef HAVE_STOKHOS_DAKOTA
66 for (
unsigned int p=pmin; p<=pmax; p++) {
68 std::cout <<
"p = " << p << std::endl;
71 for (
unsigned int i=0; i<d; i++)
79 for (
unsigned int i=0; i<d; i++) {
83 double x_pt = x.evaluate(eval_pt);
88 #ifdef HAVE_STOKHOS_DAKOTA
91 Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(basis, p));
99 basis->computeTripleProductTensor();
115 if (project_integrals) {
122 st_bases[0] = stp_basis_u;
123 st_bases[1] = stp_basis_v;
132 st_bases[0] = st_basis_u;
133 st_bases[1] = st_basis_v;
140 normalize, project_integrals, Cijk));
144 normalize, project_integrals, Cijk));
155 if (project_integrals) {
156 u_st.term(0, 0) = stp_basis_u->getNewCoeffs(0);
157 u_st.term(0, 1) = stp_basis_u->getNewCoeffs(1);
158 v_st.term(0, 0) = stp_basis_v->getNewCoeffs(0);
159 v_st.term(1, 1) = stp_basis_v->getNewCoeffs(1);
162 u_st.term(0, 0) = st_basis_u->getNewCoeffs(0);
163 u_st.term(0, 1) = st_basis_u->getNewCoeffs(1);
164 v_st.term(0, 0) = st_basis_v->getNewCoeffs(0);
165 v_st.term(1, 1) = st_basis_v->getNewCoeffs(1);
169 u_st.term(0, 0) = u.mean();
170 u_st.term(0, 1) = 1.0;
171 v_st.term(0, 0) = v.mean();
172 v_st.term(1, 1) = 1.0;
177 st_basis->computeTripleProductTensor();
181 if (!use_pce_quad_points) {
182 #ifdef HAVE_STOKHOS_DAKOTA
184 st_quad =
Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(st_basis, p));
193 st_bases[0]->getQuadPoints(p+1, st_points_0, st_weights_0, st_values_0);
197 st_bases[1]->getQuadPoints(p+1, st_points_1, st_weights_1, st_values_1);
200 for (
int i=0; i<st_points_0.
size(); i++) {
201 (*st_points)[i].resize(2);
202 (*st_points)[i][0] = st_points_0[i];
203 (*st_points)[i][1] = st_points_1[i];
221 st_quad_exp.
divide(w_st, u_st, v_st);
232 mean_st[n] = w2.
mean();
233 std_dev[n] = w.standard_deviation();
235 pt[n] = w.evaluate(eval_pt);
242 std::cout <<
"Statistical error:" << std::endl;
244 << std::setw(wi) <<
"mean" <<
" "
245 << std::setw(wi) <<
"mean_st" <<
" "
246 << std::setw(wi) <<
"std_dev" <<
" "
247 << std::setw(wi) <<
"std_dev_st" <<
" "
248 << std::setw(wi) <<
"point" <<
" "
249 << std::setw(wi) <<
"point_st" << std::endl;
250 for (
unsigned int p=pmin; p<pmax; p++) {
251 std::cout.precision(3);
252 std::cout.setf(std::ios::scientific);
253 std::cout << p <<
" "
254 << std::setw(wi) <<
rel_err(mean[n], mean[np-1]) <<
" "
255 << std::setw(wi) <<
rel_err(mean_st[n], mean[np-1]) <<
" "
256 << std::setw(wi) <<
rel_err(std_dev[n], std_dev[np-1]) <<
" "
257 << std::setw(wi) <<
rel_err(std_dev_st[n], std_dev[np-1])
259 << std::setw(wi) <<
rel_err(pt[n], pt_true) <<
" "
260 << std::setw(wi) <<
rel_err(pt_st[n], pt_true)
266 catch (std::exception& e) {
267 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...