Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_TensorProductPseudoSpectralOperatorUnitTest.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 #include "Teuchos_ArrayView.hpp"
15 
16 #include "Stokhos.hpp"
18 
19 namespace TensorProductUnitTest {
20 
21  // Common setup for unit tests
22  template <typename OrdinalType, typename ValueType>
23  struct UnitTestSetup {
24  ValueType rtol, atol;
25  OrdinalType p,d;
26 
28  rtol = 1e-12;
29  atol = 1e-12;
30  d = 3;
31  p = 5;
32  }
33 
34  };
35 
36  typedef int ordinal_type;
37  typedef double value_type;
39 
40  // Function for testing quadratures
42  value_type val = 0.0;
43  for (int i=0; i<x.size(); i++)
44  val += x[i];
45  return std::exp(val);
46  }
47 
48  // Function for testing quadratures
50  value_type val = 0.0;
51  for (int i=0; i<x.size(); i++)
52  val += x[i];
53  return std::sin(val);
54  }
55 
56  TEUCHOS_UNIT_TEST( TensorProduct, IsotropicPoints ) {
57  success = true;
58 
59  // Build tensor product basis of dimension d and order p
61  for (ordinal_type i=0; i<setup.d; i++)
65  *basis);
68  *basis, quad);
69 
71  tp_op, quad_op, setup.rtol, setup.atol, out);
72  }
73 
74  TEUCHOS_UNIT_TEST( TensorProduct, AnisotropicPoints ) {
75  success = true;
76 
77  // Build aniostropic tensor product basis of dimension d
79  for (ordinal_type i=0; i<setup.d; i++)
83  *basis);
86  *basis, quad);
87 
89  tp_op, quad_op, setup.rtol, setup.atol, out);
90  }
91 
92  TEUCHOS_UNIT_TEST( TensorProduct, Apply ) {
93  success = true;
94 
95  // Build anisotropic tensor product basis of dimension d
97  for (ordinal_type i=0; i<setup.d; i++)
101  *basis);
104  *basis, quad);
105 
107  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
108  }
109 
110  TEUCHOS_UNIT_TEST( TensorProduct, Apply_Trans ) {
111  success = true;
112 
113  // Build anisotropic tensor product basis of dimension d
115  for (ordinal_type i=0; i<setup.d; i++)
119  *basis);
122  *basis, quad);
123 
125  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
126  }
127 
128  TEUCHOS_UNIT_TEST( TensorProduct, Apply_PST_Lexo ) {
129  success = true;
130 
131  // Build anisotropic tensor product basis of dimension d
133  for (ordinal_type i=0; i<setup.d; i++)
138  *basis, true);
141  *basis, quad);
142 
144  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
145  }
146 
147  TEUCHOS_UNIT_TEST( TensorProduct, Apply_PST_TotalOrder ) {
148  success = true;
149 
150  // Build anisotropic tensor product basis of dimension d
152  for (ordinal_type i=0; i<setup.d; i++)
156  *basis, true);
159  *basis, quad);
160 
162  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
163  }
164 
165  TEUCHOS_UNIT_TEST( TensorProduct, Apply_PST_Trans_Lexo ) {
166  success = true;
167 
168  // Build anisotropic tensor product basis of dimension d
170  for (ordinal_type i=0; i<setup.d; i++)
175  *basis, true);
178  *basis, quad);
179 
181  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
182  }
183 
184  TEUCHOS_UNIT_TEST( TensorProduct, Apply_PST_Trans_TotalOrder ) {
185  success = true;
186 
187  // Build anisotropic tensor product basis of dimension d
189  for (ordinal_type i=0; i<setup.d; i++)
193  *basis, true);
196  *basis, quad);
197 
199  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
200  }
201 
202  TEUCHOS_UNIT_TEST( TensorProduct, IsotropicDiscreteOrthogonality ) {
203  success = true;
204 
205  // Build tensor product basis of dimension d and order p
207  for (ordinal_type i=0; i<setup.d; i++)
211  *basis, true);
212 
214  *basis, tp_op, setup.rtol, setup.atol, out);
215  }
216 
217  TEUCHOS_UNIT_TEST( TensorProduct, AnisotropicDiscreteOrthogonality ) {
218  success = true;
219 
220  // Build tensor product basis of dimension d and order p
222  for (ordinal_type i=0; i<setup.d; i++)
226  *basis, true);
227 
229  *basis, tp_op, setup.rtol, setup.atol, out);
230  }
231 
232  TEUCHOS_UNIT_TEST( TotalOrder, IsotropicPoints ) {
233  success = true;
234 
235  // Build total order basis of dimension d and order p
237  for (ordinal_type i=0; i<setup.d; i++)
241  *basis);
244  *basis, quad);
245 
247  tp_op, quad_op, setup.rtol, setup.atol, out);
248  }
249 
250  TEUCHOS_UNIT_TEST( TotalOrder, AnisotropicPoints ) {
251  success = true;
252 
253  // Build aniostropic tensor product basis of dimension d
255  for (ordinal_type i=0; i<setup.d; i++)
259  *basis);
262  *basis, quad);
263 
265  tp_op, quad_op, setup.rtol, setup.atol, out);
266  }
267 
268  TEUCHOS_UNIT_TEST( TotalOrder, Apply ) {
269  success = true;
270 
271  // Build anisotropic tensor product basis of dimension d
273  for (ordinal_type i=0; i<setup.d; i++)
277  *basis);
280  *basis, quad);
281 
283  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
284  }
285 
286  TEUCHOS_UNIT_TEST( TotalOrder, ApplyTrans ) {
287  success = true;
288 
289  // Build anisotropic tensor product basis of dimension d
291  for (ordinal_type i=0; i<setup.d; i++)
295  *basis);
298  *basis, quad);
299 
301  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
302  }
303 
304  TEUCHOS_UNIT_TEST( TotalOrder, IsotropicDiscreteOrthogonality ) {
305  success = true;
306 
307  // Build tensor product basis of dimension d and order p
309  for (ordinal_type i=0; i<setup.d; i++)
313  *basis);
314 
316  *basis, tp_op, setup.rtol, setup.atol, out);
317  }
318 
319  TEUCHOS_UNIT_TEST( TotalOrder, AnisotropicDiscreteOrthogonality ) {
320  success = true;
321 
322  // Build tensor product basis of dimension d and order p
324  for (ordinal_type i=0; i<setup.d; i++)
328  *basis);
329 
331  *basis, tp_op, setup.rtol, setup.atol, out);
332  }
333 
334 }
335 
336 int main( int argc, char* argv[] ) {
337  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
340  return res;
341 }
Multivariate orthogonal polynomial basis generated from a total order tensor product of univariate po...
size_type size() const
value_type quad_func2(const Teuchos::ArrayView< const value_type > &x)
static int runUnitTestsFromMain(int argc, char *argv[])
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="", const bool ignoreZeroTimers=false)
value_type quad_func1(const Teuchos::ArrayView< const value_type > &x)
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(const PCE< Storage > &a)
Multivariate orthogonal polynomial basis generated from a tensor product of univariate polynomials...
Legendre polynomial basis.
int main(int argc, char **argv)
expr val()
bool testPseudoSpectralDiscreteOrthogonality(const basis_type &basis, const operator_type &op, const scalar_type &rel_tol, const scalar_type &abs_tol, Teuchos::FancyOStream &out)
UnitTestSetup< ordinal_type, value_type > setup
A comparison functor implementing a strict weak ordering based lexographic ordering.
KOKKOS_INLINE_FUNCTION PCE< Storage > sin(const PCE< Storage > &a)
An operator for building pseudo-spectral coefficients using tensor-product quadrature.
An operator for building pseudo-spectral coefficients using an arbitrary quadrature rule...
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)
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...
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)