44#include "Teuchos_UnitTestHarness.hpp"
45#include "Teuchos_TestingHelpers.hpp"
46#include "Teuchos_UnitTestRepository.hpp"
47#include "Teuchos_GlobalMPISession.hpp"
67 mutable Teuchos::Array<double>
vec;
72template <
typename Func>
79 Teuchos::RCP<const Stokhos::CompletePolynomialBasis<OrdinalType,ValueType> >
basis;
80 Teuchos::RCP< Stokhos::QuadOrthogPolyExpansion<OrdinalType,ValueType> >
exp;
81 Teuchos::RCP<const Stokhos::LanczosProjPCEBasis<OrdinalType,ValueType> >
st_1d_proj_basis;
82 Teuchos::RCP<const Stokhos::LanczosPCEBasis<OrdinalType,ValueType> >
st_1d_basis;
83 Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<OrdinalType,ValueType> > >
st_bases;
84 Teuchos::RCP<const Stokhos::CompletePolynomialBasis<OrdinalType,ValueType> >
st_basis;
85 Teuchos::RCP<const Stokhos::Quadrature<OrdinalType,ValueType> >
st_quad;
97 Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<OrdinalType,ValueType> > > bases(d);
111 Teuchos::RCP<const Stokhos::Quadrature<OrdinalType,ValueType> > quad =
115 Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > Cijk =
116 basis->computeTripleProductTensor();
124 func.eval(*exp, x,
u);
132 p, Teuchos::rcp(&
u,
false), Cijk, normalize));
138 p, Teuchos::rcp(&
u,
false), quad, normalize,
false));
161 Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > st_Cijk =
162 st_basis->computeTripleProductTensor();
174#define LANCZOS_UNIT_TESTS(BASENAME, TAG, FUNC, NORMALIZE, PROJECT) \
175namespace BASENAME ## TAG { \
177 Lanczos_PCE_Setup< FUNC<int,double> > setup(NORMALIZE, PROJECT); \
179 TEUCHOS_UNIT_TEST( BASENAME, TAG ## Map ) { \
180 Stokhos::OrthogPolyApprox<int,double> u2(setup.basis); \
182 setup.st_1d_proj_basis->transformCoeffsFromLanczos( \
183 setup.u_st.coeff(), \
186 setup.st_1d_basis->transformCoeffsFromLanczos( \
187 setup.u_st.coeff(), \
189 success = Stokhos::comparePCEs(setup.u, "u", u2, "u2", \
190 setup.rtol, setup.atol, out); \
193 TEUCHOS_UNIT_TEST( BASENAME, TAG ## Orthog ) { \
194 const Teuchos::Array<double>& norms = \
195 setup.st_bases[0]->norm_squared(); \
196 const Teuchos::Array<double>& weights = \
197 setup.st_quad->getQuadWeights(); \
198 const Teuchos::Array< Teuchos::Array<double> >& values = \
199 setup.st_quad->getBasisAtQuadPoints(); \
200 Teuchos::SerialDenseMatrix<int,double> mat(setup.st_sz, \
202 for (int i=0; i<setup.st_sz; i++) { \
203 for (int j=0; j<setup.st_sz; j++) { \
204 for (unsigned int k=0; k<weights.size(); k++) \
205 mat(i,j) += weights[k]*values[k][i]*values[k][j]; \
206 mat(i,j) /= std::sqrt(norms[i]*norms[j]); \
210 success = mat.normInf() < setup.atol; \
212 out << "\n Error, mat.normInf() < atol = " << mat.normInf() \
213 << " < " << setup.atol << ": failed!\n"; \
214 out << "mat = " << printMat(mat) << std::endl; \
218 TEUCHOS_UNIT_TEST( BASENAME, TAG ## PCE ) { \
219 Stokhos::OrthogPolyApprox<int,double> v2(setup.basis); \
220 lanczos_pce_quad_func quad_func(setup.v_st, *setup.st_basis); \
221 setup.exp->unary_op(quad_func, v2, setup.u); \
222 success = comparePCEs(setup.v, "v", v2, "v2", setup.rtol, \
226 TEUCHOS_UNIT_TEST( BASENAME, TAG ## Mean ) { \
227 success = Teuchos::testRelErr( \
228 "v.mean()", setup.v.mean(), \
229 "v_st.mean()", setup.v_st.mean(), \
230 "rtol", setup.rtol, \
231 "rtol", setup.rtol, \
232 Teuchos::Ptr<std::ostream>(out.getOStream().get())); \
236 TEUCHOS_UNIT_TEST( BASENAME, TAG ## StandardDeviation ) { \
237 success = Teuchos::testRelErr( \
238 "v.standard_deviation()", \
239 setup.v.standard_deviation(), \
240 "v_st.standard_devaition()", \
241 setup.v_st.standard_deviation(), \
244 Teuchos::Ptr<std::ostream>(out.getOStream().get())); \
253template <
typename Ordinal_Type,
typename Value_Type>
257 static const bool is_even =
true;
278template <typename Ordinal_Type, typename Value_Type>
282 static const bool is_even =
false;
304template <typename Ordinal_Type, typename Value_Type>
308 static const bool is_even =
false;
326 Teuchos::GlobalMPISession mpiSession(&argc, &
argv);
327 return Teuchos::UnitTestRepository::runUnitTestsFromMain(argc,
argv);
#define LANCZOS_UNIT_TESTS(BASENAME, TAG, FUNC, NORMALIZE, PROJECT)
true false int main(int argc, char *argv[])
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
Generates three-term recurrence using the Lanczos procedure applied to a polynomial chaos expansion i...
Generates three-term recurrence using the Lanczos procedure applied to a polynomial chaos expansion i...
Legendre polynomial basis.
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.
Abstract base class for multivariate orthogonal polynomials.
Orthogonal polynomial expansions based on numerical quadrature.
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::Quadrature< OrdinalType, ValueType > > st_quad
Func::ValueType ValueType
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > v
Teuchos::RCP< const Stokhos::LanczosPCEBasis< OrdinalType, ValueType > > st_1d_basis
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
Teuchos::RCP< const Stokhos::LanczosProjPCEBasis< OrdinalType, ValueType > > st_1d_proj_basis
Func::OrdinalType OrdinalType
Lanczos_PCE_Setup(bool normalize, bool project)
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