46 template<
class PCEType,
class OrdinalType,
class ValueType>
48 const std::string& a1_name,
50 const std::string& a2_name,
51 const ValueType& rel_tol,
const ValueType& abs_tol,
56 out <<
"Comparing " << a1_name <<
" == " << a2_name <<
" ... ";
58 const OrdinalType
n = a1.size();
62 out <<
"\nError, "<<a1_name<<
".size() = "<<a1.size()<<
" == "
63 << a2_name<<
".size() = "<<a2.
size()<<
" : failed!\n";
68 for( OrdinalType i = 0; i < n; ++i ) {
70 ValueType err =
std::abs(a1.coeff(i) - a2[i]) / nrm;
75 <<
"\nError, relErr("<<a1_name<<
"["<<i<<
"],"
76 <<a2_name<<
"["<<i<<
"]) = relErr("<<a1.coeff(i)<<
","<<a2[i]<<
") = "
77 <<err<<
" <= tol = "<<tol<<
": failed!\n";
86 << a1_name <<
" = " << a1 << std::endl
87 << a2_name <<
" = " << a2 << std::endl;
95 namespace SacadoPCEUnitTest {
98 template <
typename PCEType>
114 pce_type x,
y,
sin_x,
cos_y,
cx,
u,
u2,
cu,
cu2,
sx,
su,
su2;
139 cijk = Stokhos::create_product_tensor<execution_space>(*
basis, *
Cijk);
159 for (
int i=0; i<d; i++) {
186 sx.fastAccessCoeff(i+1) = 0.0;
197 setup.exp->unaryMinus(u_opa, setup.sin_x_opa);
199 setup.rtol, setup.atol, out);
203 #define UNARY_UNIT_TEST(OP) \
204 TEUCHOS_UNIT_TEST( Stokhos_PCE, OP##_const) { \
206 UTS::pce_type u = OP(setup.cx); \
207 UTS::opa_type u_opa(setup.basis); \
208 setup.exp->OP(u_opa, setup.cx_opa); \
209 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
210 setup.rtol, setup.atol, out); \
212 TEUCHOS_UNIT_TEST( Stokhos_PCE, OP##_resize) { \
216 UTS::opa_type u_opa(setup.basis); \
217 setup.exp->OP(u_opa, setup.cx_opa); \
218 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
219 setup.rtol, setup.atol, out); \
240 #define BINARY_UNIT_TEST(OP, EXPOP) \
241 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP) { \
243 UTS::pce_type v = setup.sin_x; \
244 UTS::pce_type w = setup.cos_y; \
245 UTS::pce_type u = OP(v,w); \
246 UTS::opa_type u_opa(setup.basis); \
247 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.cos_y_opa); \
248 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
249 setup.rtol, setup.atol, out); \
251 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const) { \
253 UTS::pce_type w = setup.sin_x; \
254 UTS::pce_type u = OP(setup.a, w); \
255 UTS::opa_type u_opa(setup.basis); \
256 setup.exp->EXPOP(u_opa, setup.a, setup.sin_x_opa); \
257 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
258 setup.rtol, setup.atol, out); \
260 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const) { \
262 UTS::pce_type v = setup.sin_x; \
263 UTS::pce_type u = OP(v, setup.a); \
264 UTS::opa_type u_opa(setup.basis); \
265 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.a); \
266 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
267 setup.rtol, setup.atol, out); \
269 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_both_const) { \
271 UTS::pce_type u = OP(setup.cx, setup.cx); \
272 UTS::opa_type u_opa(setup.basis); \
273 setup.exp->EXPOP(u_opa, setup.cx_opa, setup.cx_opa); \
274 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
275 setup.rtol, setup.atol, out); \
277 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const2) { \
279 UTS::pce_type w = setup.sin_x; \
280 UTS::pce_type u = OP(setup.cx, w); \
281 UTS::opa_type u_opa(setup.basis); \
282 setup.exp->EXPOP(u_opa, setup.cx_opa, setup.sin_x_opa); \
283 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
284 setup.rtol, setup.atol, out); \
286 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const2) { \
288 UTS::pce_type v = setup.sin_x; \
289 UTS::pce_type u = OP(v, setup.cx); \
290 UTS::opa_type u_opa(setup.basis); \
291 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.cx_opa); \
292 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
293 setup.rtol, setup.atol, out); \
295 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_resize) { \
297 UTS::pce_type v = setup.sin_x; \
298 UTS::pce_type w = setup.cos_y; \
301 UTS::opa_type u_opa(setup.basis); \
302 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.cos_y_opa); \
303 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
304 setup.rtol, setup.atol, out); \
306 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const_resize) { \
308 UTS::pce_type w = setup.sin_x; \
310 u = OP(setup.a, w); \
311 UTS::opa_type u_opa(setup.basis); \
312 setup.exp->EXPOP(u_opa, setup.a, setup.sin_x_opa); \
313 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
314 setup.rtol, setup.atol, out); \
316 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const_resize) { \
318 UTS::pce_type v = setup.sin_x; \
320 u = OP(v, setup.a); \
321 UTS::opa_type u_opa(setup.basis); \
322 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.a); \
323 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
324 setup.rtol, setup.atol, out); \
332 #define OPASSIGN_UNIT_TEST(OP, EXPOP) \
333 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP) { \
335 UTS::pce_type v = setup.sin_x; \
336 UTS::pce_type u = setup.cos_y; \
338 UTS::opa_type u_opa = setup.cos_y_opa; \
339 setup.exp->EXPOP(u_opa, setup.sin_x_opa); \
340 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
341 setup.rtol, setup.atol, out); \
343 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_const) { \
345 UTS::pce_type u = setup.sin_x; \
347 UTS::opa_type u_opa = setup.sin_x_opa; \
348 setup.exp->EXPOP(u_opa, setup.a); \
349 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
350 setup.rtol, setup.atol, out); \
352 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_const2) { \
354 UTS::pce_type u = setup.sin_x; \
356 UTS::opa_type u_opa = setup.sin_x_opa; \
357 setup.exp->EXPOP(u_opa, setup.cx_opa); \
358 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
359 setup.rtol, setup.atol, out); \
361 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_resize) { \
363 UTS::pce_type v = setup.sin_x; \
364 UTS::pce_type u = setup.a; \
366 UTS::opa_type u_opa = setup.cx_opa; \
367 setup.exp->EXPOP(u_opa, setup.sin_x_opa); \
368 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
369 setup.rtol, setup.atol, out); \
374 OPASSIGN_UNIT_TEST(*=, timesEqual)
375 OPASSIGN_UNIT_TEST(/=, divideEqual)
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > tan(const PCE< Storage > &a)
Stokhos::OrthogPolyApprox< ordinal_type, value_type > opa_type
KOKKOS_INLINE_FUNCTION PCE< Storage > sinh(const PCE< Storage > &a)
Teuchos::RCP< const Stokhos::Quadrature< int, double > > quad
Kokkos::DefaultExecutionSpace execution_space
Stokhos::OrthogPolyApprox< int, double > opa_type
#define OPASSIGN_UNIT_TEST(OP, EXPOP)
bool comparePCEs(const PCEType &a1, const std::string &a1_name, const Stokhos::OrthogPolyApprox< OrdinalType, ValueType > &a2, const std::string &a2_name, const ValueType &rel_tol, const ValueType &abs_tol, Teuchos::FancyOStream &out)
Teuchos::RCP< Stokhos::Sparse3Tensor< int, double > > Cijk
Orthogonal polynomial expansions limited to algebraic operations.
pointer coeff()
Return coefficient array.
KOKKOS_INLINE_FUNCTION PCE< Storage > tanh(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cbrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > acos(const PCE< Storage > &a)
UnitTestSetup< pce_type > UTS
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
pce_type::execution_space execution_space
void reset(const Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > &new_basis, ordinal_type sz=0)
Reset to a new basis.
pce_type::ordinal_type ordinal_type
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
TEUCHOS_UNIT_TEST(Stokhos_PCE, UMinus)
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeTripleProductTensor() const
Compute triple product tensor.
KOKKOS_INLINE_FUNCTION PCE< Storage > cosh(const PCE< Storage > &a)
Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > basis() const
Return basis.
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
virtual const Teuchos::Array< value_type > & norm_squared() const =0
Return array storing norm-squared of each basis polynomial.
#define BINARY_UNIT_TEST(OP, EXPOP)
KOKKOS_INLINE_FUNCTION PCE< Storage > atan(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(const PCE< Storage > &a)
Legendre polynomial basis.
pce_type::value_type value_type
#define UNARY_UNIT_TEST(OP)
KOKKOS_INLINE_FUNCTION PCE< Storage > sin(const PCE< Storage > &a)
ordinal_type size() const
Return size.
Teuchos::RCP< Stokhos::QuadOrthogPolyExpansion< int, double > > exp
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< int, double > > basis
KOKKOS_INLINE_FUNCTION PCE< Storage > log(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > log10(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > asin(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cos(const PCE< Storage > &a)
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...
pce_type::cijk_type kokkos_cijk_type
reference term(ordinal_type dimension, ordinal_type order)
Get coefficient term for given dimension and order.