18 namespace Sparse3TensorUnitTest {
23 template <
typename OrdinalType,
typename ValueType>
38 for (OrdinalType i=0; i<
d; i++)
61 setup.quad->getBasisAtQuadPoints();
65 k_it!=
setup.Cijk->k_end(); ++k_it) {
66 int k = Stokhos::index(k_it);
68 j_it !=
setup.Cijk->j_end(k_it); ++j_it) {
69 int j = Stokhos::index(j_it);
71 i_it !=
setup.Cijk->i_end(j_it); ++i_it) {
72 int i = Stokhos::index(i_it);
73 double c = Stokhos::value(i_it);
76 int nqp = weights.
size();
77 for (
int qp=0; qp<nqp; qp++)
78 c2 += weights[qp]*values[qp][i]*values[qp][j]*values[qp][k];
85 <<
"Check: rel_err( C(" << i <<
"," << j <<
"," << k <<
") )"
86 <<
" = " <<
"rel_err( " << c <<
", " << c2 <<
" ) = " << err
87 <<
" <= " << tol <<
" : ";
88 if (s) out <<
"Passed.";
93 success = success && s;
105 for (
int i=0; i<
setup.d; i++)
106 Cijk_1d[i] =
setup.bases[i]->computeTripleProductTensor();
110 for (
int i=0; i<
setup.sz; i++) {
112 for (
int k=0; k<
setup.sz; k++) {
115 for (
int l=0; l<
setup.d; l++)
116 c *= (*Cijk_1d[l])(terms_i[l],terms_j[l],terms_k[l]);
118 Cijk_quad->add_term(i,
j,k,c);
122 Cijk_quad->fillComplete();
125 int nnz =
setup.Cijk->num_entries();
126 int nnz_quad = Cijk_quad->num_entries();
127 success = (nnz == nnz_quad);
130 <<
"Check: nnz(C) = " << nnz <<
" == nnz(C_quad) = " << nnz_quad
133 k_it!=Cijk_quad->k_end(); ++k_it) {
134 int k = Stokhos::index(k_it);
136 j_it != Cijk_quad->j_end(k_it); ++j_it) {
137 int j = Stokhos::index(j_it);
139 i_it != Cijk_quad->i_end(j_it); ++i_it) {
140 int i = Stokhos::index(i_it);
141 double c =
setup.Cijk->getValue(i,j,k);
142 double c2 = Stokhos::value(i_it);
149 <<
"Check: rel_err( C(" << i <<
"," << j <<
"," << k <<
") )"
150 <<
" = " <<
"rel_err( " << c <<
", " << c2 <<
" ) = " << err
151 <<
" <= " << tol <<
" : ";
152 if (s) out <<
"Passed.";
157 success = success && s;
170 c =
setup.Cijk->getValue(0, 0, 0);
174 success = success && s;
176 c =
setup.Cijk->getValue(9, 25, 4);
180 success = success && s;
182 c =
setup.Cijk->getValue(8, 25, 4);
186 success = success && s;
TEUCHOS_UNIT_TEST(Stokhos_Sparse3Tensor, Values)
bool compareValues(const ValueType &a1, const std::string &a1_name, const ValueType &a2, const std::string &a2_name, const ValueType &rel_tol, const ValueType &abs_tol, Teuchos::FancyOStream &out)
Bi-directional iterator for traversing a sparse array.
UnitTestSetup< int, double > setup
A multidimensional index.
static int runUnitTestsFromMain(int argc, char *argv[])
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeTripleProductTensor() const
Compute triple product tensor.
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
Stokhos::Sparse3Tensor< int, double > Cijk_type
Teuchos::RCP< Cijk_type > Cijk
int main(int argc, char **argv)
virtual ordinal_type size() const
Return total size of basis.
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< OrdinalType, ValueType > > basis
Teuchos::RCP< const Stokhos::Quadrature< OrdinalType, ValueType > > quad
Teuchos::Array< Teuchos::RCP< const Stokhos::OneDOrthogPolyBasis< OrdinalType, ValueType > > > bases
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...