Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_TensorProductBasisUnitTest.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
14 
15 #include "Stokhos.hpp"
17 
18 #include <iterator>
19 
20 namespace TensorProductBasisUnitTest {
21 
22  // Common setup for unit tests
23  template <typename OrdinalType, typename ValueType>
24  struct UnitTestSetup {
25  ValueType rtol, atol, sparse_tol;
26  OrdinalType p,d;
27 
29  rtol = 1e-12;
30  atol = 1e-12;
31  sparse_tol = 1e-12;
32  d = 3;
33  p = 4;
34  }
35 
36  };
37 
38  typedef int ordinal_type;
39  typedef double value_type;
41 
42  TEUCHOS_UNIT_TEST( Coefficients, Isotropic ) {
43  success = true;
44 
45  // Build tensor product basis of dimension d and order p
47  for (ordinal_type i=0; i<setup.d; i++)
50 
51  // Compute expected size
52  ordinal_type sz = 1;
53  for (ordinal_type i=0; i<setup.d; ++i)
54  sz *= setup.p+1;
55 
56  // Check sizes
57  TEUCHOS_TEST_EQUALITY(sz, basis->size(), out, success);
58 
59  std::ostream_iterator<ordinal_type> out_iterator(out, " ");
60  for (ordinal_type i=0; i<sz; i++) {
61  const Stokhos::MultiIndex<ordinal_type>& term = basis->term(i);
62 
63  // Verify terms match
64  out << "term " << term << " <= " << setup.p << " : ";
65  bool is_less = true;
66  for (ordinal_type j=0; j<setup.d; j++)
67  is_less = is_less && term[j] <= setup.p;
68  if (is_less)
69  out << "passed" << std::endl;
70  else {
71  out << "failed" << std::endl;
72  success = false;
73  }
74 
75  }
76 
77  }
78 
79  TEUCHOS_UNIT_TEST( Coeficients, Anisotropic ) {
80  success = true;
81 
82  // Build anisotropic tensor product basis of dimension d
84  for (ordinal_type i=0; i<setup.d; i++)
87 
88  // Compute expected size
89  ordinal_type sz = 1;
90  for (ordinal_type i=0; i<setup.d; ++i)
91  sz *= i+2;
92 
93  // Check sizes
94  TEUCHOS_TEST_EQUALITY(sz, basis->size(), out, success);
95 
96  std::ostream_iterator<ordinal_type> out_iterator(out, " ");
97  for (ordinal_type i=0; i<sz; i++) {
98  const Stokhos::MultiIndex<ordinal_type>& term = basis->term(i);
99 
100  // Verify terms match
101  out << "term " << term << " <= " << setup.p << " : ";
102  bool is_less = true;
103  for (ordinal_type j=0; j<setup.d; j++)
104  is_less = is_less && term[j] <= setup.p;
105  if (is_less)
106  out << "passed" << std::endl;
107  else {
108  out << "failed" << std::endl;
109  success = false;
110  }
111 
112  }
113 
114  }
115 
116  TEUCHOS_UNIT_TEST( Sparse3Tensor, Anisotropic_Full ) {
117  success = true;
118 
119  // Build anisotropic tensor product basis of dimension d
121  for (ordinal_type i=0; i<setup.d; i++)
125  basis->computeTripleProductTensor();
126 
127  success = Stokhos::testSparse3Tensor(*Cijk, *basis, setup.sparse_tol,
128  setup.rtol, setup.atol, out);
129  }
130 
131  TEUCHOS_UNIT_TEST( Sparse3Tensor, Anisotropic_Linear ) {
132  success = true;
133 
134  // Build anisotropic tensor product basis of dimension d
136  for (ordinal_type i=0; i<setup.d; i++)
140  basis->computeLinearTripleProductTensor();
141 
142  success = Stokhos::testSparse3Tensor(*Cijk, *basis, setup.sparse_tol,
143  setup.rtol, setup.atol, out, true);
144  }
145 
146 
147 }
148 
149 int main( int argc, char* argv[] ) {
150  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
152  return res;
153 }
bool testSparse3Tensor(const Stokhos::Sparse3Tensor< ordinal_type, scalar_type > &Cijk, const Stokhos::ProductBasis< ordinal_type, scalar_type > &basis, const scalar_type &sparse_tol, const scalar_type &rel_tol, const scalar_type &abs_tol, Teuchos::FancyOStream &out, bool linear=false)
static int runUnitTestsFromMain(int argc, char *argv[])
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
UnitTestSetup< ordinal_type, value_type > setup
Multivariate orthogonal polynomial basis generated from a tensor product of univariate polynomials...
Legendre polynomial basis.
int main(int argc, char **argv)
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)