44#include "Teuchos_UnitTestHarness.hpp"
45#include "Teuchos_TestingHelpers.hpp"
46#include "Teuchos_UnitTestRepository.hpp"
47#include "Teuchos_GlobalMPISession.hpp"
66 mutable Teuchos::Array<double>
vec;
71template <
typename Func>
78 Teuchos::RCP<const Stokhos::CompletePolynomialBasis<OrdinalType,ValueType> >
basis;
79 Teuchos::RCP< Stokhos::QuadOrthogPolyExpansion<OrdinalType,ValueType> >
exp;
80 Teuchos::RCP<const Stokhos::MonoProjPCEBasis<OrdinalType,ValueType> >
st_1d_proj_basis;
81 Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<OrdinalType,ValueType> > >
st_bases;
82 Teuchos::RCP<const Stokhos::CompletePolynomialBasis<OrdinalType,ValueType> >
st_basis;
83 Teuchos::RCP<const Stokhos::Quadrature<OrdinalType,ValueType> >
st_quad;
95 Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<OrdinalType,ValueType> > > bases(d);
109 Teuchos::RCP<const Stokhos::Quadrature<OrdinalType,ValueType> > quad =
113 Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > Cijk =
114 basis->computeTripleProductTensor(
basis->size());
129 p,
u, *quad, *Cijk));
145 Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > st_Cijk =
158#define LANCZOS_UNIT_TESTS(BASENAME, TAG, FUNC, NORMALIZE) \
159namespace BASENAME ## TAG { \
161 Lanczos_PCE_Setup< FUNC<int,double> > setup(NORMALIZE); \
163 TEUCHOS_UNIT_TEST( BASENAME, TAG ## Map ) { \
164 Stokhos::OrthogPolyApprox<int,double> u2(setup.basis); \
165 setup.st_1d_proj_basis->transformCoeffs( \
166 setup.u_st.coeff(), \
168 success = Stokhos::comparePCEs(setup.u, "u", u2, "u2", \
169 setup.rtol, setup.atol, out); \
172 TEUCHOS_UNIT_TEST( BASENAME, TAG ## Orthog ) { \
173 const Teuchos::Array<double>& norms = \
174 setup.st_bases[0]->norm_squared(); \
175 const Teuchos::Array<double>& weights = \
176 setup.st_quad->getQuadWeights(); \
177 const Teuchos::Array< Teuchos::Array<double> >& values = \
178 setup.st_quad->getBasisAtQuadPoints(); \
179 Teuchos::SerialDenseMatrix<int,double> mat(setup.st_sz, \
181 for (int i=0; i<setup.st_sz; i++) { \
182 for (int j=0; j<setup.st_sz; j++) { \
183 for (unsigned int k=0; k<weights.size(); k++) \
184 mat(i,j) += weights[k]*values[k][i]*values[k][j]; \
185 mat(i,j) /= std::sqrt(norms[i]*norms[j]); \
189 success = mat.normInf() < setup.atol; \
191 out << "\n Error, mat.normInf() < atol = " << mat.normInf() \
192 << " < " << setup.atol << ": failed!\n"; \
193 out << "mat = " << mat << std::endl; \
197 TEUCHOS_UNIT_TEST( BASENAME, TAG ## PCE ) { \
198 Stokhos::OrthogPolyApprox<int,double> v2(setup.basis); \
199 lanczos_pce_quad_func quad_func(setup.v_st, *setup.st_basis); \
200 setup.exp->unary_op(quad_func, v2, setup.u); \
201 success = comparePCEs(setup.v, "v", v2, "v2", setup.rtol, \
205 TEUCHOS_UNIT_TEST( BASENAME, TAG ## Mean ) { \
206 success = Teuchos::testRelErr( \
207 "v.mean()", setup.v.mean(), \
208 "v_st.mean()", setup.v_st.mean(), \
209 "rtol", setup.rtol, \
210 "rtol", setup.rtol, \
211 Teuchos::Ptr<std::ostream>(out.getOStream().get())); \
215 TEUCHOS_UNIT_TEST( BASENAME, TAG ## StandardDeviation ) { \
216 success = Teuchos::testRelErr( \
217 "v.standard_deviation()", \
218 setup.v.standard_deviation(), \
219 "v_st.standard_devaition()", \
220 setup.v_st.standard_deviation(), \
223 Teuchos::Ptr<std::ostream>(out.getOStream().get())); \
232template <
typename Ordinal_Type,
typename Value_Type>
236 static const bool is_even =
true;
251template <typename Ordinal_Type, typename Value_Type>
255 static const bool is_even =
false;
271template <typename Ordinal_Type, typename Value_Type>
275 static const bool is_even =
false;
286int main(
int argc,
char*
argv[] ) {
287 Teuchos::GlobalMPISession mpiSession(&argc, &
argv);
288 return Teuchos::UnitTestRepository::runUnitTestsFromMain(argc,
argv);
#define LANCZOS_UNIT_TESTS(BASENAME, TAG, FUNC, NORMALIZE)
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
Legendre polynomial basis.
Generates three-term recurrence using the Lanczos procedure applied to a polynomial chaos expansion i...
Class to store coefficients of a projection onto an orthogonal polynomial basis.
void reset(const Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > &new_basis, ordinal_type sz=0)
Reset to a new basis.
value_type evaluate(const Teuchos::Array< value_type > &point) const
Evaluate polynomial approximation at a point.
Abstract base class for multivariate orthogonal polynomials.
Orthogonal polynomial expansions based on numerical quadrature.
void times(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)
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules.
static const bool is_even
void eval(Stokhos::QuadOrthogPolyExpansion< OrdinalType, ValueType > &exp, const Stokhos::OrthogPolyApprox< OrdinalType, ValueType > &x, Stokhos::OrthogPolyApprox< OrdinalType, ValueType > &u)
void eval(Stokhos::QuadOrthogPolyExpansion< OrdinalType, ValueType > &exp, const Stokhos::OrthogPolyApprox< OrdinalType, ValueType > &x, Stokhos::OrthogPolyApprox< OrdinalType, ValueType > &u)
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< OrdinalType, ValueType > > basis
Teuchos::RCP< const Stokhos::MonoProjPCEBasis< OrdinalType, ValueType > > st_1d_proj_basis
Teuchos::RCP< const Stokhos::Quadrature< OrdinalType, ValueType > > st_quad
Func::ValueType ValueType
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > v
Lanczos_PCE_Setup(bool normalize)
Teuchos::RCP< const Stokhos::HouseTriDiagPCEBasis< OrdinalType, ValueType > > st_1d_proj_basis
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< OrdinalType, ValueType > > st_basis
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > v_st
Teuchos::RCP< Stokhos::QuadOrthogPolyExpansion< OrdinalType, ValueType > > exp
Func::OrdinalType OrdinalType
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > u_st
Teuchos::Array< Teuchos::RCP< const Stokhos::OneDOrthogPolyBasis< OrdinalType, ValueType > > > st_bases
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > u
void eval(Stokhos::QuadOrthogPolyExpansion< OrdinalType, ValueType > &exp, const Stokhos::OrthogPolyApprox< OrdinalType, ValueType > &x, Stokhos::OrthogPolyApprox< OrdinalType, ValueType > &u)
double operator()(const double &a) const
const Stokhos::OrthogPolyBasis< int, double > & basis
Teuchos::Array< double > vec
lanczos_pce_quad_func(const Stokhos::OrthogPolyApprox< int, double > &pce_, const Stokhos::OrthogPolyBasis< int, double > &basis_)
const Stokhos::OrthogPolyApprox< int, double > & pce