26 template<
class PCEType,
class OrdinalType,
class ValueType>
28 const std::string& a1_name,
30 const std::string& a2_name,
31 const ValueType& rel_tol,
const ValueType& abs_tol,
36 out <<
"Comparing " << a1_name <<
" == " << a2_name <<
" ... ";
38 const OrdinalType
n = a1.size();
42 out <<
"\nError, "<<a1_name<<
".size() = "<<a1.size()<<
" == "
43 << a2_name<<
".size() = "<<a2.
size()<<
" : failed!\n";
48 for( OrdinalType i = 0; i < n; ++i ) {
50 ValueType err =
std::abs(a1.coeff(i) - a2[i]) / nrm;
55 <<
"\nError, relErr("<<a1_name<<
"["<<i<<
"],"
56 <<a2_name<<
"["<<i<<
"]) = relErr("<<a1.coeff(i)<<
","<<a2[i]<<
") = "
57 <<err<<
" <= tol = "<<tol<<
": failed!\n";
66 << a1_name <<
" = " << a1 << std::endl
67 << a2_name <<
" = " << a2 << std::endl;
75 namespace SacadoPCEUnitTest {
78 template <
typename PCEType>
94 pce_type x,
y,
sin_x,
cos_y,
cx,
u,
u2,
cu,
cu2,
sx,
su,
su2;
119 cijk = Stokhos::create_product_tensor<execution_space>(*
basis, *
Cijk);
139 for (
int i=0; i<d; i++) {
166 sx.fastAccessCoeff(i+1) = 0.0;
177 setup.exp->unaryMinus(u_opa, setup.sin_x_opa);
179 setup.rtol, setup.atol, out);
183 #define UNARY_UNIT_TEST(OP) \
184 TEUCHOS_UNIT_TEST( Stokhos_PCE, OP##_const) { \
186 UTS::pce_type u = OP(setup.cx); \
187 UTS::opa_type u_opa(setup.basis); \
188 setup.exp->OP(u_opa, setup.cx_opa); \
189 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
190 setup.rtol, setup.atol, out); \
192 TEUCHOS_UNIT_TEST( Stokhos_PCE, OP##_resize) { \
196 UTS::opa_type u_opa(setup.basis); \
197 setup.exp->OP(u_opa, setup.cx_opa); \
198 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
199 setup.rtol, setup.atol, out); \
220 #define BINARY_UNIT_TEST(OP, EXPOP) \
221 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP) { \
223 UTS::pce_type v = setup.sin_x; \
224 UTS::pce_type w = setup.cos_y; \
225 UTS::pce_type u = OP(v,w); \
226 UTS::opa_type u_opa(setup.basis); \
227 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.cos_y_opa); \
228 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
229 setup.rtol, setup.atol, out); \
231 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const) { \
233 UTS::pce_type w = setup.sin_x; \
234 UTS::pce_type u = OP(setup.a, w); \
235 UTS::opa_type u_opa(setup.basis); \
236 setup.exp->EXPOP(u_opa, setup.a, setup.sin_x_opa); \
237 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
238 setup.rtol, setup.atol, out); \
240 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const) { \
242 UTS::pce_type v = setup.sin_x; \
243 UTS::pce_type u = OP(v, setup.a); \
244 UTS::opa_type u_opa(setup.basis); \
245 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.a); \
246 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
247 setup.rtol, setup.atol, out); \
249 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_both_const) { \
251 UTS::pce_type u = OP(setup.cx, setup.cx); \
252 UTS::opa_type u_opa(setup.basis); \
253 setup.exp->EXPOP(u_opa, setup.cx_opa, setup.cx_opa); \
254 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
255 setup.rtol, setup.atol, out); \
257 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const2) { \
259 UTS::pce_type w = setup.sin_x; \
260 UTS::pce_type u = OP(setup.cx, w); \
261 UTS::opa_type u_opa(setup.basis); \
262 setup.exp->EXPOP(u_opa, setup.cx_opa, setup.sin_x_opa); \
263 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
264 setup.rtol, setup.atol, out); \
266 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const2) { \
268 UTS::pce_type v = setup.sin_x; \
269 UTS::pce_type u = OP(v, setup.cx); \
270 UTS::opa_type u_opa(setup.basis); \
271 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.cx_opa); \
272 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
273 setup.rtol, setup.atol, out); \
275 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_resize) { \
277 UTS::pce_type v = setup.sin_x; \
278 UTS::pce_type w = setup.cos_y; \
281 UTS::opa_type u_opa(setup.basis); \
282 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.cos_y_opa); \
283 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
284 setup.rtol, setup.atol, out); \
286 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const_resize) { \
288 UTS::pce_type w = setup.sin_x; \
290 u = OP(setup.a, w); \
291 UTS::opa_type u_opa(setup.basis); \
292 setup.exp->EXPOP(u_opa, setup.a, setup.sin_x_opa); \
293 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
294 setup.rtol, setup.atol, out); \
296 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const_resize) { \
298 UTS::pce_type v = setup.sin_x; \
300 u = OP(v, setup.a); \
301 UTS::opa_type u_opa(setup.basis); \
302 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.a); \
303 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
304 setup.rtol, setup.atol, out); \
312 #define OPASSIGN_UNIT_TEST(OP, EXPOP) \
313 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP) { \
315 UTS::pce_type v = setup.sin_x; \
316 UTS::pce_type u = setup.cos_y; \
318 UTS::opa_type u_opa = setup.cos_y_opa; \
319 setup.exp->EXPOP(u_opa, setup.sin_x_opa); \
320 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
321 setup.rtol, setup.atol, out); \
323 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_const) { \
325 UTS::pce_type u = setup.sin_x; \
327 UTS::opa_type u_opa = setup.sin_x_opa; \
328 setup.exp->EXPOP(u_opa, setup.a); \
329 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
330 setup.rtol, setup.atol, out); \
332 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_const2) { \
334 UTS::pce_type u = setup.sin_x; \
336 UTS::opa_type u_opa = setup.sin_x_opa; \
337 setup.exp->EXPOP(u_opa, setup.cx_opa); \
338 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
339 setup.rtol, setup.atol, out); \
341 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_resize) { \
343 UTS::pce_type v = setup.sin_x; \
344 UTS::pce_type u = setup.a; \
346 UTS::opa_type u_opa = setup.cx_opa; \
347 setup.exp->EXPOP(u_opa, setup.sin_x_opa); \
348 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
349 setup.rtol, setup.atol, out); \
354 OPASSIGN_UNIT_TEST(*=, timesEqual)
355 OPASSIGN_UNIT_TEST(/=, divideEqual)
359 UTS::pce_type u = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
361 for (
int i=0; i<8; i++)
369 u = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
371 for (
int i=0; i<8; i++)
379 u.reset(UTS::pce_type::cijk_type(), 8);
380 for (
auto& z : u) { z = 3.0; }
382 for (
int i=0; i<8; i++)
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
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
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.