Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_TotalOrderBasisUnitTest.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 TotalOrderBasisUnitTest {
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 = 5;
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 total order basis of dimension d and order p
47  for (ordinal_type i=0; i<setup.d; i++)
50 
51  // Compute expected size
53 
54  // Check sizes
55  TEUCHOS_TEST_EQUALITY(sz, basis->size(), out, success);
56 
57  std::ostream_iterator<ordinal_type> out_iterator(out, " ");
58  for (ordinal_type i=0; i<sz; i++) {
59  const Stokhos::MultiIndex<ordinal_type>& term = basis->term(i);
60 
61  // Verify terms match
62  out << "term " << term << " <= " << setup.p << " : ";
63  bool is_less = true;
64  for (ordinal_type j=0; j<setup.d; j++)
65  is_less = is_less && term[j] <= setup.p;
66  if (is_less)
67  out << "passed" << std::endl;
68  else {
69  out << "failed" << std::endl;
70  success = false;
71  }
72 
73  }
74 
75  }
76 
77  TEUCHOS_UNIT_TEST( Coefficients, Anisotropic ) {
78  success = true;
79 
80  // Build anisotropic total order basis of dimension d
82  for (ordinal_type i=0; i<setup.d; i++)
85 
86  // Compute expected size
87  // Need to figure out how to do this
88  ordinal_type sz = basis->size();
89 
90  // Check sizes
91  TEUCHOS_TEST_EQUALITY(sz, basis->size(), out, success);
92 
93  std::ostream_iterator<ordinal_type> out_iterator(out, " ");
94  for (ordinal_type i=0; i<sz; i++) {
95  const Stokhos::MultiIndex<ordinal_type>& term = basis->term(i);
96 
97  // Verify terms match
98  out << "term " << term << " <= " << setup.p << " : ";
99  bool is_less = true;
100  for (ordinal_type j=0; j<setup.d; j++)
101  is_less = is_less && term[j] <= j+1;
102  if (is_less)
103  out << "passed" << std::endl;
104  else {
105  out << "failed" << std::endl;
106  success = false;
107  }
108 
109  }
110 
111  }
112 
113  TEUCHOS_UNIT_TEST( Sparse3Tensor, Anisotropic_Full ) {
114  success = true;
115 
116  // Build anisotropic tensor product basis of dimension d
118  for (ordinal_type i=0; i<setup.d; i++)
122  basis->computeTripleProductTensor();
123 
124  success = Stokhos::testSparse3Tensor(*Cijk, *basis, setup.sparse_tol,
125  setup.rtol, setup.atol, out);
126 
127  }
128 
129  TEUCHOS_UNIT_TEST( Sparse3Tensor, Anisotropic_Linear ) {
130  success = true;
131 
132  // Build anisotropic tensor product basis of dimension d
134  for (ordinal_type i=0; i<setup.d; i++)
138  basis->computeLinearTripleProductTensor();
139 
140  success = Stokhos::testSparse3Tensor(*Cijk, *basis, setup.sparse_tol,
141  setup.rtol, setup.atol, out, true);
142 
143  }
144 
145 }
146 
147 int main( int argc, char* argv[] ) {
148  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
150  return res;
151 }
ordinal_type n_choose_k(const ordinal_type &n, const ordinal_type &k)
Compute bionomial coefficient (n ; k) = n!/( k! (n-k)! )
Multivariate orthogonal polynomial basis generated from a total order tensor product of univariate po...
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)
TEUCHOS_UNIT_TEST(LexicographicTreeCoefficients, Isotropic)
static int runUnitTestsFromMain(int argc, char *argv[])
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Legendre polynomial basis.
int main(int argc, char **argv)
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
UnitTestSetup< ordinal_type, value_type > setup