Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Stokhos_UnitTestHelpers.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 #ifndef STOKHOS_UNIT_TEST_HELPERS_HPP
43 #define STOKHOS_UNIT_TEST_HELPERS_HPP
44 
46 #include "Stokhos_ProductBasis.hpp"
48 #include "Teuchos_SerialDenseMatrix.hpp"
49 #include "Teuchos_FancyOStream.hpp"
50 
51 namespace Stokhos {
52 
53  template<class OrdinalType, class ValueType>
55  const std::string& a1_name,
57  const std::string& a2_name,
58  const ValueType& rel_tol, const ValueType& abs_tol,
59  Teuchos::FancyOStream& out)
60  {
61  bool success = true;
62 
63  out << "Comparing " << a1_name << " == " << a2_name << " ... ";
64 
65  const OrdinalType n = a1.size();
66 
67  // Compare sizes
68  if (a2.size() != n) {
69  out << "\nError, "<<a1_name<<".size() = "<<a1.size()<<" == "
70  << a2_name<<".size() = "<<a2.size()<<" : failed!\n";
71  return false;
72  }
73 
74  // Compare elements
75  for( OrdinalType i = 0; i < n; ++i ) {
76  ValueType nrm = std::sqrt(a1.basis()->norm_squared(i));
77  ValueType err = std::abs(a1[i] - a2[i]) / nrm;
78  ValueType tol =
79  abs_tol + rel_tol*std::max(std::abs(a1[i]),std::abs(a2[i]))/nrm;
80  if (err > tol) {
81  out
82  <<"\nError, relErr("<<a1_name<<"["<<i<<"],"
83  <<a2_name<<"["<<i<<"]) = relErr("<<a1[i]<<","<<a2[i]<<") = "
84  <<err<<" <= tol = "<<tol<<": failed!\n";
85  success = false;
86  }
87  }
88  if (success) {
89  out << "passed\n";
90  }
91  else {
92  out << std::endl
93  << a1_name << " = " << a1 << std::endl
94  << a2_name << " = " << a2 << std::endl;
95  }
96 
97  return success;
98  }
99 
100  template<class ValueType>
101  bool compareValues(const ValueType& a1,
102  const std::string& a1_name,
103  const ValueType&a2,
104  const std::string& a2_name,
105  const ValueType& rel_tol, const ValueType& abs_tol,
106  Teuchos::FancyOStream& out)
107  {
108  bool success = true;
109 
110  ValueType err = std::abs(a1 - a2);
111  ValueType tol = abs_tol + rel_tol*std::max(std::abs(a1),std::abs(a2));
112  if (err > tol) {
113  out << "\nError, relErr(" << a1_name <<","
114  << a2_name << ") = relErr(" << a1 <<"," << a2 <<") = "
115  << err << " <= tol = " << tol << ": failed!\n";
116  success = false;
117  }
118 
119  return success;
120  }
121 
122  template<class ValueType, class VectorType1, class VectorType2>
123  bool compareVecs(const VectorType1& a1,
124  const std::string& a1_name,
125  const VectorType2&a2,
126  const std::string& a2_name,
127  const ValueType& rel_tol, const ValueType& abs_tol,
128  Teuchos::FancyOStream& out)
129  {
130  using value_t_1 = typename VectorType1::value_type;
131  using value_t_2 = typename VectorType2::value_type;
132  static_assert(std::is_same<value_t_1,value_t_2>::value,"Inconsistent types.");
133 
134  bool success = true;
135 
136  out << "Comparing " << a1_name << " == " << a2_name << " ... ";
137 
138  const int n = a1.size();
139 
140  // Compare sizes
141  if (a2.size() != n) {
142  out << "\nError, "<<a1_name<<".size() = "<<a1.size()<<" == "
143  << a2_name<<".size() = "<<a2.size()<<" : failed!\n";
144  return false;
145  }
146 
147  // Compare elements
148  for( int i = 0; i < n; ++i ) {
149  ValueType err = abs(a1.coeff(i) - a2.coeff(i));
150  ValueType tol =
151  abs_tol + rel_tol*std::max(abs(a1.fastAccessCoeff(i)),
152  abs(a2.fastAccessCoeff(i)));
153  if (err > tol) {
154  out
155  <<"\nError, relErr("<<a1_name<<"["<<i<<"],"
156  <<a2_name<<"["<<i<<"]) = relErr("<<a1.coeff(i)<<","<<a2.coeff(i)
157  <<") = "<<err<<" <= tol = "<<tol<<": failed!\n";
158  success = false;
159  }
160  }
161  if (success) {
162  out << "passed\n";
163  }
164  else {
165  out << std::endl
166  << a1_name << " = " << a1 << std::endl
167  << a2_name << " = " << a2 << std::endl;
168  }
169 
170  return success;
171  }
172 
173  template<class Array1, class Array2, class ValueType>
174  bool compareArrays(const Array1& a1, const std::string& a1_name,
175  const Array2& a2, const std::string& a2_name,
176  const ValueType& rel_tol,
177  const ValueType& abs_tol,
178  Teuchos::FancyOStream& out)
179  {
180  using Teuchos::as;
181  bool success = true;
182 
183  out << "Comparing " << a1_name << " == " << a2_name << " ... ";
184 
185  const int n = a1.size();
186 
187  // Compare sizes
188  if (as<int>(a2.size()) != n) {
189  out << "\nError, "<<a1_name<<".size() = "<<a1.size()<<" == "
190  << a2_name<<".size() = "<<a2.size()<<" : failed!\n";
191  return false;
192  }
193 
194  // Compare elements
195  for( int i = 0; i < n; ++i ) {
196  ValueType err = std::abs(a1[i] - a2[i]);
197  ValueType tol =
198  abs_tol + rel_tol*std::max(std::abs(a1[i]),std::abs(a2[i]));
199  if (err > tol) {
200  out << "\nError, relErr(" << a1_name << "[" << i << "]," << a2_name
201  << "[" << i << "]) = relErr(" << a1[i] << "," <<a2[i] <<") = "
202  << err << " <= tol = " << tol << ": failed!\n";
203  success = false;
204  }
205  }
206  if (success) {
207  out << "passed\n";
208  }
209 
210  return success;
211  }
212 
213  template<class ordinal_type, class scalar_type>
215  const Teuchos::SerialDenseMatrix<ordinal_type,scalar_type>& a1,
216  const std::string& a1_name,
217  const Teuchos::SerialDenseMatrix<ordinal_type,scalar_type>& a2,
218  const std::string& a2_name,
219  const scalar_type& rel_tol,
220  const scalar_type& abs_tol,
221  Teuchos::FancyOStream& out)
222  {
223  using Teuchos::as;
224  bool success = true;
225 
226  out << "Comparing " << a1_name << " == " << a2_name << " ... ";
227 
228  const ordinal_type m = a1.numRows();
229  const ordinal_type n = a1.numCols();
230 
231  // Compare number of rows
232  if (a2.numRows() != m) {
233  out << "\nError, "<<a1_name<<".numRows() = "<<a1.numRows()<<" == "
234  << a2_name<<".numRows() = "<<a2.numRows()<<" : failed!\n";
235  return false;
236  }
237 
238  // Compare number of columnns
239  if (a2.numCols() != n) {
240  out << "\nError, "<<a1_name<<".numCols() = "<<a1.numCols()<<" == "
241  << a2_name<<".numCols() = "<<a2.numCols()<<" : failed!\n";
242  return false;
243  }
244 
245  // Compare elements
246  for (ordinal_type i=0; i<m; i++) {
247  for (ordinal_type j=0; j<n; j++) {
248  scalar_type err = std::abs(a1(i,j) - a2(i,j));
249  scalar_type tol =
250  abs_tol + rel_tol*std::max(std::abs(a1(i,j)),std::abs(a2(i,j)));
251  if (err > tol) {
252  out << "\nError, relErr(" << a1_name << "(" << i << "," << j << "), "
253  << a2_name << "(" << i << "," << j << ")) = relErr("
254  << a1(i,j) << ", " <<a2(i,j) <<") = "
255  << err << " <= tol = " << tol << ": failed!\n";
256  success = false;
257  }
258  }
259  }
260  if (success) {
261  out << "passed\n";
262  }
263 
264  return success;
265  }
266 
267  template<class ordinal_type, class scalar_type>
270  const std::string& cijk1_name,
272  const std::string& cijk2_name,
273  const scalar_type& rel_tol,
274  const scalar_type& abs_tol,
275  Teuchos::FancyOStream& out)
276  {
278  bool success = true;
279 
280  out << "Comparing " << cijk1_name << " == " << cijk2_name << " ... ";
281 
282  // Check number of nonzeros
283  TEUCHOS_TEST_EQUALITY(Cijk1.num_entries(), Cijk2.num_entries(), out,
284  success);
285 
286  // Check entries
287  for (typename Cijk_type::k_iterator k_it=Cijk2.k_begin();
288  k_it!=Cijk2.k_end(); ++k_it) {
289  ordinal_type k = Stokhos::index(k_it);
290  for (typename Cijk_type::kj_iterator j_it = Cijk2.j_begin(k_it);
291  j_it != Cijk2.j_end(k_it); ++j_it) {
292  ordinal_type j = Stokhos::index(j_it);
293  for (typename Cijk_type::kji_iterator i_it = Cijk2.i_begin(j_it);
294  i_it != Cijk2.i_end(j_it); ++i_it) {
295  ordinal_type i = Stokhos::index(i_it);
296  scalar_type c1 = Cijk1.getValue(i,j,k);
297  scalar_type c2 = Stokhos::value(i_it);
298 
299  double tol = abs_tol + c2*rel_tol;
300  double err = std::abs(c1-c2);
301  bool s = err < tol;
302  if (!s) {
303  out << std::endl
304  << "Check: rel_err( C(" << i << "," << j << "," << k << ") )"
305  << " = " << "rel_err( " << c1 << ", " << c2 << " ) = " << err
306  << " <= " << tol << " : ";
307  if (s) out << "Passed.";
308  else
309  out << "Failed!";
310  out << std::endl;
311  }
312  success = success && s;
313  }
314  }
315  }
316 
317  return success;
318  }
319 
320  template<class ordinal_type, class scalar_type>
324  const scalar_type& sparse_tol,
325  const scalar_type& rel_tol,
326  const scalar_type& abs_tol,
327  Teuchos::FancyOStream& out,
328  bool linear = false)
329  {
330  ordinal_type d = basis.dimension();
331  ordinal_type sz = basis.size();
332  Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<ordinal_type,scalar_type> > > bases = basis.getCoordinateBases();
334  Teuchos::Array< Teuchos::RCP<Stokhos::Dense3Tensor<ordinal_type,scalar_type> > > Cijk_1d(d);
335  for (ordinal_type i=0; i<d; i++)
336  Cijk_1d[i] = bases[i]->computeTripleProductTensor();
337  for (ordinal_type j=0; j<sz; j++) {
338  Stokhos::MultiIndex<ordinal_type> terms_j = basis.term(j);
339  for (ordinal_type i=0; i<sz; i++) {
340  Stokhos::MultiIndex<ordinal_type> terms_i = basis.term(i);
341  for (ordinal_type k=0; k<sz; k++) {
342  Stokhos::MultiIndex<ordinal_type> terms_k = basis.term(k);
343  if (!linear || terms_k.order() <= 1) {
344  scalar_type c = 1.0;
345  for (ordinal_type l=0; l<d; l++)
346  c *= (*Cijk_1d[l])(terms_i[l],terms_j[l],terms_k[l]);
347  if (std::abs(c/basis.norm_squared(i)) > sparse_tol)
348  Cijk2.add_term(i,j,k,c);
349  }
350  }
351  }
352  }
353  Cijk2.fillComplete();
354 
355  // std::cout << std::endl << Cijk << std::endl;
356  // std::cout << std::endl << Cijk2 << std::endl;
357 
358  bool success = compareSparse3Tensor(Cijk, "Cijk", Cijk2, "Cijk2",
359  rel_tol, abs_tol, out);
360 
361  return success;
362  }
363 
364  template <typename operator_type1, typename operator_type2,
365  typename scalar_type>
366  bool testPseudoSpectralPoints(const operator_type1& op1,
367  const operator_type2& op2,
368  const scalar_type& rel_tol,
369  const scalar_type& abs_tol,
370  Teuchos::FancyOStream& out) {
371  bool success = true;
372 
373  typedef typename operator_type1::const_set_iterator point_iterator_type;
374 
375  // Check sizes
376  TEUCHOS_TEST_EQUALITY(op1.point_size(), op2.point_size(), out, success);
377  if (!success) return false;
378 
379  // Compare points
380  point_iterator_type pi1 = op1.set_begin();
381  point_iterator_type pi2 = op2.set_begin();
382  while (pi1 != op1.set_end() || pi2 != op2.set_end()) {
383  std::stringstream ss1, ss2;
384  ss1 << pi1->first;
385  ss2 << pi2->first;
386  success = success &&
387  Stokhos::compareArrays(pi1->first, ss1.str(),
388  pi2->first, ss2.str(),
389  rel_tol, abs_tol, out);
390 
391  std::stringstream ss3, ss4;
392  ss3 << pi1->second.first;
393  ss4 << pi2->second.first;
394  success = success &&
395  Stokhos::compareValues(pi1->second.first, ss3.str(),
396  pi2->second.first, ss4.str(),
397  rel_tol, abs_tol, out);
398  ++pi1;
399  ++pi2;
400  }
401 
402  return success;
403  }
404 
405  template <typename operator_type1, typename operator_type2,
406  typename func_type1, typename func_type2,
407  typename scalar_type>
408  bool testPseudoSpectralApply(const operator_type1& op1,
409  const operator_type2& op2,
410  const func_type1& func1,
411  const func_type2& func2,
412  const scalar_type& rel_tol,
413  const scalar_type& abs_tol,
414  Teuchos::FancyOStream& out) {
415  bool success = true;
416 
418  typedef typename operator_type1::value_type value_type;
419  typedef typename operator_type1::const_iterator point_iterator_type;
420 
421  // Check sizes
422  TEUCHOS_TEST_EQUALITY(op1.coeff_size(), op2.coeff_size(), out, success);
423  if (!success)
424  return false;
425 
426  ordinal_type point_sz1 = op1.point_size();
427  ordinal_type point_sz2 = op2.point_size();
428  ordinal_type coeff_sz = op1.coeff_size();
429 
430  // Evaluate function at quadrature points
431  Teuchos::SerialDenseMatrix<ordinal_type,value_type> f(point_sz1,2);
432  ordinal_type idx = 0;
433  for (point_iterator_type pi = op1.begin(); pi != op1.end(); ++pi) {
434  f(idx,0) = func1(*pi);
435  f(idx,1) = func2(*pi);
436  ++idx;
437  }
438 
439  Teuchos::SerialDenseMatrix<ordinal_type,value_type> f2(point_sz2,2);
440  idx = 0;
441  for (point_iterator_type pi = op2.begin(); pi != op2.end(); ++pi) {
442  f2(idx,0) = func1(*pi);
443  f2(idx,1) = func2(*pi);
444  ++idx;
445  }
446 
447  // Compare function evaluations
448  if (point_sz1 == point_sz2)
449  success = success &&
450  Stokhos::compareSDM(f, "f", f2, "f2", rel_tol, abs_tol, out);
451 
452  // Compute PCE coefficients
453  Teuchos::SerialDenseMatrix<ordinal_type,value_type> x(coeff_sz,2);
454  op1.transformQP2PCE(1.0, f, x, 0.0);
455 
456  Teuchos::SerialDenseMatrix<ordinal_type,value_type> x2(coeff_sz,2);
457  op2.transformQP2PCE(1.0, f2, x2, 0.0);
458 
459  // Compare PCE coefficients
460  success = success &&
461  Stokhos::compareSDM(x, "x", x2, "x2", rel_tol, abs_tol, out);
462 
463  return success;
464  }
465 
466  template <typename operator_type1, typename operator_type2,
467  typename func_type1, typename func_type2,
468  typename scalar_type>
469  bool testPseudoSpectralApplyTrans(const operator_type1& op1,
470  const operator_type2& op2,
471  const func_type1& func1,
472  const func_type2& func2,
473  const scalar_type& rel_tol,
474  const scalar_type& abs_tol,
475  Teuchos::FancyOStream& out) {
476  bool success = true;
477 
479  typedef typename operator_type1::value_type value_type;
480  typedef typename operator_type1::const_iterator point_iterator_type;
481 
482  // Check sizes
483  TEUCHOS_TEST_EQUALITY(op1.coeff_size(), op2.coeff_size(), out, success);
484  if (!success)
485  return false;
486 
487  ordinal_type point_sz1 = op1.point_size();
488  ordinal_type point_sz2 = op2.point_size();
489  ordinal_type coeff_sz = op1.coeff_size();
490 
491  // Evaluate function at quadrature points
492  Teuchos::SerialDenseMatrix<ordinal_type,value_type> f(2,point_sz1);
493  ordinal_type idx = 0;
494  for (point_iterator_type pi = op1.begin(); pi != op1.end(); ++pi) {
495  f(0,idx) = func1(*pi);
496  f(1,idx) = func2(*pi);
497  ++idx;
498  }
499 
500  Teuchos::SerialDenseMatrix<ordinal_type,value_type> f2(2,point_sz2);
501  idx = 0;
502  for (point_iterator_type pi = op2.begin(); pi != op2.end(); ++pi) {
503  f2(0,idx) = func1(*pi);
504  f2(1,idx) = func2(*pi);
505  ++idx;
506  }
507 
508  // Compare function evaluations
509  if (point_sz1 == point_sz2)
510  success = success &&
511  Stokhos::compareSDM(f, "f", f2, "f2", rel_tol, abs_tol, out);
512 
513  // Compute PCE coefficients
514  Teuchos::SerialDenseMatrix<ordinal_type,value_type> x(2,coeff_sz);
515  op1.transformQP2PCE(1.0, f, x, 0.0, true);
516 
517  Teuchos::SerialDenseMatrix<ordinal_type,value_type> x2(2,coeff_sz);
518  op2.transformQP2PCE(1.0, f2, x2, 0.0, true);
519 
520  // Compare PCE coefficients
521  success = success &&
522  Stokhos::compareSDM(x, "x", x2, "x2", rel_tol, abs_tol, out);
523 
524  return success;
525  }
526 
527  template <typename basis_type, typename operator_type, typename scalar_type>
529  const operator_type& op,
530  const scalar_type& rel_tol,
531  const scalar_type& abs_tol,
532  Teuchos::FancyOStream& out) {
533  typedef typename operator_type::ordinal_type ordinal_type;
534  typedef typename operator_type::value_type value_type;
535 
536  ordinal_type coeff_sz = op.coeff_size();
537  ordinal_type point_sz = op.point_size();
538  Teuchos::SerialDenseMatrix<ordinal_type,value_type> eye(coeff_sz,coeff_sz);
539  eye.putScalar(0.0);
540  for (ordinal_type i=0; i<coeff_sz; ++i)
541  eye(i,i) = 1.0;
542 
543  // Map PCE coefficients to quad values
544  Teuchos::SerialDenseMatrix<ordinal_type,value_type> f(point_sz,coeff_sz);
545  op.transformPCE2QP(1.0, eye, f, 0.0);
546 
547  // Map quad values to PCE coefficients
548  Teuchos::SerialDenseMatrix<ordinal_type,value_type> x(coeff_sz,coeff_sz);
549  op.transformQP2PCE(1.0, f, x, 0.0);
550 
551  // Subtract identity
552  for (ordinal_type i=0; i<coeff_sz; ++i)
553  x(i,i) -= 1.0;
554 
555  // Expected answer, which is zero
556  Teuchos::SerialDenseMatrix<ordinal_type,value_type> z(coeff_sz,coeff_sz);
557  z.putScalar(0.0);
558 
559  out << "Discrete orthogonality error = " << x.normInf() << std::endl;
560 
561  // Compare PCE coefficients
562  bool success = Stokhos::compareSDM(x, "x", z, "zero", rel_tol, abs_tol, out);
563 
564  return success;
565  }
566 
567  /*
568  template <typename basis_type, typename operator_type, typename scalar_type>
569  bool testPseudoSpectralDiscreteOrthogonality(const basis_type& basis,
570  const operator_type& op,
571  const scalar_type& rel_tol,
572  const scalar_type& abs_tol,
573  Teuchos::FancyOStream& out) {
574  typedef typename operator_type::ordinal_type ordinal_type;
575  typedef typename operator_type::value_type value_type;
576 
577  // Evaluate full basis at all quadrature points
578  ordinal_type coeff_sz = op.coeff_size();
579  ordinal_type point_sz = op.point_size();
580  Teuchos::SerialDenseMatrix<ordinal_type,value_type> f(point_sz,coeff_sz);
581  Teuchos::Array<value_type> vals(coeff_sz);
582  ordinal_type i = 0;
583  typename operator_type::const_iterator pi = op.begin();
584  for (; pi != op.end(); ++pi) {
585  basis.evaluateBases(*pi, vals);
586  for (ordinal_type j=0; j<coeff_sz; ++j)
587  f(i,j) = vals[j];
588 
589  ++i;
590  }
591 
592  // Compute PCE coefficients
593  Teuchos::SerialDenseMatrix<ordinal_type,value_type> x(coeff_sz,coeff_sz);
594  op.transformQP2PCE(1.0, f, x, 0.0);
595 
596  // Subtract identity
597  for (ordinal_type i=0; i<coeff_sz; ++i)
598  x(i,i) -= 1.0;
599 
600  // Expected answer, which is zero
601  Teuchos::SerialDenseMatrix<ordinal_type,value_type> z(coeff_sz,coeff_sz);
602  z.putScalar(0.0);
603 
604  out << "Discrete orthogonality error = " << x.normInf() << std::endl;
605 
606  // Compare PCE coefficients
607  bool success = Stokhos::compareSDM(x, "x", z, "zero", 1e-14, 1e-14, out);
608 
609  return success;
610  }
611  */
612 }
613 
614 #endif // STOKHOS_UNIT_TEST_HELPERS_HPP
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
kji_iterator i_end(const kj_iterator &j) const
Iterator pointing to last i entry for given j and k.
bool compareVecs(const VectorType1 &a1, const std::string &a1_name, const VectorType2 &a2, const std::string &a2_name, const ValueType &rel_tol, const ValueType &abs_tol, Teuchos::FancyOStream &out)
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
bool compareArrays(const Array1 &a1, const std::string &a1_name, const Array2 &a2, const std::string &a2_name, const ValueType &rel_tol, const ValueType &abs_tol, Teuchos::FancyOStream &out)
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)
void fillComplete()
Signal all terms have been added.
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)
virtual ordinal_type dimension() const =0
Return dimension of basis.
ordinal_type order() const
Compute total order of index.
ordinal_type size() const
Return size.
bool compareSparse3Tensor(const Stokhos::Sparse3Tensor< ordinal_type, scalar_type > &Cijk1, const std::string &cijk1_name, const Stokhos::Sparse3Tensor< ordinal_type, scalar_type > &Cijk2, const std::string &cijk2_name, const scalar_type &rel_tol, const scalar_type &abs_tol, Teuchos::FancyOStream &out)
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)
virtual const MultiIndex< ordinal_type > & term(ordinal_type i) const =0
Get orders of each coordinate polynomial given an index i.
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:260
bool compareSDM(const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &a1, const std::string &a1_name, const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &a2, const std::string &a2_name, const scalar_type &rel_tol, const scalar_type &abs_tol, Teuchos::FancyOStream &out)
void add_term(ordinal_type i, ordinal_type j, ordinal_type k, const value_type &c)
Add new term for given (i,j,k)
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
Top-level namespace for Stokhos classes and functions.
value_type getValue(ordinal_type i, ordinal_type j, ordinal_type k) const
Get Cijk value for a given i, j, k indices.
ordinal_type num_entries() const
Return number of non-zero entries.
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
Abstract base class for multivariate orthogonal polynomials generated from tensor products of univari...
virtual const Teuchos::Array< value_type > & norm_squared() const =0
Return array storing norm-squared of each basis polynomial.
virtual Teuchos::Array< Teuchos::RCP< const OneDOrthogPolyBasis< ordinal_type, value_type > > > getCoordinateBases() const =0
Return array of coordinate bases.
Legendre polynomial basis.
Stokhos::Sparse3Tensor< int, double > Cijk_type
bool testPseudoSpectralDiscreteOrthogonality(const basis_type &basis, const operator_type &op, const scalar_type &rel_tol, const scalar_type &abs_tol, Teuchos::FancyOStream &out)
ScalarType f(const Teuchos::Array< ScalarType > &x, double a, double b)
k_iterator k_end() const
Iterator pointing to last k entry.
kj_iterator j_begin(const k_iterator &k) const
Iterator pointing to first j entry for given k.
kj_iterator j_end(const k_iterator &k) const
Iterator pointing to last j entry for given k.
bool testPseudoSpectralPoints(const operator_type1 &op1, const operator_type2 &op2, const scalar_type &rel_tol, const scalar_type &abs_tol, Teuchos::FancyOStream &out)
bool testPseudoSpectralApply(const operator_type1 &op1, const operator_type2 &op2, const func_type1 &func1, const func_type2 &func2, const scalar_type &rel_tol, const scalar_type &abs_tol, Teuchos::FancyOStream &out)
Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > basis() const
Return basis.
kji_iterator i_begin(const kj_iterator &j) const
Iterator pointing to first i entry for given j and k.
virtual ordinal_type size() const =0
Return total size of basis.
bool testPseudoSpectralApplyTrans(const operator_type1 &op1, const operator_type2 &op2, const func_type1 &func1, const func_type2 &func2, const scalar_type &rel_tol, const scalar_type &abs_tol, Teuchos::FancyOStream &out)
k_iterator k_begin() const
Iterator pointing to first k entry.