Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_SacadoPCEUnitTest.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 namespace SacadoPCEUnitTest {
43 
44  // Common setup for unit tests
45  template <typename PCEType>
46  struct UnitTestSetup {
47 
48  typedef PCEType pce_type;
50  double rtol, atol;
51  double crtol, catol;
52  int sz;
57  pce_type x, y, u, u2, cx, cu, cu2, sx, su, su2;
58  double a;
59 
61  rtol = 1e-4;
62  atol = 1e-5;
63  crtol = 1e-12;
64  catol = 1e-12;
65  a = 3.1;
66  const int d = 2;
67  const int p = 7;
68 
69  // Create product basis
71  for (int i=0; i<d; i++)
72  bases[i] =
74  basis =
76 
77  // Tensor product quadrature
78  quad =
80 
81  // Triple product tensor
83 
84  // Quadrature expansion
85  exp =
87 
88  // Create approximation
89  sz = basis->size();
90  x.reset(exp);
91  y.reset(exp);
92  u.reset(exp);
93  u2.reset(exp);
94  cx.reset(exp, 1);
95  x.term(0, 0) = 1.0;
96  cx.term(0, 0) = a;
97  cu.reset(exp);
98  cu2.reset(exp, 1);
99  sx.reset(exp, d+1);
100  su.reset(exp, d+1);
101  su2.reset(exp, d+1);
102  for (int i=0; i<d; i++) {
103  x.term(i, 1) = 0.1;
104  sx.term(i, 1) = 0.0;
105  }
106  y.term(0, 0) = 2.0;
107  for (int i=0; i<d; i++)
108  y.term(i, 1) = 0.25;
109  }
110  };
111 
114 
115  TEUCHOS_UNIT_TEST( Stokhos_PCE, UMinus) {
117  UTS::pce_type u = -v;
118  UTS::opa_type u_opa(setup.basis);
119  setup.exp->unaryMinus(u_opa, v.getOrthogPolyApprox());
120  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
121  u_opa, "u_opa",
122  setup.rtol, setup.atol, out);
123  }
124 
125 #define UNARY_UNIT_TEST(OP) \
126  TEUCHOS_UNIT_TEST( Stokhos_PCE, OP) { \
127  UTS::pce_type u = OP(setup.x); \
128  UTS::opa_type u_opa(setup.basis); \
129  setup.exp->OP(u_opa, setup.x.getOrthogPolyApprox()); \
130  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
131  u_opa, "u_opa", \
132  setup.rtol, setup.atol, out); \
133  } \
134  TEUCHOS_UNIT_TEST( Stokhos_PCE, OP##_const) { \
135  UTS::pce_type u = OP(setup.cx); \
136  UTS::opa_type u_opa(setup.basis); \
137  setup.exp->OP(u_opa, setup.cx.getOrthogPolyApprox()); \
138  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
139  u_opa, "u_opa", \
140  setup.rtol, setup.atol, out); \
141  } \
142  TEUCHOS_UNIT_TEST( Stokhos_PCE, OP##_resize) { \
143  UTS::pce_type u; \
144  u = OP(setup.x); \
145  UTS::opa_type u_opa(setup.basis); \
146  setup.exp->OP(u_opa, setup.x.getOrthogPolyApprox()); \
147  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
148  u_opa, "u_opa", \
149  setup.rtol, setup.atol, out); \
150  }
151 
169 
170 #define BINARY_UNIT_TEST(OP, EXPOP) \
171  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP) { \
172  UTS::pce_type v = std::sin(setup.x); \
173  UTS::pce_type w = std::cos(setup.x); \
174  UTS::pce_type u = OP(v,w); \
175  UTS::opa_type u_opa(setup.basis); \
176  setup.exp->EXPOP(u_opa, v.getOrthogPolyApprox(), \
177  w.getOrthogPolyApprox()); \
178  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
179  u_opa, "u_opa", \
180  setup.rtol, setup.atol, out); \
181  } \
182  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const) { \
183  UTS::pce_type w = std::cos(setup.x); \
184  UTS::pce_type u = OP(setup.a, w); \
185  UTS::opa_type u_opa(setup.basis); \
186  setup.exp->EXPOP(u_opa, setup.a, \
187  w.getOrthogPolyApprox()); \
188  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
189  u_opa, "u_opa", \
190  setup.rtol, setup.atol, out); \
191  } \
192  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const) { \
193  UTS::pce_type v = std::sin(setup.x); \
194  UTS::pce_type u = OP(v, setup.a); \
195  UTS::opa_type u_opa(setup.basis); \
196  setup.exp->EXPOP(u_opa, v.getOrthogPolyApprox(), \
197  setup.a); \
198  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
199  u_opa, "u_opa", \
200  setup.rtol, setup.atol, out); \
201  } \
202  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_both_const) { \
203  UTS::pce_type u = OP(setup.cx, setup.cx); \
204  UTS::opa_type u_opa(setup.basis); \
205  setup.exp->EXPOP(u_opa, setup.cx.getOrthogPolyApprox(), \
206  setup.cx.getOrthogPolyApprox()); \
207  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
208  u_opa, "u_opa", \
209  setup.rtol, setup.atol, out); \
210  } \
211  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const2) { \
212  UTS::pce_type w = std::cos(setup.x); \
213  UTS::pce_type u = OP(setup.cx, w); \
214  UTS::opa_type u_opa(setup.basis); \
215  setup.exp->EXPOP(u_opa, setup.cx.getOrthogPolyApprox(), \
216  w.getOrthogPolyApprox()); \
217  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
218  u_opa, "u_opa", \
219  setup.rtol, setup.atol, out); \
220  } \
221  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const2) { \
222  UTS::pce_type v = std::sin(setup.x); \
223  UTS::pce_type u = OP(v, setup.cx); \
224  UTS::opa_type u_opa(setup.basis); \
225  setup.exp->EXPOP(u_opa, v.getOrthogPolyApprox(), \
226  setup.cx.getOrthogPolyApprox()); \
227  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
228  u_opa, "u_opa", \
229  setup.rtol, setup.atol, out); \
230  } \
231  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_resize) { \
232  UTS::pce_type v = std::sin(setup.x); \
233  UTS::pce_type w = std::cos(setup.x); \
234  UTS::pce_type u; \
235  u = OP(v, w); \
236  UTS::opa_type u_opa(setup.basis); \
237  setup.exp->EXPOP(u_opa, v.getOrthogPolyApprox(), \
238  w.getOrthogPolyApprox()); \
239  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
240  u_opa, "u_opa", \
241  setup.rtol, setup.atol, out); \
242  } \
243  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_const_resize) { \
244  UTS::pce_type w = std::cos(setup.x); \
245  UTS::pce_type u; \
246  u = OP(setup.a, w); \
247  UTS::opa_type u_opa(setup.basis); \
248  setup.exp->EXPOP(u_opa, setup.a, \
249  w.getOrthogPolyApprox()); \
250  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
251  u_opa, "u_opa", \
252  setup.rtol, setup.atol, out); \
253  } \
254  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_const_resize) { \
255  UTS::pce_type v = std::sin(setup.x); \
256  UTS::pce_type u; \
257  u = OP(v, setup.a); \
258  UTS::opa_type u_opa(setup.basis); \
259  setup.exp->EXPOP(u_opa, v.getOrthogPolyApprox(), \
260  setup.a); \
261  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
262  u_opa, "u_opa", \
263  setup.rtol, setup.atol, out); \
264  } \
265  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_short) { \
266  UTS::pce_type w = std::cos(setup.x); \
267  UTS::pce_type u = OP(setup.sx, w); \
268  UTS::opa_type u_opa(setup.basis); \
269  setup.exp->EXPOP(u_opa, setup.sx.getOrthogPolyApprox(), \
270  w.getOrthogPolyApprox()); \
271  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
272  u_opa, "u_opa", \
273  setup.rtol, setup.atol, out); \
274  } \
275  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_short) { \
276  UTS::pce_type v = std::sin(setup.x); \
277  UTS::pce_type u = OP(v, setup.sx); \
278  UTS::opa_type u_opa(setup.basis); \
279  setup.exp->EXPOP(u_opa, v.getOrthogPolyApprox(), \
280  setup.sx.getOrthogPolyApprox()); \
281  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
282  u_opa, "u_opa", \
283  setup.rtol, setup.atol, out); \
284  } \
285  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_both_short) { \
286  UTS::pce_type u = OP(setup.sx, setup.sx); \
287  UTS::opa_type u_opa(setup.basis); \
288  setup.exp->EXPOP(u_opa, setup.sx.getOrthogPolyApprox(), \
289  setup.sx.getOrthogPolyApprox()); \
290  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
291  u_opa, "u_opa", \
292  setup.rtol, setup.atol, out); \
293  } \
294 TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_short_resize) { \
295  UTS::pce_type w = std::cos(setup.x); \
296  UTS::pce_type u; \
297  u = OP(setup.sx, w); \
298  UTS::opa_type u_opa(setup.basis); \
299  setup.exp->EXPOP(u_opa, setup.sx.getOrthogPolyApprox(), \
300  w.getOrthogPolyApprox()); \
301  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
302  u_opa, "u_opa", \
303  setup.rtol, setup.atol, out); \
304  } \
305  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_short_resize) { \
306  UTS::pce_type v = std::sin(setup.x); \
307  UTS::pce_type u; \
308  u = OP(v, setup.sx); \
309  UTS::opa_type u_opa(setup.basis); \
310  setup.exp->EXPOP(u_opa, v.getOrthogPolyApprox(), \
311  setup.sx.getOrthogPolyApprox()); \
312  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
313  u_opa, "u_opa", \
314  setup.rtol, setup.atol, out); \
315  } \
316  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_short_right_const) { \
317  UTS::pce_type u = OP(setup.sx, setup.a); \
318  UTS::opa_type u_opa(setup.basis); \
319  setup.exp->EXPOP(u_opa, setup.sx.getOrthogPolyApprox(), \
320  setup.a); \
321  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
322  u_opa, "u_opa", \
323  setup.rtol, setup.atol, out); \
324  } \
325  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_short_left_const) { \
326  UTS::pce_type u = OP(setup.a, setup.sx); \
327  UTS::opa_type u_opa(setup.basis); \
328  setup.exp->EXPOP(u_opa, setup.a, \
329  setup.sx.getOrthogPolyApprox()); \
330  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
331  u_opa, "u_opa", \
332  setup.rtol, setup.atol, out); \
333  } \
334  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_left_short_right_const2) { \
335  UTS::pce_type u = OP(setup.sx, setup.cx); \
336  UTS::opa_type u_opa(setup.basis); \
337  setup.exp->EXPOP(u_opa, setup.sx.getOrthogPolyApprox(), \
338  setup.cx.getOrthogPolyApprox()); \
339  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
340  u_opa, "u_opa", \
341  setup.rtol, setup.atol, out); \
342  } \
343  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_right_short_left_const2) { \
344  UTS::pce_type u = OP(setup.cx, setup.sx); \
345  UTS::opa_type u_opa(setup.basis); \
346  setup.exp->EXPOP(u_opa, setup.cx.getOrthogPolyApprox(), \
347  setup.sx.getOrthogPolyApprox()); \
348  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
349  u_opa, "u_opa", \
350  setup.rtol, setup.atol, out); \
351  }
352 
353  BINARY_UNIT_TEST(operator+, plus)
354  BINARY_UNIT_TEST(operator-, minus)
355  BINARY_UNIT_TEST(operator*, times)
356  BINARY_UNIT_TEST(operator/, divide)
357 
358 #define OPASSIGN_UNIT_TEST(OP, EXPOP) \
359  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP) { \
360  UTS::pce_type v = std::sin(setup.x); \
361  UTS::pce_type u = std::cos(setup.x); \
362  UTS::opa_type u_opa = u.getOrthogPolyApprox(); \
363  u OP v; \
364  setup.exp->EXPOP(u_opa, v.getOrthogPolyApprox()); \
365  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
366  u_opa, "u_opa", \
367  setup.rtol, setup.atol, out); \
368  } \
369  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_const) { \
370  UTS::pce_type u = std::cos(setup.x); \
371  UTS::opa_type u_opa = u.getOrthogPolyApprox(); \
372  u OP setup.a; \
373  setup.exp->EXPOP(u_opa, setup.a); \
374  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
375  u_opa, "u_opa", \
376  setup.rtol, setup.atol, out); \
377  } \
378  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_const2) { \
379  UTS::pce_type u = std::cos(setup.x); \
380  UTS::opa_type u_opa = u.getOrthogPolyApprox(); \
381  u OP setup.cx; \
382  setup.exp->EXPOP(u_opa, setup.cx.getOrthogPolyApprox()); \
383  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
384  u_opa, "u_opa", \
385  setup.rtol, setup.atol, out); \
386  } \
387  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_resize) { \
388  UTS::pce_type v = std::sin(setup.x); \
389  UTS::pce_type u = setup.a; \
390  UTS::opa_type u_opa = u.getOrthogPolyApprox(); \
391  u OP v; \
392  setup.exp->EXPOP(u_opa, v.getOrthogPolyApprox()); \
393  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
394  u_opa, "u_opa", \
395  setup.rtol, setup.atol, out); \
396  } \
397  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_short) { \
398  UTS::pce_type u = std::cos(setup.x); \
399  UTS::opa_type u_opa = u.getOrthogPolyApprox(); \
400  u OP setup.sx; \
401  setup.exp->EXPOP(u_opa, setup.sx.getOrthogPolyApprox()); \
402  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
403  u_opa, "u_opa", \
404  setup.rtol, setup.atol, out); \
405  } \
406  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_short_resize) { \
407  UTS::pce_type u = setup.sx; \
408  UTS::pce_type v = std::cos(setup.x); \
409  UTS::opa_type u_opa = u.getOrthogPolyApprox(); \
410  u OP v; \
411  setup.exp->EXPOP(u_opa, v.getOrthogPolyApprox()); \
412  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
413  u_opa, "u_opa", \
414  setup.rtol, setup.atol, out); \
415  } \
416  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_short_const) { \
417  UTS::pce_type u = setup.sx; \
418  UTS::opa_type u_opa = u.getOrthogPolyApprox(); \
419  u OP setup.a; \
420  setup.exp->EXPOP(u_opa, setup.a); \
421  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
422  u_opa, "u_opa", \
423  setup.rtol, setup.atol, out); \
424  } \
425  TEUCHOS_UNIT_TEST( Stokhos_PCE, EXPOP##_short_const2) { \
426  UTS::pce_type u = setup.sx; \
427  UTS::opa_type u_opa = u.getOrthogPolyApprox(); \
428  u OP setup.cx; \
429  setup.exp->EXPOP(u_opa, setup.cx.getOrthogPolyApprox()); \
430  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u", \
431  u_opa, "u_opa", \
432  setup.rtol, setup.atol, out); \
433  }
434 
435  OPASSIGN_UNIT_TEST(+=, plusEqual)
436  OPASSIGN_UNIT_TEST(-=, minusEqual)
437  OPASSIGN_UNIT_TEST(*=, timesEqual)
438  OPASSIGN_UNIT_TEST(/=, divideEqual)
439 
440  TEUCHOS_UNIT_TEST( Stokhos_PCE, saxpy) {
444  UTS::opa_type u_opa = u.getOrthogPolyApprox();
445  UTS::opa_type t_opa(setup.basis);
446  u += v*w;
447  setup.exp->times(t_opa, v.getOrthogPolyApprox(), w.getOrthogPolyApprox());
448  setup.exp->plusEqual(u_opa, t_opa);
449  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
450  u_opa, "u_opa",
451  setup.rtol, setup.atol, out);
452  }
453  TEUCHOS_UNIT_TEST( Stokhos_PCE, saxpy_resize) {
454  UTS::pce_type u = setup.cx;
457  UTS::opa_type u_opa = u.getOrthogPolyApprox();
458  UTS::opa_type t_opa(setup.basis);
459  u += v*w;
460  setup.exp->times(t_opa, v.getOrthogPolyApprox(), w.getOrthogPolyApprox());
461  setup.exp->plusEqual(u_opa, t_opa);
462  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
463  u_opa, "u_opa",
464  setup.rtol, setup.atol, out);
465  }
466  TEUCHOS_UNIT_TEST( Stokhos_PCE, saxpy_resize2) {
467  UTS::pce_type u = setup.sx;
470  UTS::opa_type u_opa = u.getOrthogPolyApprox();
471  UTS::opa_type t_opa(setup.basis);
472  u += v*w;
473  setup.exp->times(t_opa, v.getOrthogPolyApprox(), w.getOrthogPolyApprox());
474  setup.exp->plusEqual(u_opa, t_opa);
475  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
476  u_opa, "u_opa",
477  setup.rtol, setup.atol, out);
478  }
479  TEUCHOS_UNIT_TEST( Stokhos_PCE, saxpy_const) {
482  UTS::opa_type u_opa = u.getOrthogPolyApprox();
483  UTS::opa_type t_opa(setup.basis);
484  u += setup.a*w;
485  setup.exp->times(t_opa, setup.a, w.getOrthogPolyApprox());
486  setup.exp->plusEqual(u_opa, t_opa);
487  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
488  u_opa, "u_opa",
489  setup.rtol, setup.atol, out);
490  }
491  TEUCHOS_UNIT_TEST( Stokhos_PCE, saxpy_const2) {
494  UTS::opa_type u_opa = u.getOrthogPolyApprox();
495  UTS::opa_type t_opa(setup.basis);
496  u += setup.cx*w;
497  setup.exp->times(t_opa, setup.cx.getOrthogPolyApprox(),
498  w.getOrthogPolyApprox());
499  setup.exp->plusEqual(u_opa, t_opa);
500  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
501  u_opa, "u_opa",
502  setup.rtol, setup.atol, out);
503  }
504  TEUCHOS_UNIT_TEST( Stokhos_PCE, saxpy_short) {
507  UTS::opa_type u_opa = u.getOrthogPolyApprox();
508  UTS::opa_type t_opa(setup.basis);
509  u += setup.sx*w;
510  setup.exp->times(t_opa, setup.sx.getOrthogPolyApprox(),
511  w.getOrthogPolyApprox());
512  setup.exp->plusEqual(u_opa, t_opa);
513  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
514  u_opa, "u_opa",
515  setup.rtol, setup.atol, out);
516  }
517  TEUCHOS_UNIT_TEST( Stokhos_PCE, saxpy_short_const) {
519  UTS::opa_type u_opa = u.getOrthogPolyApprox();
520  UTS::opa_type t_opa(setup.basis);
521  u += setup.sx*setup.a;
522  setup.exp->times(t_opa, setup.sx.getOrthogPolyApprox(),
523  setup.a);
524  setup.exp->plusEqual(u_opa, t_opa);
525  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
526  u_opa, "u_opa",
527  setup.rtol, setup.atol, out);
528  }
529  TEUCHOS_UNIT_TEST( Stokhos_PCE, saxpy_short_const2) {
531  UTS::opa_type u_opa = u.getOrthogPolyApprox();
532  UTS::opa_type t_opa(setup.basis);
533  u += setup.sx*setup.cx;
534  setup.exp->times(t_opa, setup.sx.getOrthogPolyApprox(),
535  setup.cx.getOrthogPolyApprox());
536  setup.exp->plusEqual(u_opa, t_opa);
537  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
538  u_opa, "u_opa",
539  setup.rtol, setup.atol, out);
540  }
541  TEUCHOS_UNIT_TEST( Stokhos_PCE, saxpy_resize_const) {
542  UTS::pce_type u = setup.cx;
544  UTS::opa_type u_opa = u.getOrthogPolyApprox();
545  UTS::opa_type t_opa(setup.basis);
546  u += setup.a*w;
547  setup.exp->times(t_opa, setup.a, w.getOrthogPolyApprox());
548  setup.exp->plusEqual(u_opa, t_opa);
549  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
550  u_opa, "u_opa",
551  setup.rtol, setup.atol, out);
552  }
553  TEUCHOS_UNIT_TEST( Stokhos_PCE, saxpy_resize_const2) {
554  UTS::pce_type u = setup.cx;
556  UTS::opa_type u_opa = u.getOrthogPolyApprox();
557  UTS::opa_type t_opa(setup.basis);
558  u += setup.cx*w;
559  setup.exp->times(t_opa, setup.cx.getOrthogPolyApprox(),
560  w.getOrthogPolyApprox());
561  setup.exp->plusEqual(u_opa, t_opa);
562  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
563  u_opa, "u_opa",
564  setup.rtol, setup.atol, out);
565  }
566  TEUCHOS_UNIT_TEST( Stokhos_PCE, saxpy_short_resize_const) {
567  UTS::pce_type u = setup.sx;
569  UTS::opa_type u_opa = u.getOrthogPolyApprox();
570  UTS::opa_type t_opa(setup.basis);
571  u += setup.a*w;
572  setup.exp->times(t_opa, setup.a, w.getOrthogPolyApprox());
573  setup.exp->plusEqual(u_opa, t_opa);
574  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
575  u_opa, "u_opa",
576  setup.rtol, setup.atol, out);
577  }
578  TEUCHOS_UNIT_TEST( Stokhos_PCE, saxpy_short_resize_const2) {
579  UTS::pce_type u = setup.sx;
581  UTS::opa_type u_opa = u.getOrthogPolyApprox();
582  UTS::opa_type t_opa(setup.basis);
583  u += setup.cx*w;
584  setup.exp->times(t_opa, setup.cx.getOrthogPolyApprox(),
585  w.getOrthogPolyApprox());
586  setup.exp->plusEqual(u_opa, t_opa);
587  success = Stokhos::comparePCEs(u.getOrthogPolyApprox(), "u",
588  u_opa, "u_opa",
589  setup.rtol, setup.atol, out);
590  }
591 }
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > tan(const PCE< Storage > &a)
#define BINARY_UNIT_TEST(OP, EXPOP)
#define OPASSIGN_UNIT_TEST(OP, EXPOP)
void times(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a, const OrthogPolyApprox< ordinal_type, value_type, node_type > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > sinh(const PCE< Storage > &a)
atanh(expr.val())
Teuchos::RCP< const Stokhos::Quadrature< int, double > > quad
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
void saxpy(const scalar_type &alpha, Teuchos::SerialDenseVector< ordinal_type, scalar_type > &x, const scalar_type &beta, const Teuchos::SerialDenseVector< ordinal_type, scalar_type > &y)
Overwrite x with alpha*x + beta*y.
KOKKOS_INLINE_FUNCTION PCE< Storage > tanh(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cbrt(const PCE< Storage > &a)
void plusEqual(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const value_type &x)
KOKKOS_INLINE_FUNCTION PCE< Storage > acos(const PCE< Storage > &a)
asinh(expr.val())
UnitTestSetup< pce_type > UTS
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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)
KOKKOS_INLINE_FUNCTION PCE< Storage > atan(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(const PCE< Storage > &a)
#define UNARY_UNIT_TEST(OP)
Legendre polynomial basis.
acosh(expr.val())
virtual ordinal_type size() const
Return total size of basis.
KOKKOS_INLINE_FUNCTION PCE< Storage > sin(const PCE< Storage > &a)
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)
void unaryMinus(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &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...