26 double operator() (
const double& a,
const double& b)
const {
62 const unsigned int d = 2;
63 const unsigned int pmin = 1;
64 const unsigned int pmax = 10;
65 const unsigned int np = pmax-pmin+1;
66 bool use_pce_quad_points =
false;
67 bool normalize =
false;
68 bool sparse_grid =
true;
69 #ifndef HAVE_STOKHOS_DAKOTA
81 for (
unsigned int p=pmin; p<=pmax; p++) {
83 std::cout <<
"p = " << p << std::endl;
86 for (
unsigned int i=0; i<d; i++)
94 for (
unsigned int i=0; i<d; i++) {
98 double x_pt = x.evaluate(eval_pt);
103 #ifdef HAVE_STOKHOS_DAKOTA
106 Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(basis, p));
114 basis->computeTripleProductTensor();
131 p, sf, quad, use_pce_quad_points, normalize));
134 p, ef, quad, use_pce_quad_points, normalize));
142 u_st.term(0, 0) = u.mean();
143 u_st.term(0, 1) = 1.0;
144 v_st.term(0, 0) = v.mean();
145 v_st.term(1, 1) = 1.0;
149 st_basis->computeTripleProductTensor();
153 if (!use_pce_quad_points) {
154 #ifdef HAVE_STOKHOS_DAKOTA
156 st_quad =
Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(st_basis, p));
165 st_bases[0]->getQuadPoints(p+1, st_points_0, st_weights_0, st_values_0);
169 st_bases[1]->getQuadPoints(p+1, st_points_1, st_weights_1, st_values_1);
172 for (
int i=0; i<st_points_0.
size(); i++) {
173 (*st_points)[i].resize(2);
174 (*st_points)[i][0] = st_points_0[i];
175 (*st_points)[i][1] = st_points_1[i];
193 st_quad_exp.
divide(w_st, u_st, v_st);
204 mean_st[n] = w2.
mean();
205 std_dev[n] = w.standard_deviation();
207 pt[n] = w.evaluate(eval_pt);
214 std::cout <<
"Statistical error:" << std::endl;
216 << std::setw(wi) <<
"mean" <<
" "
217 << std::setw(wi) <<
"mean_st" <<
" "
218 << std::setw(wi) <<
"std_dev" <<
" "
219 << std::setw(wi) <<
"std_dev_st" <<
" "
220 << std::setw(wi) <<
"point" <<
" "
221 << std::setw(wi) <<
"point_st" << std::endl;
222 for (
unsigned int p=pmin; p<pmax; p++) {
223 std::cout.precision(3);
224 std::cout.setf(std::ios::scientific);
225 std::cout << p <<
" "
226 << std::setw(wi) <<
rel_err(mean[n], mean[np-1]) <<
" "
227 << std::setw(wi) <<
rel_err(mean_st[n], mean[np-1]) <<
" "
228 << std::setw(wi) <<
rel_err(std_dev[n], std_dev[np-1]) <<
" "
229 << std::setw(wi) <<
rel_err(std_dev_st[n], std_dev[np-1])
231 << std::setw(wi) <<
rel_err(pt[n], pt_true) <<
" "
232 << std::setw(wi) <<
rel_err(pt_st[n], pt_true)
238 catch (std::exception& e) {
239 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.
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)
const Stokhos::OrthogPolyApprox< int, double > & pce
const Stokhos::OrthogPolyApprox< int, double > & pce
sin_func(const Stokhos::OrthogPolyApprox< int, double > &pce_)
pce_quad_func(const Stokhos::OrthogPolyApprox< int, double > &pce_, const Stokhos::OrthogPolyBasis< int, double > &basis_)
double operator()(const Teuchos::Array< double > &x) const
void plusEqual(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const value_type &x)
Teuchos::Array< double > vec
Stokhos::LegendreBasis< int, double > basis_type
exp_func(const Stokhos::OrthogPolyApprox< int, double > &pce_)
Generates three-term recurrence using the Discretized Stieltjes procedure applied to a functional map...
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)
value_type standard_deviation() const
Compute standard deviation of expansion.
double operator()(const Teuchos::Array< double > &x) const
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)
int main(int argc, char **argv)
Legendre polynomial basis using Clenshaw-Curtis quadrature points.
double rel_err(double a, double b)
KOKKOS_INLINE_FUNCTION PCE< Storage > sin(const PCE< Storage > &a)
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...