57 template<
class PCEType,
class OrdinalType,
class ValueType>
59 const std::string& a1_name,
61 const std::string& a2_name,
62 const ValueType& rel_tol,
const ValueType& abs_tol,
67 out <<
"Comparing " << a1_name <<
" == " << a2_name <<
" ... ";
69 const OrdinalType
n = a1.size();
73 out <<
"\nError, "<<a1_name<<
".size() = "<<a1.size()<<
" == "
74 << a2_name<<
".size() = "<<a2.
size()<<
" : failed!\n";
79 for( OrdinalType i = 0; i < n; ++i ) {
81 ValueType err =
std::abs(a1.coeff(i) - a2[i]) / nrm;
86 <<
"\nError, relErr("<<a1_name<<
"["<<i<<
"],"
87 <<a2_name<<
"["<<i<<
"]) = relErr("<<a1.coeff(i)<<
","<<a2[i]<<
") = "
88 <<err<<
" <= tol = "<<tol<<
": failed!\n";
97 << a1_name <<
" = " << a1 << std::endl
98 << a2_name <<
" = " << a2 << std::endl;
106 namespace SacadoPCEUnitTest {
109 template <
typename PCEType>
125 pce_type x,
y,
sin_x,
cos_y,
cx,
u,
u2,
cu,
cu2,
sx,
su,
su2;
150 cijk = Stokhos::create_product_tensor<execution_space>(*
basis, *
Cijk);
170 for (
int i=0; i<d; i++) {
197 sx.fastAccessCoeff(i+1) = 0.0;
208 setup.exp->unaryMinus(u_opa, setup.sin_x_opa);
210 setup.rtol, setup.atol, out);
214 #define UNARY_UNIT_TEST(OP) \
215 TEUCHOS_UNIT_TEST( Stokhos_PCE, OP##_const) { \
217 UTS::pce_type u = OP(setup.cx); \
218 UTS::opa_type u_opa(setup.basis); \
219 setup.exp->OP(u_opa, setup.cx_opa); \
220 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
221 setup.rtol, setup.atol, out); \
223 TEUCHOS_UNIT_TEST( Stokhos_PCE, OP##_resize) { \
227 UTS::opa_type u_opa(setup.basis); \
228 setup.exp->OP(u_opa, setup.cx_opa); \
229 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
230 setup.rtol, setup.atol, out); \
251 #define BINARY_UNIT_TEST(OP, EXPOP) \
252 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP) { \
254 UTS::pce_type v = setup.sin_x; \
255 UTS::pce_type w = setup.cos_y; \
256 UTS::pce_type u = OP(v,w); \
257 UTS::opa_type u_opa(setup.basis); \
258 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.cos_y_opa); \
259 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
260 setup.rtol, setup.atol, out); \
262 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const) { \
264 UTS::pce_type w = setup.sin_x; \
265 UTS::pce_type u = OP(setup.a, w); \
266 UTS::opa_type u_opa(setup.basis); \
267 setup.exp->EXPOP(u_opa, setup.a, setup.sin_x_opa); \
268 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
269 setup.rtol, setup.atol, out); \
271 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const) { \
273 UTS::pce_type v = setup.sin_x; \
274 UTS::pce_type u = OP(v, setup.a); \
275 UTS::opa_type u_opa(setup.basis); \
276 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.a); \
277 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
278 setup.rtol, setup.atol, out); \
280 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_both_const) { \
282 UTS::pce_type u = OP(setup.cx, setup.cx); \
283 UTS::opa_type u_opa(setup.basis); \
284 setup.exp->EXPOP(u_opa, setup.cx_opa, setup.cx_opa); \
285 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
286 setup.rtol, setup.atol, out); \
288 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const2) { \
290 UTS::pce_type w = setup.sin_x; \
291 UTS::pce_type u = OP(setup.cx, w); \
292 UTS::opa_type u_opa(setup.basis); \
293 setup.exp->EXPOP(u_opa, setup.cx_opa, setup.sin_x_opa); \
294 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
295 setup.rtol, setup.atol, out); \
297 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const2) { \
299 UTS::pce_type v = setup.sin_x; \
300 UTS::pce_type u = OP(v, setup.cx); \
301 UTS::opa_type u_opa(setup.basis); \
302 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.cx_opa); \
303 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
304 setup.rtol, setup.atol, out); \
306 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_resize) { \
308 UTS::pce_type v = setup.sin_x; \
309 UTS::pce_type w = setup.cos_y; \
312 UTS::opa_type u_opa(setup.basis); \
313 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.cos_y_opa); \
314 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
315 setup.rtol, setup.atol, out); \
317 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const_resize) { \
319 UTS::pce_type w = setup.sin_x; \
321 u = OP(setup.a, w); \
322 UTS::opa_type u_opa(setup.basis); \
323 setup.exp->EXPOP(u_opa, setup.a, setup.sin_x_opa); \
324 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
325 setup.rtol, setup.atol, out); \
327 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const_resize) { \
329 UTS::pce_type v = setup.sin_x; \
331 u = OP(v, setup.a); \
332 UTS::opa_type u_opa(setup.basis); \
333 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.a); \
334 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
335 setup.rtol, setup.atol, out); \
343 #define OPASSIGN_UNIT_TEST(OP, EXPOP) \
344 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP) { \
346 UTS::pce_type v = setup.sin_x; \
347 UTS::pce_type u = setup.cos_y; \
349 UTS::opa_type u_opa = setup.cos_y_opa; \
350 setup.exp->EXPOP(u_opa, setup.sin_x_opa); \
351 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
352 setup.rtol, setup.atol, out); \
354 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_const) { \
356 UTS::pce_type u = setup.sin_x; \
358 UTS::opa_type u_opa = setup.sin_x_opa; \
359 setup.exp->EXPOP(u_opa, setup.a); \
360 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
361 setup.rtol, setup.atol, out); \
363 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_const2) { \
365 UTS::pce_type u = setup.sin_x; \
367 UTS::opa_type u_opa = setup.sin_x_opa; \
368 setup.exp->EXPOP(u_opa, setup.cx_opa); \
369 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
370 setup.rtol, setup.atol, out); \
372 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_resize) { \
374 UTS::pce_type v = setup.sin_x; \
375 UTS::pce_type u = setup.a; \
377 UTS::opa_type u_opa = setup.cx_opa; \
378 setup.exp->EXPOP(u_opa, setup.sin_x_opa); \
379 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
380 setup.rtol, setup.atol, out); \
385 OPASSIGN_UNIT_TEST(*=, timesEqual)
386 OPASSIGN_UNIT_TEST(/=, divideEqual)
390 UTS::pce_type u = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
392 for (
int i=0; i<8; i++)
400 u = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
402 for (
int i=0; i<8; i++)
410 u.reset(UTS::pce_type::cijk_type(), 8);
411 for (
auto& z : u) { z = 3.0; }
413 for (
int i=0; i<8; i++)
423 Kokkos::initialize();
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
Stokhos::StandardStorage< int, double > storage_type
KOKKOS_INLINE_FUNCTION PCE< Storage > sinh(const PCE< Storage > &a)
Sacado::ETPCE::OrthogPoly< double, Stokhos::StandardStorage< int, double > > pce_type
Teuchos::RCP< const Stokhos::Quadrature< int, double > > quad
Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > Cijk
#define UNARY_UNIT_TEST(OP)
Kokkos::DefaultExecutionSpace execution_space
Stokhos::OrthogPolyApprox< int, double > opa_type
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
static int runUnitTestsFromMain(int argc, char *argv[])
Teuchos::RCP< Stokhos::AlgebraicOrthogPolyExpansion< ordinal_type, value_type > > exp
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.
#define BINARY_UNIT_TEST(OP, EXPOP)
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.
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
int main(int argc, char **argv)
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< ordinal_type, value_type > > basis
#define OPASSIGN_UNIT_TEST(OP, EXPOP)
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.