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 // $Id$
2 // $Source$
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Stokhos Package
7 // Copyright (2009) Sandia Corporation
8 //
9 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
10 // license for use of this work by or on behalf of the U.S. Government.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
40 //
41 // ***********************************************************************
42 // @HEADER
43 
48 #include "Teuchos_ArrayView.hpp"
49 
50 #include "Stokhos.hpp"
52 
53 namespace TensorProductUnitTest {
54 
55  // Common setup for unit tests
56  template <typename OrdinalType, typename ValueType>
57  struct UnitTestSetup {
58  ValueType rtol, atol;
59  OrdinalType p,d;
60 
62  rtol = 1e-12;
63  atol = 1e-12;
64  d = 3;
65  p = 5;
66  }
67 
68  };
69 
70  typedef int ordinal_type;
71  typedef double value_type;
73 
74  // Function for testing quadratures
76  value_type val = 0.0;
77  for (int i=0; i<x.size(); i++)
78  val += x[i];
79  return std::exp(val);
80  }
81 
82  // Function for testing quadratures
84  value_type val = 0.0;
85  for (int i=0; i<x.size(); i++)
86  val += x[i];
87  return std::sin(val);
88  }
89 
90  TEUCHOS_UNIT_TEST( TensorProduct, IsotropicPoints ) {
91  success = true;
92 
93  // Build tensor product basis of dimension d and order p
95  for (ordinal_type i=0; i<setup.d; i++)
99  *basis);
102  *basis, quad);
103 
105  tp_op, quad_op, setup.rtol, setup.atol, out);
106  }
107 
108  TEUCHOS_UNIT_TEST( TensorProduct, AnisotropicPoints ) {
109  success = true;
110 
111  // Build aniostropic tensor product basis of dimension d
113  for (ordinal_type i=0; i<setup.d; i++)
117  *basis);
120  *basis, quad);
121 
123  tp_op, quad_op, setup.rtol, setup.atol, out);
124  }
125 
126  TEUCHOS_UNIT_TEST( TensorProduct, Apply ) {
127  success = true;
128 
129  // Build anisotropic tensor product basis of dimension d
131  for (ordinal_type i=0; i<setup.d; i++)
135  *basis);
138  *basis, quad);
139 
141  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
142  }
143 
144  TEUCHOS_UNIT_TEST( TensorProduct, Apply_Trans ) {
145  success = true;
146 
147  // Build anisotropic tensor product basis of dimension d
149  for (ordinal_type i=0; i<setup.d; i++)
153  *basis);
156  *basis, quad);
157 
159  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
160  }
161 
162  TEUCHOS_UNIT_TEST( TensorProduct, Apply_PST_Lexo ) {
163  success = true;
164 
165  // Build anisotropic tensor product basis of dimension d
167  for (ordinal_type i=0; i<setup.d; i++)
172  *basis, true);
175  *basis, quad);
176 
178  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
179  }
180 
181  TEUCHOS_UNIT_TEST( TensorProduct, Apply_PST_TotalOrder ) {
182  success = true;
183 
184  // Build anisotropic tensor product basis of dimension d
186  for (ordinal_type i=0; i<setup.d; i++)
190  *basis, true);
193  *basis, quad);
194 
196  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
197  }
198 
199  TEUCHOS_UNIT_TEST( TensorProduct, Apply_PST_Trans_Lexo ) {
200  success = true;
201 
202  // Build anisotropic tensor product basis of dimension d
204  for (ordinal_type i=0; i<setup.d; i++)
209  *basis, true);
212  *basis, quad);
213 
215  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
216  }
217 
218  TEUCHOS_UNIT_TEST( TensorProduct, Apply_PST_Trans_TotalOrder ) {
219  success = true;
220 
221  // Build anisotropic tensor product basis of dimension d
223  for (ordinal_type i=0; i<setup.d; i++)
227  *basis, true);
230  *basis, quad);
231 
233  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
234  }
235 
236  TEUCHOS_UNIT_TEST( TensorProduct, IsotropicDiscreteOrthogonality ) {
237  success = true;
238 
239  // Build tensor product basis of dimension d and order p
241  for (ordinal_type i=0; i<setup.d; i++)
245  *basis, true);
246 
248  *basis, tp_op, setup.rtol, setup.atol, out);
249  }
250 
251  TEUCHOS_UNIT_TEST( TensorProduct, AnisotropicDiscreteOrthogonality ) {
252  success = true;
253 
254  // Build tensor product basis of dimension d and order p
256  for (ordinal_type i=0; i<setup.d; i++)
260  *basis, true);
261 
263  *basis, tp_op, setup.rtol, setup.atol, out);
264  }
265 
266  TEUCHOS_UNIT_TEST( TotalOrder, IsotropicPoints ) {
267  success = true;
268 
269  // Build total order basis of dimension d and order p
271  for (ordinal_type i=0; i<setup.d; i++)
275  *basis);
278  *basis, quad);
279 
281  tp_op, quad_op, setup.rtol, setup.atol, out);
282  }
283 
284  TEUCHOS_UNIT_TEST( TotalOrder, AnisotropicPoints ) {
285  success = true;
286 
287  // Build aniostropic tensor product basis of dimension d
289  for (ordinal_type i=0; i<setup.d; i++)
293  *basis);
296  *basis, quad);
297 
299  tp_op, quad_op, setup.rtol, setup.atol, out);
300  }
301 
302  TEUCHOS_UNIT_TEST( TotalOrder, Apply ) {
303  success = true;
304 
305  // Build anisotropic tensor product basis of dimension d
307  for (ordinal_type i=0; i<setup.d; i++)
311  *basis);
314  *basis, quad);
315 
317  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
318  }
319 
320  TEUCHOS_UNIT_TEST( TotalOrder, ApplyTrans ) {
321  success = true;
322 
323  // Build anisotropic tensor product basis of dimension d
325  for (ordinal_type i=0; i<setup.d; i++)
329  *basis);
332  *basis, quad);
333 
335  tp_op, quad_op, quad_func1, quad_func2, setup.rtol, setup.atol, out);
336  }
337 
338  TEUCHOS_UNIT_TEST( TotalOrder, IsotropicDiscreteOrthogonality ) {
339  success = true;
340 
341  // Build tensor product basis of dimension d and order p
343  for (ordinal_type i=0; i<setup.d; i++)
347  *basis);
348 
350  *basis, tp_op, setup.rtol, setup.atol, out);
351  }
352 
353  TEUCHOS_UNIT_TEST( TotalOrder, AnisotropicDiscreteOrthogonality ) {
354  success = true;
355 
356  // Build tensor product basis of dimension d and order p
358  for (ordinal_type i=0; i<setup.d; i++)
362  *basis);
363 
365  *basis, tp_op, setup.rtol, setup.atol, out);
366  }
367 
368 }
369 
370 int main( int argc, char* argv[] ) {
371  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
374  return res;
375 }
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)