14 template<
class PCEType,
class OrdinalType,
class ValueType>
16 const std::string& a1_name,
18 const std::string& a2_name,
19 const ValueType& rel_tol,
const ValueType& abs_tol,
24 out <<
"Comparing " << a1_name <<
" == " << a2_name <<
" ... ";
26 const OrdinalType
n = a1.size();
30 out <<
"\nError, "<<a1_name<<
".size() = "<<a1.size()<<
" == "
31 << a2_name<<
".size() = "<<a2.
size()<<
" : failed!\n";
36 for( OrdinalType i = 0; i < n; ++i ) {
38 ValueType err =
std::abs(a1.coeff(i) - a2[i]) / nrm;
43 <<
"\nError, relErr("<<a1_name<<
"["<<i<<
"],"
44 <<a2_name<<
"["<<i<<
"]) = relErr("<<a1.coeff(i)<<
","<<a2[i]<<
") = "
45 <<err<<
" <= tol = "<<tol<<
": failed!\n";
54 << a1_name <<
" = " << a1 << std::endl
55 << a2_name <<
" = " << a2 << std::endl;
63 namespace SacadoPCEUnitTest {
66 template <
typename PCEType>
82 pce_type x,
y,
sin_x,
cos_y,
cx,
u,
u2,
cu,
cu2,
sx,
su,
su2;
107 cijk = Stokhos::create_product_tensor<execution_space>(*
basis, *
Cijk);
127 for (
int i=0; i<d; i++) {
154 sx.fastAccessCoeff(i+1) = 0.0;
165 setup.exp->unaryMinus(u_opa, setup.sin_x_opa);
167 setup.rtol, setup.atol, out);
171 #define UNARY_UNIT_TEST(OP) \
172 TEUCHOS_UNIT_TEST( Stokhos_PCE, OP##_const) { \
174 UTS::pce_type u = OP(setup.cx); \
175 UTS::opa_type u_opa(setup.basis); \
176 setup.exp->OP(u_opa, setup.cx_opa); \
177 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
178 setup.rtol, setup.atol, out); \
180 TEUCHOS_UNIT_TEST( Stokhos_PCE, OP##_resize) { \
184 UTS::opa_type u_opa(setup.basis); \
185 setup.exp->OP(u_opa, setup.cx_opa); \
186 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
187 setup.rtol, setup.atol, out); \
208 #define BINARY_UNIT_TEST(OP, EXPOP) \
209 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP) { \
211 UTS::pce_type v = setup.sin_x; \
212 UTS::pce_type w = setup.cos_y; \
213 UTS::pce_type u = OP(v,w); \
214 UTS::opa_type u_opa(setup.basis); \
215 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.cos_y_opa); \
216 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
217 setup.rtol, setup.atol, out); \
219 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const) { \
221 UTS::pce_type w = setup.sin_x; \
222 UTS::pce_type u = OP(setup.a, w); \
223 UTS::opa_type u_opa(setup.basis); \
224 setup.exp->EXPOP(u_opa, setup.a, setup.sin_x_opa); \
225 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
226 setup.rtol, setup.atol, out); \
228 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const) { \
230 UTS::pce_type v = setup.sin_x; \
231 UTS::pce_type u = OP(v, setup.a); \
232 UTS::opa_type u_opa(setup.basis); \
233 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.a); \
234 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
235 setup.rtol, setup.atol, out); \
237 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_both_const) { \
239 UTS::pce_type u = OP(setup.cx, setup.cx); \
240 UTS::opa_type u_opa(setup.basis); \
241 setup.exp->EXPOP(u_opa, setup.cx_opa, setup.cx_opa); \
242 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
243 setup.rtol, setup.atol, out); \
245 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const2) { \
247 UTS::pce_type w = setup.sin_x; \
248 UTS::pce_type u = OP(setup.cx, w); \
249 UTS::opa_type u_opa(setup.basis); \
250 setup.exp->EXPOP(u_opa, setup.cx_opa, setup.sin_x_opa); \
251 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
252 setup.rtol, setup.atol, out); \
254 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const2) { \
256 UTS::pce_type v = setup.sin_x; \
257 UTS::pce_type u = OP(v, setup.cx); \
258 UTS::opa_type u_opa(setup.basis); \
259 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.cx_opa); \
260 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
261 setup.rtol, setup.atol, out); \
263 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_resize) { \
265 UTS::pce_type v = setup.sin_x; \
266 UTS::pce_type w = setup.cos_y; \
269 UTS::opa_type u_opa(setup.basis); \
270 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.cos_y_opa); \
271 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
272 setup.rtol, setup.atol, out); \
274 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const_resize) { \
276 UTS::pce_type w = setup.sin_x; \
278 u = OP(setup.a, w); \
279 UTS::opa_type u_opa(setup.basis); \
280 setup.exp->EXPOP(u_opa, setup.a, setup.sin_x_opa); \
281 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
282 setup.rtol, setup.atol, out); \
284 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const_resize) { \
286 UTS::pce_type v = setup.sin_x; \
288 u = OP(v, setup.a); \
289 UTS::opa_type u_opa(setup.basis); \
290 setup.exp->EXPOP(u_opa, setup.sin_x_opa, setup.a); \
291 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
292 setup.rtol, setup.atol, out); \
300 #define OPASSIGN_UNIT_TEST(OP, EXPOP) \
301 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP) { \
303 UTS::pce_type v = setup.sin_x; \
304 UTS::pce_type u = setup.cos_y; \
306 UTS::opa_type u_opa = setup.cos_y_opa; \
307 setup.exp->EXPOP(u_opa, setup.sin_x_opa); \
308 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
309 setup.rtol, setup.atol, out); \
311 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_const) { \
313 UTS::pce_type u = setup.sin_x; \
315 UTS::opa_type u_opa = setup.sin_x_opa; \
316 setup.exp->EXPOP(u_opa, setup.a); \
317 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
318 setup.rtol, setup.atol, out); \
320 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_const2) { \
322 UTS::pce_type u = setup.sin_x; \
324 UTS::opa_type u_opa = setup.sin_x_opa; \
325 setup.exp->EXPOP(u_opa, setup.cx_opa); \
326 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
327 setup.rtol, setup.atol, out); \
329 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_resize) { \
331 UTS::pce_type v = setup.sin_x; \
332 UTS::pce_type u = setup.a; \
334 UTS::opa_type u_opa = setup.cx_opa; \
335 setup.exp->EXPOP(u_opa, setup.sin_x_opa); \
336 success = Stokhos::comparePCEs(u, "u", u_opa, "u_opa", \
337 setup.rtol, setup.atol, out); \
342 OPASSIGN_UNIT_TEST(*=, timesEqual)
343 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.